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)
| 194 | // Returns a *ast.AST containing all parsed statements, or an error if tokenization |
| 195 | // or parsing fails. |
| 196 | func 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 |