Skip to content

Commit

Permalink
feat: add on delete/ update missing options
Browse files Browse the repository at this point in the history
  • Loading branch information
antoineB committed Sep 26, 2023
1 parent c0f2c1d commit 154767b
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 3 deletions.
21 changes: 20 additions & 1 deletion grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ module.exports = grammar({
keyword_nowait: _ => make_keyword("nowait"),
keyword_attribute: _ => make_keyword("attribute"),
keyword_authorization: _ => make_keyword("authorization"),
keyword_action: _ => make_keyword("action"),

keyword_trigger: _ => make_keyword('trigger'),
keyword_function: _ => make_keyword("function"),
Expand Down Expand Up @@ -2274,13 +2275,31 @@ module.exports = grammar({
seq(
$.keyword_on,
$.keyword_delete,
$.keyword_cascade,
$.referential_action,
),
),
optional(
seq(
$.keyword_on,
$.keyword_update,
$.referential_action,
),
),
),
),
),

referential_action: $ => choice(
seq($.keyword_no, $.keyword_action),
$.keyword_restrict,
$.keyword_cascade,
seq(
$.keyword_set,
choice($.keyword_null, $.keyword_default),
optional(paren_list($.identifier))
),
),

ordered_columns: $ => paren_list(alias($.ordered_column, $.column), true),

ordered_column: $ => seq(
Expand Down
49 changes: 47 additions & 2 deletions test/corpus/alter.txt
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,6 @@ ALTER TABLE "Role" ADD CONSTRAINT "pkRole" PRIMARY KEY ("roleId");
(column
name: (literal))))))))


================================================================================
Add foreign key constraint
================================================================================
Expand Down Expand Up @@ -568,7 +567,8 @@ FOREIGN KEY ("accountId") REFERENCES "Account" ("accountId") ON DELETE CASCADE;
name: (literal)))
(keyword_on)
(keyword_delete)
(keyword_cascade))))))
(referential_action
(keyword_cascade)))))))

================================================================================
MySQL: Rename table
Expand Down Expand Up @@ -1131,3 +1131,48 @@ OWNED BY numbers.number_sequences
(object_reference
(identifier)
(identifier)))))

================================================================================
Add foreign key constraint
================================================================================

ALTER TABLE "AccountRole" ADD CONSTRAINT "fkAccountRoleAccount"
FOREIGN KEY ("accountId") REFERENCES "Account" ("accountId")
ON DELETE SET NULL
ON UPDATE SET DEFAULT;

--------------------------------------------------------------------------------

(program
(statement
(alter_table
(keyword_alter)
(keyword_table)
(object_reference
(identifier))
(add_constraint
(keyword_add)
(keyword_constraint)
(identifier)
(constraint
(keyword_foreign)
(keyword_key)
(ordered_columns
(column
(literal)))
(keyword_references)
(object_reference
(identifier))
(ordered_columns
(column
(literal)))
(keyword_on)
(keyword_delete)
(referential_action
(keyword_set)
(keyword_null))
(keyword_on)
(keyword_update)
(referential_action
(keyword_set)
(keyword_default)))))))

0 comments on commit 154767b

Please sign in to comment.