Documentation
¶
Overview ¶
Package parser loads SQL text into TiDB parser ASTs (after token-level preprocessing of MariaDB-only syntax the parser rejects) and restores ASTs back into formatted SQL.
Index ¶
- func SplitScript(s string) []string
- type BaseVisitor
- type Loader
- func (l *Loader) LoadFromFile(filename string) ([]ast.StmtNode, error)
- func (l *Loader) LoadFromReader(reader io.Reader) ([]ast.StmtNode, error)
- func (l *Loader) LoadFromString(sql string) ([]ast.StmtNode, error)
- func (l *Loader) ParseTiDB(sql string) ([]ast.StmtNode, error)
- func (l *Loader) ValidateFile(filename string) (int, []error, error)
- func (l *Loader) ValidateSQL(sql string) (int, []error, error)
- func (l *Loader) WithCharsetMappings(charsetMap map[string]string, collationMap map[string]string) *Loader
- func (l *Loader) WithReporter(r *compat.Reporter) *Loader
- type Visitor
- type Walker
- type Writer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SplitScript ¶ added in v1.3.0
SplitScript splits a mysql-client script into statements without their delimiters, honoring DELIMITER directives; blank statements are omitted.
Types ¶
type BaseVisitor ¶
type BaseVisitor struct {
// contains filtered or unexported fields
}
BaseVisitor provides a default implementation of Visitor
type Loader ¶
type Loader struct {
// contains filtered or unexported fields
}
Loader handles loading and parsing SQL files
func NewLoader ¶
func NewLoader() *Loader
NewLoader creates a SQL loader without charset mappings; collations TiDB does not support still fall back to a supported one of the same charset.
func NewLoaderWithConfig ¶
NewLoaderWithConfig creates a loader configured with charset mappings from config
func (*Loader) LoadFromFile ¶
LoadFromFile loads and parses SQL from a file
func (*Loader) LoadFromReader ¶
LoadFromReader loads and parses SQL from an io.Reader
func (*Loader) LoadFromString ¶
LoadFromString loads and parses SQL from a string
func (*Loader) ParseTiDB ¶ added in v1.3.0
ParseTiDB parses SQL with the TiDB parser only, without preprocessing.
func (*Loader) ValidateFile ¶ added in v1.1.0
ValidateFile parses a file with the TiDB parser without any preprocessing and returns the statement count, parser warnings, and the first hard error.
func (*Loader) ValidateSQL ¶ added in v1.1.0
ValidateSQL parses SQL text with the TiDB parser without any preprocessing and returns the statement count, parser warnings, and the first hard error.
type Visitor ¶
type Visitor interface {
// Enter is called when entering a node
Enter(node ast.Node) (ast.Node, bool)
// Leave is called when leaving a node
Leave(node ast.Node) (ast.Node, bool)
}
Visitor interface for traversing AST nodes
type Walker ¶
type Walker struct {
// contains filtered or unexported fields
}
Walker provides functionality to walk the AST with a visitor
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer handles writing AST back to formatted SQL. Output is produced by the TiDB parser's own Restore, so keywords and identifier quoting always follow the TiDB grammar that validated the input.
func NewWriter ¶
func NewWriter() *Writer
NewWriter creates a new SQL writer with default formatting options.
func NewWriterWithConfig ¶ added in v1.2.0
NewWriterWithConfig creates a new SQL writer honoring cfg.FormattingOptions. A nil cfg means the default configuration.
func (*Writer) WriteStatement ¶
WriteStatement writes a single statement to formatted SQL