parser

package
v0.0.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 19, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrSQLStringEmpty = errors.New("SQL string is empty")
	ErrParserNotReady = errors.New("Parser is not ready. Call New() to create a new parser")
)

Functions

This section is empty.

Types

type Config added in v0.0.4

type Config struct{}

Config defines the configuration for the parser

type ParsedFields

type ParsedFields struct {
	// FromFields is a map of all references to table names and their fields from the FROM clause (includes JOINs)
	FromFields map[string][]string

	// WhereFields is a map of all references to table names and their fields from the WHERE clause
	WhereFields map[string][]string

	// GroupByFields is a map of all references to table names and their fields from the GROUP BY clause
	GroupByFields map[string][]string

	// TableFields is a map of all references to table names and their fields
	TableFields map[string][]string

	// AliasMap is a map of table aliases to table names
	AliasMap map[string]string

	// DefaultTableName is the default table name fields are mapped to use when no table name is specified. We're using the first aliased table definition to set this
	DefaultTableName string
	// contains filtered or unexported fields
}

func (*ParsedFields) AddTable

func (f *ParsedFields) AddTable(tableName, as string)

AddTable adds a table to the list of tables, with an optional alias

func (*ParsedFields) AddTableField

func (f *ParsedFields) AddTableField(area parsedFieldsArea, tableName, fieldName string)

AddTableField adds a field to the list of fields for a table in a specific area

func (*ParsedFields) Equal

func (f *ParsedFields) Equal(other *ParsedFields) bool

Equal compares this ParsedFields to another and returns true if they are equal. Order of fields is not considered

func (*ParsedFields) MapDefaultTableName

func (f *ParsedFields) MapDefaultTableName(fieldMap map[string][]string)

MapDefaultTableName maps empty table names to the default table name

func (*ParsedFields) MergeAliasTables

func (f *ParsedFields) MergeAliasTables()

MergeAliasTables merges the table names where an alias is used

func (*ParsedFields) PurgeEmptyTables

func (f *ParsedFields) PurgeEmptyTables()

PurgeEmptyTables removes any tables that have no fields

type Parser added in v0.0.4

type Parser struct {
	// contains filtered or unexported fields
}

Parser is our SQL parser and configuration

func New added in v0.0.4

func New(cfg Config) (*Parser, error)

New creates a new parser

func (*Parser) ParseSQL added in v0.0.4

func (p *Parser) ParseSQL(sql string) (*ParsedFields, error)

ParseSQL parses the SQL string and returns a ParsedFields struct

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL