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

Function analyze

wasm/main.go:137–166  ·  view source on GitHub ↗
(_ js.Value, args []js.Value)

Source from the content-addressed store, hash-verified

135}
136
137func analyze(_ js.Value, args []js.Value) any {
138 if len(args) == 0 {
139 return jsonError("no SQL provided")
140 }
141 sql := args[0].String()
142 // dialect is accepted for API consistency
143 _ = getDialect(args)
144
145 // Run security scan
146 scanner := security.NewScanner()
147 securityResult := scanner.ScanSQL(sql)
148
149 // Run optimization analysis
150 opt := advisor.New()
151 optResult, err := opt.AnalyzeSQL(sql)
152 if err != nil {
153 // If parsing fails, still return security results with an optimization error
154 combined := map[string]any{
155 "security": securityResult,
156 "optimization": map[string]any{"error": err.Error()},
157 }
158 return jsonResult(combined)
159 }
160
161 combined := map[string]any{
162 "security": securityResult,
163 "optimization": optResult,
164 }
165 return jsonResult(combined)
166}
167
168func jsonError(msg string) string {
169 b, _ := json.Marshal(map[string]any{"error": msg})

Callers

nothing calls this directly

Calls 9

ScanSQLMethod · 0.95
NewScannerFunction · 0.92
NewFunction · 0.92
jsonErrorFunction · 0.85
getDialectFunction · 0.85
jsonResultFunction · 0.85
AnalyzeSQLMethod · 0.80
StringMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected