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

Function extractMetadataInternal

pkg/mcp/tools.go:126–156  ·  view source on GitHub ↗

extractMetadataInternal parses a SQL string and extracts tables, columns, and functions.

(sql string)

Source from the content-addressed store, hash-verified

124
125// extractMetadataInternal parses a SQL string and extracts tables, columns, and functions.
126func extractMetadataInternal(sql string) (map[string]any, error) {
127 if sql == "" {
128 return nil, fmt.Errorf("parameter 'sql' is required and must not be empty")
129 }
130
131 tree, err := gosqlx.Parse(sql)
132 if err != nil {
133 return nil, fmt.Errorf("parse failed: %w", err)
134 }
135
136 meta := gosqlx.ExtractMetadata(tree)
137
138 tables := meta.Tables
139 if tables == nil {
140 tables = []string{}
141 }
142 columns := meta.Columns
143 if columns == nil {
144 columns = []string{}
145 }
146 functions := meta.Functions
147 if functions == nil {
148 functions = []string{}
149 }
150
151 return map[string]any{
152 "tables": tables,
153 "columns": columns,
154 "functions": functions,
155 }, nil
156}
157
158// securityScanInternal scans a SQL string for injection patterns and other threats.
159func securityScanInternal(sql string) (map[string]any, error) {

Calls 3

ParseFunction · 0.92
ExtractMetadataFunction · 0.92
ErrorfMethod · 0.65