(query: string)
| 29 | * ``` |
| 30 | */ |
| 31 | export function parseSQLQuery(query: string): SQLParsedInfo { |
| 32 | // Remove quoted strings to avoid false positives |
| 33 | // SQLite uses doubled quotes for escaping: 'don''t' or "test""quote" |
| 34 | const cleaned = query |
| 35 | .replace(SINGLE_QUOTED_STRING, "''") // Remove single-quoted strings |
| 36 | .replace(DOUBLE_QUOTED_STRING, '""'); // Remove double-quoted strings |
| 37 | |
| 38 | // Priority 1: Check for RETURNING (highest priority - makes any query return rows) |
| 39 | if (RETURNING_KEYWORD.test(cleaned)) { |
| 40 | return { canReturnRows: true }; |
| 41 | } |
| 42 | |
| 43 | // Priority 2: Check for mutations (these don't return rows unless they have RETURNING) |
| 44 | if (MUTATION_KEYWORDS.test(cleaned)) { |
| 45 | return { canReturnRows: false }; |
| 46 | } |
| 47 | |
| 48 | // Priority 3: Check for queries (these return rows) |
| 49 | if (QUERY_KEYWORDS.test(cleaned)) { |
| 50 | return { canReturnRows: true }; |
| 51 | } |
| 52 | |
| 53 | // Default: doesn't return rows |
| 54 | return { canReturnRows: false }; |
| 55 | } |
no test coverage detected
searching dependent graphs…