dialects

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package dialects implements SQL dialect parsers.

Index

Constants

This section is empty.

Variables

View Source
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.

func (*BaseParser) Validate

func (b *BaseParser) Validate(sql string) ([]string, error)

Validate validates the SQL syntax for the parser's dialect.

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

func NewParser

func NewParser(dialect grammars.Dialect) (DialectParser, error)

NewParser creates a new dialect parser for the specified dialect

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.

func (*MySQLParser) ParseDDL

func (m *MySQLParser) ParseDDL(_ context.Context, sql string) (*model.Catalog, error)

ParseDDL parses MySQL DDL and returns a catalog.

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.

func (*PostgreSQLParser) ParseDDL

func (p *PostgreSQLParser) ParseDDL(_ context.Context, sql string) (*model.Catalog, error)

ParseDDL parses PostgreSQL DDL and returns a catalog.

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.

func (*SQLiteParser) ParseDDL

func (s *SQLiteParser) ParseDDL(_ context.Context, sql string) (*model.Catalog, error)

ParseDDL parses SQLite DDL and returns a catalog.

Jump to

Keyboard shortcuts

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