Skip to content

Commit

Permalink
Drop table restrict
Browse files Browse the repository at this point in the history
  • Loading branch information
oguimbal committed May 5, 2022
1 parent 766fa1e commit 97b5063
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pgsql-ast-parser",
"version": "10.0.4",
"version": "10.0.5",
"description": "Yet another simple Postgres SQL parser/modifier",
"main": "index.js",
"repository": "https://github.com/oguimbal/pgsql-ast-parser",
Expand Down
2 changes: 1 addition & 1 deletion src/syntax/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ export interface DropTableStatement extends PGNode {
type: 'drop table';
name: QName;
ifExists?: boolean;
cascade?: boolean;
cascade?: 'cascade' | 'restrict';
}

export interface DropSequenceStatement extends PGNode {
Expand Down
4 changes: 2 additions & 2 deletions src/syntax/drop.ne
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

# https://www.postgresql.org/docs/9.3/sql-dropindex.html

drop_statement -> kw_drop drop_what kw_ifexists:? qualified_name kw_cascade:? {% (x: any, rej: any) => {
drop_statement -> kw_drop drop_what kw_ifexists:? qualified_name (kw_cascade | kw_restrict):? {% (x: any, rej: any) => {
const v = unwrap(x[1]);
return track(x, {
...v,
... x[2] && {ifExists: true},
name: unwrap(x[3]),
... x[4] && {cascade: true},
... x[4] && {cascade: toStr(x[4]) },
});
}%}

Expand Down
9 changes: 8 additions & 1 deletion src/syntax/drop.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@ describe('Drop', () => {
type: 'drop table',
name: { name: 'Users' },
ifExists: true,
cascade: true,
cascade: 'cascade',
});

checkStatement([`DROP TABLE IF EXISTS "Users" RESTRICT`], {
type: 'drop table',
name: { name: 'Users' },
ifExists: true,
cascade: 'restrict',
});


Expand Down
2 changes: 1 addition & 1 deletion src/to-sql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ const visitor = astVisitor<IAstFullVisitor>(m => ({
}
m.tableRef(val.name);
if (val.cascade) {
ret.push(' CASCADE ');
ret.push(' ', val.cascade, ' ');
}
},
dropIndex: val => {
Expand Down

0 comments on commit 97b5063

Please sign in to comment.