| 14 | | "OTHER"; |
| 15 | |
| 16 | export function getSQLStatementType(statement: string): SQLStatementType { |
| 17 | let trimmed = statement.trim().toUpperCase(); |
| 18 | |
| 19 | // Reduce continuous whitespaces to single whitespace |
| 20 | trimmed = trimmed.replace(/\s+/g, " "); |
| 21 | |
| 22 | // Replace the "IF NOT EXISTS" clause with an empty string |
| 23 | trimmed = trimmed.replace("IF NOT EXISTS", ""); |
| 24 | |
| 25 | if (trimmed.startsWith("SELECT")) return "SELECT"; |
| 26 | if (trimmed.startsWith("INSERT")) return "INSERT"; |
| 27 | if (trimmed.startsWith("UPDATE")) return "UPDATE"; |
| 28 | if (trimmed.startsWith("CREATE TABLE")) return "CREATE_TABLE"; |
| 29 | if (trimmed.startsWith("ALTER TABLE")) return "ALTER_TABLE"; |
| 30 | if (trimmed.startsWith("DROP TABLE")) return "DROP_TABLE"; |
| 31 | if (trimmed.startsWith("CREATE INDEX")) return "CREATE_INDEX"; |
| 32 | if (trimmed.startsWith("DROP INDEX")) return "DROP_INDEX"; |
| 33 | if (trimmed.startsWith("CREATE VIEW")) return "CREATE_VIEW"; |
| 34 | if (trimmed.startsWith("DROP VIEW")) return "DROP_VIEW"; |
| 35 | if (trimmed.startsWith("CREATE TRIGGER")) return "CREATE_TRIGGER"; |
| 36 | if (trimmed.startsWith("DROP TRIGGER")) return "DROP_TRIGGER"; |
| 37 | |
| 38 | return "OTHER"; |
| 39 | } |