Skip to content

Commit

Permalink
Build deno [autogenerated commit]
Browse files Browse the repository at this point in the history
  • Loading branch information
oguimbal committed Aug 28, 2021
1 parent aca8395 commit 9ca2e91
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 45 deletions.
77 changes: 40 additions & 37 deletions .deno/ast-mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface IAstPartialMapper {
transaction?: (val: a.CommitStatement | a.RollbackStatement | a.StartTransactionStatement) => a.Statement | nil
createIndex?: (val: a.CreateIndexStatement) => a.Statement | nil
alterTable?: (st: a.AlterTableStatement) => a.Statement | nil
tableAlteration?: (change: a.TableAlteration, table: a.QNameAliased) => a.TableAlteration | nil
dropColumn?: (change: a.TableAlterationDropColumn, table: a.QNameAliased) => a.TableAlteration | nil
renameConstraint?: (change: a.TableAlterationRenameConstraint, table: a.QNameAliased) => a.TableAlteration | nil
setTableOwner?: (change: a.TableAlterationOwner, table: a.QNameAliased) => a.TableAlteration | nil
Expand Down Expand Up @@ -642,55 +643,57 @@ export class AstDefaultMapper implements IAstMapper {
if (!table) {
return null; // no table
}
let change: a.TableAlteration | nil;
switch (st.change.type) {
case 'add column': {
change = this.addColumn(st.change, st.table);
break;
}
case 'add constraint': {
change = this.addConstraint(st.change, st.table);
break;
}
case 'alter column': {
change = this.alterColumn(st.change, st.table);
break;
}
case 'rename': {
change = this.renameTable(st.change, st.table);
break;
}
case 'rename column': {
change = this.renameColumn(st.change, st.table);
break;
}
case 'rename constraint': {
change = this.renameConstraint(st.change, st.table);
break;
}
case 'drop column': {
change = this.dropColumn(st.change, st.table);
break;
}
case 'owner': {
change = this.setTableOwner(st.change, st.table);
break;
let changes: a.TableAlteration[] = [];
let hasChanged: boolean = false;
for (let i = 0; i < (st.changes?.length || 0); i++) {
const currentChange: a.TableAlteration = st.changes[i];
const change: a.TableAlteration | nil = this.tableAlteration(currentChange, st.table);

hasChanged = hasChanged || (change != currentChange);

if (!!change) {
changes.push(change);
}
default:
throw NotSupported.never(st.change);
}

if (!change) {
if (!changes.length) {
return null; // no change left
}

if (!hasChanged) {
return st;
}

return assignChanged(st, {
table,
change,
changes,
});

}

tableAlteration(change: a.TableAlteration, table: a.QNameAliased): a.TableAlteration | nil {
switch (change.type) {
case 'add column':
return this.addColumn(change, table);
case 'add constraint':
return this.addConstraint(change, table);
case 'alter column':
return this.alterColumn(change, table);
case 'rename':
return this.renameTable(change, table);
case 'rename column':
return this.renameColumn(change, table);
case 'rename constraint':
return this.renameConstraint(change, table);
case 'drop column':
return this.dropColumn(change, table);
case 'owner':
return this.setTableOwner(change, table);
default:
throw NotSupported.never(change);
}
}

dropColumn(change: a.TableAlterationDropColumn, table: a.QNameAliased): a.TableAlteration | nil {
return change;
}
Expand Down
7 changes: 6 additions & 1 deletion .deno/syntax/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ export interface AlterTableStatement extends PGNode {
table: QNameAliased;
only?: boolean;
ifExists?: boolean;
change: TableAlteration;
changes: TableAlteration[];
}

export interface TableAlterationRename extends PGNode {
Expand Down Expand Up @@ -542,6 +542,7 @@ export interface SelectFromStatement extends PGNode {
limit?: LimitStatement | nil;
orderBy?: OrderByStatement[] | nil;
distinct?: 'all' | 'distinct' | Expr[] | nil;
for?: ForStatement;
}

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

export interface ForStatement extends PGNode {
type: 'update' | 'no key update' | 'share' | 'key share';
}

export interface LimitStatement extends PGNode {
limit?: Expr | nil;
offset?: Expr | nil;
Expand Down
25 changes: 20 additions & 5 deletions .deno/syntax/main.ne.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ declare var kw_group: any;
declare var kw_limit: any;
declare var kw_offset: any;
declare var kw_fetch: any;
declare var kw_for: any;
declare var kw_order: any;
declare var kw_asc: any;
declare var kw_desc: any;
Expand Down Expand Up @@ -102,7 +103,6 @@ declare var kw_user: any;
declare var kw_current_user: any;
declare var lparen: any;
declare var kw_placing: any;
declare var kw_for: any;
declare var rparen: any;
declare var kw_create: any;
declare var kw_table: any;
Expand Down Expand Up @@ -460,6 +460,7 @@ const grammar: Grammar = {
{"name": "kw_prepare", "symbols": [(lexerAny.has("word") ? {type: "word"} : word)], "postprocess": notReservedKw('prepare')},
{"name": "kw_raise", "symbols": [(lexerAny.has("word") ? {type: "word"} : word)], "postprocess": notReservedKw('raise')},
{"name": "kw_continue", "symbols": [(lexerAny.has("word") ? {type: "word"} : word)], "postprocess": notReservedKw('continue')},
{"name": "kw_share", "symbols": [(lexerAny.has("word") ? {type: "word"} : word)], "postprocess": notReservedKw('share')},
{"name": "kw_ifnotexists", "symbols": ["kw_if", (lexerAny.has("kw_not") ? {type: "kw_not"} : kw_not), "kw_exists"]},
{"name": "kw_ifexists", "symbols": ["kw_if", "kw_exists"]},
{"name": "kw_not_null", "symbols": [(lexerAny.has("kw_not") ? {type: "kw_not"} : kw_not), (lexerAny.has("kw_null") ? {type: "kw_null"} : kw_null)]},
Expand Down Expand Up @@ -574,8 +575,10 @@ const grammar: Grammar = {
{"name": "select_statement$ebnf$3", "symbols": [], "postprocess": () => null},
{"name": "select_statement$ebnf$4", "symbols": ["select_order_by"], "postprocess": id},
{"name": "select_statement$ebnf$4", "symbols": [], "postprocess": () => null},
{"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 => {
let [what, from, where, groupBy, orderBy, limit] = x;
{"name": "select_statement$ebnf$5", "symbols": ["select_for"], "postprocess": id},
{"name": "select_statement$ebnf$5", "symbols": [], "postprocess": () => null},
{"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 => {
let [what, from, where, groupBy, orderBy, limit, selectFor] = x;
from = unwrap(from);
groupBy = groupBy && (groupBy.length === 1 && groupBy[0].type === 'list' ? groupBy[0].expressions : groupBy);
return track(x, {
Expand All @@ -585,6 +588,7 @@ const grammar: Grammar = {
...limit ? { limit } : {},
...orderBy ? { orderBy } : {},
...where ? { where } : {},
...selectFor ? { for: selectFor[1] } : {},
type: 'select',
});
} },
Expand Down Expand Up @@ -736,6 +740,11 @@ const grammar: Grammar = {
...offset ? {offset} : {},
});
}},
{"name": "select_for$subexpression$1", "symbols": ["kw_update"], "postprocess": x => track(x, {type: 'update'})},
{"name": "select_for$subexpression$1", "symbols": ["kw_no", "kw_key", "kw_update"], "postprocess": x => track(x, {type: 'no key update'})},
{"name": "select_for$subexpression$1", "symbols": ["kw_share"], "postprocess": x => track(x, {type: 'share'})},
{"name": "select_for$subexpression$1", "symbols": ["kw_key", "kw_share"], "postprocess": x => track(x, {type: 'key share'})},
{"name": "select_for", "symbols": [(lexerAny.has("kw_for") ? {type: "kw_for"} : kw_for), "select_for$subexpression$1"]},
{"name": "select_order_by$subexpression$1", "symbols": [(lexerAny.has("kw_order") ? {type: "kw_order"} : kw_order), "kw_by"]},
{"name": "select_order_by$ebnf$1", "symbols": []},
{"name": "select_order_by$ebnf$1$subexpression$1", "symbols": ["comma", "select_order_by_expr"], "postprocess": last},
Expand Down Expand Up @@ -1826,13 +1835,19 @@ const grammar: Grammar = {
{"name": "altertable_statement$ebnf$1", "symbols": [], "postprocess": () => null},
{"name": "altertable_statement$ebnf$2", "symbols": [(lexerAny.has("kw_only") ? {type: "kw_only"} : kw_only)], "postprocess": id},
{"name": "altertable_statement$ebnf$2", "symbols": [], "postprocess": () => null},
{"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, {
{"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, {
type: 'alter table',
... x[2] ? {ifExists: true} : {},
... x[3] ? {only: true} : {},
table: unwrap(x[4]),
change: unwrap(x[5]),
changes: unbox(x[5]).map(unwrap),
}) },
{"name": "altertable_actions$ebnf$1", "symbols": []},
{"name": "altertable_actions$ebnf$1$subexpression$1", "symbols": ["comma", "altertable_action"], "postprocess": last},
{"name": "altertable_actions$ebnf$1", "symbols": ["altertable_actions$ebnf$1", "altertable_actions$ebnf$1$subexpression$1"], "postprocess": (d) => d[0].concat([d[1]])},
{"name": "altertable_actions", "symbols": ["altertable_action", "altertable_actions$ebnf$1"], "postprocess": ([head, tail]) => {
return [head, ...(tail || [])];
} },
{"name": "altertable_action", "symbols": ["altertable_rename_table"]},
{"name": "altertable_action", "symbols": ["altertable_rename_column"]},
{"name": "altertable_action", "symbols": ["altertable_rename_constraint"]},
Expand Down
39 changes: 37 additions & 2 deletions .deno/to-sql.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { IAstPartialMapper, AstDefaultMapper } from './ast-mapper.ts';
import { astVisitor, IAstVisitor, IAstFullVisitor } from './ast-visitor.ts';
import { NotSupported, nil, ReplaceReturnType, NoExtraProperties } from './utils.ts';
import { TableConstraint, JoinClause, ColumnConstraint, AlterSequenceStatement, CreateSequenceStatement, AlterSequenceSetOptions, CreateSequenceOptions, QName, SetGlobalValue, AlterColumnAddGenerated, QColumn, Name, OrderByStatement } from './syntax/ast.ts';
import { TableConstraint, JoinClause, ColumnConstraint, AlterSequenceStatement, CreateSequenceStatement, AlterSequenceSetOptions, CreateSequenceOptions, QName, SetGlobalValue, AlterColumnAddGenerated, QColumn, Name, OrderByStatement, QNameAliased } from './syntax/ast.ts';
import { literal } from './pg-escape.ts';
import { sqlKeywords } from './keywords.ts';

Expand Down Expand Up @@ -100,6 +100,13 @@ function visitQualifiedName(cs: QName) {
ret.push(ident(cs.name), ' ');
}

function visitQualifiedNameAliased(cs: QNameAliased) {
visitQualifiedName(cs);
if (cs.alias) {
ret.push(' AS ', ident(cs.alias), ' ');
}
}

function visitOrderBy(m: IAstVisitor, orderBy: OrderByStatement[]) {
ret.push(' ORDER BY ');
list(orderBy, e => {
Expand Down Expand Up @@ -325,7 +332,31 @@ const visitor = astVisitor<IAstFullVisitor>(m => ({
if (t.only) {
ret.push(' ONLY ');
}
m.super().alterTable(t);
visitQualifiedNameAliased(t.table);
list(t.changes, change => m.tableAlteration(change, t.table), false);
},

tableAlteration: (change, table) => {
switch (change.type) {
case 'add column':
return m.addColumn(change, table);
case 'add constraint':
return m.addConstraint(change, table);
case 'alter column':
return m.alterColumn(change, table);
case 'rename':
return m.renameTable(change, table);
case 'rename column':
return m.renameColumn(change, table);
case 'rename constraint':
return m.renameConstraint(change, table);
case 'drop column':
return m.dropColumn(change, table);
case 'owner':
return m.setTableOwner(change, table);
default:
throw NotSupported.never(change);
}
},

array: v => {
Expand Down Expand Up @@ -1183,6 +1214,10 @@ const visitor = astVisitor<IAstFullVisitor>(m => ({
m.expr(s.limit.limit);
}
}

if (s.for) {
ret.push('FOR ', s.for.type.toUpperCase());
}
},

show: s => {
Expand Down

0 comments on commit 9ca2e91

Please sign in to comment.