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

Method buildQueryInfo

cmd/gosqlx/cmd/sql_analyzer.go:505–541  ·  view source on GitHub ↗

buildQueryInfo constructs query metadata from the AST

(astObj *ast.AST, sql string)

Source from the content-addressed store, hash-verified

503
504// buildQueryInfo constructs query metadata from the AST
505func (a *SQLAnalyzer) buildQueryInfo(astObj *ast.AST, sql string) QueryInfo {
506 stmtTypes := make([]string, 0, len(astObj.Statements))
507
508 for _, stmt := range astObj.Statements {
509 switch stmt.(type) {
510 case *ast.SelectStatement:
511 stmtTypes = append(stmtTypes, "SELECT")
512 case *ast.InsertStatement:
513 stmtTypes = append(stmtTypes, "INSERT")
514 case *ast.UpdateStatement:
515 stmtTypes = append(stmtTypes, "UPDATE")
516 case *ast.DeleteStatement:
517 stmtTypes = append(stmtTypes, "DELETE")
518 case *ast.CreateTableStatement:
519 stmtTypes = append(stmtTypes, "CREATE TABLE")
520 case *ast.CreateIndexStatement:
521 stmtTypes = append(stmtTypes, "CREATE INDEX")
522 case *ast.AlterTableStatement: //nolint:staticcheck // AlterTableStatement kept for backward compatibility
523 stmtTypes = append(stmtTypes, "ALTER TABLE")
524 default:
525 stmtTypes = append(stmtTypes, "OTHER")
526 }
527 }
528
529 size := len(sql)
530 lines := 1
531 if size > 0 {
532 lines = strings.Count(sql, "\n") + 1
533 }
534
535 return QueryInfo{
536 Size: size,
537 Lines: lines,
538 StatementCount: len(astObj.Statements),
539 StatementTypes: stmtTypes,
540 }
541}
542
543// reset resets analyzer state for new analysis
544func (a *SQLAnalyzer) reset() {

Callers 1

AnalyzeMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected