Skip to content

Commit

Permalink
Support ABORT as alias for ROLLBACK
Browse files Browse the repository at this point in the history
Fixes #99
  • Loading branch information
nene committed Dec 3, 2024
1 parent 94b4c59 commit 3e89684
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/cst/Transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export interface CommitTransactionStmt extends BaseNode {

export interface RollbackTransactionStmt extends BaseNode {
type: "rollback_transaction_stmt";
rollbackKw: Keyword<"ROLLBACK">;
rollbackKw: Keyword<"ROLLBACK" | "ABORT">;
transactionKw?: Keyword<"TRANSACTION" | "WORK">;
savepoint?: RollbackToSavepoint;
chain?: TransactionChainClause | TransactionNoChainClause;
Expand Down
6 changes: 5 additions & 1 deletion src/parser.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -4771,7 +4771,7 @@ commit_kw
/ kw:END (&sqlite / &postgres) { return kw; }

rollback_transaction_stmt
= kw:ROLLBACK tKw:(__ transaction_kw)?
= kw:rollback_kw tKw:(__ transaction_kw)?
sp:(__ rollback_to_savepoint)?
chain:(__ transaction_chain_clause)? {
return loc({
Expand All @@ -4783,6 +4783,10 @@ rollback_transaction_stmt
});
}

rollback_kw
= ROLLBACK
/ &postgres x:ABORT { return x; }

rollback_to_savepoint
= toKw:(TO __) spKw:(SAVEPOINT __)? id:ident {
return loc({
Expand Down
12 changes: 12 additions & 0 deletions test/transactions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,18 @@ describe("transactions", () => {
});
});

dialect("postgresql", () => {
describe("ABORT as alias for ROLLBACK", () => {
it("supports ABORT", () => {
testWc("ABORT");
testWc("ABORT WORK");
testWc("ABORT TRANSACTION");
testWc("ABORT AND CHAIN");
testWc("ABORT AND NO CHAIN");
});
});
});

dialect(["mysql", "mariadb", "sqlite", "postgresql"], () => {
describe("creating savepoints", () => {
it("supports SAVEPOINT", () => {
Expand Down

0 comments on commit 3e89684

Please sign in to comment.