Skip to content

Commit 9ca2e91

Browse files
committed
Build deno [autogenerated commit]
1 parent aca8395 commit 9ca2e91

File tree

4 files changed

+103
-45
lines changed

4 files changed

+103
-45
lines changed

.deno/ast-mapper.ts

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export interface IAstPartialMapper {
2929
transaction?: (val: a.CommitStatement | a.RollbackStatement | a.StartTransactionStatement) => a.Statement | nil
3030
createIndex?: (val: a.CreateIndexStatement) => a.Statement | nil
3131
alterTable?: (st: a.AlterTableStatement) => a.Statement | nil
32+
tableAlteration?: (change: a.TableAlteration, table: a.QNameAliased) => a.TableAlteration | nil
3233
dropColumn?: (change: a.TableAlterationDropColumn, table: a.QNameAliased) => a.TableAlteration | nil
3334
renameConstraint?: (change: a.TableAlterationRenameConstraint, table: a.QNameAliased) => a.TableAlteration | nil
3435
setTableOwner?: (change: a.TableAlterationOwner, table: a.QNameAliased) => a.TableAlteration | nil
@@ -642,55 +643,57 @@ export class AstDefaultMapper implements IAstMapper {
642643
if (!table) {
643644
return null; // no table
644645
}
645-
let change: a.TableAlteration | nil;
646-
switch (st.change.type) {
647-
case 'add column': {
648-
change = this.addColumn(st.change, st.table);
649-
break;
650-
}
651-
case 'add constraint': {
652-
change = this.addConstraint(st.change, st.table);
653-
break;
654-
}
655-
case 'alter column': {
656-
change = this.alterColumn(st.change, st.table);
657-
break;
658-
}
659-
case 'rename': {
660-
change = this.renameTable(st.change, st.table);
661-
break;
662-
}
663-
case 'rename column': {
664-
change = this.renameColumn(st.change, st.table);
665-
break;
666-
}
667-
case 'rename constraint': {
668-
change = this.renameConstraint(st.change, st.table);
669-
break;
670-
}
671-
case 'drop column': {
672-
change = this.dropColumn(st.change, st.table);
673-
break;
674-
}
675-
case 'owner': {
676-
change = this.setTableOwner(st.change, st.table);
677-
break;
646+
let changes: a.TableAlteration[] = [];
647+
let hasChanged: boolean = false;
648+
for (let i = 0; i < (st.changes?.length || 0); i++) {
649+
const currentChange: a.TableAlteration = st.changes[i];
650+
const change: a.TableAlteration | nil = this.tableAlteration(currentChange, st.table);
651+
652+
hasChanged = hasChanged || (change != currentChange);
653+
654+
if (!!change) {
655+
changes.push(change);
678656
}
679-
default:
680-
throw NotSupported.never(st.change);
681657
}
682658

683-
if (!change) {
659+
if (!changes.length) {
684660
return null; // no change left
685661
}
686662

663+
if (!hasChanged) {
664+
return st;
665+
}
666+
687667
return assignChanged(st, {
688668
table,
689-
change,
669+
changes,
690670
});
691671

692672
}
693673

674+
tableAlteration(change: a.TableAlteration, table: a.QNameAliased): a.TableAlteration | nil {
675+
switch (change.type) {
676+
case 'add column':
677+
return this.addColumn(change, table);
678+
case 'add constraint':
679+
return this.addConstraint(change, table);
680+
case 'alter column':
681+
return this.alterColumn(change, table);
682+
case 'rename':
683+
return this.renameTable(change, table);
684+
case 'rename column':
685+
return this.renameColumn(change, table);
686+
case 'rename constraint':
687+
return this.renameConstraint(change, table);
688+
case 'drop column':
689+
return this.dropColumn(change, table);
690+
case 'owner':
691+
return this.setTableOwner(change, table);
692+
default:
693+
throw NotSupported.never(change);
694+
}
695+
}
696+
694697
dropColumn(change: a.TableAlterationDropColumn, table: a.QNameAliased): a.TableAlteration | nil {
695698
return change;
696699
}

.deno/syntax/ast.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ export interface AlterTableStatement extends PGNode {
231231
table: QNameAliased;
232232
only?: boolean;
233233
ifExists?: boolean;
234-
change: TableAlteration;
234+
changes: TableAlteration[];
235235
}
236236

237237
export interface TableAlterationRename extends PGNode {
@@ -542,6 +542,7 @@ export interface SelectFromStatement extends PGNode {
542542
limit?: LimitStatement | nil;
543543
orderBy?: OrderByStatement[] | nil;
544544
distinct?: 'all' | 'distinct' | Expr[] | nil;
545+
for?: ForStatement;
545546
}
546547

547548
export interface SelectFromUnion extends PGNode {
@@ -555,6 +556,10 @@ export interface OrderByStatement extends PGNode {
555556
order?: 'ASC' | 'DESC' | nil;
556557
}
557558

559+
export interface ForStatement extends PGNode {
560+
type: 'update' | 'no key update' | 'share' | 'key share';
561+
}
562+
558563
export interface LimitStatement extends PGNode {
559564
limit?: Expr | nil;
560565
offset?: Expr | nil;

.deno/syntax/main.ne.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ declare var kw_group: any;
4343
declare var kw_limit: any;
4444
declare var kw_offset: any;
4545
declare var kw_fetch: any;
46+
declare var kw_for: any;
4647
declare var kw_order: any;
4748
declare var kw_asc: any;
4849
declare var kw_desc: any;
@@ -102,7 +103,6 @@ declare var kw_user: any;
102103
declare var kw_current_user: any;
103104
declare var lparen: any;
104105
declare var kw_placing: any;
105-
declare var kw_for: any;
106106
declare var rparen: any;
107107
declare var kw_create: any;
108108
declare var kw_table: any;
@@ -460,6 +460,7 @@ const grammar: Grammar = {
460460
{"name": "kw_prepare", "symbols": [(lexerAny.has("word") ? {type: "word"} : word)], "postprocess": notReservedKw('prepare')},
461461
{"name": "kw_raise", "symbols": [(lexerAny.has("word") ? {type: "word"} : word)], "postprocess": notReservedKw('raise')},
462462
{"name": "kw_continue", "symbols": [(lexerAny.has("word") ? {type: "word"} : word)], "postprocess": notReservedKw('continue')},
463+
{"name": "kw_share", "symbols": [(lexerAny.has("word") ? {type: "word"} : word)], "postprocess": notReservedKw('share')},
463464
{"name": "kw_ifnotexists", "symbols": ["kw_if", (lexerAny.has("kw_not") ? {type: "kw_not"} : kw_not), "kw_exists"]},
464465
{"name": "kw_ifexists", "symbols": ["kw_if", "kw_exists"]},
465466
{"name": "kw_not_null", "symbols": [(lexerAny.has("kw_not") ? {type: "kw_not"} : kw_not), (lexerAny.has("kw_null") ? {type: "kw_null"} : kw_null)]},
@@ -574,8 +575,10 @@ const grammar: Grammar = {
574575
{"name": "select_statement$ebnf$3", "symbols": [], "postprocess": () => null},
575576
{"name": "select_statement$ebnf$4", "symbols": ["select_order_by"], "postprocess": id},
576577
{"name": "select_statement$ebnf$4", "symbols": [], "postprocess": () => null},
577-
{"name": "select_statement", "symbols": ["select_what", "select_statement$ebnf$1", "select_statement$ebnf$2", "select_statement$ebnf$3", "select_statement$ebnf$4", "select_limit"], "postprocess": x => {
578-
let [what, from, where, groupBy, orderBy, limit] = x;
578+
{"name": "select_statement$ebnf$5", "symbols": ["select_for"], "postprocess": id},
579+
{"name": "select_statement$ebnf$5", "symbols": [], "postprocess": () => null},
580+
{"name": "select_statement", "symbols": ["select_what", "select_statement$ebnf$1", "select_statement$ebnf$2", "select_statement$ebnf$3", "select_statement$ebnf$4", "select_limit", "select_statement$ebnf$5"], "postprocess": x => {
581+
let [what, from, where, groupBy, orderBy, limit, selectFor] = x;
579582
from = unwrap(from);
580583
groupBy = groupBy && (groupBy.length === 1 && groupBy[0].type === 'list' ? groupBy[0].expressions : groupBy);
581584
return track(x, {
@@ -585,6 +588,7 @@ const grammar: Grammar = {
585588
...limit ? { limit } : {},
586589
...orderBy ? { orderBy } : {},
587590
...where ? { where } : {},
591+
...selectFor ? { for: selectFor[1] } : {},
588592
type: 'select',
589593
});
590594
} },
@@ -736,6 +740,11 @@ const grammar: Grammar = {
736740
...offset ? {offset} : {},
737741
});
738742
}},
743+
{"name": "select_for$subexpression$1", "symbols": ["kw_update"], "postprocess": x => track(x, {type: 'update'})},
744+
{"name": "select_for$subexpression$1", "symbols": ["kw_no", "kw_key", "kw_update"], "postprocess": x => track(x, {type: 'no key update'})},
745+
{"name": "select_for$subexpression$1", "symbols": ["kw_share"], "postprocess": x => track(x, {type: 'share'})},
746+
{"name": "select_for$subexpression$1", "symbols": ["kw_key", "kw_share"], "postprocess": x => track(x, {type: 'key share'})},
747+
{"name": "select_for", "symbols": [(lexerAny.has("kw_for") ? {type: "kw_for"} : kw_for), "select_for$subexpression$1"]},
739748
{"name": "select_order_by$subexpression$1", "symbols": [(lexerAny.has("kw_order") ? {type: "kw_order"} : kw_order), "kw_by"]},
740749
{"name": "select_order_by$ebnf$1", "symbols": []},
741750
{"name": "select_order_by$ebnf$1$subexpression$1", "symbols": ["comma", "select_order_by_expr"], "postprocess": last},
@@ -1826,13 +1835,19 @@ const grammar: Grammar = {
18261835
{"name": "altertable_statement$ebnf$1", "symbols": [], "postprocess": () => null},
18271836
{"name": "altertable_statement$ebnf$2", "symbols": [(lexerAny.has("kw_only") ? {type: "kw_only"} : kw_only)], "postprocess": id},
18281837
{"name": "altertable_statement$ebnf$2", "symbols": [], "postprocess": () => null},
1829-
{"name": "altertable_statement", "symbols": ["kw_alter", (lexerAny.has("kw_table") ? {type: "kw_table"} : kw_table), "altertable_statement$ebnf$1", "altertable_statement$ebnf$2", "table_ref", "altertable_action"], "postprocess": x => track(x, {
1838+
{"name": "altertable_statement", "symbols": ["kw_alter", (lexerAny.has("kw_table") ? {type: "kw_table"} : kw_table), "altertable_statement$ebnf$1", "altertable_statement$ebnf$2", "table_ref", "altertable_actions"], "postprocess": x => track(x, {
18301839
type: 'alter table',
18311840
... x[2] ? {ifExists: true} : {},
18321841
... x[3] ? {only: true} : {},
18331842
table: unwrap(x[4]),
1834-
change: unwrap(x[5]),
1843+
changes: unbox(x[5]).map(unwrap),
18351844
}) },
1845+
{"name": "altertable_actions$ebnf$1", "symbols": []},
1846+
{"name": "altertable_actions$ebnf$1$subexpression$1", "symbols": ["comma", "altertable_action"], "postprocess": last},
1847+
{"name": "altertable_actions$ebnf$1", "symbols": ["altertable_actions$ebnf$1", "altertable_actions$ebnf$1$subexpression$1"], "postprocess": (d) => d[0].concat([d[1]])},
1848+
{"name": "altertable_actions", "symbols": ["altertable_action", "altertable_actions$ebnf$1"], "postprocess": ([head, tail]) => {
1849+
return [head, ...(tail || [])];
1850+
} },
18361851
{"name": "altertable_action", "symbols": ["altertable_rename_table"]},
18371852
{"name": "altertable_action", "symbols": ["altertable_rename_column"]},
18381853
{"name": "altertable_action", "symbols": ["altertable_rename_constraint"]},

.deno/to-sql.ts

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { IAstPartialMapper, AstDefaultMapper } from './ast-mapper.ts';
22
import { astVisitor, IAstVisitor, IAstFullVisitor } from './ast-visitor.ts';
33
import { NotSupported, nil, ReplaceReturnType, NoExtraProperties } from './utils.ts';
4-
import { TableConstraint, JoinClause, ColumnConstraint, AlterSequenceStatement, CreateSequenceStatement, AlterSequenceSetOptions, CreateSequenceOptions, QName, SetGlobalValue, AlterColumnAddGenerated, QColumn, Name, OrderByStatement } from './syntax/ast.ts';
4+
import { TableConstraint, JoinClause, ColumnConstraint, AlterSequenceStatement, CreateSequenceStatement, AlterSequenceSetOptions, CreateSequenceOptions, QName, SetGlobalValue, AlterColumnAddGenerated, QColumn, Name, OrderByStatement, QNameAliased } from './syntax/ast.ts';
55
import { literal } from './pg-escape.ts';
66
import { sqlKeywords } from './keywords.ts';
77

@@ -100,6 +100,13 @@ function visitQualifiedName(cs: QName) {
100100
ret.push(ident(cs.name), ' ');
101101
}
102102

103+
function visitQualifiedNameAliased(cs: QNameAliased) {
104+
visitQualifiedName(cs);
105+
if (cs.alias) {
106+
ret.push(' AS ', ident(cs.alias), ' ');
107+
}
108+
}
109+
103110
function visitOrderBy(m: IAstVisitor, orderBy: OrderByStatement[]) {
104111
ret.push(' ORDER BY ');
105112
list(orderBy, e => {
@@ -325,7 +332,31 @@ const visitor = astVisitor<IAstFullVisitor>(m => ({
325332
if (t.only) {
326333
ret.push(' ONLY ');
327334
}
328-
m.super().alterTable(t);
335+
visitQualifiedNameAliased(t.table);
336+
list(t.changes, change => m.tableAlteration(change, t.table), false);
337+
},
338+
339+
tableAlteration: (change, table) => {
340+
switch (change.type) {
341+
case 'add column':
342+
return m.addColumn(change, table);
343+
case 'add constraint':
344+
return m.addConstraint(change, table);
345+
case 'alter column':
346+
return m.alterColumn(change, table);
347+
case 'rename':
348+
return m.renameTable(change, table);
349+
case 'rename column':
350+
return m.renameColumn(change, table);
351+
case 'rename constraint':
352+
return m.renameConstraint(change, table);
353+
case 'drop column':
354+
return m.dropColumn(change, table);
355+
case 'owner':
356+
return m.setTableOwner(change, table);
357+
default:
358+
throw NotSupported.never(change);
359+
}
329360
},
330361

331362
array: v => {
@@ -1183,6 +1214,10 @@ const visitor = astVisitor<IAstFullVisitor>(m => ({
11831214
m.expr(s.limit.limit);
11841215
}
11851216
}
1217+
1218+
if (s.for) {
1219+
ret.push('FOR ', s.for.type.toUpperCase());
1220+
}
11861221
},
11871222

11881223
show: s => {

0 commit comments

Comments
 (0)