Skip to content

Commit

Permalink
BREAKING! Extract TriggerTarget from TriggerEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
nene committed Feb 12, 2024
1 parent fc8b8bc commit d37a94b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
6 changes: 6 additions & 0 deletions src/cst/Trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { BlockStmt } from "./ProceduralLanguage";
export type AllTriggerNodes =
| AllTriggerStatements
| TriggerEvent
| TriggerTarget
| ForEachClause
| WhenClause
| FromReferencedTableClause
Expand All @@ -26,6 +27,7 @@ export interface CreateTriggerStmt extends BaseNode {
ifNotExistsKw?: [Keyword<"IF">, Keyword<"NOT">, Keyword<"EXISTS">];
name: EntityName;
event: TriggerEvent;
target: TriggerTarget;
clauses: TriggerClause[];
body: BlockStmt | ExecuteClause;
}
Expand All @@ -36,6 +38,10 @@ export interface TriggerEvent extends BaseNode {
eventKw: Keyword<"INSERT" | "DELETE" | "UPDATE" | "TRUNCATE">;
ofKw?: Keyword<"OF">;
columns?: ListExpr<Identifier>;
}

export interface TriggerTarget extends BaseNode {
type: "trigger_target";
onKw: Keyword<"ON">;
table: EntityName;
}
Expand Down
19 changes: 13 additions & 6 deletions src/parser.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -3283,6 +3283,7 @@ create_trigger_stmt
ifKw:(if_not_exists __)?
name:(entity_name __)
event:(trigger_event __)
target:(trigger_target __)
clauses:(trigger_clause __)*
body:trigger_body
{
Expand All @@ -3295,6 +3296,7 @@ create_trigger_stmt
ifNotExistsKw: read(ifKw),
name: read(name),
event: read(event),
target: read(target),
clauses: clauses.map(read),
body,
});
Expand All @@ -3309,29 +3311,34 @@ trigger_kind
}

trigger_event
= timeKw:(trigger_time_kw __)? eventKw:(UPDATE __) ofKw:(OF __) cols:(list$column __) onKw:(ON __) table:entity_name {
= timeKw:(trigger_time_kw __)? eventKw:(UPDATE __) ofKw:(OF __) cols:list$column {
return loc({
type: "trigger_event",
timeKw: read(timeKw),
eventKw: read(eventKw),
ofKw: read(ofKw),
columns: read(cols),
onKw: read(onKw),
table,
});
}
/ timeKw:(trigger_time_kw __)? eventKw:(DELETE / INSERT / UPDATE / TRUNCATE) onKw:(__ ON __) table:entity_name {
/ timeKw:(trigger_time_kw __)? eventKw:(DELETE / INSERT / UPDATE / TRUNCATE) {
return loc({
type: "trigger_event",
timeKw: read(timeKw),
eventKw: read(eventKw),
onKw: read(onKw),
table,
});
}

trigger_time_kw = kw:(BEFORE / AFTER / INSTEAD __ OF) { return read(kw); }

trigger_target
= onKw:(__ ON __) table:entity_name {
return loc({
type: "trigger_target",
onKw: read(onKw),
table,
});
}

trigger_clause
= for_each_clause
/ when_clause
Expand Down
11 changes: 3 additions & 8 deletions src/showNode/trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,13 @@ export const triggerMap: FullTransformMap<string, AllTriggerNodes> = {
node.ifNotExistsKw,
node.name,
node.event,
node.target,
node.clauses,
node.body,
]),
trigger_event: (node) =>
show([
node.timeKw,
node.eventKw,
node.ofKw,
node.columns,
node.onKw,
node.table,
]),
show([node.timeKw, node.eventKw, node.ofKw, node.columns]),
trigger_target: (node) => show([node.onKw, node.table]),
for_each_clause: (node) => show([node.forEachKw, node.itemKw]),
when_clause: (node) => show([node.whenKw, node.expr]),
from_referenced_table_clause: (node) => show([node.fromKw, node.table]),
Expand Down

0 comments on commit d37a94b

Please sign in to comment.