ExtractFunctions extracts all function calls from an AST. This function traverses the AST and collects all function names, including: - Aggregate functions (COUNT, SUM, AVG, etc.) - Window functions (ROW_NUMBER, RANK, etc.) - Scalar functions (UPPER, LOWER, NOW, etc.) Returns a deduplicated slice
(astNode *ast.AST)
| 367 | // functions := gosqlx.ExtractFunctions(ast) |
| 368 | // // functions = ["COUNT", "UPPER"] |
| 369 | func ExtractFunctions(astNode *ast.AST) []string { |
| 370 | if astNode == nil { |
| 371 | return nil |
| 372 | } |
| 373 | |
| 374 | collector := &functionCollector{ |
| 375 | functions: make(map[string]bool), |
| 376 | } |
| 377 | |
| 378 | for _, stmt := range astNode.Statements { |
| 379 | collector.collectFromNode(stmt) |
| 380 | } |
| 381 | |
| 382 | return collector.toSlice() |
| 383 | } |
| 384 | |
| 385 | // tableCollector collects table names from AST nodes |
| 386 | type tableCollector struct { |