MCPcopy Create free account
hub / github.com/outerbase/studio / getSQLStatementType

Function getSQLStatementType

src/drivers/sql-helper.ts:16–39  ·  view source on GitHub ↗
(statement: string)

Source from the content-addressed store, hash-verified

14 | "OTHER";
15
16export 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}

Callers 1

multipleQueryFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected