(_ js.Value, args []js.Value)
| 135 | } |
| 136 | |
| 137 | func 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 | |
| 168 | func jsonError(msg string) string { |
| 169 | b, _ := json.Marshal(map[string]any{"error": msg}) |
nothing calls this directly
no test coverage detected