MCPcopy Index your code
hub / github.com/outerbase/studio / parseCreateTriggerScript

Function parseCreateTriggerScript

src/drivers/sqlite/sql-parse-trigger.ts:9–105  ·  view source on GitHub ↗
(
  schemaName: string,
  sql: string
)

Source from the content-addressed store, hash-verified

7import { CursorV2, parseColumnList } from "./sql-parse-table";
8
9export function parseCreateTriggerScript(
10 schemaName: string,
11 sql: string
12): DatabaseTriggerSchema {
13 const cursor = new CursorV2(tokenizeSql(sql, "sqlite"));
14
15 cursor.expectToken("CREATE");
16 cursor.expectTokenOptional("TEMP");
17 cursor.expectTokenOptional("TEMPORARY");
18 cursor.expectToken("TRIGGER");
19 cursor.expectTokensOptional(["IF", "NOT", "EXIST"]);
20 const name = cursor.consumeIdentifier();
21
22 let when: TriggerWhen = "BEFORE";
23
24 if (cursor.match("BEFORE")) {
25 cursor.next();
26 } else if (cursor.match("AFTER")) {
27 when = "AFTER";
28 cursor.next();
29 } else if (cursor.match("INSTEAD")) {
30 cursor.expectTokens(["INSTEAD", "OF"]);
31 when = "INSTEAD_OF";
32 }
33
34 let operation: TriggerOperation = "INSERT";
35 let columnNames;
36
37 if (cursor.match("DELETE")) {
38 operation = "DELETE";
39 cursor.next();
40 } else if (cursor.match("INSERT")) {
41 operation = "INSERT";
42 cursor.next();
43 } else if (cursor.match("UPDATE")) {
44 operation = "UPDATE";
45 cursor.next();
46 if (cursor.match("OF")) {
47 cursor.next();
48 columnNames = parseColumnList(cursor);
49 }
50 }
51
52 cursor.expectToken("ON");
53 const tableName = cursor.consumeIdentifier();
54 cursor.expectTokensOptional(["FOR", "EACH", "ROW"]);
55
56 let whenExpression = "";
57 const fromExpression = cursor.getPointer();
58 let toExpression;
59
60 if (cursor.match("WHEN")) {
61 // Loop till the end or meet the BEGIN
62 cursor.next();
63
64 while (!cursor.end()) {
65 toExpression = cursor.getPointer();
66 if (cursor.match("BEGIN")) break;

Callers 2

triggerMethod · 0.90

Calls 11

expectTokenMethod · 0.95
expectTokenOptionalMethod · 0.95
expectTokensOptionalMethod · 0.95
consumeIdentifierMethod · 0.95
matchMethod · 0.95
nextMethod · 0.95
expectTokensMethod · 0.95
getPointerMethod · 0.95
endMethod · 0.95
toStringRangeMethod · 0.95
parseColumnListFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…