MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / ParseSQLWithDialect

Function ParseSQLWithDialect

pkg/transform/transform.go:258–280  ·  view source on GitHub ↗

ParseSQLWithDialect parses a SQL string using dialect-specific tokenization and parsing rules. This enables correct handling of dialect-specific syntax such as SQL Server TOP, MySQL backtick identifiers, and Snowflake QUALIFY. Use this when the input SQL uses dialect-specific constructs that the ge

(sql string, dialect keywords.SQLDialect)

Source from the content-addressed store, hash-verified

256//
257// tree, err := transform.ParseSQLWithDialect("SELECT TOP 10 * FROM users", keywords.DialectSQLServer)
258func ParseSQLWithDialect(sql string, dialect keywords.SQLDialect) (*ast.AST, error) {
259 tkz := tokenizer.GetTokenizer()
260 defer tokenizer.PutTokenizer(tkz)
261
262 if dialect != "" {
263 tkz.SetDialect(dialect)
264 }
265
266 tokens, err := tkz.Tokenize([]byte(sql))
267 if err != nil {
268 return nil, fmt.Errorf("tokenize: %w", err)
269 }
270
271 p := parser.NewParser(parser.WithDialect(string(dialect)))
272 defer p.Release()
273
274 tree, err := p.ParseFromModelTokens(tokens)
275 if err != nil {
276 return nil, fmt.Errorf("parse: %w", err)
277 }
278
279 return tree, nil
280}

Callers 1

Calls 9

ReleaseMethod · 0.95
ParseFromModelTokensMethod · 0.95
GetTokenizerFunction · 0.92
PutTokenizerFunction · 0.92
NewParserFunction · 0.92
WithDialectFunction · 0.92
SetDialectMethod · 0.80
TokenizeMethod · 0.80
ErrorfMethod · 0.65

Tested by 1