ExtractColumns extracts all column references from an AST. This function traverses the AST and collects column references from: - SELECT lists - WHERE conditions - GROUP BY clauses - ORDER BY clauses - JOIN conditions - HAVING clauses Returns a deduplicated slice of column names (without table qua
(astNode *ast.AST)
| 300 | // columns := gosqlx.ExtractColumns(ast) |
| 301 | // // columns = ["name", "email", "active", "created_at"] |
| 302 | func ExtractColumns(astNode *ast.AST) []string { |
| 303 | if astNode == nil { |
| 304 | return nil |
| 305 | } |
| 306 | |
| 307 | collector := &columnCollector{ |
| 308 | columns: make(map[string]bool), |
| 309 | } |
| 310 | |
| 311 | for _, stmt := range astNode.Statements { |
| 312 | collector.collectFromNode(stmt) |
| 313 | } |
| 314 | |
| 315 | return collector.toSlice() |
| 316 | } |
| 317 | |
| 318 | // ExtractColumnsQualified extracts all column references with their table qualifiers. |
| 319 | // |