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

Function extractColumns

pkg/gosqlx/testing/testing.go:378–404  ·  view source on GitHub ↗

extractColumns extracts column names from SELECT statements

(astNode *ast.AST)

Source from the content-addressed store, hash-verified

376
377// extractColumns extracts column names from SELECT statements
378func extractColumns(astNode *ast.AST) []string {
379 if astNode == nil {
380 return nil
381 }
382
383 columns := make(map[string]bool)
384
385 for _, stmt := range astNode.Statements {
386 if selectStmt, ok := stmt.(*ast.SelectStatement); ok {
387 for _, col := range selectStmt.Columns {
388 extractColumnNames(col, columns)
389 }
390 }
391 }
392
393 // Convert map to slice
394 result := make([]string, 0, len(columns))
395 for col := range columns {
396 // Skip wildcard
397 if col == "*" {
398 continue
399 }
400 result = append(result, col)
401 }
402
403 return result
404}
405
406// extractColumnNames extracts column names from expressions
407func extractColumnNames(expr ast.Expression, columns map[string]bool) {

Callers 4

AssertColumnsFunction · 0.70

Calls 1

extractColumnNamesFunction · 0.85