-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tracking error and query type behavior
- Loading branch information
Showing
9 changed files
with
208 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
export type SQLStatementType = | ||
| "SELECT" | ||
| "INSERT" | ||
| "UPDATE" | ||
| "CREATE_TABLE" | ||
| "ALTER_TABLE" | ||
| "DROP_TABLE" | ||
| "CREATE_INDEX" | ||
| "DROP_INDEX" | ||
| "CREATE_VIEW" | ||
| "DROP_VIEW" | ||
| "CREATE_TRIGGER" | ||
| "DROP_TRIGGER" | ||
| "OTHER"; | ||
|
||
export function getSQLStatementType(statement: string): SQLStatementType { | ||
let trimmed = statement.trim().toUpperCase(); | ||
|
||
// Reduce continuous whitespaces to single whitespace | ||
trimmed = trimmed.replace(/\s+/g, " "); | ||
|
||
// Replace the "IF NOT EXISTS" clause with an empty string | ||
trimmed = trimmed.replace("IF NOT EXISTS", ""); | ||
|
||
if (trimmed.startsWith("SELECT")) return "SELECT"; | ||
if (trimmed.startsWith("INSERT")) return "INSERT"; | ||
if (trimmed.startsWith("UPDATE")) return "UPDATE"; | ||
if (trimmed.startsWith("CREATE TABLE")) return "CREATE_TABLE"; | ||
if (trimmed.startsWith("ALTER TABLE")) return "ALTER_TABLE"; | ||
if (trimmed.startsWith("DROP TABLE")) return "DROP_TABLE"; | ||
if (trimmed.startsWith("CREATE INDEX")) return "CREATE_INDEX"; | ||
if (trimmed.startsWith("DROP INDEX")) return "DROP_INDEX"; | ||
if (trimmed.startsWith("CREATE VIEW")) return "CREATE_VIEW"; | ||
if (trimmed.startsWith("DROP VIEW")) return "DROP_VIEW"; | ||
if (trimmed.startsWith("CREATE TRIGGER")) return "CREATE_TRIGGER"; | ||
if (trimmed.startsWith("DROP TRIGGER")) return "DROP_TRIGGER"; | ||
|
||
return "OTHER"; | ||
} |
Oops, something went wrong.