@prisma-next/sql-relational-core 0.5.0-dev.3 → 0.5.0-dev.31
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/README.md +67 -1
- package/dist/codec-types-DJEaWT36.d.mts +313 -0
- package/dist/codec-types-DJEaWT36.d.mts.map +1 -0
- package/dist/{errors-ChY_dHam.d.mts → errors-BRt5yHo9.d.mts} +2 -2
- package/dist/errors-BRt5yHo9.d.mts.map +1 -0
- package/dist/{errors-D3xmG4h-.mjs → errors-D6kqqjHM.mjs} +1 -1
- package/dist/{errors-D3xmG4h-.mjs.map → errors-D6kqqjHM.mjs.map} +1 -1
- package/dist/exports/ast.d.mts +27 -12
- package/dist/exports/ast.d.mts.map +1 -1
- package/dist/exports/ast.mjs +63 -1089
- package/dist/exports/ast.mjs.map +1 -1
- package/dist/exports/errors.d.mts +4 -4
- package/dist/exports/errors.mjs +1 -1
- package/dist/exports/expression.d.mts +79 -0
- package/dist/exports/expression.d.mts.map +1 -0
- package/dist/exports/expression.mjs +41 -0
- package/dist/exports/expression.mjs.map +1 -0
- package/dist/exports/plan.d.mts +3 -2
- package/dist/exports/plan.mjs +1 -17
- package/dist/exports/query-lane-context.d.mts +3 -3
- package/dist/exports/types.d.mts +5 -4
- package/dist/index.d.mts +11 -9
- package/dist/index.mjs +6 -4
- package/dist/plan-C7SiEWkN.d.mts +25 -0
- package/dist/plan-C7SiEWkN.d.mts.map +1 -0
- package/dist/{query-lane-context-UlR8vOkd.d.mts → query-lane-context-BF-wuc0r.d.mts} +53 -3
- package/dist/query-lane-context-BF-wuc0r.d.mts.map +1 -0
- package/dist/sql-execution-plan-Dgx7BGin.d.mts +33 -0
- package/dist/sql-execution-plan-Dgx7BGin.d.mts.map +1 -0
- package/dist/{types-C3Hg-CVz.d.mts → types-B4dL4lc3.d.mts} +17 -22
- package/dist/types-B4dL4lc3.d.mts.map +1 -0
- package/dist/types-BUlUvdIU.d.mts +24 -0
- package/dist/types-BUlUvdIU.d.mts.map +1 -0
- package/dist/{types-k9pir8XY.d.mts → types-BWOCTYd8.d.mts} +12 -19
- package/dist/types-BWOCTYd8.d.mts.map +1 -0
- package/dist/types-DUL-3vy6.mjs +1064 -0
- package/dist/types-DUL-3vy6.mjs.map +1 -0
- package/package.json +11 -10
- package/src/ast/adapter-types.ts +8 -0
- package/src/ast/codec-types.ts +251 -45
- package/src/ast/sql-codecs.ts +20 -3
- package/src/ast/types.ts +142 -172
- package/src/ast/util.ts +23 -0
- package/src/exports/expression.ts +1 -0
- package/src/exports/plan.ts +1 -0
- package/src/exports/types.ts +1 -0
- package/src/expression.ts +117 -0
- package/src/index.ts +1 -0
- package/src/plan.ts +11 -30
- package/src/query-lane-context.ts +52 -1
- package/src/runtime-scope.ts +20 -0
- package/src/sql-execution-plan.ts +28 -0
- package/src/types.ts +9 -22
- package/dist/codec-types-DcEITed4.d.mts +0 -144
- package/dist/codec-types-DcEITed4.d.mts.map +0 -1
- package/dist/errors-ChY_dHam.d.mts.map +0 -1
- package/dist/exports/plan.mjs.map +0 -1
- package/dist/plan-Cs65hb-E.d.mts +0 -28
- package/dist/plan-Cs65hb-E.d.mts.map +0 -1
- package/dist/query-lane-context-UlR8vOkd.d.mts.map +0 -1
- package/dist/types-C3Hg-CVz.d.mts.map +0 -1
- package/dist/types-k9pir8XY.d.mts.map +0 -1
|
@@ -0,0 +1,1064 @@
|
|
|
1
|
+
//#region src/ast/types.ts
|
|
2
|
+
function frozenArrayCopy(values) {
|
|
3
|
+
return Object.freeze([...values]);
|
|
4
|
+
}
|
|
5
|
+
function frozenOptionalRecordCopy(value) {
|
|
6
|
+
return value === void 0 ? void 0 : Object.freeze({ ...value });
|
|
7
|
+
}
|
|
8
|
+
function frozenRecordCopy(record) {
|
|
9
|
+
return Object.freeze({ ...record });
|
|
10
|
+
}
|
|
11
|
+
function freezeRows(rows) {
|
|
12
|
+
return Object.freeze(rows.map((row) => Object.freeze({ ...row })));
|
|
13
|
+
}
|
|
14
|
+
function combineAll(folder, thunks) {
|
|
15
|
+
let result = folder.empty;
|
|
16
|
+
for (const thunk of thunks) {
|
|
17
|
+
if (folder.isAbsorbing?.(result)) return result;
|
|
18
|
+
result = folder.combine(result, thunk());
|
|
19
|
+
}
|
|
20
|
+
return result;
|
|
21
|
+
}
|
|
22
|
+
function rewriteComparable(value, rewriter) {
|
|
23
|
+
switch (value.kind) {
|
|
24
|
+
case "param-ref": return rewriter.paramRef ? rewriter.paramRef(value) : value;
|
|
25
|
+
case "literal": return rewriter.literal ? rewriter.literal(value) : value;
|
|
26
|
+
case "list":
|
|
27
|
+
if (rewriter.list) return rewriter.list(value);
|
|
28
|
+
return value.rewrite(rewriter);
|
|
29
|
+
default: return value.rewrite(rewriter);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function foldComparable(value, folder) {
|
|
33
|
+
switch (value.kind) {
|
|
34
|
+
case "param-ref": return folder.paramRef ? folder.paramRef(value) : folder.empty;
|
|
35
|
+
case "literal": return folder.literal ? folder.literal(value) : folder.empty;
|
|
36
|
+
case "list": return value.fold(folder);
|
|
37
|
+
default: return value.fold(folder);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function collectColumnRefsWith(node) {
|
|
41
|
+
return node.fold({
|
|
42
|
+
empty: [],
|
|
43
|
+
combine: (a, b) => [...a, ...b],
|
|
44
|
+
columnRef: (columnRef) => [columnRef],
|
|
45
|
+
select: (ast) => ast.collectColumnRefs()
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
function collectParamRefsWith(node) {
|
|
49
|
+
return node.fold({
|
|
50
|
+
empty: [],
|
|
51
|
+
combine: (a, b) => [...a, ...b],
|
|
52
|
+
paramRef: (paramRef) => [paramRef],
|
|
53
|
+
select: (ast) => ast.collectParamRefs()
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
function rewriteTableSource(table, rewriter) {
|
|
57
|
+
return rewriter.tableSource ? rewriter.tableSource(table) : table;
|
|
58
|
+
}
|
|
59
|
+
function rewriteProjectionItem(item, rewriter) {
|
|
60
|
+
const rewrittenExpr = item.expr.kind === "literal" ? rewriter.literal ? rewriter.literal(item.expr) : item.expr : item.expr.rewrite(rewriter);
|
|
61
|
+
return new ProjectionItem(item.alias, rewrittenExpr, item.codecId);
|
|
62
|
+
}
|
|
63
|
+
function rewriteInsertValue(value, rewriter) {
|
|
64
|
+
switch (value.kind) {
|
|
65
|
+
case "param-ref": return rewriter.paramRef ? rewriteParamRefForInsert(value, rewriter) : value;
|
|
66
|
+
case "column-ref": return rewriter.columnRef ? rewriteColumnRefForInsert(value, rewriter) : value;
|
|
67
|
+
case "default-value": return value;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function rewriteParamRefForInsert(value, rewriter) {
|
|
71
|
+
const rewritten = rewriter.paramRef ? rewriter.paramRef(value) : value;
|
|
72
|
+
return rewritten.kind === "param-ref" ? rewritten : value;
|
|
73
|
+
}
|
|
74
|
+
function rewriteColumnRefForInsert(value, rewriter) {
|
|
75
|
+
const rewritten = rewriter.columnRef ? rewriter.columnRef(value) : value;
|
|
76
|
+
return rewritten.kind === "column-ref" ? rewritten : value;
|
|
77
|
+
}
|
|
78
|
+
function rewriteInsertRow(row, rewriter) {
|
|
79
|
+
const result = {};
|
|
80
|
+
for (const [key, value] of Object.entries(row)) result[key] = rewriteInsertValue(value, rewriter);
|
|
81
|
+
return result;
|
|
82
|
+
}
|
|
83
|
+
function rewriteUpdateSetValue(value, rewriter) {
|
|
84
|
+
if (value.kind === "column-ref") {
|
|
85
|
+
const rewritten$1 = rewriter.columnRef ? rewriter.columnRef(value) : value;
|
|
86
|
+
return rewritten$1.kind === "column-ref" ? rewritten$1 : value;
|
|
87
|
+
}
|
|
88
|
+
const rewritten = rewriter.paramRef ? rewriter.paramRef(value) : value;
|
|
89
|
+
return rewritten.kind === "param-ref" ? rewritten : value;
|
|
90
|
+
}
|
|
91
|
+
function rewriteUpdateSet(set, rewriter) {
|
|
92
|
+
const result = {};
|
|
93
|
+
for (const [key, value] of Object.entries(set)) result[key] = rewriteUpdateSetValue(value, rewriter);
|
|
94
|
+
return result;
|
|
95
|
+
}
|
|
96
|
+
function rewriteOnConflict(onConflict, rewriter) {
|
|
97
|
+
const columns = onConflict.columns.map((columnRef) => {
|
|
98
|
+
const rewritten = rewriter.columnRef ? rewriter.columnRef(columnRef) : columnRef;
|
|
99
|
+
return rewritten.kind === "column-ref" ? rewritten : columnRef;
|
|
100
|
+
});
|
|
101
|
+
if (onConflict.action.kind === "do-nothing") return new InsertOnConflict(columns, new DoNothingConflictAction());
|
|
102
|
+
return new InsertOnConflict(columns, new DoUpdateSetConflictAction(rewriteUpdateSet(onConflict.action.set, rewriter)));
|
|
103
|
+
}
|
|
104
|
+
var AstNode = class {
|
|
105
|
+
freeze() {
|
|
106
|
+
Object.freeze(this);
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
var QueryAst = class extends AstNode {};
|
|
110
|
+
var FromSource = class extends AstNode {};
|
|
111
|
+
var Expression = class extends AstNode {
|
|
112
|
+
collectColumnRefs() {
|
|
113
|
+
return collectColumnRefsWith(this);
|
|
114
|
+
}
|
|
115
|
+
collectParamRefs() {
|
|
116
|
+
return collectParamRefsWith(this);
|
|
117
|
+
}
|
|
118
|
+
baseColumnRef() {
|
|
119
|
+
throw new Error(`${this.constructor.name} does not expose a base column reference`);
|
|
120
|
+
}
|
|
121
|
+
toExpr() {
|
|
122
|
+
return this;
|
|
123
|
+
}
|
|
124
|
+
not() {
|
|
125
|
+
return new NotExpr(this);
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
var TableSource = class TableSource extends FromSource {
|
|
129
|
+
kind = "table-source";
|
|
130
|
+
name;
|
|
131
|
+
alias;
|
|
132
|
+
constructor(name, alias) {
|
|
133
|
+
super();
|
|
134
|
+
this.name = name;
|
|
135
|
+
this.alias = alias;
|
|
136
|
+
this.freeze();
|
|
137
|
+
}
|
|
138
|
+
static named(name, alias) {
|
|
139
|
+
return new TableSource(name, alias);
|
|
140
|
+
}
|
|
141
|
+
rewrite(rewriter) {
|
|
142
|
+
return rewriter.tableSource ? rewriter.tableSource(this) : this;
|
|
143
|
+
}
|
|
144
|
+
toFromSource() {
|
|
145
|
+
return this;
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
var DerivedTableSource = class DerivedTableSource extends FromSource {
|
|
149
|
+
kind = "derived-table-source";
|
|
150
|
+
alias;
|
|
151
|
+
query;
|
|
152
|
+
constructor(alias, query) {
|
|
153
|
+
super();
|
|
154
|
+
this.alias = alias;
|
|
155
|
+
this.query = query;
|
|
156
|
+
this.freeze();
|
|
157
|
+
}
|
|
158
|
+
static as(alias, query) {
|
|
159
|
+
return new DerivedTableSource(alias, query);
|
|
160
|
+
}
|
|
161
|
+
rewrite(rewriter) {
|
|
162
|
+
return new DerivedTableSource(this.alias, this.query.rewrite(rewriter));
|
|
163
|
+
}
|
|
164
|
+
toFromSource() {
|
|
165
|
+
return this;
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
var ColumnRef = class ColumnRef extends Expression {
|
|
169
|
+
kind = "column-ref";
|
|
170
|
+
table;
|
|
171
|
+
column;
|
|
172
|
+
constructor(table, column) {
|
|
173
|
+
super();
|
|
174
|
+
this.table = table;
|
|
175
|
+
this.column = column;
|
|
176
|
+
this.freeze();
|
|
177
|
+
}
|
|
178
|
+
static of(table, column) {
|
|
179
|
+
return new ColumnRef(table, column);
|
|
180
|
+
}
|
|
181
|
+
accept(visitor) {
|
|
182
|
+
return visitor.columnRef(this);
|
|
183
|
+
}
|
|
184
|
+
rewrite(rewriter) {
|
|
185
|
+
return rewriter.columnRef ? rewriter.columnRef(this) : this;
|
|
186
|
+
}
|
|
187
|
+
fold(folder) {
|
|
188
|
+
return folder.columnRef ? folder.columnRef(this) : folder.empty;
|
|
189
|
+
}
|
|
190
|
+
baseColumnRef() {
|
|
191
|
+
return this;
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
var IdentifierRef = class IdentifierRef extends Expression {
|
|
195
|
+
kind = "identifier-ref";
|
|
196
|
+
name;
|
|
197
|
+
constructor(name) {
|
|
198
|
+
super();
|
|
199
|
+
this.name = name;
|
|
200
|
+
this.freeze();
|
|
201
|
+
}
|
|
202
|
+
static of(name) {
|
|
203
|
+
return new IdentifierRef(name);
|
|
204
|
+
}
|
|
205
|
+
accept(visitor) {
|
|
206
|
+
return visitor.identifierRef(this);
|
|
207
|
+
}
|
|
208
|
+
rewrite(rewriter) {
|
|
209
|
+
return rewriter.identifierRef ? rewriter.identifierRef(this) : this;
|
|
210
|
+
}
|
|
211
|
+
fold(folder) {
|
|
212
|
+
return folder.identifierRef ? folder.identifierRef(this) : folder.empty;
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
var ParamRef = class ParamRef extends Expression {
|
|
216
|
+
kind = "param-ref";
|
|
217
|
+
value;
|
|
218
|
+
name;
|
|
219
|
+
codecId;
|
|
220
|
+
constructor(value, options) {
|
|
221
|
+
super();
|
|
222
|
+
this.value = value;
|
|
223
|
+
this.name = options?.name;
|
|
224
|
+
this.codecId = options?.codecId;
|
|
225
|
+
this.freeze();
|
|
226
|
+
}
|
|
227
|
+
static of(value, options) {
|
|
228
|
+
return new ParamRef(value, options);
|
|
229
|
+
}
|
|
230
|
+
accept(visitor) {
|
|
231
|
+
return visitor.param(this);
|
|
232
|
+
}
|
|
233
|
+
rewrite(rewriter) {
|
|
234
|
+
return rewriter.paramRef ? rewriter.paramRef(this) : this;
|
|
235
|
+
}
|
|
236
|
+
fold(folder) {
|
|
237
|
+
return folder.paramRef ? folder.paramRef(this) : folder.empty;
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
var DefaultValueExpr = class extends AstNode {
|
|
241
|
+
kind = "default-value";
|
|
242
|
+
constructor() {
|
|
243
|
+
super();
|
|
244
|
+
this.freeze();
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
var LiteralExpr = class LiteralExpr extends Expression {
|
|
248
|
+
kind = "literal";
|
|
249
|
+
value;
|
|
250
|
+
constructor(value) {
|
|
251
|
+
super();
|
|
252
|
+
this.value = value;
|
|
253
|
+
this.freeze();
|
|
254
|
+
}
|
|
255
|
+
static of(value) {
|
|
256
|
+
return new LiteralExpr(value);
|
|
257
|
+
}
|
|
258
|
+
accept(visitor) {
|
|
259
|
+
return visitor.literal(this);
|
|
260
|
+
}
|
|
261
|
+
rewrite(rewriter) {
|
|
262
|
+
return rewriter.literal ? rewriter.literal(this) : this;
|
|
263
|
+
}
|
|
264
|
+
fold(folder) {
|
|
265
|
+
return folder.literal ? folder.literal(this) : folder.empty;
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
var SubqueryExpr = class SubqueryExpr extends Expression {
|
|
269
|
+
kind = "subquery";
|
|
270
|
+
query;
|
|
271
|
+
constructor(query) {
|
|
272
|
+
super();
|
|
273
|
+
this.query = query;
|
|
274
|
+
this.freeze();
|
|
275
|
+
}
|
|
276
|
+
static of(query) {
|
|
277
|
+
return new SubqueryExpr(query);
|
|
278
|
+
}
|
|
279
|
+
accept(visitor) {
|
|
280
|
+
return visitor.subquery(this);
|
|
281
|
+
}
|
|
282
|
+
rewrite(rewriter) {
|
|
283
|
+
return new SubqueryExpr(this.query.rewrite(rewriter));
|
|
284
|
+
}
|
|
285
|
+
fold(folder) {
|
|
286
|
+
return folder.select ? folder.select(this.query) : folder.empty;
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
var OperationExpr = class OperationExpr extends Expression {
|
|
290
|
+
kind = "operation";
|
|
291
|
+
method;
|
|
292
|
+
self;
|
|
293
|
+
args;
|
|
294
|
+
returns;
|
|
295
|
+
lowering;
|
|
296
|
+
constructor(options) {
|
|
297
|
+
super();
|
|
298
|
+
this.method = options.method;
|
|
299
|
+
this.self = options.self;
|
|
300
|
+
this.args = frozenArrayCopy(options.args ?? []);
|
|
301
|
+
this.returns = options.returns;
|
|
302
|
+
this.lowering = options.lowering;
|
|
303
|
+
this.freeze();
|
|
304
|
+
}
|
|
305
|
+
accept(visitor) {
|
|
306
|
+
return visitor.operation(this);
|
|
307
|
+
}
|
|
308
|
+
rewrite(rewriter) {
|
|
309
|
+
return new OperationExpr({
|
|
310
|
+
method: this.method,
|
|
311
|
+
self: this.self.rewrite(rewriter),
|
|
312
|
+
args: this.args.map((arg) => rewriteComparable(arg, rewriter)),
|
|
313
|
+
returns: this.returns,
|
|
314
|
+
lowering: this.lowering
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
fold(folder) {
|
|
318
|
+
return combineAll(folder, [() => this.self.fold(folder), ...this.args.map((arg) => () => foldComparable(arg, folder))]);
|
|
319
|
+
}
|
|
320
|
+
baseColumnRef() {
|
|
321
|
+
return this.self.baseColumnRef();
|
|
322
|
+
}
|
|
323
|
+
};
|
|
324
|
+
var AggregateExpr = class AggregateExpr extends Expression {
|
|
325
|
+
kind = "aggregate";
|
|
326
|
+
fn;
|
|
327
|
+
expr;
|
|
328
|
+
constructor(fn, expr) {
|
|
329
|
+
super();
|
|
330
|
+
if (fn !== "count" && expr === void 0) throw new Error(`Aggregate function "${fn}" requires an expression`);
|
|
331
|
+
this.fn = fn;
|
|
332
|
+
this.expr = expr;
|
|
333
|
+
this.freeze();
|
|
334
|
+
}
|
|
335
|
+
static count(expr) {
|
|
336
|
+
return new AggregateExpr("count", expr);
|
|
337
|
+
}
|
|
338
|
+
static sum(expr) {
|
|
339
|
+
return new AggregateExpr("sum", expr);
|
|
340
|
+
}
|
|
341
|
+
static avg(expr) {
|
|
342
|
+
return new AggregateExpr("avg", expr);
|
|
343
|
+
}
|
|
344
|
+
static min(expr) {
|
|
345
|
+
return new AggregateExpr("min", expr);
|
|
346
|
+
}
|
|
347
|
+
static max(expr) {
|
|
348
|
+
return new AggregateExpr("max", expr);
|
|
349
|
+
}
|
|
350
|
+
accept(visitor) {
|
|
351
|
+
return visitor.aggregate(this);
|
|
352
|
+
}
|
|
353
|
+
rewrite(rewriter) {
|
|
354
|
+
return this.expr === void 0 ? this : new AggregateExpr(this.fn, this.expr.rewrite(rewriter));
|
|
355
|
+
}
|
|
356
|
+
fold(folder) {
|
|
357
|
+
return this.expr ? this.expr.fold(folder) : folder.empty;
|
|
358
|
+
}
|
|
359
|
+
};
|
|
360
|
+
var JsonObjectExpr = class JsonObjectExpr extends Expression {
|
|
361
|
+
kind = "json-object";
|
|
362
|
+
entries;
|
|
363
|
+
constructor(entries) {
|
|
364
|
+
super();
|
|
365
|
+
this.entries = frozenArrayCopy(entries.map((entry) => Object.freeze({ ...entry })));
|
|
366
|
+
this.freeze();
|
|
367
|
+
}
|
|
368
|
+
static entry(key, value) {
|
|
369
|
+
return {
|
|
370
|
+
key,
|
|
371
|
+
value
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
static fromEntries(entries) {
|
|
375
|
+
return new JsonObjectExpr(entries);
|
|
376
|
+
}
|
|
377
|
+
accept(visitor) {
|
|
378
|
+
return visitor.jsonObject(this);
|
|
379
|
+
}
|
|
380
|
+
rewrite(rewriter) {
|
|
381
|
+
return new JsonObjectExpr(this.entries.map((entry) => ({
|
|
382
|
+
key: entry.key,
|
|
383
|
+
value: entry.value.kind === "literal" ? rewriter.literal ? rewriter.literal(entry.value) : entry.value : entry.value.rewrite(rewriter)
|
|
384
|
+
})));
|
|
385
|
+
}
|
|
386
|
+
fold(folder) {
|
|
387
|
+
return combineAll(folder, this.entries.map((entry) => () => entry.value.kind === "literal" ? folder.literal ? folder.literal(entry.value) : folder.empty : entry.value.fold(folder)));
|
|
388
|
+
}
|
|
389
|
+
};
|
|
390
|
+
var OrderByItem = class OrderByItem extends AstNode {
|
|
391
|
+
kind = "order-by-item";
|
|
392
|
+
expr;
|
|
393
|
+
dir;
|
|
394
|
+
constructor(expr, dir) {
|
|
395
|
+
super();
|
|
396
|
+
this.expr = expr;
|
|
397
|
+
this.dir = dir;
|
|
398
|
+
this.freeze();
|
|
399
|
+
}
|
|
400
|
+
static asc(expr) {
|
|
401
|
+
return new OrderByItem(expr, "asc");
|
|
402
|
+
}
|
|
403
|
+
static desc(expr) {
|
|
404
|
+
return new OrderByItem(expr, "desc");
|
|
405
|
+
}
|
|
406
|
+
rewrite(rewriter) {
|
|
407
|
+
return new OrderByItem(this.expr.rewrite(rewriter), this.dir);
|
|
408
|
+
}
|
|
409
|
+
};
|
|
410
|
+
var JsonArrayAggExpr = class JsonArrayAggExpr extends Expression {
|
|
411
|
+
kind = "json-array-agg";
|
|
412
|
+
expr;
|
|
413
|
+
onEmpty;
|
|
414
|
+
orderBy;
|
|
415
|
+
constructor(expr, onEmpty = "null", orderBy) {
|
|
416
|
+
super();
|
|
417
|
+
this.expr = expr;
|
|
418
|
+
this.onEmpty = onEmpty;
|
|
419
|
+
this.orderBy = orderBy && orderBy.length > 0 ? frozenArrayCopy(orderBy) : void 0;
|
|
420
|
+
this.freeze();
|
|
421
|
+
}
|
|
422
|
+
static of(expr, onEmpty = "null", orderBy) {
|
|
423
|
+
return new JsonArrayAggExpr(expr, onEmpty, orderBy);
|
|
424
|
+
}
|
|
425
|
+
accept(visitor) {
|
|
426
|
+
return visitor.jsonArrayAgg(this);
|
|
427
|
+
}
|
|
428
|
+
rewrite(rewriter) {
|
|
429
|
+
return new JsonArrayAggExpr(this.expr.rewrite(rewriter), this.onEmpty, this.orderBy?.map((orderItem) => orderItem.rewrite(rewriter)));
|
|
430
|
+
}
|
|
431
|
+
fold(folder) {
|
|
432
|
+
return combineAll(folder, [() => this.expr.fold(folder), ...(this.orderBy ?? []).map((orderItem) => () => orderItem.expr.fold(folder))]);
|
|
433
|
+
}
|
|
434
|
+
};
|
|
435
|
+
var ListExpression = class ListExpression extends Expression {
|
|
436
|
+
kind = "list";
|
|
437
|
+
values;
|
|
438
|
+
constructor(values) {
|
|
439
|
+
super();
|
|
440
|
+
this.values = frozenArrayCopy(values);
|
|
441
|
+
this.freeze();
|
|
442
|
+
}
|
|
443
|
+
static of(values) {
|
|
444
|
+
return new ListExpression(values);
|
|
445
|
+
}
|
|
446
|
+
static fromValues(values) {
|
|
447
|
+
return new ListExpression(values.map((value) => new LiteralExpr(value)));
|
|
448
|
+
}
|
|
449
|
+
accept(visitor) {
|
|
450
|
+
return visitor.list(this);
|
|
451
|
+
}
|
|
452
|
+
rewrite(rewriter) {
|
|
453
|
+
if (rewriter.list) return rewriter.list(this);
|
|
454
|
+
return new ListExpression(this.values.map((value) => value.rewrite(rewriter)));
|
|
455
|
+
}
|
|
456
|
+
fold(folder) {
|
|
457
|
+
if (folder.list) return folder.list(this);
|
|
458
|
+
return combineAll(folder, this.values.map((value) => () => value.fold(folder)));
|
|
459
|
+
}
|
|
460
|
+
};
|
|
461
|
+
var BinaryExpr = class BinaryExpr extends Expression {
|
|
462
|
+
kind = "binary";
|
|
463
|
+
op;
|
|
464
|
+
left;
|
|
465
|
+
right;
|
|
466
|
+
constructor(op, left, right) {
|
|
467
|
+
super();
|
|
468
|
+
this.op = op;
|
|
469
|
+
this.left = left;
|
|
470
|
+
this.right = right;
|
|
471
|
+
this.freeze();
|
|
472
|
+
}
|
|
473
|
+
static eq(left, right) {
|
|
474
|
+
return new BinaryExpr("eq", left, right);
|
|
475
|
+
}
|
|
476
|
+
static neq(left, right) {
|
|
477
|
+
return new BinaryExpr("neq", left, right);
|
|
478
|
+
}
|
|
479
|
+
static gt(left, right) {
|
|
480
|
+
return new BinaryExpr("gt", left, right);
|
|
481
|
+
}
|
|
482
|
+
static lt(left, right) {
|
|
483
|
+
return new BinaryExpr("lt", left, right);
|
|
484
|
+
}
|
|
485
|
+
static gte(left, right) {
|
|
486
|
+
return new BinaryExpr("gte", left, right);
|
|
487
|
+
}
|
|
488
|
+
static lte(left, right) {
|
|
489
|
+
return new BinaryExpr("lte", left, right);
|
|
490
|
+
}
|
|
491
|
+
static like(left, right) {
|
|
492
|
+
return new BinaryExpr("like", left, right);
|
|
493
|
+
}
|
|
494
|
+
static in(left, right) {
|
|
495
|
+
return new BinaryExpr("in", left, right);
|
|
496
|
+
}
|
|
497
|
+
static notIn(left, right) {
|
|
498
|
+
return new BinaryExpr("notIn", left, right);
|
|
499
|
+
}
|
|
500
|
+
accept(visitor) {
|
|
501
|
+
return visitor.binary(this);
|
|
502
|
+
}
|
|
503
|
+
rewrite(rewriter) {
|
|
504
|
+
return new BinaryExpr(this.op, rewriteComparable(this.left, rewriter), rewriteComparable(this.right, rewriter));
|
|
505
|
+
}
|
|
506
|
+
fold(folder) {
|
|
507
|
+
return combineAll(folder, [() => foldComparable(this.left, folder), () => foldComparable(this.right, folder)]);
|
|
508
|
+
}
|
|
509
|
+
};
|
|
510
|
+
var AndExpr = class AndExpr extends Expression {
|
|
511
|
+
kind = "and";
|
|
512
|
+
exprs;
|
|
513
|
+
constructor(exprs) {
|
|
514
|
+
super();
|
|
515
|
+
this.exprs = frozenArrayCopy(exprs);
|
|
516
|
+
this.freeze();
|
|
517
|
+
}
|
|
518
|
+
static of(exprs) {
|
|
519
|
+
return new AndExpr(exprs);
|
|
520
|
+
}
|
|
521
|
+
static true() {
|
|
522
|
+
return new AndExpr([]);
|
|
523
|
+
}
|
|
524
|
+
accept(visitor) {
|
|
525
|
+
return visitor.and(this);
|
|
526
|
+
}
|
|
527
|
+
rewrite(rewriter) {
|
|
528
|
+
return new AndExpr(this.exprs.map((expr) => expr.rewrite(rewriter)));
|
|
529
|
+
}
|
|
530
|
+
fold(folder) {
|
|
531
|
+
return combineAll(folder, this.exprs.map((expr) => () => expr.fold(folder)));
|
|
532
|
+
}
|
|
533
|
+
};
|
|
534
|
+
var OrExpr = class OrExpr extends Expression {
|
|
535
|
+
kind = "or";
|
|
536
|
+
exprs;
|
|
537
|
+
constructor(exprs) {
|
|
538
|
+
super();
|
|
539
|
+
this.exprs = frozenArrayCopy(exprs);
|
|
540
|
+
this.freeze();
|
|
541
|
+
}
|
|
542
|
+
static of(exprs) {
|
|
543
|
+
return new OrExpr(exprs);
|
|
544
|
+
}
|
|
545
|
+
static false() {
|
|
546
|
+
return new OrExpr([]);
|
|
547
|
+
}
|
|
548
|
+
accept(visitor) {
|
|
549
|
+
return visitor.or(this);
|
|
550
|
+
}
|
|
551
|
+
rewrite(rewriter) {
|
|
552
|
+
return new OrExpr(this.exprs.map((expr) => expr.rewrite(rewriter)));
|
|
553
|
+
}
|
|
554
|
+
fold(folder) {
|
|
555
|
+
return combineAll(folder, this.exprs.map((expr) => () => expr.fold(folder)));
|
|
556
|
+
}
|
|
557
|
+
};
|
|
558
|
+
var ExistsExpr = class ExistsExpr extends Expression {
|
|
559
|
+
kind = "exists";
|
|
560
|
+
notExists;
|
|
561
|
+
subquery;
|
|
562
|
+
constructor(subquery, notExists = false) {
|
|
563
|
+
super();
|
|
564
|
+
this.notExists = notExists;
|
|
565
|
+
this.subquery = subquery;
|
|
566
|
+
this.freeze();
|
|
567
|
+
}
|
|
568
|
+
static exists(subquery) {
|
|
569
|
+
return new ExistsExpr(subquery, false);
|
|
570
|
+
}
|
|
571
|
+
static notExists(subquery) {
|
|
572
|
+
return new ExistsExpr(subquery, true);
|
|
573
|
+
}
|
|
574
|
+
accept(visitor) {
|
|
575
|
+
return visitor.exists(this);
|
|
576
|
+
}
|
|
577
|
+
rewrite(rewriter) {
|
|
578
|
+
return new ExistsExpr(this.subquery.rewrite(rewriter), this.notExists);
|
|
579
|
+
}
|
|
580
|
+
fold(folder) {
|
|
581
|
+
return folder.select ? folder.select(this.subquery) : folder.empty;
|
|
582
|
+
}
|
|
583
|
+
};
|
|
584
|
+
var NullCheckExpr = class NullCheckExpr extends Expression {
|
|
585
|
+
kind = "null-check";
|
|
586
|
+
expr;
|
|
587
|
+
isNull;
|
|
588
|
+
constructor(expr, isNull) {
|
|
589
|
+
super();
|
|
590
|
+
this.expr = expr;
|
|
591
|
+
this.isNull = isNull;
|
|
592
|
+
this.freeze();
|
|
593
|
+
}
|
|
594
|
+
static isNull(expr) {
|
|
595
|
+
return new NullCheckExpr(expr, true);
|
|
596
|
+
}
|
|
597
|
+
static isNotNull(expr) {
|
|
598
|
+
return new NullCheckExpr(expr, false);
|
|
599
|
+
}
|
|
600
|
+
accept(visitor) {
|
|
601
|
+
return visitor.nullCheck(this);
|
|
602
|
+
}
|
|
603
|
+
rewrite(rewriter) {
|
|
604
|
+
return new NullCheckExpr(this.expr.rewrite(rewriter), this.isNull);
|
|
605
|
+
}
|
|
606
|
+
fold(folder) {
|
|
607
|
+
return this.expr.fold(folder);
|
|
608
|
+
}
|
|
609
|
+
};
|
|
610
|
+
var NotExpr = class NotExpr extends Expression {
|
|
611
|
+
kind = "not";
|
|
612
|
+
expr;
|
|
613
|
+
constructor(expr) {
|
|
614
|
+
super();
|
|
615
|
+
this.expr = expr;
|
|
616
|
+
this.freeze();
|
|
617
|
+
}
|
|
618
|
+
toWhereExpr() {
|
|
619
|
+
return this;
|
|
620
|
+
}
|
|
621
|
+
accept(visitor) {
|
|
622
|
+
return visitor.not(this);
|
|
623
|
+
}
|
|
624
|
+
rewrite(rewriter) {
|
|
625
|
+
return new NotExpr(this.expr.rewrite(rewriter));
|
|
626
|
+
}
|
|
627
|
+
fold(folder) {
|
|
628
|
+
return this.expr.fold(folder);
|
|
629
|
+
}
|
|
630
|
+
};
|
|
631
|
+
var EqColJoinOn = class EqColJoinOn extends AstNode {
|
|
632
|
+
kind = "eq-col-join-on";
|
|
633
|
+
left;
|
|
634
|
+
right;
|
|
635
|
+
constructor(left, right) {
|
|
636
|
+
super();
|
|
637
|
+
this.left = left;
|
|
638
|
+
this.right = right;
|
|
639
|
+
this.freeze();
|
|
640
|
+
}
|
|
641
|
+
static of(left, right) {
|
|
642
|
+
return new EqColJoinOn(left, right);
|
|
643
|
+
}
|
|
644
|
+
rewrite(rewriter) {
|
|
645
|
+
return rewriter.eqColJoinOn ? rewriter.eqColJoinOn(this) : this;
|
|
646
|
+
}
|
|
647
|
+
};
|
|
648
|
+
var JoinAst = class JoinAst extends AstNode {
|
|
649
|
+
kind = "join";
|
|
650
|
+
joinType;
|
|
651
|
+
source;
|
|
652
|
+
lateral;
|
|
653
|
+
on;
|
|
654
|
+
constructor(joinType, source, on, lateral = false) {
|
|
655
|
+
super();
|
|
656
|
+
this.joinType = joinType;
|
|
657
|
+
this.source = source;
|
|
658
|
+
this.lateral = lateral;
|
|
659
|
+
this.on = on;
|
|
660
|
+
this.freeze();
|
|
661
|
+
}
|
|
662
|
+
static inner(source, on, lateral = false) {
|
|
663
|
+
return new JoinAst("inner", source, on, lateral);
|
|
664
|
+
}
|
|
665
|
+
static left(source, on, lateral = false) {
|
|
666
|
+
return new JoinAst("left", source, on, lateral);
|
|
667
|
+
}
|
|
668
|
+
static right(source, on, lateral = false) {
|
|
669
|
+
return new JoinAst("right", source, on, lateral);
|
|
670
|
+
}
|
|
671
|
+
static full(source, on, lateral = false) {
|
|
672
|
+
return new JoinAst("full", source, on, lateral);
|
|
673
|
+
}
|
|
674
|
+
rewrite(rewriter) {
|
|
675
|
+
return new JoinAst(this.joinType, this.source.rewrite(rewriter), this.on.kind === "eq-col-join-on" ? this.on.rewrite(rewriter) : this.on.rewrite(rewriter), this.lateral);
|
|
676
|
+
}
|
|
677
|
+
};
|
|
678
|
+
var ProjectionItem = class ProjectionItem extends AstNode {
|
|
679
|
+
kind = "projection-item";
|
|
680
|
+
alias;
|
|
681
|
+
expr;
|
|
682
|
+
codecId;
|
|
683
|
+
constructor(alias, expr, codecId) {
|
|
684
|
+
super();
|
|
685
|
+
this.alias = alias;
|
|
686
|
+
this.expr = expr;
|
|
687
|
+
this.codecId = codecId;
|
|
688
|
+
this.freeze();
|
|
689
|
+
}
|
|
690
|
+
static of(alias, expr, codecId) {
|
|
691
|
+
return new ProjectionItem(alias, expr, codecId);
|
|
692
|
+
}
|
|
693
|
+
withCodecId(codecId) {
|
|
694
|
+
return new ProjectionItem(this.alias, this.expr, codecId);
|
|
695
|
+
}
|
|
696
|
+
};
|
|
697
|
+
var SelectAst = class SelectAst extends QueryAst {
|
|
698
|
+
kind = "select";
|
|
699
|
+
from;
|
|
700
|
+
joins;
|
|
701
|
+
projection;
|
|
702
|
+
where;
|
|
703
|
+
orderBy;
|
|
704
|
+
distinct;
|
|
705
|
+
distinctOn;
|
|
706
|
+
groupBy;
|
|
707
|
+
having;
|
|
708
|
+
limit;
|
|
709
|
+
offset;
|
|
710
|
+
selectAllIntent;
|
|
711
|
+
constructor(options) {
|
|
712
|
+
super();
|
|
713
|
+
this.from = options.from;
|
|
714
|
+
this.joins = options.joins && options.joins.length > 0 ? frozenArrayCopy(options.joins) : void 0;
|
|
715
|
+
this.projection = frozenArrayCopy(options.projection);
|
|
716
|
+
this.where = options.where;
|
|
717
|
+
this.orderBy = options.orderBy && options.orderBy.length > 0 ? frozenArrayCopy(options.orderBy) : void 0;
|
|
718
|
+
this.distinct = options.distinct;
|
|
719
|
+
this.distinctOn = options.distinctOn && options.distinctOn.length > 0 ? frozenArrayCopy(options.distinctOn) : void 0;
|
|
720
|
+
this.groupBy = options.groupBy && options.groupBy.length > 0 ? frozenArrayCopy(options.groupBy) : void 0;
|
|
721
|
+
this.having = options.having;
|
|
722
|
+
this.limit = options.limit;
|
|
723
|
+
this.offset = options.offset;
|
|
724
|
+
this.selectAllIntent = frozenOptionalRecordCopy(options.selectAllIntent);
|
|
725
|
+
this.freeze();
|
|
726
|
+
}
|
|
727
|
+
static from(from) {
|
|
728
|
+
return new SelectAst({
|
|
729
|
+
from,
|
|
730
|
+
joins: void 0,
|
|
731
|
+
projection: [],
|
|
732
|
+
where: void 0,
|
|
733
|
+
orderBy: void 0,
|
|
734
|
+
distinct: void 0,
|
|
735
|
+
distinctOn: void 0,
|
|
736
|
+
groupBy: void 0,
|
|
737
|
+
having: void 0,
|
|
738
|
+
limit: void 0,
|
|
739
|
+
offset: void 0,
|
|
740
|
+
selectAllIntent: void 0
|
|
741
|
+
});
|
|
742
|
+
}
|
|
743
|
+
withFrom(from) {
|
|
744
|
+
return new SelectAst({
|
|
745
|
+
...this,
|
|
746
|
+
from
|
|
747
|
+
});
|
|
748
|
+
}
|
|
749
|
+
withJoins(joins) {
|
|
750
|
+
return new SelectAst({
|
|
751
|
+
...this,
|
|
752
|
+
joins: joins.length > 0 ? joins : void 0
|
|
753
|
+
});
|
|
754
|
+
}
|
|
755
|
+
withProjection(projection) {
|
|
756
|
+
return new SelectAst({
|
|
757
|
+
...this,
|
|
758
|
+
projection
|
|
759
|
+
});
|
|
760
|
+
}
|
|
761
|
+
addProjection(alias, expr) {
|
|
762
|
+
return new SelectAst({
|
|
763
|
+
...this,
|
|
764
|
+
projection: [...this.projection, new ProjectionItem(alias, expr)]
|
|
765
|
+
});
|
|
766
|
+
}
|
|
767
|
+
withWhere(where) {
|
|
768
|
+
return new SelectAst({
|
|
769
|
+
...this,
|
|
770
|
+
where
|
|
771
|
+
});
|
|
772
|
+
}
|
|
773
|
+
withOrderBy(orderBy) {
|
|
774
|
+
return new SelectAst({
|
|
775
|
+
...this,
|
|
776
|
+
orderBy: orderBy.length > 0 ? orderBy : void 0
|
|
777
|
+
});
|
|
778
|
+
}
|
|
779
|
+
withDistinct(enabled = true) {
|
|
780
|
+
return new SelectAst({
|
|
781
|
+
...this,
|
|
782
|
+
distinct: enabled ? true : void 0
|
|
783
|
+
});
|
|
784
|
+
}
|
|
785
|
+
withDistinctOn(distinctOn) {
|
|
786
|
+
return new SelectAst({
|
|
787
|
+
...this,
|
|
788
|
+
distinctOn: distinctOn.length > 0 ? distinctOn : void 0
|
|
789
|
+
});
|
|
790
|
+
}
|
|
791
|
+
withGroupBy(groupBy) {
|
|
792
|
+
return new SelectAst({
|
|
793
|
+
...this,
|
|
794
|
+
groupBy: groupBy.length > 0 ? groupBy : void 0
|
|
795
|
+
});
|
|
796
|
+
}
|
|
797
|
+
withHaving(having) {
|
|
798
|
+
return new SelectAst({
|
|
799
|
+
...this,
|
|
800
|
+
having
|
|
801
|
+
});
|
|
802
|
+
}
|
|
803
|
+
withLimit(limit) {
|
|
804
|
+
return new SelectAst({
|
|
805
|
+
...this,
|
|
806
|
+
limit
|
|
807
|
+
});
|
|
808
|
+
}
|
|
809
|
+
withOffset(offset) {
|
|
810
|
+
return new SelectAst({
|
|
811
|
+
...this,
|
|
812
|
+
offset
|
|
813
|
+
});
|
|
814
|
+
}
|
|
815
|
+
withSelectAllIntent(selectAllIntent) {
|
|
816
|
+
return new SelectAst({
|
|
817
|
+
...this,
|
|
818
|
+
selectAllIntent
|
|
819
|
+
});
|
|
820
|
+
}
|
|
821
|
+
rewrite(rewriter) {
|
|
822
|
+
const rewritten = new SelectAst({
|
|
823
|
+
from: this.from.rewrite(rewriter),
|
|
824
|
+
joins: this.joins?.map((join) => join.rewrite(rewriter)),
|
|
825
|
+
projection: this.projection.map((projection) => new ProjectionItem(projection.alias, projection.expr.kind === "literal" ? rewriter.literal ? rewriter.literal(projection.expr) : projection.expr : projection.expr.rewrite(rewriter), projection.codecId)),
|
|
826
|
+
where: this.where?.rewrite(rewriter),
|
|
827
|
+
orderBy: this.orderBy?.map((orderItem) => orderItem.rewrite(rewriter)),
|
|
828
|
+
distinct: this.distinct,
|
|
829
|
+
distinctOn: this.distinctOn?.map((expr) => expr.rewrite(rewriter)),
|
|
830
|
+
groupBy: this.groupBy?.map((expr) => expr.rewrite(rewriter)),
|
|
831
|
+
having: this.having?.rewrite(rewriter),
|
|
832
|
+
limit: this.limit,
|
|
833
|
+
offset: this.offset,
|
|
834
|
+
selectAllIntent: this.selectAllIntent
|
|
835
|
+
});
|
|
836
|
+
return rewriter.select ? rewriter.select(rewritten) : rewritten;
|
|
837
|
+
}
|
|
838
|
+
collectColumnRefs() {
|
|
839
|
+
const refs = [];
|
|
840
|
+
const pushRefs = (columns) => {
|
|
841
|
+
refs.push(...columns);
|
|
842
|
+
};
|
|
843
|
+
if (this.from.kind === "derived-table-source") pushRefs(this.from.query.collectColumnRefs());
|
|
844
|
+
for (const projection of this.projection) if (!(projection.expr.kind === "literal")) pushRefs(projection.expr.collectColumnRefs());
|
|
845
|
+
if (this.where) pushRefs(this.where.collectColumnRefs());
|
|
846
|
+
if (this.having) pushRefs(this.having.collectColumnRefs());
|
|
847
|
+
for (const orderItem of this.orderBy ?? []) pushRefs(orderItem.expr.collectColumnRefs());
|
|
848
|
+
for (const expr of this.distinctOn ?? []) pushRefs(expr.collectColumnRefs());
|
|
849
|
+
for (const expr of this.groupBy ?? []) pushRefs(expr.collectColumnRefs());
|
|
850
|
+
for (const join of this.joins ?? []) {
|
|
851
|
+
if (join.source.kind === "derived-table-source") pushRefs(join.source.query.collectColumnRefs());
|
|
852
|
+
if (join.on.kind === "eq-col-join-on") refs.push(join.on.left, join.on.right);
|
|
853
|
+
else pushRefs(join.on.collectColumnRefs());
|
|
854
|
+
}
|
|
855
|
+
return refs;
|
|
856
|
+
}
|
|
857
|
+
collectParamRefs() {
|
|
858
|
+
const refs = [];
|
|
859
|
+
const pushRefs = (params) => {
|
|
860
|
+
refs.push(...params);
|
|
861
|
+
};
|
|
862
|
+
if (this.from.kind === "derived-table-source") pushRefs(this.from.query.collectParamRefs());
|
|
863
|
+
for (const projection of this.projection) if (!(projection.expr.kind === "literal")) pushRefs(projection.expr.collectParamRefs());
|
|
864
|
+
if (this.where) pushRefs(this.where.collectParamRefs());
|
|
865
|
+
if (this.having) pushRefs(this.having.collectParamRefs());
|
|
866
|
+
for (const orderItem of this.orderBy ?? []) pushRefs(orderItem.expr.collectParamRefs());
|
|
867
|
+
for (const expr of this.distinctOn ?? []) pushRefs(expr.collectParamRefs());
|
|
868
|
+
for (const expr of this.groupBy ?? []) pushRefs(expr.collectParamRefs());
|
|
869
|
+
for (const join of this.joins ?? []) {
|
|
870
|
+
if (join.source.kind === "derived-table-source") pushRefs(join.source.query.collectParamRefs());
|
|
871
|
+
if (!(join.on.kind === "eq-col-join-on")) pushRefs(join.on.collectParamRefs());
|
|
872
|
+
}
|
|
873
|
+
return refs;
|
|
874
|
+
}
|
|
875
|
+
toQueryAst() {
|
|
876
|
+
return this;
|
|
877
|
+
}
|
|
878
|
+
};
|
|
879
|
+
var InsertOnConflictAction = class extends AstNode {};
|
|
880
|
+
var DoNothingConflictAction = class extends InsertOnConflictAction {
|
|
881
|
+
kind = "do-nothing";
|
|
882
|
+
constructor() {
|
|
883
|
+
super();
|
|
884
|
+
this.freeze();
|
|
885
|
+
}
|
|
886
|
+
toInsertOnConflictAction() {
|
|
887
|
+
return this;
|
|
888
|
+
}
|
|
889
|
+
};
|
|
890
|
+
var DoUpdateSetConflictAction = class extends InsertOnConflictAction {
|
|
891
|
+
kind = "do-update-set";
|
|
892
|
+
set;
|
|
893
|
+
constructor(set) {
|
|
894
|
+
super();
|
|
895
|
+
this.set = frozenRecordCopy(set);
|
|
896
|
+
this.freeze();
|
|
897
|
+
}
|
|
898
|
+
toInsertOnConflictAction() {
|
|
899
|
+
return this;
|
|
900
|
+
}
|
|
901
|
+
};
|
|
902
|
+
var InsertOnConflict = class InsertOnConflict extends AstNode {
|
|
903
|
+
kind = "insert-on-conflict";
|
|
904
|
+
columns;
|
|
905
|
+
action;
|
|
906
|
+
constructor(columns, action) {
|
|
907
|
+
super();
|
|
908
|
+
this.columns = frozenArrayCopy(columns);
|
|
909
|
+
this.action = action;
|
|
910
|
+
this.freeze();
|
|
911
|
+
}
|
|
912
|
+
static on(columns) {
|
|
913
|
+
return new InsertOnConflict(columns, new DoNothingConflictAction());
|
|
914
|
+
}
|
|
915
|
+
doNothing() {
|
|
916
|
+
return new InsertOnConflict(this.columns, new DoNothingConflictAction());
|
|
917
|
+
}
|
|
918
|
+
doUpdateSet(set) {
|
|
919
|
+
return new InsertOnConflict(this.columns, new DoUpdateSetConflictAction(set));
|
|
920
|
+
}
|
|
921
|
+
};
|
|
922
|
+
var InsertAst = class InsertAst extends QueryAst {
|
|
923
|
+
kind = "insert";
|
|
924
|
+
table;
|
|
925
|
+
rows;
|
|
926
|
+
onConflict;
|
|
927
|
+
returning;
|
|
928
|
+
constructor(table, rows = [{}], onConflict, returning) {
|
|
929
|
+
super();
|
|
930
|
+
this.table = table;
|
|
931
|
+
this.rows = freezeRows(rows);
|
|
932
|
+
this.onConflict = onConflict;
|
|
933
|
+
this.returning = returning && returning.length > 0 ? frozenArrayCopy(returning) : void 0;
|
|
934
|
+
this.freeze();
|
|
935
|
+
}
|
|
936
|
+
static into(table) {
|
|
937
|
+
return new InsertAst(table);
|
|
938
|
+
}
|
|
939
|
+
withValues(values) {
|
|
940
|
+
return new InsertAst(this.table, [{ ...values }], this.onConflict, this.returning);
|
|
941
|
+
}
|
|
942
|
+
withRows(rows) {
|
|
943
|
+
return new InsertAst(this.table, rows.map((row) => ({ ...row })), this.onConflict, this.returning);
|
|
944
|
+
}
|
|
945
|
+
withReturning(returning) {
|
|
946
|
+
return new InsertAst(this.table, this.rows.map((row) => ({ ...row })), this.onConflict, returning);
|
|
947
|
+
}
|
|
948
|
+
withOnConflict(onConflict) {
|
|
949
|
+
return new InsertAst(this.table, this.rows.map((row) => ({ ...row })), onConflict, this.returning);
|
|
950
|
+
}
|
|
951
|
+
rewrite(rewriter) {
|
|
952
|
+
return new InsertAst(rewriteTableSource(this.table, rewriter), this.rows.map((row) => rewriteInsertRow(row, rewriter)), this.onConflict ? rewriteOnConflict(this.onConflict, rewriter) : void 0, this.returning?.map((item) => rewriteProjectionItem(item, rewriter)));
|
|
953
|
+
}
|
|
954
|
+
collectParamRefs() {
|
|
955
|
+
const refs = [];
|
|
956
|
+
for (const row of this.rows) for (const value of Object.values(row)) if (value.kind === "param-ref") refs.push(value);
|
|
957
|
+
if (this.onConflict?.action.kind === "do-update-set") {
|
|
958
|
+
for (const value of Object.values(this.onConflict.action.set)) if (value.kind === "param-ref") refs.push(value);
|
|
959
|
+
}
|
|
960
|
+
for (const item of this.returning ?? []) if (item.expr.kind !== "literal") refs.push(...item.expr.collectParamRefs());
|
|
961
|
+
return refs;
|
|
962
|
+
}
|
|
963
|
+
toQueryAst() {
|
|
964
|
+
return this;
|
|
965
|
+
}
|
|
966
|
+
};
|
|
967
|
+
var UpdateAst = class UpdateAst extends QueryAst {
|
|
968
|
+
kind = "update";
|
|
969
|
+
table;
|
|
970
|
+
set;
|
|
971
|
+
where;
|
|
972
|
+
returning;
|
|
973
|
+
constructor(table, set = {}, where, returning) {
|
|
974
|
+
super();
|
|
975
|
+
this.table = table;
|
|
976
|
+
this.set = frozenRecordCopy(set);
|
|
977
|
+
this.where = where;
|
|
978
|
+
this.returning = returning && returning.length > 0 ? frozenArrayCopy(returning) : void 0;
|
|
979
|
+
this.freeze();
|
|
980
|
+
}
|
|
981
|
+
static table(table) {
|
|
982
|
+
return new UpdateAst(table);
|
|
983
|
+
}
|
|
984
|
+
withSet(set) {
|
|
985
|
+
return new UpdateAst(this.table, set, this.where, this.returning);
|
|
986
|
+
}
|
|
987
|
+
withWhere(where) {
|
|
988
|
+
return new UpdateAst(this.table, this.set, where, this.returning);
|
|
989
|
+
}
|
|
990
|
+
withReturning(returning) {
|
|
991
|
+
return new UpdateAst(this.table, this.set, this.where, returning);
|
|
992
|
+
}
|
|
993
|
+
rewrite(rewriter) {
|
|
994
|
+
return new UpdateAst(rewriteTableSource(this.table, rewriter), rewriteUpdateSet(this.set, rewriter), this.where?.rewrite(rewriter), this.returning?.map((item) => rewriteProjectionItem(item, rewriter)));
|
|
995
|
+
}
|
|
996
|
+
collectParamRefs() {
|
|
997
|
+
const refs = [];
|
|
998
|
+
for (const value of Object.values(this.set)) if (value.kind === "param-ref") refs.push(value);
|
|
999
|
+
if (this.where) refs.push(...this.where.collectParamRefs());
|
|
1000
|
+
for (const item of this.returning ?? []) if (item.expr.kind !== "literal") refs.push(...item.expr.collectParamRefs());
|
|
1001
|
+
return refs;
|
|
1002
|
+
}
|
|
1003
|
+
toQueryAst() {
|
|
1004
|
+
return this;
|
|
1005
|
+
}
|
|
1006
|
+
};
|
|
1007
|
+
var DeleteAst = class DeleteAst extends QueryAst {
|
|
1008
|
+
kind = "delete";
|
|
1009
|
+
table;
|
|
1010
|
+
where;
|
|
1011
|
+
returning;
|
|
1012
|
+
constructor(table, where, returning) {
|
|
1013
|
+
super();
|
|
1014
|
+
this.table = table;
|
|
1015
|
+
this.where = where;
|
|
1016
|
+
this.returning = returning && returning.length > 0 ? frozenArrayCopy(returning) : void 0;
|
|
1017
|
+
this.freeze();
|
|
1018
|
+
}
|
|
1019
|
+
static from(table) {
|
|
1020
|
+
return new DeleteAst(table);
|
|
1021
|
+
}
|
|
1022
|
+
withWhere(where) {
|
|
1023
|
+
return new DeleteAst(this.table, where, this.returning);
|
|
1024
|
+
}
|
|
1025
|
+
withReturning(returning) {
|
|
1026
|
+
return new DeleteAst(this.table, this.where, returning);
|
|
1027
|
+
}
|
|
1028
|
+
rewrite(rewriter) {
|
|
1029
|
+
return new DeleteAst(rewriteTableSource(this.table, rewriter), this.where?.rewrite(rewriter), this.returning?.map((item) => rewriteProjectionItem(item, rewriter)));
|
|
1030
|
+
}
|
|
1031
|
+
collectParamRefs() {
|
|
1032
|
+
const refs = [];
|
|
1033
|
+
if (this.where) refs.push(...this.where.collectParamRefs());
|
|
1034
|
+
for (const item of this.returning ?? []) if (item.expr.kind !== "literal") refs.push(...item.expr.collectParamRefs());
|
|
1035
|
+
return refs;
|
|
1036
|
+
}
|
|
1037
|
+
toQueryAst() {
|
|
1038
|
+
return this;
|
|
1039
|
+
}
|
|
1040
|
+
};
|
|
1041
|
+
const queryAstKinds = new Set([
|
|
1042
|
+
"select",
|
|
1043
|
+
"insert",
|
|
1044
|
+
"update",
|
|
1045
|
+
"delete"
|
|
1046
|
+
]);
|
|
1047
|
+
const whereExprKinds = new Set([
|
|
1048
|
+
"binary",
|
|
1049
|
+
"and",
|
|
1050
|
+
"or",
|
|
1051
|
+
"exists",
|
|
1052
|
+
"null-check",
|
|
1053
|
+
"not"
|
|
1054
|
+
]);
|
|
1055
|
+
function isQueryAst(value) {
|
|
1056
|
+
return typeof value === "object" && value !== null && "kind" in value && queryAstKinds.has(value.kind);
|
|
1057
|
+
}
|
|
1058
|
+
function isWhereExpr(value) {
|
|
1059
|
+
return typeof value === "object" && value !== null && "kind" in value && whereExprKinds.has(value.kind);
|
|
1060
|
+
}
|
|
1061
|
+
|
|
1062
|
+
//#endregion
|
|
1063
|
+
export { UpdateAst as A, OrExpr as C, SelectAst as D, ProjectionItem as E, isWhereExpr as M, queryAstKinds as N, SubqueryExpr as O, whereExprKinds as P, OperationExpr as S, ParamRef as T, JsonObjectExpr as _, DefaultValueExpr as a, NotExpr as b, DoNothingConflictAction as c, ExistsExpr as d, IdentifierRef as f, JsonArrayAggExpr as g, JoinAst as h, ColumnRef as i, isQueryAst as j, TableSource as k, DoUpdateSetConflictAction as l, InsertOnConflict as m, AndExpr as n, DeleteAst as o, InsertAst as p, BinaryExpr as r, DerivedTableSource as s, AggregateExpr as t, EqColJoinOn as u, ListExpression as v, OrderByItem as w, NullCheckExpr as x, LiteralExpr as y };
|
|
1064
|
+
//# sourceMappingURL=types-DUL-3vy6.mjs.map
|