kysely 0.9.2 → 0.9.3
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/dist/cjs/operation-node/operation-node-transformer.d.ts +2 -0
- package/dist/cjs/operation-node/operation-node-transformer.js +9 -0
- package/dist/cjs/operation-node/operation-node-visitor.d.ts +61 -59
- package/dist/cjs/operation-node/operation-node-visitor.js +1 -316
- package/dist/cjs/operation-node/operation-node.d.ts +1 -1
- package/dist/cjs/operation-node/select-query-node.d.ts +3 -0
- package/dist/cjs/operation-node/select-query-node.js +8 -0
- package/dist/cjs/operation-node/union-node.d.ts +16 -0
- package/dist/cjs/operation-node/union-node.js +19 -0
- package/dist/cjs/parser/insert-values-parser.d.ts +1 -1
- package/dist/cjs/parser/union-parser.d.ts +5 -0
- package/dist/cjs/parser/union-parser.js +13 -0
- package/dist/cjs/parser/value-parser.d.ts +1 -1
- package/dist/cjs/query-builder/query-builder.d.ts +30 -1
- package/dist/cjs/query-builder/query-builder.js +46 -0
- package/dist/cjs/query-compiler/default-query-compiler.d.ts +5 -0
- package/dist/cjs/query-compiler/default-query-compiler.js +18 -1
- package/dist/esm/operation-node/operation-node-transformer.d.ts +2 -0
- package/dist/esm/operation-node/operation-node-transformer.js +9 -0
- package/dist/esm/operation-node/operation-node-visitor.d.ts +61 -59
- package/dist/esm/operation-node/operation-node-visitor.js +1 -316
- package/dist/esm/operation-node/operation-node.d.ts +1 -1
- package/dist/esm/operation-node/select-query-node.d.ts +3 -0
- package/dist/esm/operation-node/select-query-node.js +8 -0
- package/dist/esm/operation-node/union-node.d.ts +16 -0
- package/dist/esm/operation-node/union-node.js +16 -0
- package/dist/esm/parser/insert-values-parser.d.ts +1 -1
- package/dist/esm/parser/union-parser.d.ts +5 -0
- package/dist/esm/parser/union-parser.js +9 -0
- package/dist/esm/parser/value-parser.d.ts +1 -1
- package/dist/esm/query-builder/query-builder.d.ts +30 -1
- package/dist/esm/query-builder/query-builder.js +46 -0
- package/dist/esm/query-compiler/default-query-compiler.d.ts +5 -0
- package/dist/esm/query-compiler/default-query-compiler.js +18 -1
- package/package.json +1 -1
|
@@ -59,326 +59,11 @@ export class OperationNodeVisitor {
|
|
|
59
59
|
AddConstraintNode: this.visitAddConstraint.bind(this),
|
|
60
60
|
DropConstraintNode: this.visitDropConstraint.bind(this),
|
|
61
61
|
ForeignKeyConstraintNode: this.visitForeignKeyConstraint.bind(this),
|
|
62
|
+
UnionNode: this.visitUnion.bind(this),
|
|
62
63
|
};
|
|
63
64
|
visitNode = (node) => {
|
|
64
65
|
this.nodeStack.push(node);
|
|
65
66
|
this.#visitors[node.kind](node);
|
|
66
67
|
this.nodeStack.pop();
|
|
67
68
|
};
|
|
68
|
-
visitSelectQuery(node) {
|
|
69
|
-
if (node.with) {
|
|
70
|
-
this.visitNode(node.with);
|
|
71
|
-
}
|
|
72
|
-
if (node.distinctOnSelections) {
|
|
73
|
-
node.distinctOnSelections.forEach(this.visitNode);
|
|
74
|
-
}
|
|
75
|
-
if (node.selections) {
|
|
76
|
-
node.selections.forEach(this.visitNode);
|
|
77
|
-
}
|
|
78
|
-
this.visitNode(node.from);
|
|
79
|
-
if (node.joins) {
|
|
80
|
-
node.joins.forEach(this.visitNode);
|
|
81
|
-
}
|
|
82
|
-
if (node.where) {
|
|
83
|
-
this.visitNode(node.where);
|
|
84
|
-
}
|
|
85
|
-
if (node.groupBy) {
|
|
86
|
-
this.visitNode(node.groupBy);
|
|
87
|
-
}
|
|
88
|
-
if (node.having) {
|
|
89
|
-
this.visitNode(node.having);
|
|
90
|
-
}
|
|
91
|
-
if (node.orderBy) {
|
|
92
|
-
this.visitNode(node.orderBy);
|
|
93
|
-
}
|
|
94
|
-
if (node.limit) {
|
|
95
|
-
this.visitNode(node.limit);
|
|
96
|
-
}
|
|
97
|
-
if (node.offset) {
|
|
98
|
-
this.visitNode(node.offset);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
visitSelection(node) {
|
|
102
|
-
this.visitNode(node.selection);
|
|
103
|
-
}
|
|
104
|
-
visitColumn(node) {
|
|
105
|
-
this.visitNode(node.column);
|
|
106
|
-
}
|
|
107
|
-
visitAlias(node) {
|
|
108
|
-
this.visitNode(node.node);
|
|
109
|
-
}
|
|
110
|
-
visitTable(node) {
|
|
111
|
-
if (node.schema) {
|
|
112
|
-
this.visitNode(node.schema);
|
|
113
|
-
}
|
|
114
|
-
this.visitNode(node.table);
|
|
115
|
-
}
|
|
116
|
-
visitFrom(node) {
|
|
117
|
-
node.froms.forEach(this.visitNode);
|
|
118
|
-
}
|
|
119
|
-
visitReference(node) {
|
|
120
|
-
this.visitNode(node.column);
|
|
121
|
-
this.visitNode(node.table);
|
|
122
|
-
}
|
|
123
|
-
visitFilter(node) {
|
|
124
|
-
if (node.left) {
|
|
125
|
-
this.visitNode(node.left);
|
|
126
|
-
}
|
|
127
|
-
this.visitNode(node.op);
|
|
128
|
-
this.visitNode(node.right);
|
|
129
|
-
}
|
|
130
|
-
visitAnd(node) {
|
|
131
|
-
this.visitNode(node.left);
|
|
132
|
-
this.visitNode(node.right);
|
|
133
|
-
}
|
|
134
|
-
visitOr(node) {
|
|
135
|
-
this.visitNode(node.left);
|
|
136
|
-
this.visitNode(node.right);
|
|
137
|
-
}
|
|
138
|
-
visitValueList(node) {
|
|
139
|
-
node.values.forEach(this.visitNode);
|
|
140
|
-
}
|
|
141
|
-
visitParens(node) {
|
|
142
|
-
this.visitNode(node.node);
|
|
143
|
-
}
|
|
144
|
-
visitJoin(node) {
|
|
145
|
-
this.visitNode(node.table);
|
|
146
|
-
if (node.on) {
|
|
147
|
-
this.visitNode(node.on);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
visitRaw(node) {
|
|
151
|
-
node.params.forEach(this.visitNode);
|
|
152
|
-
}
|
|
153
|
-
visitWhere(node) {
|
|
154
|
-
this.visitNode(node.where);
|
|
155
|
-
}
|
|
156
|
-
visitInsertQuery(node) {
|
|
157
|
-
if (node.with) {
|
|
158
|
-
this.visitNode(node.with);
|
|
159
|
-
}
|
|
160
|
-
this.visitNode(node.into);
|
|
161
|
-
if (node.columns) {
|
|
162
|
-
node.columns.forEach(this.visitNode);
|
|
163
|
-
}
|
|
164
|
-
if (node.values) {
|
|
165
|
-
node.values.forEach(this.visitNode);
|
|
166
|
-
}
|
|
167
|
-
if (node.returning) {
|
|
168
|
-
this.visitNode(node.returning);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
visitDeleteQuery(node) {
|
|
172
|
-
if (node.with) {
|
|
173
|
-
this.visitNode(node.with);
|
|
174
|
-
}
|
|
175
|
-
this.visitNode(node.from);
|
|
176
|
-
if (node.joins) {
|
|
177
|
-
node.joins.forEach(this.visitNode);
|
|
178
|
-
}
|
|
179
|
-
if (node.where) {
|
|
180
|
-
this.visitNode(node.where);
|
|
181
|
-
}
|
|
182
|
-
if (node.returning) {
|
|
183
|
-
this.visitNode(node.returning);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
visitReturning(node) {
|
|
187
|
-
node.selections.forEach(this.visitNode);
|
|
188
|
-
}
|
|
189
|
-
visitCreateTable(node) {
|
|
190
|
-
this.visitNode(node.table);
|
|
191
|
-
node.columns.forEach(this.visitNode);
|
|
192
|
-
if (node.constraints) {
|
|
193
|
-
node.constraints.forEach(this.visitNode);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
visitAddColumn(node) {
|
|
197
|
-
this.visitNode(node.column);
|
|
198
|
-
}
|
|
199
|
-
visitColumnDefinition(node) {
|
|
200
|
-
this.visitNode(node.column);
|
|
201
|
-
this.visitNode(node.dataType);
|
|
202
|
-
if (node.defaultTo) {
|
|
203
|
-
this.visitNode(node.defaultTo);
|
|
204
|
-
}
|
|
205
|
-
if (node.references) {
|
|
206
|
-
this.visitNode(node.references);
|
|
207
|
-
}
|
|
208
|
-
if (node.check) {
|
|
209
|
-
this.visitNode(node.check);
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
visitDropTable(node) {
|
|
213
|
-
this.visitNode(node.table);
|
|
214
|
-
}
|
|
215
|
-
visitOrderBy(node) {
|
|
216
|
-
node.items.forEach(this.visitNode);
|
|
217
|
-
}
|
|
218
|
-
visitOrderByItem(node) {
|
|
219
|
-
this.visitNode(node.orderBy);
|
|
220
|
-
}
|
|
221
|
-
visitGroupBy(node) {
|
|
222
|
-
node.items.forEach(this.visitNode);
|
|
223
|
-
}
|
|
224
|
-
visitGroupByItem(node) {
|
|
225
|
-
this.visitNode(node.groupBy);
|
|
226
|
-
}
|
|
227
|
-
visitUpdateQuery(node) {
|
|
228
|
-
if (node.with) {
|
|
229
|
-
this.visitNode(node.with);
|
|
230
|
-
}
|
|
231
|
-
this.visitNode(node.table);
|
|
232
|
-
if (node.updates) {
|
|
233
|
-
node.updates.forEach(this.visitNode);
|
|
234
|
-
}
|
|
235
|
-
if (node.joins) {
|
|
236
|
-
node.joins.forEach(this.visitNode);
|
|
237
|
-
}
|
|
238
|
-
if (node.where) {
|
|
239
|
-
this.visitNode(node.where);
|
|
240
|
-
}
|
|
241
|
-
if (node.returning) {
|
|
242
|
-
this.visitNode(node.returning);
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
visitColumnUpdate(node) {
|
|
246
|
-
this.visitNode(node.column);
|
|
247
|
-
this.visitNode(node.value);
|
|
248
|
-
}
|
|
249
|
-
visitLimit(node) {
|
|
250
|
-
this.visitNode(node.limit);
|
|
251
|
-
}
|
|
252
|
-
visitOffset(node) {
|
|
253
|
-
this.visitNode(node.offset);
|
|
254
|
-
}
|
|
255
|
-
visitOnConflict(node) {
|
|
256
|
-
if (node.columns) {
|
|
257
|
-
node.columns.forEach(this.visitNode);
|
|
258
|
-
}
|
|
259
|
-
if (node.constraint) {
|
|
260
|
-
this.visitNode(node.constraint);
|
|
261
|
-
}
|
|
262
|
-
if (node.updates) {
|
|
263
|
-
node.updates.forEach(this.visitNode);
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
visitOnDuplicateKey(node) {
|
|
267
|
-
node.updates.forEach(this.visitNode);
|
|
268
|
-
}
|
|
269
|
-
visitCreateIndex(node) {
|
|
270
|
-
this.visitNode(node.name);
|
|
271
|
-
if (node.table) {
|
|
272
|
-
this.visitNode(node.table);
|
|
273
|
-
}
|
|
274
|
-
if (node.using) {
|
|
275
|
-
this.visitNode(node.using);
|
|
276
|
-
}
|
|
277
|
-
if (node.expression) {
|
|
278
|
-
this.visitNode(node.expression);
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
visitList(node) {
|
|
282
|
-
node.items.forEach(this.visitNode);
|
|
283
|
-
}
|
|
284
|
-
visitDropIndex(node) {
|
|
285
|
-
this.visitNode(node.name);
|
|
286
|
-
if (node.table) {
|
|
287
|
-
this.visitNode(node.table);
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
visitPrimaryKeyConstraint(node) {
|
|
291
|
-
if (node.name) {
|
|
292
|
-
this.visitNode(node.name);
|
|
293
|
-
}
|
|
294
|
-
node.columns.forEach(this.visitNode);
|
|
295
|
-
}
|
|
296
|
-
visitUniqueConstraint(node) {
|
|
297
|
-
if (node.name) {
|
|
298
|
-
this.visitNode(node.name);
|
|
299
|
-
}
|
|
300
|
-
node.columns.forEach(this.visitNode);
|
|
301
|
-
}
|
|
302
|
-
visitReferences(node) {
|
|
303
|
-
node.columns.forEach(this.visitNode);
|
|
304
|
-
this.visitNode(node.table);
|
|
305
|
-
}
|
|
306
|
-
visitCheckConstraint(node) {
|
|
307
|
-
if (node.name) {
|
|
308
|
-
this.visitNode(node.name);
|
|
309
|
-
}
|
|
310
|
-
this.visitNode(node.expression);
|
|
311
|
-
}
|
|
312
|
-
visitWith(node) {
|
|
313
|
-
node.expressions.forEach(this.visitNode);
|
|
314
|
-
}
|
|
315
|
-
visitCommonTableExpression(node) {
|
|
316
|
-
this.visitNode(node.name);
|
|
317
|
-
this.visitNode(node.expression);
|
|
318
|
-
}
|
|
319
|
-
visitHaving(node) {
|
|
320
|
-
this.visitNode(node.having);
|
|
321
|
-
}
|
|
322
|
-
visitCreateSchema(node) {
|
|
323
|
-
this.visitNode(node.schema);
|
|
324
|
-
}
|
|
325
|
-
visitDropSchema(node) {
|
|
326
|
-
this.visitNode(node.schema);
|
|
327
|
-
}
|
|
328
|
-
visitAlterTable(node) {
|
|
329
|
-
this.visitNode(node.table);
|
|
330
|
-
if (node.renameTo) {
|
|
331
|
-
this.visitNode(node.renameTo);
|
|
332
|
-
}
|
|
333
|
-
if (node.renameColumn) {
|
|
334
|
-
this.visitNode(node.renameColumn);
|
|
335
|
-
}
|
|
336
|
-
if (node.setSchema) {
|
|
337
|
-
this.visitNode(node.setSchema);
|
|
338
|
-
}
|
|
339
|
-
if (node.addColumn) {
|
|
340
|
-
this.visitNode(node.addColumn);
|
|
341
|
-
}
|
|
342
|
-
if (node.dropColumn) {
|
|
343
|
-
this.visitNode(node.dropColumn);
|
|
344
|
-
}
|
|
345
|
-
if (node.alterColumn) {
|
|
346
|
-
this.visitNode(node.alterColumn);
|
|
347
|
-
}
|
|
348
|
-
if (node.modifyColumn) {
|
|
349
|
-
this.visitNode(node.modifyColumn);
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
visitDropColumn(node) {
|
|
353
|
-
this.visitNode(node.column);
|
|
354
|
-
}
|
|
355
|
-
visitRenameColumn(node) {
|
|
356
|
-
this.visitNode(node.column);
|
|
357
|
-
this.visitNode(node.renameTo);
|
|
358
|
-
}
|
|
359
|
-
visitAlterColumn(node) {
|
|
360
|
-
this.visitNode(node.column);
|
|
361
|
-
}
|
|
362
|
-
visitModifyColumn(node) {
|
|
363
|
-
this.visitNode(node.column);
|
|
364
|
-
}
|
|
365
|
-
visitAddConstraint(node) {
|
|
366
|
-
this.visitNode(node.constraint);
|
|
367
|
-
}
|
|
368
|
-
visitDropConstraint(node) {
|
|
369
|
-
this.visitNode(node.constraintName);
|
|
370
|
-
}
|
|
371
|
-
visitForeignKeyConstraint(node) {
|
|
372
|
-
if (node.name) {
|
|
373
|
-
this.visitNode(node.name);
|
|
374
|
-
}
|
|
375
|
-
node.columns.forEach(this.visitNode);
|
|
376
|
-
this.visitNode(node.references);
|
|
377
|
-
}
|
|
378
|
-
visitDataType(node) { }
|
|
379
|
-
visitSelectAll(_) { }
|
|
380
|
-
visitIdentifier(_) { }
|
|
381
|
-
visitValue(_) { }
|
|
382
|
-
visitPrimitiveValueList(_) { }
|
|
383
|
-
visitOperator(node) { }
|
|
384
69
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare type OperationNodeKind = 'IdentifierNode' | 'RawNode' | 'SelectQueryNode' | 'SelectionNode' | 'ReferenceNode' | 'ColumnNode' | 'TableNode' | 'AliasNode' | 'FromNode' | 'SelectAllNode' | 'FilterNode' | 'AndNode' | 'OrNode' | 'ParensNode' | 'ValueNode' | 'ValueListNode' | 'PrimitiveValueListNode' | 'JoinNode' | 'OperatorNode' | 'WhereNode' | 'InsertQueryNode' | 'DeleteQueryNode' | 'ReturningNode' | 'CreateTableNode' | 'ColumnDefinitionNode' | 'AddColumnNode' | 'DropTableNode' | 'DataTypeNode' | 'OrderByNode' | 'OrderByItemNode' | 'GroupByNode' | 'GroupByItemNode' | 'UpdateQueryNode' | 'ColumnUpdateNode' | 'LimitNode' | 'OffsetNode' | 'OnConflictNode' | 'OnDuplicateKeyNode' | 'CreateIndexNode' | 'DropIndexNode' | 'ListNode' | 'ReferencesNode' | 'PrimaryKeyConstraintNode' | 'UniqueConstraintNode' | 'CheckConstraintNode' | 'ForeignKeyConstraintNode' | 'WithNode' | 'CommonTableExpressionNode' | 'HavingNode' | 'CreateSchemaNode' | 'DropSchemaNode' | 'AlterTableNode' | 'ModifyColumnNode' | 'DropColumnNode' | 'RenameColumnNode' | 'AlterColumnNode' | 'AddConstraintNode' | 'DropConstraintNode';
|
|
1
|
+
export declare type OperationNodeKind = 'IdentifierNode' | 'RawNode' | 'SelectQueryNode' | 'SelectionNode' | 'ReferenceNode' | 'ColumnNode' | 'TableNode' | 'AliasNode' | 'FromNode' | 'SelectAllNode' | 'FilterNode' | 'AndNode' | 'OrNode' | 'ParensNode' | 'ValueNode' | 'ValueListNode' | 'PrimitiveValueListNode' | 'JoinNode' | 'OperatorNode' | 'WhereNode' | 'InsertQueryNode' | 'DeleteQueryNode' | 'ReturningNode' | 'CreateTableNode' | 'ColumnDefinitionNode' | 'AddColumnNode' | 'DropTableNode' | 'DataTypeNode' | 'OrderByNode' | 'OrderByItemNode' | 'GroupByNode' | 'GroupByItemNode' | 'UpdateQueryNode' | 'ColumnUpdateNode' | 'LimitNode' | 'OffsetNode' | 'OnConflictNode' | 'OnDuplicateKeyNode' | 'CreateIndexNode' | 'DropIndexNode' | 'ListNode' | 'ReferencesNode' | 'PrimaryKeyConstraintNode' | 'UniqueConstraintNode' | 'CheckConstraintNode' | 'ForeignKeyConstraintNode' | 'WithNode' | 'CommonTableExpressionNode' | 'HavingNode' | 'CreateSchemaNode' | 'DropSchemaNode' | 'AlterTableNode' | 'ModifyColumnNode' | 'DropColumnNode' | 'RenameColumnNode' | 'AlterColumnNode' | 'AddConstraintNode' | 'DropConstraintNode' | 'UnionNode';
|
|
2
2
|
export interface OperationNode {
|
|
3
3
|
readonly kind: OperationNodeKind;
|
|
4
4
|
}
|
|
@@ -12,6 +12,7 @@ import { OrderByNode } from './order-by-node.js';
|
|
|
12
12
|
import { SelectionNode } from './selection-node.js';
|
|
13
13
|
import { WhereNode } from './where-node.js';
|
|
14
14
|
import { WithNode } from './with-node.js';
|
|
15
|
+
import { UnionNode } from './union-node.js';
|
|
15
16
|
export declare type SelectModifier = 'ForUpdate' | 'ForNoKeyUpdate' | 'ForShare' | 'ForKeyShare' | 'NoWait' | 'SkipLocked';
|
|
16
17
|
export interface SelectQueryNode extends OperationNode {
|
|
17
18
|
readonly kind: 'SelectQueryNode';
|
|
@@ -28,6 +29,7 @@ export interface SelectQueryNode extends OperationNode {
|
|
|
28
29
|
readonly offset?: OffsetNode;
|
|
29
30
|
readonly with?: WithNode;
|
|
30
31
|
readonly having?: HavingNode;
|
|
32
|
+
readonly union?: ReadonlyArray<UnionNode>;
|
|
31
33
|
}
|
|
32
34
|
/**
|
|
33
35
|
* @internal
|
|
@@ -45,4 +47,5 @@ export declare const SelectQueryNode: Readonly<{
|
|
|
45
47
|
cloneWithHaving(selectNode: SelectQueryNode, filter: HavingNodeChild): SelectQueryNode;
|
|
46
48
|
cloneWithOrHaving(selectNode: SelectQueryNode, filter: HavingNodeChild): SelectQueryNode;
|
|
47
49
|
cloneWithDistinct(selectNode: SelectQueryNode): SelectQueryNode;
|
|
50
|
+
cloneWithUnion(selectNode: SelectQueryNode, union: UnionNode): SelectQueryNode;
|
|
48
51
|
}>;
|
|
@@ -91,4 +91,12 @@ export const SelectQueryNode = freeze({
|
|
|
91
91
|
isDistinct: true,
|
|
92
92
|
});
|
|
93
93
|
},
|
|
94
|
+
cloneWithUnion(selectNode, union) {
|
|
95
|
+
return freeze({
|
|
96
|
+
...selectNode,
|
|
97
|
+
union: selectNode.union
|
|
98
|
+
? freeze([...selectNode.union, union])
|
|
99
|
+
: freeze([union]),
|
|
100
|
+
});
|
|
101
|
+
},
|
|
94
102
|
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { OperationNode } from './operation-node.js';
|
|
2
|
+
import { RawNode } from './raw-node.js';
|
|
3
|
+
import { SelectQueryNode } from './select-query-node.js';
|
|
4
|
+
export declare type UnionExpressionNode = SelectQueryNode | RawNode;
|
|
5
|
+
export interface UnionNode extends OperationNode {
|
|
6
|
+
readonly kind: 'UnionNode';
|
|
7
|
+
readonly union: UnionExpressionNode;
|
|
8
|
+
readonly all: boolean;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
export declare const UnionNode: Readonly<{
|
|
14
|
+
is(node: OperationNode): node is UnionNode;
|
|
15
|
+
create(union: UnionExpressionNode, all: boolean): UnionNode;
|
|
16
|
+
}>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { freeze } from '../util/object-utils.js';
|
|
2
|
+
/**
|
|
3
|
+
* @internal
|
|
4
|
+
*/
|
|
5
|
+
export const UnionNode = freeze({
|
|
6
|
+
is(node) {
|
|
7
|
+
return node.kind === 'UnionNode';
|
|
8
|
+
},
|
|
9
|
+
create(union, all) {
|
|
10
|
+
return freeze({
|
|
11
|
+
kind: 'UnionNode',
|
|
12
|
+
union,
|
|
13
|
+
all,
|
|
14
|
+
});
|
|
15
|
+
},
|
|
16
|
+
});
|
|
@@ -8,7 +8,7 @@ import { PrimitiveValue } from '../util/object-utils.js';
|
|
|
8
8
|
export declare type InsertObject<DB, TB extends keyof DB> = {
|
|
9
9
|
[C in keyof DB[TB]]: InsertValueExpression<DB[TB][C]>;
|
|
10
10
|
};
|
|
11
|
-
export declare type InsertObjectOrList<DB, TB extends keyof DB> = InsertObject<DB, TB> | InsertObject<DB, TB
|
|
11
|
+
export declare type InsertObjectOrList<DB, TB extends keyof DB> = InsertObject<DB, TB> | ReadonlyArray<InsertObject<DB, TB>>;
|
|
12
12
|
declare type InsertValueExpression<T> = T | AnyQueryBuilder | AnyRawBuilder | GeneratedPlaceholder;
|
|
13
13
|
export declare function parseInsertObjectOrList(args: InsertObjectOrList<any, any>): [ReadonlyArray<ColumnNode>, ReadonlyArray<InsertValuesNode>];
|
|
14
14
|
export declare function parseInsertValueExpression(value: InsertValueExpression<PrimitiveValue>): ValueNode | RawNode | SelectQueryNode;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { UnionNode } from '../operation-node/union-node.js';
|
|
2
|
+
import { QueryBuilder } from '../query-builder/query-builder.js';
|
|
3
|
+
import { RawBuilder } from '../raw-builder/raw-builder.js';
|
|
4
|
+
export declare type UnionExpression<DB, O> = QueryBuilder<DB, any, O> | RawBuilder<O>;
|
|
5
|
+
export declare function parseUnion(union: UnionExpression<any, any>, all: boolean): UnionNode;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { QueryNode } from '../operation-node/query-node.js';
|
|
2
|
+
import { UnionNode } from '../operation-node/union-node.js';
|
|
3
|
+
export function parseUnion(union, all) {
|
|
4
|
+
const node = union.toOperationNode();
|
|
5
|
+
if (QueryNode.isMutating(node)) {
|
|
6
|
+
throw new Error("can't combine insert, update or delete queries using union");
|
|
7
|
+
}
|
|
8
|
+
return UnionNode.create(node, all);
|
|
9
|
+
}
|
|
@@ -3,6 +3,6 @@ import { AnyQueryBuilder, AnyRawBuilder, QueryBuilderFactory, RawBuilderFactory
|
|
|
3
3
|
import { ExtractTypeFromReferenceExpression } from './reference-parser.js';
|
|
4
4
|
import { ParseContext } from './parse-context.js';
|
|
5
5
|
export declare type ValueExpression<DB, TB extends keyof DB, RE> = ExtractTypeFromReferenceExpression<DB, TB, RE> | AnyQueryBuilder | QueryBuilderFactory<DB, TB> | AnyRawBuilder | RawBuilderFactory<DB, TB>;
|
|
6
|
-
export declare type ValueExpressionOrList<DB, TB extends keyof DB, RE> = ValueExpression<DB, TB, RE> | ValueExpression<DB, TB, RE
|
|
6
|
+
export declare type ValueExpressionOrList<DB, TB extends keyof DB, RE> = ValueExpression<DB, TB, RE> | ReadonlyArray<ValueExpression<DB, TB, RE>>;
|
|
7
7
|
export declare function parseValueExpressionOrList(ctx: ParseContext, arg: ValueExpressionOrList<any, any, any>): ValueExpressionNode;
|
|
8
8
|
export declare function parseValueExpression(ctx: ParseContext, arg: ValueExpression<any, any, any>): ValueExpressionNode;
|
|
@@ -18,6 +18,7 @@ import { QueryExecutor } from '../query-executor/query-executor.js';
|
|
|
18
18
|
import { QueryId } from '../util/query-id.js';
|
|
19
19
|
import { OnConflictConstraintTarget } from '../parser/on-conflict-parser.js';
|
|
20
20
|
import { ParseContext } from '../parser/parse-context.js';
|
|
21
|
+
import { UnionExpression } from '../parser/union-parser.js';
|
|
21
22
|
/**
|
|
22
23
|
* The main query builder class.
|
|
23
24
|
*
|
|
@@ -998,7 +999,7 @@ export declare class QueryBuilder<DB, TB extends keyof DB, O = {}> implements Op
|
|
|
998
999
|
* ```
|
|
999
1000
|
*/
|
|
1000
1001
|
values(row: InsertObject<DB, TB>): QueryBuilder<DB, TB, O>;
|
|
1001
|
-
values(row: InsertObject<DB, TB
|
|
1002
|
+
values(row: ReadonlyArray<InsertObject<DB, TB>>): QueryBuilder<DB, TB, O>;
|
|
1002
1003
|
/**
|
|
1003
1004
|
* Ignores the insert if the column or constraint given as the first
|
|
1004
1005
|
* argument conflicts with the current rows in the database. The
|
|
@@ -1553,6 +1554,34 @@ export declare class QueryBuilder<DB, TB extends keyof DB, O = {}> implements Op
|
|
|
1553
1554
|
* ```
|
|
1554
1555
|
*/
|
|
1555
1556
|
offset(offset: number): QueryBuilder<DB, TB, O>;
|
|
1557
|
+
/**
|
|
1558
|
+
* Combines another select query or raw expression to this query using `union`.
|
|
1559
|
+
*
|
|
1560
|
+
* The output row type of the combined query must match `this` query.
|
|
1561
|
+
*
|
|
1562
|
+
* @xample
|
|
1563
|
+
* ```ts
|
|
1564
|
+
* db.selectFrom('person')
|
|
1565
|
+
* .select(['id', 'first_name as name'])
|
|
1566
|
+
* .union(db.selectFrom('pet').select(['id', 'name']))
|
|
1567
|
+
* .orderBy('name')
|
|
1568
|
+
* ```
|
|
1569
|
+
*/
|
|
1570
|
+
union(expression: UnionExpression<DB, O>): QueryBuilder<DB, TB, O>;
|
|
1571
|
+
/**
|
|
1572
|
+
* Combines another select query or raw expression to this query using `union all`.
|
|
1573
|
+
*
|
|
1574
|
+
* The output row type of the combined query must match `this` query.
|
|
1575
|
+
*
|
|
1576
|
+
* @xample
|
|
1577
|
+
* ```ts
|
|
1578
|
+
* db.selectFrom('person')
|
|
1579
|
+
* .select(['id', 'first_name as name'])
|
|
1580
|
+
* .unionAll(db.selectFrom('pet').select(['id', 'name']))
|
|
1581
|
+
* .orderBy('name')
|
|
1582
|
+
* ```
|
|
1583
|
+
*/
|
|
1584
|
+
unionAll(expression: UnionExpression<DB, O>): QueryBuilder<DB, TB, O>;
|
|
1556
1585
|
/**
|
|
1557
1586
|
* Gives an alias for the query. This method is only useful for sub queries.
|
|
1558
1587
|
*
|
|
@@ -17,6 +17,7 @@ import { freeze } from '../util/object-utils.js';
|
|
|
17
17
|
import { DeleteQueryNode } from '../operation-node/delete-query-node.js';
|
|
18
18
|
import { OnDuplicateKeyNode } from '../operation-node/on-duplicate-key-node.js';
|
|
19
19
|
import { parseGroupBy } from '../parser/group-by-parser.js';
|
|
20
|
+
import { parseUnion } from '../parser/union-parser.js';
|
|
20
21
|
/**
|
|
21
22
|
* The main query builder class.
|
|
22
23
|
*
|
|
@@ -774,6 +775,46 @@ export class QueryBuilder {
|
|
|
774
775
|
queryNode: SelectQueryNode.cloneWithOffset(this.#props.queryNode, OffsetNode.create(offset)),
|
|
775
776
|
});
|
|
776
777
|
}
|
|
778
|
+
/**
|
|
779
|
+
* Combines another select query or raw expression to this query using `union`.
|
|
780
|
+
*
|
|
781
|
+
* The output row type of the combined query must match `this` query.
|
|
782
|
+
*
|
|
783
|
+
* @xample
|
|
784
|
+
* ```ts
|
|
785
|
+
* db.selectFrom('person')
|
|
786
|
+
* .select(['id', 'first_name as name'])
|
|
787
|
+
* .union(db.selectFrom('pet').select(['id', 'name']))
|
|
788
|
+
* .orderBy('name')
|
|
789
|
+
* ```
|
|
790
|
+
*/
|
|
791
|
+
union(expression) {
|
|
792
|
+
assertCanHaveUnion(this.#props.queryNode);
|
|
793
|
+
return new QueryBuilder({
|
|
794
|
+
...this.#props,
|
|
795
|
+
queryNode: SelectQueryNode.cloneWithUnion(this.#props.queryNode, parseUnion(expression, false)),
|
|
796
|
+
});
|
|
797
|
+
}
|
|
798
|
+
/**
|
|
799
|
+
* Combines another select query or raw expression to this query using `union all`.
|
|
800
|
+
*
|
|
801
|
+
* The output row type of the combined query must match `this` query.
|
|
802
|
+
*
|
|
803
|
+
* @xample
|
|
804
|
+
* ```ts
|
|
805
|
+
* db.selectFrom('person')
|
|
806
|
+
* .select(['id', 'first_name as name'])
|
|
807
|
+
* .unionAll(db.selectFrom('pet').select(['id', 'name']))
|
|
808
|
+
* .orderBy('name')
|
|
809
|
+
* ```
|
|
810
|
+
*/
|
|
811
|
+
unionAll(expression) {
|
|
812
|
+
assertCanHaveUnion(this.#props.queryNode);
|
|
813
|
+
return new QueryBuilder({
|
|
814
|
+
...this.#props,
|
|
815
|
+
queryNode: SelectQueryNode.cloneWithUnion(this.#props.queryNode, parseUnion(expression, true)),
|
|
816
|
+
});
|
|
817
|
+
}
|
|
777
818
|
/**
|
|
778
819
|
* Gives an alias for the query. This method is only useful for sub queries.
|
|
779
820
|
*
|
|
@@ -979,3 +1020,8 @@ function assertCanHaveOffset(node) {
|
|
|
979
1020
|
throw new Error('only a select query can have an offset');
|
|
980
1021
|
}
|
|
981
1022
|
}
|
|
1023
|
+
function assertCanHaveUnion(node) {
|
|
1024
|
+
if (!SelectQueryNode.is(node)) {
|
|
1025
|
+
throw new Error('only a select query can have an union');
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
@@ -60,6 +60,8 @@ import { ForeignKeyConstraintNode } from '../operation-node/foreign-key-constrai
|
|
|
60
60
|
import { ColumnDefinitionNode } from '../operation-node/column-definition-node.js';
|
|
61
61
|
import { ModifyColumnNode } from '../operation-node/modify-column-node.js';
|
|
62
62
|
import { OnDuplicateKeyNode } from '../operation-node/on-duplicate-key-node.js';
|
|
63
|
+
import { ColumnNode } from '../operation-node/column-node.js';
|
|
64
|
+
import { UnionNode } from '../operation-node/union-node.js';
|
|
63
65
|
export declare class DefaultQueryCompiler extends OperationNodeVisitor implements QueryCompiler {
|
|
64
66
|
#private;
|
|
65
67
|
protected get numParameters(): number;
|
|
@@ -67,6 +69,8 @@ export declare class DefaultQueryCompiler extends OperationNodeVisitor implement
|
|
|
67
69
|
protected getSql(): string;
|
|
68
70
|
protected visitSelectQuery(node: SelectQueryNode): void;
|
|
69
71
|
protected visitFrom(node: FromNode): void;
|
|
72
|
+
protected visitSelection(node: SelectionNode): void;
|
|
73
|
+
protected visitColumn(node: ColumnNode): void;
|
|
70
74
|
protected compileDistinctOn(selections: ReadonlyArray<SelectionNode>): void;
|
|
71
75
|
protected compileList(nodes: ReadonlyArray<OperationNode>, separator?: string): void;
|
|
72
76
|
protected visitWhere(node: WhereNode): void;
|
|
@@ -125,6 +129,7 @@ export declare class DefaultQueryCompiler extends OperationNodeVisitor implement
|
|
|
125
129
|
protected visitModifyColumn(node: ModifyColumnNode): void;
|
|
126
130
|
protected visitAddConstraint(node: AddConstraintNode): void;
|
|
127
131
|
protected visitDropConstraint(node: DropConstraintNode): void;
|
|
132
|
+
protected visitUnion(node: UnionNode): void;
|
|
128
133
|
protected append(str: string): void;
|
|
129
134
|
protected appendValue(parameter: unknown): void;
|
|
130
135
|
protected getLeftIdentifierWrapper(): string;
|
|
@@ -14,7 +14,7 @@ export class DefaultQueryCompiler extends OperationNodeVisitor {
|
|
|
14
14
|
this.visitNode(node);
|
|
15
15
|
return freeze({
|
|
16
16
|
sql: this.getSql(),
|
|
17
|
-
parameters: this.#parameters,
|
|
17
|
+
parameters: [...this.#parameters],
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
20
|
getSql() {
|
|
@@ -60,6 +60,10 @@ export class DefaultQueryCompiler extends OperationNodeVisitor {
|
|
|
60
60
|
this.append(' ');
|
|
61
61
|
this.visitNode(node.having);
|
|
62
62
|
}
|
|
63
|
+
if (node.union) {
|
|
64
|
+
this.append(' ');
|
|
65
|
+
this.compileList(node.union, ' ');
|
|
66
|
+
}
|
|
63
67
|
if (node.orderBy) {
|
|
64
68
|
this.append(' ');
|
|
65
69
|
this.visitNode(node.orderBy);
|
|
@@ -86,6 +90,12 @@ export class DefaultQueryCompiler extends OperationNodeVisitor {
|
|
|
86
90
|
this.append('from ');
|
|
87
91
|
this.compileList(node.froms);
|
|
88
92
|
}
|
|
93
|
+
visitSelection(node) {
|
|
94
|
+
this.visitNode(node.selection);
|
|
95
|
+
}
|
|
96
|
+
visitColumn(node) {
|
|
97
|
+
this.visitNode(node.column);
|
|
98
|
+
}
|
|
89
99
|
compileDistinctOn(selections) {
|
|
90
100
|
this.append('distinct on (');
|
|
91
101
|
this.compileList(selections);
|
|
@@ -627,6 +637,13 @@ export class DefaultQueryCompiler extends OperationNodeVisitor {
|
|
|
627
637
|
this.append('drop constraint ');
|
|
628
638
|
this.visitNode(node.constraintName);
|
|
629
639
|
}
|
|
640
|
+
visitUnion(node) {
|
|
641
|
+
this.append('union ');
|
|
642
|
+
if (node.all) {
|
|
643
|
+
this.append('all ');
|
|
644
|
+
}
|
|
645
|
+
this.visitNode(node.union);
|
|
646
|
+
}
|
|
630
647
|
append(str) {
|
|
631
648
|
this.#sql += str;
|
|
632
649
|
}
|