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

Function ParseSQL

pkg/transform/transform.go:196–214  ·  view source on GitHub ↗

ParseSQL parses a SQL string into a full AST containing all statements. This is a convenience wrapper around the tokenizer and parser pipeline that handles resource pooling automatically. Use this function when you need an AST for subsequent Apply calls: tree, err := transform.ParseSQL("SELECT id

(sql string)

Source from the content-addressed store, hash-verified

194// Returns a *ast.AST containing all parsed statements, or an error if tokenization
195// or parsing fails.
196func ParseSQL(sql string) (*ast.AST, error) {
197 tkz := tokenizer.GetTokenizer()
198 defer tokenizer.PutTokenizer(tkz)
199
200 tokens, err := tkz.Tokenize([]byte(sql))
201 if err != nil {
202 return nil, fmt.Errorf("tokenize: %w", err)
203 }
204
205 p := parser.NewParser()
206 defer p.Release()
207
208 tree, err := p.ParseFromModelTokens(tokens)
209 if err != nil {
210 return nil, fmt.Errorf("parse: %w", err)
211 }
212
213 return tree, nil
214}
215
216// FormatSQL converts an AST statement back into a compact SQL string using the
217// GoSQLX formatter. It is the inverse of ParseSQL and completes the

Calls 7

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