happy-sql 2.2.1 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ChangeLog +86 -0
- package/bin/convert.js +3 -9
- package/lib/parser/visitors/clause/alter-table/alter-table.js +21 -0
- package/lib/parser/visitors/clause/binary.js +30 -6
- package/lib/parser/visitors/clause/column-definition/column-definition.js +49 -8
- package/lib/parser/visitors/clause/count/count.js +5 -2
- package/lib/parser/visitors/clause/create-extension/create-extension.js +7 -0
- package/lib/parser/visitors/clause/create-index/create-index.js +36 -5
- package/lib/parser/visitors/clause/create-schema/create-schema.js +7 -0
- package/lib/parser/visitors/clause/create-table/create-table.js +58 -7
- package/lib/parser/visitors/clause/create-view/create-view.js +17 -0
- package/lib/parser/visitors/clause/drop-index/drop-index.js +3 -0
- package/lib/parser/visitors/clause/drop-view/drop-view.js +15 -0
- package/lib/parser/visitors/clause/explain/explain.js +16 -0
- package/lib/parser/visitors/clause/from/from.js +93 -4
- package/lib/parser/visitors/clause/from/limit.js +13 -0
- package/lib/parser/visitors/clause/from/order-by.js +14 -3
- package/lib/parser/visitors/clause/from/table-func.js +5 -18
- package/lib/parser/visitors/clause/grant/grant.js +26 -0
- package/lib/parser/visitors/clause/index.js +50 -2
- package/lib/parser/visitors/clause/insert/insert.js +64 -6
- package/lib/parser/visitors/clause/operand.js +55 -1
- package/lib/parser/visitors/clause/pragma/pragma.js +52 -2
- package/lib/parser/visitors/clause/select/select.js +139 -6
- package/lib/parser/visitors/clause/set-param/set-param.js +19 -0
- package/lib/parser/visitors/clause/table-constraint.js +27 -0
- package/lib/parser/visitors/clause/union/union.js +14 -2
- package/lib/parser/visitors/clause/update/update.js +17 -0
- package/lib/parser/visitors/clause/where/where.js +17 -0
- package/lib/printer/visitors/call-expression/clauses/access-method/access-method.js +4 -0
- package/lib/printer/visitors/call-expression/clauses/analyze/analyze.js +10 -0
- package/lib/printer/visitors/call-expression/clauses/array-type/array-type.js +4 -0
- package/lib/printer/visitors/call-expression/clauses/clauses.js +138 -2
- package/lib/printer/visitors/call-expression/clauses/collate/collate.js +7 -0
- package/lib/printer/visitors/call-expression/clauses/concurrently/concurrently.js +2 -0
- package/lib/printer/visitors/call-expression/clauses/constraint/constraint.js +11 -0
- package/lib/printer/visitors/call-expression/clauses/count-distinct/count-distinct.js +13 -0
- package/lib/printer/visitors/call-expression/clauses/create-extension/create-extension.js +4 -0
- package/lib/printer/visitors/call-expression/clauses/create-index/create-index.js +43 -9
- package/lib/printer/visitors/call-expression/clauses/create-index/create-unique-index.js +5 -19
- package/lib/printer/visitors/call-expression/clauses/create-materialized-view/create-materialized-view.js +8 -0
- package/lib/printer/visitors/call-expression/clauses/create-schema/create-schema.js +4 -0
- package/lib/printer/visitors/call-expression/clauses/create-table/create-table.js +16 -1
- package/lib/printer/visitors/call-expression/clauses/create-table-as/create-table-as.js +8 -0
- package/lib/printer/visitors/call-expression/clauses/create-temp-table/create-temp-table.js +11 -0
- package/lib/printer/visitors/call-expression/clauses/create-view/create-view.js +8 -0
- package/lib/printer/visitors/call-expression/clauses/create-virtual-table/create-virtual-table.js +8 -0
- package/lib/printer/visitors/call-expression/clauses/{nextval/nextval.js → default-nextval/default-nextval.js} +2 -1
- package/lib/printer/visitors/call-expression/clauses/default-values/default-values.js +3 -0
- package/lib/printer/visitors/call-expression/clauses/detach/detach.js +6 -0
- package/lib/printer/visitors/call-expression/clauses/distinct-on/distinct-on.js +14 -0
- package/lib/printer/visitors/call-expression/clauses/do-block/do-block.js +5 -0
- package/lib/printer/visitors/call-expression/clauses/drop-index/drop-index.js +13 -1
- package/lib/printer/visitors/call-expression/clauses/drop-view/drop-view.js +24 -0
- package/lib/printer/visitors/call-expression/clauses/except/except.js +9 -0
- package/lib/printer/visitors/call-expression/clauses/explain/explain.js +4 -0
- package/lib/printer/visitors/call-expression/clauses/explain-analyze/explain-analyze.js +4 -0
- package/lib/printer/visitors/call-expression/clauses/explain-query-plan/explain-query-plan.js +4 -0
- package/lib/printer/visitors/call-expression/clauses/fetch-first/fetch-first.js +5 -0
- package/lib/printer/visitors/call-expression/clauses/filter/filter.js +8 -0
- package/lib/printer/visitors/call-expression/clauses/for-update/for-update.js +3 -0
- package/lib/printer/visitors/call-expression/clauses/from/from.js +34 -3
- package/lib/printer/visitors/call-expression/clauses/generated-always-as/generated-always-as.js +10 -0
- package/lib/printer/visitors/call-expression/clauses/grant/grant.js +10 -0
- package/lib/printer/visitors/call-expression/clauses/grant-on/grant-on.js +10 -0
- package/lib/printer/visitors/call-expression/clauses/if-not-exists/if-not-exists.js +2 -0
- package/lib/printer/visitors/call-expression/clauses/indexed-by/indexed-by.js +7 -0
- package/lib/printer/visitors/call-expression/clauses/intersect/intersect.js +9 -0
- package/lib/printer/visitors/call-expression/clauses/into/into.js +30 -2
- package/lib/printer/visitors/call-expression/clauses/json-op.js +1 -0
- package/lib/printer/visitors/call-expression/clauses/lateral-join/lateral-join.js +26 -3
- package/lib/printer/visitors/call-expression/clauses/like/like.js +7 -0
- package/lib/printer/visitors/call-expression/clauses/limit-all/limit-all.js +3 -0
- package/lib/printer/visitors/call-expression/clauses/limit-clauses.js +4 -0
- package/lib/printer/visitors/call-expression/clauses/named-window/named-window.js +16 -0
- package/lib/printer/visitors/call-expression/clauses/not/not.js +4 -0
- package/lib/printer/visitors/call-expression/clauses/not-indexed/not-indexed.js +4 -0
- package/lib/printer/visitors/call-expression/clauses/nulls-order/nulls-order.js +9 -0
- package/lib/printer/visitors/call-expression/clauses/offset/offset.js +4 -0
- package/lib/printer/visitors/call-expression/clauses/on-conflict/on-conflict.js +16 -1
- package/lib/printer/visitors/call-expression/clauses/on-delete/on-delete.js +32 -0
- package/lib/printer/visitors/call-expression/clauses/or-abort/or-abort.js +3 -0
- package/lib/printer/visitors/call-expression/clauses/or-fail/or-fail.js +3 -0
- package/lib/printer/visitors/call-expression/clauses/over/over.js +12 -0
- package/lib/printer/visitors/call-expression/clauses/pragma/pragma.js +14 -5
- package/lib/printer/visitors/call-expression/clauses/privilege/privilege.js +10 -0
- package/lib/printer/visitors/call-expression/clauses/references/references.js +14 -4
- package/lib/printer/visitors/call-expression/clauses/reindex/reindex.js +10 -0
- package/lib/printer/visitors/call-expression/clauses/release-savepoint/release-savepoint.js +4 -0
- package/lib/printer/visitors/call-expression/clauses/rename-table/rename-table.js +4 -0
- package/lib/printer/visitors/call-expression/clauses/replace-into/replace-into.js +11 -0
- package/lib/printer/visitors/call-expression/clauses/right-outer-join/right-outer-join.js +8 -0
- package/lib/printer/visitors/call-expression/clauses/row-level-security/row-level-security.js +7 -0
- package/lib/printer/visitors/call-expression/clauses/select/select.js +37 -9
- package/lib/printer/visitors/call-expression/clauses/set-param/set-param.js +14 -0
- package/lib/printer/visitors/call-expression/clauses/show-param/show-param.js +4 -0
- package/lib/printer/visitors/call-expression/clauses/table-primary-key/table-primary-key.js +13 -0
- package/lib/printer/visitors/call-expression/clauses/table-unique/table-unique.js +13 -0
- package/lib/printer/visitors/call-expression/clauses/to/to.js +10 -0
- package/lib/printer/visitors/call-expression/clauses/truncate/truncate.js +12 -0
- package/lib/printer/visitors/call-expression/clauses/unary-minus/unary-minus.js +4 -0
- package/lib/printer/visitors/call-expression/clauses/update/update.js +24 -3
- package/lib/printer/visitors/call-expression/clauses/using/using.js +13 -0
- package/lib/printer/visitors/call-expression/clauses/vacuum/vacuum.js +8 -1
- package/lib/printer/visitors/call-expression/clauses/window-frame/window-frame.js +38 -0
- package/lib/printer/visitors/call-expression/clauses/with-named/with-named.js +8 -20
- package/lib/printer/visitors/call-expression/clauses/without-rowid/without-rowid.js +1 -0
- package/lib/printer/visitors/member-expression.js +14 -0
- package/lib/printer/visitors/string-literal.js +9 -5
- package/package.json +9 -2
|
@@ -7,8 +7,18 @@ import {convertFrom} from '#parser/clause/from';
|
|
|
7
7
|
import {convertCount, isCount} from '#parser/clause/count';
|
|
8
8
|
import {convertCaseWhen} from '#parser/clause/case-when';
|
|
9
9
|
import {convertBinary} from '#parser/clause/binary';
|
|
10
|
+
import {
|
|
11
|
+
convertCondition,
|
|
12
|
+
convertBetween,
|
|
13
|
+
} from '#parser/clause/where';
|
|
10
14
|
import {findClause} from '#parser/clause/find';
|
|
11
15
|
import {convertOrderBy} from '../from/order-by.js';
|
|
16
|
+
import {
|
|
17
|
+
convertLimit,
|
|
18
|
+
convertOffset,
|
|
19
|
+
convertFetch,
|
|
20
|
+
convertForUpdate,
|
|
21
|
+
} from '../from/limit.js';
|
|
12
22
|
|
|
13
23
|
const isString = (a) => typeof a === 'string';
|
|
14
24
|
|
|
@@ -48,16 +58,29 @@ const convertExtract = (column) => {
|
|
|
48
58
|
]);
|
|
49
59
|
};
|
|
50
60
|
|
|
61
|
+
const convertFilter = (column, fn) => {
|
|
62
|
+
if (!column.filter)
|
|
63
|
+
return fn;
|
|
64
|
+
|
|
65
|
+
const {where} = column.filter;
|
|
66
|
+
const condition = convertCondition(where.expr.expr);
|
|
67
|
+
|
|
68
|
+
return callExpression(identifier('filter'), [fn, condition]);
|
|
69
|
+
};
|
|
70
|
+
|
|
51
71
|
const convertColumn = (column) => {
|
|
52
72
|
if (isCount(column))
|
|
53
|
-
return convertCount(column);
|
|
73
|
+
return convertOverIfPresent(column, convertFilter(column, convertCount(column)));
|
|
54
74
|
|
|
55
75
|
if (column.type === 'func_call')
|
|
56
|
-
return convertFuncCall(column);
|
|
76
|
+
return convertFilter(column, convertFuncCall(column));
|
|
57
77
|
|
|
58
78
|
if (column.type === 'cast_expr')
|
|
59
79
|
return convertCast(column);
|
|
60
80
|
|
|
81
|
+
if (column.type === 'cast_operator_expr')
|
|
82
|
+
return convertOperand(column);
|
|
83
|
+
|
|
61
84
|
if (column.type === 'extract_expr')
|
|
62
85
|
return convertExtract(column);
|
|
63
86
|
|
|
@@ -91,12 +114,63 @@ const convertColumn = (column) => {
|
|
|
91
114
|
if (column.type === 'array_literal_expr')
|
|
92
115
|
return convertOperand(column);
|
|
93
116
|
|
|
117
|
+
if (column.type === 'prefix_op_expr')
|
|
118
|
+
return convertOperand(column);
|
|
119
|
+
|
|
120
|
+
if (column.type === 'postfix_op_expr')
|
|
121
|
+
return convertCondition(column);
|
|
122
|
+
|
|
123
|
+
if (column.type === 'between_expr')
|
|
124
|
+
return convertBetween(column);
|
|
125
|
+
|
|
126
|
+
// quoted identifier like "weird col" — keep original text
|
|
127
|
+
if (isString(column.text) && column.text.startsWith('"'))
|
|
128
|
+
return stringLiteral(column.text);
|
|
129
|
+
|
|
94
130
|
return identifier(column.name);
|
|
95
131
|
};
|
|
96
132
|
|
|
133
|
+
const convertOverIfPresent = (column, fn) => {
|
|
134
|
+
if (!column.over)
|
|
135
|
+
return fn;
|
|
136
|
+
|
|
137
|
+
return convertOver(column, fn);
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
const isWindowRef = (over) => over.window.type === 'identifier';
|
|
141
|
+
|
|
142
|
+
const convertFrameBound = (bound) => {
|
|
143
|
+
if (bound.type === 'frame_bound_current_row')
|
|
144
|
+
return callExpression(identifier('currentRow'), []);
|
|
145
|
+
|
|
146
|
+
const name = bound.type === 'frame_bound_preceding' ? 'preceding' : 'following';
|
|
147
|
+
|
|
148
|
+
const isUnbounded = bound.expr?.type === 'frame_unbounded';
|
|
149
|
+
const args = !isUnbounded && bound.expr ? [
|
|
150
|
+
numericLiteral(bound.expr.value),
|
|
151
|
+
] : [];
|
|
152
|
+
|
|
153
|
+
return callExpression(identifier(name), args);
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
const convertFrame = ({extent}) => callExpression(identifier('rowsBetween'), [
|
|
157
|
+
convertFrameBound(extent.begin),
|
|
158
|
+
convertFrameBound(extent.end),
|
|
159
|
+
]);
|
|
160
|
+
|
|
97
161
|
const convertOverClause = (over) => {
|
|
162
|
+
if (isWindowRef(over))
|
|
163
|
+
return [
|
|
164
|
+
identifier(over.window.name),
|
|
165
|
+
];
|
|
166
|
+
|
|
98
167
|
const result = [];
|
|
99
|
-
|
|
168
|
+
|
|
169
|
+
const {
|
|
170
|
+
partitionBy,
|
|
171
|
+
orderBy,
|
|
172
|
+
frame,
|
|
173
|
+
} = over.window.expr;
|
|
100
174
|
|
|
101
175
|
if (partitionBy)
|
|
102
176
|
result.push(callExpression(identifier('partitionBy'), partitionBy.specifications.items.map(convertOperand)));
|
|
@@ -104,6 +178,9 @@ const convertOverClause = (over) => {
|
|
|
104
178
|
if (orderBy)
|
|
105
179
|
result.push(convertOrderBy(orderBy));
|
|
106
180
|
|
|
181
|
+
if (frame)
|
|
182
|
+
result.push(convertFrame(frame));
|
|
183
|
+
|
|
107
184
|
return result;
|
|
108
185
|
};
|
|
109
186
|
|
|
@@ -159,19 +236,57 @@ const convertColumns = (columns) => {
|
|
|
159
236
|
|
|
160
237
|
const isDistinct = (selectClause) => selectClause.modifiers.some(({type}) => type === 'select_distinct');
|
|
161
238
|
|
|
239
|
+
const convertDistinctOn = ({modifiers}) => {
|
|
240
|
+
if (!modifiers.some(({type}) => type === 'select_distinct_on'))
|
|
241
|
+
return null;
|
|
242
|
+
|
|
243
|
+
const modifier = modifiers.find(({type}) => type === 'select_distinct_on');
|
|
244
|
+
const onCols = [];
|
|
245
|
+
|
|
246
|
+
for (const item of modifier.columns.expr.items) {
|
|
247
|
+
onCols.push(identifier(item.name));
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
return callExpression(identifier('distinctOn'), onCols);
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
const convertValuesRow = (node) => {
|
|
254
|
+
const {items} = node.expr;
|
|
255
|
+
|
|
256
|
+
return callExpression(identifier('row'), items.map(convertOperand));
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
const convertValuesClause = (clause) => callExpression(identifier('values'), clause.values.items.map(convertValuesRow));
|
|
260
|
+
|
|
162
261
|
export const convertSelect = ({clauses}) => {
|
|
163
262
|
const selectClause = findClause(clauses, 'select_clause');
|
|
263
|
+
const valuesClause = findClause(clauses, 'values_clause');
|
|
264
|
+
|
|
265
|
+
if (!selectClause && valuesClause)
|
|
266
|
+
return convertValuesClause(valuesClause);
|
|
267
|
+
|
|
164
268
|
const fromClause = findClause(clauses, 'from_clause');
|
|
165
269
|
const whereClause = findClause(clauses, 'where_clause');
|
|
166
270
|
const groupByClause = findClause(clauses, 'group_by_clause');
|
|
167
271
|
const havingClause = findClause(clauses, 'having_clause');
|
|
168
272
|
const orderByClause = findClause(clauses, 'order_by_clause');
|
|
273
|
+
const windowClause = findClause(clauses, 'window_clause');
|
|
169
274
|
const limitClause = findClause(clauses, 'limit_clause');
|
|
275
|
+
const offsetClause = findClause(clauses, 'offset_clause');
|
|
276
|
+
const fetchClause = findClause(clauses, 'fetch_clause');
|
|
277
|
+
const forClause = findClause(clauses, 'for_clause');
|
|
170
278
|
|
|
171
279
|
const cols = convertColumns(selectClause.columns);
|
|
172
|
-
const
|
|
173
|
-
|
|
174
|
-
|
|
280
|
+
const distinctOn = convertDistinctOn(selectClause);
|
|
281
|
+
const selectArgs = [];
|
|
282
|
+
|
|
283
|
+
if (distinctOn)
|
|
284
|
+
selectArgs.push(distinctOn);
|
|
285
|
+
|
|
286
|
+
if (isDistinct(selectClause))
|
|
287
|
+
selectArgs.push(callExpression(identifier('distinct'), cols));
|
|
288
|
+
else
|
|
289
|
+
selectArgs.push(...cols);
|
|
175
290
|
|
|
176
291
|
const args = [
|
|
177
292
|
...selectArgs,
|
|
@@ -181,9 +296,27 @@ export const convertSelect = ({clauses}) => {
|
|
|
181
296
|
groupByClause,
|
|
182
297
|
havingClause,
|
|
183
298
|
orderByClause,
|
|
299
|
+
windowClause,
|
|
184
300
|
limitClause,
|
|
301
|
+
offsetClause,
|
|
302
|
+
fetchClause,
|
|
303
|
+
forClause,
|
|
185
304
|
}),
|
|
186
305
|
].filter(Boolean);
|
|
187
306
|
|
|
307
|
+
if (!fromClause) {
|
|
308
|
+
if (limitClause)
|
|
309
|
+
args.push(convertLimit(limitClause));
|
|
310
|
+
|
|
311
|
+
if (offsetClause)
|
|
312
|
+
args.push(convertOffset(offsetClause));
|
|
313
|
+
|
|
314
|
+
if (fetchClause)
|
|
315
|
+
args.push(convertFetch(fetchClause));
|
|
316
|
+
|
|
317
|
+
if (forClause)
|
|
318
|
+
args.push(convertForUpdate());
|
|
319
|
+
}
|
|
320
|
+
|
|
188
321
|
return callExpression(identifier('select'), args);
|
|
189
322
|
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import {types} from '@putout/babel';
|
|
2
|
+
import {convertOperand} from '#parser/clause/operand';
|
|
3
|
+
|
|
4
|
+
const {identifier, callExpression} = types;
|
|
5
|
+
|
|
6
|
+
export const convertSetParam = (stmt) => {
|
|
7
|
+
const args = [
|
|
8
|
+
identifier(stmt.name.name),
|
|
9
|
+
];
|
|
10
|
+
|
|
11
|
+
for (const item of stmt.value.items)
|
|
12
|
+
args.push(convertOperand(item));
|
|
13
|
+
|
|
14
|
+
return callExpression(identifier('setParam'), args);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const convertShowParam = (stmt) => callExpression(identifier('showParam'), [
|
|
18
|
+
identifier(stmt.name.name),
|
|
19
|
+
]);
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import {types} from '@putout/babel';
|
|
2
|
+
|
|
3
|
+
const {identifier, callExpression} = types;
|
|
4
|
+
|
|
5
|
+
export const convertConstraintColumn = (item) => {
|
|
6
|
+
if (item.expr)
|
|
7
|
+
return identifier(item.expr.name);
|
|
8
|
+
|
|
9
|
+
return identifier(item.name);
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const convertConstraintColumns = ({columns}) => columns.expr.items.map(convertConstraintColumn);
|
|
13
|
+
|
|
14
|
+
export const TABLE_CONSTRAINTS = {
|
|
15
|
+
constraint_primary_key: (item) => callExpression(identifier('tablePrimaryKey'), convertConstraintColumns(item)),
|
|
16
|
+
constraint_unique: (item) => callExpression(identifier('tableUnique'), convertConstraintColumns(item)),
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const convertTableConstraint = (item) => {
|
|
20
|
+
if (item.type === 'constraint')
|
|
21
|
+
return callExpression(identifier('constraint'), [
|
|
22
|
+
identifier(item.name.name.name),
|
|
23
|
+
convertTableConstraint(item.constraint),
|
|
24
|
+
]);
|
|
25
|
+
|
|
26
|
+
return TABLE_CONSTRAINTS[item.type](item);
|
|
27
|
+
};
|
|
@@ -16,10 +16,22 @@ const getOpNames = (operator) => {
|
|
|
16
16
|
return [operator.name];
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
+
const getName = (ops) => {
|
|
20
|
+
if (ops.includes('INTERSECT'))
|
|
21
|
+
return 'intersect';
|
|
22
|
+
|
|
23
|
+
if (ops.includes('EXCEPT'))
|
|
24
|
+
return 'except';
|
|
25
|
+
|
|
26
|
+
if (ops.includes('ALL'))
|
|
27
|
+
return 'unionAll';
|
|
28
|
+
|
|
29
|
+
return 'union';
|
|
30
|
+
};
|
|
31
|
+
|
|
19
32
|
export const convertUnion = (stmt) => {
|
|
20
33
|
const ops = getOpNames(stmt.operator);
|
|
21
|
-
const
|
|
22
|
-
const name = isAll ? 'unionAll' : 'union';
|
|
34
|
+
const name = getName(ops);
|
|
23
35
|
|
|
24
36
|
return callExpression(identifier(name), [
|
|
25
37
|
convertClause(stmt.left),
|
|
@@ -10,6 +10,20 @@ const {
|
|
|
10
10
|
callExpression,
|
|
11
11
|
} = types;
|
|
12
12
|
|
|
13
|
+
const OR_ACTION_MAP = {
|
|
14
|
+
REPLACE: () => callExpression(identifier('orReplace'), []),
|
|
15
|
+
IGNORE: () => callExpression(identifier('orIgnore'), []),
|
|
16
|
+
ABORT: () => callExpression(identifier('orAbort'), []),
|
|
17
|
+
FAIL: () => callExpression(identifier('orFail'), []),
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const convertOrAction = (orAction) => {
|
|
21
|
+
if (!orAction)
|
|
22
|
+
return null;
|
|
23
|
+
|
|
24
|
+
return OR_ACTION_MAP[orAction.actionKw.name]();
|
|
25
|
+
};
|
|
26
|
+
|
|
13
27
|
export const convertUpdate = ({clauses}) => {
|
|
14
28
|
const updateClause = findClause(clauses, 'update_clause');
|
|
15
29
|
const setClause = findClause(clauses, 'set_clause');
|
|
@@ -26,7 +40,10 @@ export const convertUpdate = ({clauses}) => {
|
|
|
26
40
|
|
|
27
41
|
const setCall = callExpression(identifier('set'), setArgs);
|
|
28
42
|
|
|
43
|
+
const orAction = convertOrAction(updateClause.orAction);
|
|
44
|
+
|
|
29
45
|
const args = [
|
|
46
|
+
orAction,
|
|
30
47
|
table,
|
|
31
48
|
setCall,
|
|
32
49
|
fromClause && convertFromClause(fromClause),
|
|
@@ -31,6 +31,20 @@ const isExists = (node) => node.type === 'prefix_op_expr' && node.operator.name
|
|
|
31
31
|
const isNotExists = (node) => node.type === 'prefix_op_expr' && node.operator.name === 'NOT' && isExists(node.expr);
|
|
32
32
|
const isParenExpr = (node) => node.type === 'paren_expr';
|
|
33
33
|
|
|
34
|
+
const POSTFIX_OP = {
|
|
35
|
+
ISNULL: 'isNull',
|
|
36
|
+
NOTNULL: 'isNotNull',
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const convertPostfix = (node) => {
|
|
40
|
+
const {name} = node.operator;
|
|
41
|
+
const fn = POSTFIX_OP[name];
|
|
42
|
+
|
|
43
|
+
return callExpression(identifier(fn), [
|
|
44
|
+
convertOperand(node.expr),
|
|
45
|
+
]);
|
|
46
|
+
};
|
|
47
|
+
|
|
34
48
|
export const convertCondition = (node) => {
|
|
35
49
|
if (node.operator && node.operator.name === 'AND')
|
|
36
50
|
return convertAnd(node);
|
|
@@ -41,6 +55,9 @@ export const convertCondition = (node) => {
|
|
|
41
55
|
if (node.type === 'between_expr')
|
|
42
56
|
return convertBetween(node);
|
|
43
57
|
|
|
58
|
+
if (node.type === 'postfix_op_expr')
|
|
59
|
+
return convertPostfix(node);
|
|
60
|
+
|
|
44
61
|
if (isNotExists(node))
|
|
45
62
|
return callExpression(identifier('notExists'), [
|
|
46
63
|
convertClause(node.expr.expr.expr),
|
|
@@ -10,6 +10,7 @@ import {select} from './select/select.js';
|
|
|
10
10
|
import {from} from './from/from.js';
|
|
11
11
|
import {where} from './where/where.js';
|
|
12
12
|
import {insert} from './insert/insert.js';
|
|
13
|
+
import {replaceInto} from './replace-into/replace-into.js';
|
|
13
14
|
import {into} from './into/into.js';
|
|
14
15
|
import {values} from './values/values.js';
|
|
15
16
|
import {onConflict} from './on-conflict/on-conflict.js';
|
|
@@ -24,6 +25,8 @@ import {withNamed} from './with-named/with-named.js';
|
|
|
24
25
|
import {withRecursive} from './with-recursive/with-recursive.js';
|
|
25
26
|
import {unionAll} from './union-all/union-all.js';
|
|
26
27
|
import {union} from './union/union.js';
|
|
28
|
+
import {intersect} from './intersect/intersect.js';
|
|
29
|
+
import {except} from './except/except.js';
|
|
27
30
|
import {groupBy} from './group-by/group-by.js';
|
|
28
31
|
import {having} from './having/having.js';
|
|
29
32
|
import {sum} from './sum/sum.js';
|
|
@@ -33,7 +36,9 @@ import {max} from './max/max.js';
|
|
|
33
36
|
import {orderBy} from './order-by/order-by.js';
|
|
34
37
|
import {desc} from './desc/desc.js';
|
|
35
38
|
import {limit} from './limit/limit.js';
|
|
39
|
+
import {namedWindow} from './named-window/named-window.js';
|
|
36
40
|
import {distinct} from './distinct/distinct.js';
|
|
41
|
+
import {distinctOn} from './distinct-on/distinct-on.js';
|
|
37
42
|
import {notInList} from './not-in-list/not-in-list.js';
|
|
38
43
|
import {between} from './between/between.js';
|
|
39
44
|
import {notBetween} from './not-between/not-between.js';
|
|
@@ -49,7 +54,31 @@ import {lateralJoin} from './lateral-join/lateral-join.js';
|
|
|
49
54
|
import {lateralSubquery} from './lateral-subquery/lateral-subquery.js';
|
|
50
55
|
import {createIndex} from './create-index/create-index.js';
|
|
51
56
|
import {createUniqueIndex} from './create-index/create-unique-index.js';
|
|
57
|
+
import {concurrently} from './concurrently/concurrently.js';
|
|
58
|
+
import {ifNotExists} from './if-not-exists/if-not-exists.js';
|
|
59
|
+
import {explain} from './explain/explain.js';
|
|
60
|
+
import {explainAnalyze} from './explain-analyze/explain-analyze.js';
|
|
61
|
+
import {explainQueryPlan} from './explain-query-plan/explain-query-plan.js';
|
|
62
|
+
import {setParam} from './set-param/set-param.js';
|
|
63
|
+
import {showParam} from './show-param/show-param.js';
|
|
64
|
+
import {createView} from './create-view/create-view.js';
|
|
65
|
+
import {createMaterializedView} from './create-materialized-view/create-materialized-view.js';
|
|
66
|
+
import {dropView} from './drop-view/drop-view.js';
|
|
67
|
+
import {createExtension} from './create-extension/create-extension.js';
|
|
68
|
+
import {createSchema} from './create-schema/create-schema.js';
|
|
69
|
+
import {grant} from './grant/grant.js';
|
|
70
|
+
import {privilege} from './privilege/privilege.js';
|
|
71
|
+
import {grantOn} from './grant-on/grant-on.js';
|
|
72
|
+
import {to} from './to/to.js';
|
|
73
|
+
import {indexedBy} from './indexed-by/indexed-by.js';
|
|
74
|
+
import {notIndexed} from './not-indexed/not-indexed.js';
|
|
75
|
+
import {createVirtualTable} from './create-virtual-table/create-virtual-table.js';
|
|
76
|
+
import {reindex} from './reindex/reindex.js';
|
|
77
|
+
import {analyze} from './analyze/analyze.js';
|
|
78
|
+
import {releaseSavepoint} from './release-savepoint/release-savepoint.js';
|
|
79
|
+
import {doBlock} from './do-block/do-block.js';
|
|
52
80
|
import {vacuum} from './vacuum/vacuum.js';
|
|
81
|
+
import {truncate} from './truncate/truncate.js';
|
|
53
82
|
import {row} from './row/row.js';
|
|
54
83
|
import {notNull} from './not-null/not-null.js';
|
|
55
84
|
import {default_} from './default/default.js';
|
|
@@ -62,8 +91,21 @@ import {leftJoin} from './left-join/left-join.js';
|
|
|
62
91
|
import {rightJoin} from './right-join/right-join.js';
|
|
63
92
|
import {innerJoin} from './inner-join/inner-join.js';
|
|
64
93
|
import {leftOuterJoin} from './left-outer-join/left-outer-join.js';
|
|
94
|
+
import {rightOuterJoin} from './right-outer-join/right-outer-join.js';
|
|
65
95
|
import {crossJoin} from './cross-join/cross-join.js';
|
|
66
96
|
import {createTable} from './create-table/create-table.js';
|
|
97
|
+
import {
|
|
98
|
+
limitAll,
|
|
99
|
+
offset,
|
|
100
|
+
fetchFirst,
|
|
101
|
+
forUpdate,
|
|
102
|
+
} from './limit-clauses.js';
|
|
103
|
+
import {
|
|
104
|
+
createTempTable,
|
|
105
|
+
createTempTableIfNotExists,
|
|
106
|
+
} from './create-temp-table/create-temp-table.js';
|
|
107
|
+
import {withoutRowid} from './without-rowid/without-rowid.js';
|
|
108
|
+
import {createTableAs} from './create-table-as/create-table-as.js';
|
|
67
109
|
import {alterTable} from './alter-table/alter-table.js';
|
|
68
110
|
import {addColumn} from './add-column/add-column.js';
|
|
69
111
|
import {dropColumn} from './drop-column/drop-column.js';
|
|
@@ -77,6 +119,7 @@ import {savepoint} from './savepoint/savepoint.js';
|
|
|
77
119
|
import {createSequence} from './create-sequence/create-sequence.js';
|
|
78
120
|
import {extract} from './extract/extract.js';
|
|
79
121
|
import {concat} from './concat/concat.js';
|
|
122
|
+
import {filter} from './filter/filter.js';
|
|
80
123
|
import {array} from './array/array.js';
|
|
81
124
|
import {over} from './over/over.js';
|
|
82
125
|
import {partitionBy} from './partition-by/partition-by.js';
|
|
@@ -85,13 +128,14 @@ import {dropTable} from './drop-table/drop-table.js';
|
|
|
85
128
|
import {dropIndex} from './drop-index/drop-index.js';
|
|
86
129
|
import {pragma} from './pragma/pragma.js';
|
|
87
130
|
import {attach} from './attach/attach.js';
|
|
131
|
+
import {detach} from './detach/detach.js';
|
|
88
132
|
import {column} from './column/column.js';
|
|
89
133
|
import {autoIncrement} from './auto-increment/auto-increment.js';
|
|
90
134
|
import {serial} from './serial/serial.js';
|
|
91
135
|
import {primaryKey} from './primary-key/primary-key.js';
|
|
92
136
|
import {lastInsertRowid} from './last-insert-rowid/last-insert-rowid.js';
|
|
93
137
|
import {lastval} from './lastval/lastval.js';
|
|
94
|
-
import {
|
|
138
|
+
import {defaultNextval} from './default-nextval/default-nextval.js';
|
|
95
139
|
import {like} from './like/like.js';
|
|
96
140
|
import {isNull, isNotNull} from './is-null/is-null.js';
|
|
97
141
|
import {orReplace} from './or-replace/or-replace.js';
|
|
@@ -101,6 +145,33 @@ import {
|
|
|
101
145
|
identity,
|
|
102
146
|
identityByDefault,
|
|
103
147
|
} from './identity/identity.js';
|
|
148
|
+
import {not} from './not/not.js';
|
|
149
|
+
import {unaryMinus} from './unary-minus/unary-minus.js';
|
|
150
|
+
import {arrayType} from './array-type/array-type.js';
|
|
151
|
+
import {using} from './using/using.js';
|
|
152
|
+
import {defaultValues} from './default-values/default-values.js';
|
|
153
|
+
import {tablePrimaryKey} from './table-primary-key/table-primary-key.js';
|
|
154
|
+
import {tableUnique} from './table-unique/table-unique.js';
|
|
155
|
+
import {constraint} from './constraint/constraint.js';
|
|
156
|
+
import {renameTable} from './rename-table/rename-table.js';
|
|
157
|
+
import {
|
|
158
|
+
enableRowLevelSecurity,
|
|
159
|
+
disableRowLevelSecurity,
|
|
160
|
+
} from './row-level-security/row-level-security.js';
|
|
161
|
+
import {nullsFirst, nullsLast} from './nulls-order/nulls-order.js';
|
|
162
|
+
import {orAbort} from './or-abort/or-abort.js';
|
|
163
|
+
import {orFail} from './or-fail/or-fail.js';
|
|
164
|
+
import {countDistinct} from './count-distinct/count-distinct.js';
|
|
165
|
+
import {generatedAlwaysAs} from './generated-always-as/generated-always-as.js';
|
|
166
|
+
import {accessMethod} from './access-method/access-method.js';
|
|
167
|
+
import {onDelete, onUpdate} from './on-delete/on-delete.js';
|
|
168
|
+
import {collate} from './collate/collate.js';
|
|
169
|
+
import {
|
|
170
|
+
rowsBetween,
|
|
171
|
+
preceding,
|
|
172
|
+
following,
|
|
173
|
+
currentRow,
|
|
174
|
+
} from './window-frame/window-frame.js';
|
|
104
175
|
|
|
105
176
|
export const clauses = {
|
|
106
177
|
join,
|
|
@@ -110,6 +181,7 @@ export const clauses = {
|
|
|
110
181
|
select,
|
|
111
182
|
where,
|
|
112
183
|
insert,
|
|
184
|
+
replaceInto,
|
|
113
185
|
into,
|
|
114
186
|
orReplace,
|
|
115
187
|
orIgnore,
|
|
@@ -120,7 +192,31 @@ export const clauses = {
|
|
|
120
192
|
lateralSubquery,
|
|
121
193
|
createIndex,
|
|
122
194
|
createUniqueIndex,
|
|
195
|
+
concurrently,
|
|
196
|
+
ifNotExists,
|
|
197
|
+
explain,
|
|
198
|
+
explainAnalyze,
|
|
199
|
+
explainQueryPlan,
|
|
200
|
+
setParam,
|
|
201
|
+
showParam,
|
|
202
|
+
createView,
|
|
203
|
+
createMaterializedView,
|
|
204
|
+
dropView,
|
|
205
|
+
createExtension,
|
|
206
|
+
createSchema,
|
|
207
|
+
grant,
|
|
208
|
+
privilege,
|
|
209
|
+
grantOn,
|
|
210
|
+
to,
|
|
211
|
+
indexedBy,
|
|
212
|
+
notIndexed,
|
|
213
|
+
createVirtualTable,
|
|
214
|
+
reindex,
|
|
215
|
+
analyze,
|
|
216
|
+
releaseSavepoint,
|
|
217
|
+
doBlock,
|
|
123
218
|
vacuum,
|
|
219
|
+
truncate,
|
|
124
220
|
row,
|
|
125
221
|
notNull,
|
|
126
222
|
default_,
|
|
@@ -140,6 +236,8 @@ export const clauses = {
|
|
|
140
236
|
withRecursive,
|
|
141
237
|
unionAll,
|
|
142
238
|
union,
|
|
239
|
+
intersect,
|
|
240
|
+
except,
|
|
143
241
|
groupBy,
|
|
144
242
|
having,
|
|
145
243
|
sum,
|
|
@@ -149,7 +247,13 @@ export const clauses = {
|
|
|
149
247
|
orderBy,
|
|
150
248
|
desc,
|
|
151
249
|
limit,
|
|
250
|
+
limitAll,
|
|
251
|
+
offset,
|
|
252
|
+
fetchFirst,
|
|
253
|
+
forUpdate,
|
|
254
|
+
namedWindow,
|
|
152
255
|
distinct,
|
|
256
|
+
distinctOn,
|
|
153
257
|
notInList,
|
|
154
258
|
notBetween,
|
|
155
259
|
between,
|
|
@@ -163,10 +267,15 @@ export const clauses = {
|
|
|
163
267
|
rightJoin,
|
|
164
268
|
innerJoin,
|
|
165
269
|
leftOuterJoin,
|
|
270
|
+
rightOuterJoin,
|
|
166
271
|
fullOuterJoin,
|
|
167
272
|
naturalJoin,
|
|
168
273
|
crossJoin,
|
|
169
274
|
createTable,
|
|
275
|
+
createTempTable,
|
|
276
|
+
createTempTableIfNotExists,
|
|
277
|
+
withoutRowid,
|
|
278
|
+
createTableAs,
|
|
170
279
|
alterTable,
|
|
171
280
|
addColumn,
|
|
172
281
|
dropColumn,
|
|
@@ -180,6 +289,7 @@ export const clauses = {
|
|
|
180
289
|
createSequence,
|
|
181
290
|
extract,
|
|
182
291
|
concat,
|
|
292
|
+
filter,
|
|
183
293
|
array,
|
|
184
294
|
over,
|
|
185
295
|
partitionBy,
|
|
@@ -188,21 +298,47 @@ export const clauses = {
|
|
|
188
298
|
dropIndex,
|
|
189
299
|
pragma,
|
|
190
300
|
attach,
|
|
301
|
+
detach,
|
|
191
302
|
column,
|
|
192
303
|
autoIncrement,
|
|
193
304
|
serial,
|
|
194
305
|
primaryKey,
|
|
195
306
|
lastInsertRowid,
|
|
196
307
|
lastval,
|
|
197
|
-
|
|
308
|
+
defaultNextval,
|
|
198
309
|
like,
|
|
199
310
|
notLike,
|
|
200
311
|
ilike,
|
|
201
312
|
similarTo,
|
|
202
313
|
isDistinctFrom,
|
|
314
|
+
collate,
|
|
203
315
|
isNull,
|
|
204
316
|
isNotNull,
|
|
205
317
|
inList,
|
|
206
318
|
identity,
|
|
207
319
|
identityByDefault,
|
|
320
|
+
not,
|
|
321
|
+
unaryMinus,
|
|
322
|
+
arrayType,
|
|
323
|
+
using,
|
|
324
|
+
defaultValues,
|
|
325
|
+
tablePrimaryKey,
|
|
326
|
+
tableUnique,
|
|
327
|
+
constraint,
|
|
328
|
+
renameTable,
|
|
329
|
+
enableRowLevelSecurity,
|
|
330
|
+
disableRowLevelSecurity,
|
|
331
|
+
nullsFirst,
|
|
332
|
+
nullsLast,
|
|
333
|
+
orAbort,
|
|
334
|
+
orFail,
|
|
335
|
+
countDistinct,
|
|
336
|
+
generatedAlwaysAs,
|
|
337
|
+
accessMethod,
|
|
338
|
+
onDelete,
|
|
339
|
+
onUpdate,
|
|
340
|
+
rowsBetween,
|
|
341
|
+
preceding,
|
|
342
|
+
following,
|
|
343
|
+
currentRow,
|
|
208
344
|
};
|