Documentation
¶
Overview ¶
Package dialects implements SQL dialect parsers.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var SQLLexer = lexer.MustStateful(lexer.Rules{ "Root": { {"Whitespace", `[ \t\r\n]+`, nil}, {"Comment", `--[^\n]*`, nil}, {"BlockComment", `/\*[\s\S]*?\*/`, nil}, {"String", `'[^']*'`, nil}, {"Ident", `[a-zA-Z_][a-zA-Z0-9_]*`, nil}, {"Number", `[0-9]+(?:\.[0-9]+)?`, nil}, {"Symbol", `[\(\)\[\]\{\},;:.]`, nil}, {"Operator", `[\+\-\*/=<>!]+`, nil}, }, })
SQLLexer defines the SQL lexer configuration
Functions ¶
This section is empty.
Types ¶
type BaseParser ¶
type BaseParser struct {
// contains filtered or unexported fields
}
BaseParser provides common functionality for dialect parsers.
func NewBaseParser ¶
func NewBaseParser(dialect grammars.Dialect) *BaseParser
NewBaseParser creates a new BaseParser for the given dialect.
func (*BaseParser) Dialect ¶
func (b *BaseParser) Dialect() grammars.Dialect
Dialect returns the dialect of the parser.
type Column ¶
type Column struct {
Name string `@Ident`
Type string `@Ident`
Constraint string `(@("PRIMARY" "KEY") | "NOT" "NULL" | "UNIQUE")?`
}
Column represents a table column
type Constraint ¶
type Constraint struct {
Type string `(@Ident ("KEY" | @Ident?) | "NOT" "NULL" | "UNIQUE")`
}
Constraint represents a column constraint
type CreateTable ¶
type CreateTable struct {
Keyword string `@"CREATE"`
Table string `@"TABLE"`
Name string `@Ident`
Columns []*Column `"(" @@ ("," @@)* ")"`
}
CreateTable represents a parsed CREATE TABLE statement
type DialectParser ¶
type DialectParser interface {
ParseDDL(ctx context.Context, sql string) (*model.Catalog, error)
Validate(sql string) ([]string, error)
Dialect() grammars.Dialect
}
DialectParser defines the interface for parsing SQL dialects
type MySQLParser ¶
type MySQLParser struct {
*BaseParser
// contains filtered or unexported fields
}
MySQLParser implements parsing for MySQL dialect.
func NewMySQLParser ¶
func NewMySQLParser() (*MySQLParser, error)
NewMySQLParser creates a new MySQL parser.
type PostgreSQLParser ¶
type PostgreSQLParser struct {
*BaseParser
// contains filtered or unexported fields
}
PostgreSQLParser implements parsing for PostgreSQL dialect.
func NewPostgreSQLParser ¶
func NewPostgreSQLParser() (*PostgreSQLParser, error)
NewPostgreSQLParser creates a new PostgreSQL parser.
type SQLiteParser ¶
type SQLiteParser struct {
*BaseParser
// contains filtered or unexported fields
}
SQLiteParser implements parsing for SQLite dialect.
func NewSQLiteParser ¶
func NewSQLiteParser() (*SQLiteParser, error)
NewSQLiteParser creates a new SQLite parser.