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

Function parseSQLInternal

pkg/mcp/tools.go:104–123  ·  view source on GitHub ↗

parseSQLInternal parses a SQL string and returns statement count and types.

(sql string)

Source from the content-addressed store, hash-verified

102
103// parseSQLInternal parses a SQL string and returns statement count and types.
104func parseSQLInternal(sql string) (map[string]any, error) {
105 if sql == "" {
106 return nil, fmt.Errorf("parameter 'sql' is required and must not be empty")
107 }
108
109 tree, err := gosqlx.Parse(sql)
110 if err != nil {
111 return nil, fmt.Errorf("parse failed: %w", err)
112 }
113
114 stmtTypes := make([]string, 0, len(tree.Statements))
115 for _, stmt := range tree.Statements {
116 stmtTypes = append(stmtTypes, fmt.Sprintf("%T", stmt))
117 }
118
119 return map[string]any{
120 "statement_count": len(tree.Statements),
121 "statement_types": stmtTypes,
122 }, nil
123}
124
125// extractMetadataInternal parses a SQL string and extracts tables, columns, and functions.
126func extractMetadataInternal(sql string) (map[string]any, error) {

Calls 2

ParseFunction · 0.92
ErrorfMethod · 0.65