effect-qb 0.19.0 → 0.20.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/README.md +7 -1
- package/dist/index.js +1990 -679
- package/dist/mysql.js +1490 -617
- package/dist/postgres/metadata.js +1334 -263
- package/dist/postgres.js +3376 -2307
- package/dist/sqlite.js +1573 -628
- package/dist/standard.js +1984 -673
- package/package.json +2 -4
- package/src/internal/coercion/rules.ts +13 -1
- package/src/internal/column-state.d.ts +3 -3
- package/src/internal/column-state.ts +13 -12
- package/src/internal/column.ts +8 -8
- package/src/internal/datatypes/define.ts +5 -0
- package/src/internal/datatypes/lookup.ts +67 -18
- package/src/internal/datatypes/matrix.ts +903 -0
- package/src/internal/datatypes/shape.ts +2 -0
- package/src/internal/dialect-renderers/mysql.ts +6 -4
- package/src/internal/dialect-renderers/postgres.ts +6 -4
- package/src/internal/dialect-renderers/sqlite.ts +6 -4
- package/src/internal/dialect.ts +1 -1
- package/src/internal/executor.ts +56 -43
- package/src/internal/json/path-access.ts +351 -0
- package/src/internal/query.d.ts +1 -1
- package/src/internal/query.ts +1 -1
- package/src/internal/runtime/driver-value-mapping.ts +3 -3
- package/src/internal/runtime/schema.ts +28 -38
- package/src/internal/runtime/value.ts +20 -23
- package/src/internal/scalar.d.ts +1 -1
- package/src/internal/scalar.ts +2 -1
- package/src/internal/schema-derivation.d.ts +7 -7
- package/src/internal/schema-derivation.ts +11 -11
- package/src/internal/standard-dsl.ts +121 -28
- package/src/internal/table.ts +451 -120
- package/src/mysql/column.ts +6 -6
- package/src/mysql/datatypes/index.ts +1 -0
- package/src/mysql/datatypes/spec.ts +6 -176
- package/src/mysql/errors/normalize.ts +0 -1
- package/src/mysql/executor.ts +4 -6
- package/src/mysql/function/temporal.ts +1 -1
- package/src/mysql/internal/dsl.ts +116 -16
- package/src/mysql/json.ts +1 -33
- package/src/mysql/renderer.ts +13 -6
- package/src/mysql/type.ts +60 -0
- package/src/mysql.ts +3 -1
- package/src/postgres/check.ts +1 -0
- package/src/postgres/column.ts +11 -11
- package/src/postgres/datatypes/index.ts +1 -0
- package/src/postgres/datatypes/spec.ts +6 -260
- package/src/postgres/errors/normalize.ts +0 -1
- package/src/postgres/executor.ts +4 -6
- package/src/postgres/foreign-key.ts +24 -0
- package/src/postgres/function/temporal.ts +1 -1
- package/src/postgres/index.ts +1 -0
- package/src/postgres/internal/dsl.ts +122 -21
- package/src/postgres/json-extension.ts +7 -0
- package/src/postgres/json.ts +726 -173
- package/src/postgres/jsonb.ts +0 -1
- package/src/postgres/primary-key.ts +24 -0
- package/src/postgres/renderer.ts +13 -6
- package/src/postgres/schema-management.ts +1 -6
- package/src/postgres/schema.ts +16 -8
- package/src/postgres/table.ts +111 -113
- package/src/postgres/type.ts +86 -4
- package/src/postgres/unique.ts +32 -0
- package/src/postgres.ts +12 -6
- package/src/sqlite/column.ts +6 -6
- package/src/sqlite/datatypes/index.ts +1 -0
- package/src/sqlite/datatypes/spec.ts +6 -94
- package/src/sqlite/errors/normalize.ts +0 -1
- package/src/sqlite/executor.ts +4 -6
- package/src/sqlite/function/temporal.ts +1 -1
- package/src/sqlite/internal/dsl.ts +100 -5
- package/src/sqlite/json.ts +1 -32
- package/src/sqlite/renderer.ts +13 -6
- package/src/sqlite/type.ts +40 -0
- package/src/sqlite.ts +3 -1
- package/src/standard/cast.ts +113 -0
- package/src/standard/check.ts +17 -0
- package/src/standard/column.ts +10 -10
- package/src/standard/datatypes/index.ts +2 -2
- package/src/standard/datatypes/spec.ts +10 -96
- package/src/standard/foreign-key.ts +37 -0
- package/src/standard/function/temporal.ts +1 -1
- package/src/standard/index.ts +17 -0
- package/src/standard/json.ts +883 -0
- package/src/standard/primary-key.ts +17 -0
- package/src/standard/renderer.ts +31 -3
- package/src/standard/table.ts +25 -21
- package/src/standard/unique.ts +17 -0
- package/src/standard.ts +14 -0
- package/src/internal/table.d.ts +0 -174
- package/src/postgres/cast.ts +0 -45
package/dist/standard.js
CHANGED
|
@@ -44,7 +44,7 @@ import * as Schema4 from "effect/Schema";
|
|
|
44
44
|
import * as Schema2 from "effect/Schema";
|
|
45
45
|
|
|
46
46
|
// src/internal/column-state.ts
|
|
47
|
-
import { pipeArguments } from "effect/Pipeable";
|
|
47
|
+
import { pipeArguments as pipeArguments2 } from "effect/Pipeable";
|
|
48
48
|
import * as Schema from "effect/Schema";
|
|
49
49
|
|
|
50
50
|
// src/internal/scalar.ts
|
|
@@ -57,12 +57,181 @@ var TypeId = Symbol.for("effect-qb/Expression");
|
|
|
57
57
|
// src/internal/expression-ast.ts
|
|
58
58
|
var TypeId2 = Symbol.for("effect-qb/ExpressionAst");
|
|
59
59
|
|
|
60
|
+
// src/internal/json/path-access.ts
|
|
61
|
+
import { pipeArguments } from "effect/Pipeable";
|
|
62
|
+
|
|
63
|
+
// src/internal/json/path.ts
|
|
64
|
+
var SegmentTypeId = Symbol.for("effect-qb/JsonPathSegment");
|
|
65
|
+
var TypeId3 = Symbol.for("effect-qb/JsonPath");
|
|
66
|
+
var makeSegment = (segment) => segment;
|
|
67
|
+
var key = (value) => makeSegment({
|
|
68
|
+
[SegmentTypeId]: {
|
|
69
|
+
kind: "key"
|
|
70
|
+
},
|
|
71
|
+
kind: "key",
|
|
72
|
+
key: value
|
|
73
|
+
});
|
|
74
|
+
var index = (value) => makeSegment({
|
|
75
|
+
[SegmentTypeId]: {
|
|
76
|
+
kind: "index"
|
|
77
|
+
},
|
|
78
|
+
kind: "index",
|
|
79
|
+
index: value
|
|
80
|
+
});
|
|
81
|
+
var wildcard = () => makeSegment({
|
|
82
|
+
[SegmentTypeId]: {
|
|
83
|
+
kind: "wildcard"
|
|
84
|
+
},
|
|
85
|
+
kind: "wildcard"
|
|
86
|
+
});
|
|
87
|
+
var slice = (start, end) => makeSegment({
|
|
88
|
+
[SegmentTypeId]: {
|
|
89
|
+
kind: "slice"
|
|
90
|
+
},
|
|
91
|
+
kind: "slice",
|
|
92
|
+
start,
|
|
93
|
+
end
|
|
94
|
+
});
|
|
95
|
+
var descend = () => makeSegment({
|
|
96
|
+
[SegmentTypeId]: {
|
|
97
|
+
kind: "descend"
|
|
98
|
+
},
|
|
99
|
+
kind: "descend"
|
|
100
|
+
});
|
|
101
|
+
var path = (...segments) => ({
|
|
102
|
+
[TypeId3]: {
|
|
103
|
+
segments
|
|
104
|
+
},
|
|
105
|
+
segments
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
// src/internal/json/path-access.ts
|
|
109
|
+
var WrappedTypeId = Symbol.for("effect-qb/JsonPathAccess");
|
|
110
|
+
var accessKinds = new Set([
|
|
111
|
+
"jsonGet",
|
|
112
|
+
"jsonPath",
|
|
113
|
+
"jsonAccess",
|
|
114
|
+
"jsonTraverse",
|
|
115
|
+
"jsonGetText",
|
|
116
|
+
"jsonPathText",
|
|
117
|
+
"jsonAccessText",
|
|
118
|
+
"jsonTraverseText"
|
|
119
|
+
]);
|
|
120
|
+
var reservedKeys = new Set([
|
|
121
|
+
"pipe",
|
|
122
|
+
"then",
|
|
123
|
+
"toString",
|
|
124
|
+
"toJSON",
|
|
125
|
+
"valueOf",
|
|
126
|
+
"constructor",
|
|
127
|
+
"__proto__",
|
|
128
|
+
"prototype",
|
|
129
|
+
"inspect",
|
|
130
|
+
"schema",
|
|
131
|
+
"metadata",
|
|
132
|
+
"columns",
|
|
133
|
+
"name"
|
|
134
|
+
]);
|
|
135
|
+
var isObjectLike = (value) => (typeof value === "object" || typeof value === "function") && value !== null;
|
|
136
|
+
var isExpression = (value) => isObjectLike(value) && (TypeId in value);
|
|
137
|
+
var isJsonExpression = (value) => {
|
|
138
|
+
if (!isExpression(value)) {
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
const dbType = value[TypeId].dbType;
|
|
142
|
+
return dbType.kind === "json" || dbType.kind === "jsonb" || dbType.variant === "json" || dbType.variant === "jsonb";
|
|
143
|
+
};
|
|
144
|
+
var isWrapped = (value) => value[WrappedTypeId] === true;
|
|
145
|
+
var normalizeSegment = (segment) => {
|
|
146
|
+
switch (segment.kind) {
|
|
147
|
+
case "key":
|
|
148
|
+
return key(segment.key);
|
|
149
|
+
case "index":
|
|
150
|
+
return index(segment.index);
|
|
151
|
+
case "wildcard":
|
|
152
|
+
return wildcard();
|
|
153
|
+
case "slice":
|
|
154
|
+
return slice(segment.start, segment.end);
|
|
155
|
+
case "descend":
|
|
156
|
+
return descend();
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
var accessPathOf = (value) => {
|
|
160
|
+
const segments = [];
|
|
161
|
+
let base = value;
|
|
162
|
+
while (isExpression(base)) {
|
|
163
|
+
const ast = base[TypeId2];
|
|
164
|
+
if (ast === undefined || typeof ast.kind !== "string" || !accessKinds.has(ast.kind) || !isExpression(ast.base) || !Array.isArray(ast.segments)) {
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
segments.unshift(...ast.segments.map(normalizeSegment));
|
|
168
|
+
base = ast.base;
|
|
169
|
+
}
|
|
170
|
+
return { base, segments };
|
|
171
|
+
};
|
|
172
|
+
var isIntegerProperty = (property) => /^(?:-?(?:0|[1-9][0-9]*))$/.test(property);
|
|
173
|
+
var jsonAccessKind = (segments) => segments.every((segment) => segment.kind === "key" || segment.kind === "index") ? segments.length === 1 ? "jsonGet" : "jsonPath" : "jsonTraverse";
|
|
174
|
+
var makeExpression = (state, ast) => {
|
|
175
|
+
const expression = Object.create(null);
|
|
176
|
+
Object.defineProperty(expression, "pipe", {
|
|
177
|
+
configurable: true,
|
|
178
|
+
writable: true,
|
|
179
|
+
value: function() {
|
|
180
|
+
return pipeArguments(expression, arguments);
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
expression[TypeId] = state;
|
|
184
|
+
expression[TypeId2] = ast;
|
|
185
|
+
return expression;
|
|
186
|
+
};
|
|
187
|
+
var makePathExpression = (value, segment) => {
|
|
188
|
+
const access = accessPathOf(value);
|
|
189
|
+
const segments = [...access.segments, normalizeSegment(segment)];
|
|
190
|
+
const base = access.base;
|
|
191
|
+
const baseState = base[TypeId];
|
|
192
|
+
return withJsonPathAccess(makeExpression({
|
|
193
|
+
...baseState,
|
|
194
|
+
runtime: undefined,
|
|
195
|
+
nullability: undefined
|
|
196
|
+
}, {
|
|
197
|
+
kind: jsonAccessKind(segments),
|
|
198
|
+
base,
|
|
199
|
+
segments
|
|
200
|
+
}));
|
|
201
|
+
};
|
|
202
|
+
var pathProxyHandler = {
|
|
203
|
+
get(target, property, receiver) {
|
|
204
|
+
if (typeof property === "symbol") {
|
|
205
|
+
return Reflect.get(target, property, receiver);
|
|
206
|
+
}
|
|
207
|
+
if (Reflect.has(target, property) || reservedKeys.has(property)) {
|
|
208
|
+
return Reflect.get(target, property, receiver);
|
|
209
|
+
}
|
|
210
|
+
const segment = isIntegerProperty(property) ? index(Number(property)) : key(property);
|
|
211
|
+
return makePathExpression(target, segment);
|
|
212
|
+
},
|
|
213
|
+
has(target, property) {
|
|
214
|
+
return Reflect.has(target, property);
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
var withJsonPathAccess = (value) => {
|
|
218
|
+
if (!isObjectLike(value) || !isJsonExpression(value) || isWrapped(value)) {
|
|
219
|
+
return value;
|
|
220
|
+
}
|
|
221
|
+
const proxy = new Proxy(value, pathProxyHandler);
|
|
222
|
+
Object.defineProperty(proxy, WrappedTypeId, {
|
|
223
|
+
configurable: false,
|
|
224
|
+
value: true
|
|
225
|
+
});
|
|
226
|
+
return proxy;
|
|
227
|
+
};
|
|
228
|
+
|
|
60
229
|
// src/internal/column-state.ts
|
|
61
230
|
var ColumnTypeId = Symbol.for("effect-qb/Column");
|
|
62
231
|
var BoundColumnTypeId = Symbol.for("effect-qb/BoundColumn");
|
|
63
232
|
var ColumnProto = {
|
|
64
233
|
pipe() {
|
|
65
|
-
return
|
|
234
|
+
return pipeArguments2(this, arguments);
|
|
66
235
|
}
|
|
67
236
|
};
|
|
68
237
|
var attachPipe = (value) => {
|
|
@@ -70,7 +239,7 @@ var attachPipe = (value) => {
|
|
|
70
239
|
configurable: true,
|
|
71
240
|
writable: true,
|
|
72
241
|
value: function() {
|
|
73
|
-
return
|
|
242
|
+
return pipeArguments2(value, arguments);
|
|
74
243
|
}
|
|
75
244
|
});
|
|
76
245
|
return value;
|
|
@@ -107,7 +276,7 @@ var makeColumnDefinition = (schema, metadata) => {
|
|
|
107
276
|
identity: metadata.identity,
|
|
108
277
|
enum: metadata.enum
|
|
109
278
|
};
|
|
110
|
-
return column;
|
|
279
|
+
return withJsonPathAccess(column);
|
|
111
280
|
};
|
|
112
281
|
var remapColumnDefinition = (column, options = {}) => {
|
|
113
282
|
const schema = options.schema ?? column.schema;
|
|
@@ -149,7 +318,7 @@ var remapColumnDefinition = (column, options = {}) => {
|
|
|
149
318
|
if (BoundColumnTypeId in column) {
|
|
150
319
|
next[BoundColumnTypeId] = column[BoundColumnTypeId];
|
|
151
320
|
}
|
|
152
|
-
return next;
|
|
321
|
+
return withJsonPathAccess(next);
|
|
153
322
|
};
|
|
154
323
|
var bindColumn = (tableName, columnName, column, baseTableName, schemaName, casing) => {
|
|
155
324
|
const brandName = `${tableName}.${columnName}`;
|
|
@@ -182,7 +351,7 @@ var bindColumn = (tableName, columnName, column, baseTableName, schemaName, casi
|
|
|
182
351
|
schemaName,
|
|
183
352
|
casing
|
|
184
353
|
};
|
|
185
|
-
return bound;
|
|
354
|
+
return withJsonPathAccess(bound);
|
|
186
355
|
};
|
|
187
356
|
|
|
188
357
|
// src/internal/column.ts
|
|
@@ -267,7 +436,7 @@ var array = (options) => (column) => remapColumnDefinition(column, {
|
|
|
267
436
|
ddlType: `${column.metadata.ddlType ?? column.metadata.dbType.kind}[]`
|
|
268
437
|
}
|
|
269
438
|
});
|
|
270
|
-
function
|
|
439
|
+
function index2(arg) {
|
|
271
440
|
if (isColumnDefinitionValue(arg)) {
|
|
272
441
|
return mapColumn(arg, {
|
|
273
442
|
...arg.metadata,
|
|
@@ -331,7 +500,7 @@ var enrichDbType = (datatypes, dbType) => {
|
|
|
331
500
|
|
|
332
501
|
// src/internal/runtime/value.ts
|
|
333
502
|
import * as Schema3 from "effect/Schema";
|
|
334
|
-
var brandString = (
|
|
503
|
+
var brandString = (pattern, brand5) => Schema3.String.pipe(Schema3.check(Schema3.isPattern(pattern)), Schema3.brand(brand5));
|
|
335
504
|
var localDatePattern = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
336
505
|
var isValidLocalDateString = (value) => {
|
|
337
506
|
const match = localDatePattern.exec(value);
|
|
@@ -384,11 +553,11 @@ var isValidInstantString = (value) => {
|
|
|
384
553
|
const match = instantPattern.exec(value);
|
|
385
554
|
return match !== null && isValidLocalDateString(match[1]) && isValidLocalTimeString(match[2]) && isValidOffset(match[3]);
|
|
386
555
|
};
|
|
387
|
-
var LocalDateStringSchema = Schema3.String.pipe(Schema3.
|
|
388
|
-
var LocalTimeStringSchema = Schema3.String.pipe(Schema3.
|
|
389
|
-
var OffsetTimeStringSchema = Schema3.String.pipe(Schema3.
|
|
390
|
-
var LocalDateTimeStringSchema = Schema3.String.pipe(Schema3.
|
|
391
|
-
var InstantStringSchema = Schema3.String.pipe(Schema3.
|
|
556
|
+
var LocalDateStringSchema = Schema3.String.pipe(Schema3.check(Schema3.isPattern(localDatePattern)), Schema3.check(Schema3.makeFilter((value) => isValidLocalDateString(value))), Schema3.brand("LocalDateString"));
|
|
557
|
+
var LocalTimeStringSchema = Schema3.String.pipe(Schema3.check(Schema3.isPattern(localTimePattern)), Schema3.check(Schema3.makeFilter((value) => isValidLocalTimeString(value))), Schema3.brand("LocalTimeString"));
|
|
558
|
+
var OffsetTimeStringSchema = Schema3.String.pipe(Schema3.check(Schema3.isPattern(offsetTimePattern)), Schema3.check(Schema3.makeFilter((value) => isValidOffsetTimeString(value))), Schema3.brand("OffsetTimeString"));
|
|
559
|
+
var LocalDateTimeStringSchema = Schema3.String.pipe(Schema3.check(Schema3.isPattern(localDateTimePattern)), Schema3.check(Schema3.makeFilter((value) => isValidLocalDateTimeString(value))), Schema3.brand("LocalDateTimeString"));
|
|
560
|
+
var InstantStringSchema = Schema3.String.pipe(Schema3.check(Schema3.isPattern(instantPattern)), Schema3.check(Schema3.makeFilter((value) => isValidInstantString(value))), Schema3.brand("InstantString"));
|
|
392
561
|
var YearStringSchema = brandString(/^\d{4}$/, "YearString");
|
|
393
562
|
var canonicalizeBigIntString = (input) => {
|
|
394
563
|
const trimmed = input.trim();
|
|
@@ -428,22 +597,790 @@ var isCanonicalDecimalString = (value) => {
|
|
|
428
597
|
return false;
|
|
429
598
|
}
|
|
430
599
|
};
|
|
431
|
-
var BigIntStringSchema = Schema3.String.pipe(Schema3.
|
|
432
|
-
var DecimalStringSchema = Schema3.String.pipe(Schema3.
|
|
433
|
-
var JsonValueSchema = Schema3.suspend(() => Schema3.Union(
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
600
|
+
var BigIntStringSchema = Schema3.String.pipe(Schema3.check(Schema3.makeFilter((value) => isCanonicalBigIntString(value))), Schema3.brand("BigIntString"));
|
|
601
|
+
var DecimalStringSchema = Schema3.String.pipe(Schema3.check(Schema3.makeFilter((value) => isCanonicalDecimalString(value))), Schema3.brand("DecimalString"));
|
|
602
|
+
var JsonValueSchema = Schema3.suspend(() => Schema3.Union([
|
|
603
|
+
Schema3.String,
|
|
604
|
+
Schema3.Number.check(Schema3.isFinite()),
|
|
605
|
+
Schema3.Boolean,
|
|
606
|
+
Schema3.Null,
|
|
607
|
+
Schema3.Array(JsonValueSchema),
|
|
608
|
+
Schema3.Record(Schema3.String, JsonValueSchema)
|
|
609
|
+
]));
|
|
610
|
+
var JsonPrimitiveSchema = Schema3.Union([
|
|
611
|
+
Schema3.String,
|
|
612
|
+
Schema3.Number.check(Schema3.isFinite()),
|
|
613
|
+
Schema3.Boolean,
|
|
614
|
+
Schema3.Null
|
|
615
|
+
]);
|
|
616
|
+
|
|
617
|
+
// src/standard/datatypes/index.ts
|
|
618
|
+
var exports_datatypes = {};
|
|
619
|
+
__export(exports_datatypes, {
|
|
620
|
+
standardDatatypes: () => standardDatatypes
|
|
621
|
+
});
|
|
622
|
+
|
|
623
|
+
// src/internal/datatypes/matrix.ts
|
|
624
|
+
var portableDatatypeFamilies = {
|
|
625
|
+
uuid: {
|
|
626
|
+
compareGroup: "uuid",
|
|
627
|
+
castTargets: ["uuid", "char", "varchar", "text"],
|
|
628
|
+
traits: {
|
|
629
|
+
textual: true
|
|
630
|
+
}
|
|
631
|
+
},
|
|
632
|
+
text: {
|
|
633
|
+
compareGroup: "text",
|
|
634
|
+
castTargets: [
|
|
635
|
+
"text",
|
|
636
|
+
"numeric",
|
|
637
|
+
"integer",
|
|
638
|
+
"real",
|
|
639
|
+
"boolean",
|
|
640
|
+
"date",
|
|
641
|
+
"time",
|
|
642
|
+
"datetime",
|
|
643
|
+
"interval",
|
|
644
|
+
"uuid",
|
|
645
|
+
"json",
|
|
646
|
+
"blob",
|
|
647
|
+
"binary",
|
|
648
|
+
"array",
|
|
649
|
+
"range",
|
|
650
|
+
"multirange",
|
|
651
|
+
"record",
|
|
652
|
+
"enum",
|
|
653
|
+
"set",
|
|
654
|
+
"money",
|
|
655
|
+
"null"
|
|
656
|
+
],
|
|
657
|
+
traits: {
|
|
658
|
+
textual: true,
|
|
659
|
+
ordered: true
|
|
660
|
+
}
|
|
661
|
+
},
|
|
662
|
+
numeric: {
|
|
663
|
+
compareGroup: "numeric",
|
|
664
|
+
castTargets: ["numeric", "integer", "real", "text", "boolean", "date", "time", "datetime"],
|
|
665
|
+
traits: {
|
|
666
|
+
ordered: true
|
|
667
|
+
}
|
|
668
|
+
},
|
|
669
|
+
integer: {
|
|
670
|
+
compareGroup: "numeric",
|
|
671
|
+
castTargets: ["integer", "numeric", "real", "text", "boolean", "date", "time", "datetime"],
|
|
672
|
+
traits: {
|
|
673
|
+
ordered: true
|
|
674
|
+
}
|
|
675
|
+
},
|
|
676
|
+
real: {
|
|
677
|
+
compareGroup: "numeric",
|
|
678
|
+
castTargets: ["real", "numeric", "integer", "text", "boolean"],
|
|
679
|
+
traits: {
|
|
680
|
+
ordered: true
|
|
681
|
+
}
|
|
682
|
+
},
|
|
683
|
+
boolean: {
|
|
684
|
+
compareGroup: "boolean",
|
|
685
|
+
castTargets: ["boolean", "integer", "numeric", "text"],
|
|
686
|
+
traits: {}
|
|
687
|
+
},
|
|
688
|
+
date: {
|
|
689
|
+
compareGroup: "date",
|
|
690
|
+
castTargets: ["date", "time", "datetime", "text", "numeric", "integer"],
|
|
691
|
+
traits: {
|
|
692
|
+
ordered: true
|
|
693
|
+
}
|
|
694
|
+
},
|
|
695
|
+
time: {
|
|
696
|
+
compareGroup: "time",
|
|
697
|
+
castTargets: ["time", "date", "datetime", "text", "numeric", "integer"],
|
|
698
|
+
traits: {
|
|
699
|
+
ordered: true
|
|
700
|
+
}
|
|
701
|
+
},
|
|
702
|
+
datetime: {
|
|
703
|
+
compareGroup: "datetime",
|
|
704
|
+
castTargets: ["datetime", "date", "time", "text", "numeric", "integer"],
|
|
705
|
+
traits: {
|
|
706
|
+
ordered: true
|
|
707
|
+
}
|
|
708
|
+
},
|
|
709
|
+
json: {
|
|
710
|
+
compareGroup: "json",
|
|
711
|
+
castTargets: ["json", "text"],
|
|
712
|
+
traits: {}
|
|
713
|
+
},
|
|
714
|
+
blob: {
|
|
715
|
+
compareGroup: "blob",
|
|
716
|
+
castTargets: ["blob", "text"],
|
|
717
|
+
traits: {}
|
|
718
|
+
},
|
|
719
|
+
null: {
|
|
720
|
+
compareGroup: "null",
|
|
721
|
+
castTargets: ["uuid", "text", "numeric", "integer", "real", "boolean", "date", "time", "datetime", "json", "blob", "null"],
|
|
722
|
+
traits: {}
|
|
723
|
+
}
|
|
724
|
+
};
|
|
725
|
+
var portableDatatypeKinds = {
|
|
726
|
+
uuid: { family: "uuid", runtime: "string" },
|
|
727
|
+
text: { family: "text", runtime: "string" },
|
|
728
|
+
varchar: { family: "text", runtime: "string" },
|
|
729
|
+
char: { family: "text", runtime: "string" },
|
|
730
|
+
int: { family: "integer", runtime: "number" },
|
|
731
|
+
integer: { family: "integer", runtime: "number" },
|
|
732
|
+
bigint: { family: "integer", runtime: "bigintString" },
|
|
733
|
+
numeric: { family: "numeric", runtime: "decimalString" },
|
|
734
|
+
decimal: { family: "numeric", runtime: "decimalString" },
|
|
735
|
+
real: { family: "real", runtime: "number" },
|
|
736
|
+
boolean: { family: "boolean", runtime: "boolean" },
|
|
737
|
+
date: { family: "date", runtime: "localDate" },
|
|
738
|
+
time: { family: "time", runtime: "localTime" },
|
|
739
|
+
datetime: { family: "datetime", runtime: "localDateTime" },
|
|
740
|
+
timestamp: { family: "datetime", runtime: "localDateTime" },
|
|
741
|
+
json: { family: "json", runtime: "json" },
|
|
742
|
+
blob: { family: "blob", runtime: "bytes" }
|
|
743
|
+
};
|
|
744
|
+
var portableDatatypeKeys = Object.keys(portableDatatypeKinds);
|
|
745
|
+
var portableDatatypeDdlTypeByDialect = {
|
|
746
|
+
standard: {
|
|
747
|
+
uuid: "uuid",
|
|
748
|
+
text: "text",
|
|
749
|
+
varchar: "varchar",
|
|
750
|
+
char: "char",
|
|
751
|
+
int: "int",
|
|
752
|
+
integer: "integer",
|
|
753
|
+
bigint: "bigint",
|
|
754
|
+
numeric: "numeric",
|
|
755
|
+
decimal: "decimal",
|
|
756
|
+
real: "real",
|
|
757
|
+
boolean: "boolean",
|
|
758
|
+
date: "date",
|
|
759
|
+
time: "time",
|
|
760
|
+
datetime: "datetime",
|
|
761
|
+
timestamp: "timestamp",
|
|
762
|
+
json: "json",
|
|
763
|
+
blob: "blob"
|
|
764
|
+
},
|
|
765
|
+
postgres: {
|
|
766
|
+
uuid: "uuid",
|
|
767
|
+
text: "text",
|
|
768
|
+
varchar: "varchar",
|
|
769
|
+
char: "char",
|
|
770
|
+
int: "int",
|
|
771
|
+
integer: "integer",
|
|
772
|
+
bigint: "bigint",
|
|
773
|
+
numeric: "numeric",
|
|
774
|
+
decimal: "decimal",
|
|
775
|
+
real: "real",
|
|
776
|
+
boolean: "boolean",
|
|
777
|
+
date: "date",
|
|
778
|
+
time: "time",
|
|
779
|
+
datetime: "timestamp",
|
|
780
|
+
timestamp: "timestamp",
|
|
781
|
+
json: "json",
|
|
782
|
+
blob: "bytea"
|
|
783
|
+
},
|
|
784
|
+
mysql: {
|
|
785
|
+
uuid: "char(36)",
|
|
786
|
+
text: "text",
|
|
787
|
+
varchar: "varchar(255)",
|
|
788
|
+
char: "char",
|
|
789
|
+
int: "int",
|
|
790
|
+
integer: "integer",
|
|
791
|
+
bigint: "bigint",
|
|
792
|
+
numeric: "numeric",
|
|
793
|
+
decimal: "decimal",
|
|
794
|
+
real: "real",
|
|
795
|
+
boolean: "boolean",
|
|
796
|
+
date: "date",
|
|
797
|
+
time: "time",
|
|
798
|
+
datetime: "datetime",
|
|
799
|
+
timestamp: "timestamp",
|
|
800
|
+
json: "json",
|
|
801
|
+
blob: "blob"
|
|
802
|
+
},
|
|
803
|
+
sqlite: {
|
|
804
|
+
uuid: "text",
|
|
805
|
+
text: "text",
|
|
806
|
+
varchar: "varchar",
|
|
807
|
+
char: "char",
|
|
808
|
+
int: "int",
|
|
809
|
+
integer: "integer",
|
|
810
|
+
bigint: "bigint",
|
|
811
|
+
numeric: "numeric",
|
|
812
|
+
decimal: "decimal",
|
|
813
|
+
real: "real",
|
|
814
|
+
boolean: "boolean",
|
|
815
|
+
date: "date",
|
|
816
|
+
time: "time",
|
|
817
|
+
datetime: "datetime",
|
|
818
|
+
timestamp: "datetime",
|
|
819
|
+
json: "json",
|
|
820
|
+
blob: "blob"
|
|
821
|
+
}
|
|
822
|
+
};
|
|
823
|
+
var portableDatatypeCastTypeByDialect = {
|
|
824
|
+
standard: portableDatatypeDdlTypeByDialect.standard,
|
|
825
|
+
postgres: portableDatatypeDdlTypeByDialect.postgres,
|
|
826
|
+
mysql: {
|
|
827
|
+
...portableDatatypeDdlTypeByDialect.mysql,
|
|
828
|
+
uuid: "char(36)",
|
|
829
|
+
text: "char",
|
|
830
|
+
varchar: "char",
|
|
831
|
+
char: "char",
|
|
832
|
+
int: "signed",
|
|
833
|
+
integer: "signed",
|
|
834
|
+
bigint: "signed",
|
|
835
|
+
numeric: "decimal",
|
|
836
|
+
decimal: "decimal",
|
|
837
|
+
boolean: "unsigned",
|
|
838
|
+
datetime: "datetime",
|
|
839
|
+
timestamp: "datetime",
|
|
840
|
+
blob: "binary"
|
|
841
|
+
},
|
|
842
|
+
sqlite: {
|
|
843
|
+
...portableDatatypeDdlTypeByDialect.sqlite,
|
|
844
|
+
uuid: "text",
|
|
845
|
+
int: "integer",
|
|
846
|
+
timestamp: "datetime"
|
|
847
|
+
}
|
|
848
|
+
};
|
|
849
|
+
var hasOwn = (value, key2) => Object.prototype.hasOwnProperty.call(value, key2);
|
|
850
|
+
var renderPortableDatatypeDdlType = (dialect, kind) => {
|
|
851
|
+
if (!hasOwn(portableDatatypeDdlTypeByDialect, dialect)) {
|
|
852
|
+
return;
|
|
853
|
+
}
|
|
854
|
+
const byKind = portableDatatypeDdlTypeByDialect[dialect];
|
|
855
|
+
return hasOwn(byKind, kind) ? byKind[kind] : undefined;
|
|
856
|
+
};
|
|
857
|
+
var renderPortableDatatypeCastType = (dialect, kind) => {
|
|
858
|
+
if (!hasOwn(portableDatatypeCastTypeByDialect, dialect)) {
|
|
859
|
+
return;
|
|
860
|
+
}
|
|
861
|
+
const byKind = portableDatatypeCastTypeByDialect[dialect];
|
|
862
|
+
return hasOwn(byKind, kind) ? byKind[kind] : undefined;
|
|
863
|
+
};
|
|
864
|
+
var postgresDatatypeFamilies = {
|
|
865
|
+
text: {
|
|
866
|
+
compareGroup: "text",
|
|
867
|
+
castTargets: [
|
|
868
|
+
"text",
|
|
869
|
+
"numeric",
|
|
870
|
+
"boolean",
|
|
871
|
+
"date",
|
|
872
|
+
"time",
|
|
873
|
+
"timestamp",
|
|
874
|
+
"interval",
|
|
875
|
+
"binary",
|
|
876
|
+
"uuid",
|
|
877
|
+
"json",
|
|
878
|
+
"xml",
|
|
879
|
+
"bit",
|
|
880
|
+
"oid",
|
|
881
|
+
"identifier",
|
|
882
|
+
"network",
|
|
883
|
+
"spatial",
|
|
884
|
+
"textsearch",
|
|
885
|
+
"range",
|
|
886
|
+
"multirange",
|
|
887
|
+
"array",
|
|
888
|
+
"money",
|
|
889
|
+
"null"
|
|
890
|
+
],
|
|
891
|
+
traits: {
|
|
892
|
+
textual: true,
|
|
893
|
+
ordered: true
|
|
894
|
+
}
|
|
895
|
+
},
|
|
896
|
+
numeric: {
|
|
897
|
+
compareGroup: "numeric",
|
|
898
|
+
castTargets: ["numeric", "text", "boolean", "date", "time", "timestamp", "interval", "uuid", "bit", "oid", "money"],
|
|
899
|
+
traits: {
|
|
900
|
+
ordered: true
|
|
901
|
+
}
|
|
902
|
+
},
|
|
903
|
+
boolean: {
|
|
904
|
+
compareGroup: "boolean",
|
|
905
|
+
castTargets: ["boolean", "text", "numeric"],
|
|
906
|
+
traits: {}
|
|
907
|
+
},
|
|
908
|
+
date: {
|
|
909
|
+
compareGroup: "date",
|
|
910
|
+
castTargets: ["date", "timestamp", "text"],
|
|
911
|
+
traits: {
|
|
912
|
+
ordered: true
|
|
913
|
+
}
|
|
914
|
+
},
|
|
915
|
+
time: {
|
|
916
|
+
compareGroup: "time",
|
|
917
|
+
castTargets: ["time", "timestamp", "text"],
|
|
918
|
+
traits: {
|
|
919
|
+
ordered: true
|
|
920
|
+
}
|
|
921
|
+
},
|
|
922
|
+
timestamp: {
|
|
923
|
+
compareGroup: "timestamp",
|
|
924
|
+
castTargets: ["timestamp", "date", "text"],
|
|
925
|
+
traits: {
|
|
926
|
+
ordered: true
|
|
927
|
+
}
|
|
928
|
+
},
|
|
929
|
+
interval: {
|
|
930
|
+
compareGroup: "interval",
|
|
931
|
+
castTargets: ["interval", "text"],
|
|
932
|
+
traits: {
|
|
933
|
+
ordered: true
|
|
934
|
+
}
|
|
935
|
+
},
|
|
936
|
+
binary: {
|
|
937
|
+
compareGroup: "binary",
|
|
938
|
+
castTargets: ["binary", "text"],
|
|
939
|
+
traits: {}
|
|
940
|
+
},
|
|
941
|
+
uuid: {
|
|
942
|
+
compareGroup: "uuid",
|
|
943
|
+
castTargets: ["uuid", "text"],
|
|
944
|
+
traits: {
|
|
945
|
+
ordered: true
|
|
946
|
+
}
|
|
947
|
+
},
|
|
948
|
+
json: {
|
|
949
|
+
compareGroup: "json",
|
|
950
|
+
castTargets: ["json", "text"],
|
|
951
|
+
traits: {}
|
|
952
|
+
},
|
|
953
|
+
xml: {
|
|
954
|
+
compareGroup: "xml",
|
|
955
|
+
castTargets: ["xml", "text"],
|
|
956
|
+
traits: {}
|
|
957
|
+
},
|
|
958
|
+
bit: {
|
|
959
|
+
compareGroup: "bit",
|
|
960
|
+
castTargets: ["bit", "text", "numeric"],
|
|
961
|
+
traits: {}
|
|
962
|
+
},
|
|
963
|
+
oid: {
|
|
964
|
+
compareGroup: "oid",
|
|
965
|
+
castTargets: ["oid", "text", "numeric"],
|
|
966
|
+
traits: {
|
|
967
|
+
ordered: true
|
|
968
|
+
}
|
|
969
|
+
},
|
|
970
|
+
identifier: {
|
|
971
|
+
compareGroup: "identifier",
|
|
972
|
+
castTargets: ["identifier", "text"],
|
|
973
|
+
traits: {}
|
|
974
|
+
},
|
|
975
|
+
network: {
|
|
976
|
+
compareGroup: "network",
|
|
977
|
+
castTargets: ["network", "text"],
|
|
978
|
+
traits: {}
|
|
979
|
+
},
|
|
980
|
+
spatial: {
|
|
981
|
+
compareGroup: "spatial",
|
|
982
|
+
castTargets: ["spatial", "text"],
|
|
983
|
+
traits: {}
|
|
984
|
+
},
|
|
985
|
+
textsearch: {
|
|
986
|
+
compareGroup: "textsearch",
|
|
987
|
+
castTargets: ["textsearch", "text"],
|
|
988
|
+
traits: {}
|
|
989
|
+
},
|
|
990
|
+
range: {
|
|
991
|
+
compareGroup: "range",
|
|
992
|
+
castTargets: ["range", "text"],
|
|
993
|
+
traits: {}
|
|
994
|
+
},
|
|
995
|
+
multirange: {
|
|
996
|
+
compareGroup: "multirange",
|
|
997
|
+
castTargets: ["multirange", "text"],
|
|
998
|
+
traits: {}
|
|
999
|
+
},
|
|
1000
|
+
enum: {
|
|
1001
|
+
compareGroup: "enum",
|
|
1002
|
+
castTargets: ["enum", "text"],
|
|
1003
|
+
traits: {
|
|
1004
|
+
textual: true,
|
|
1005
|
+
ordered: true
|
|
1006
|
+
}
|
|
1007
|
+
},
|
|
1008
|
+
record: {
|
|
1009
|
+
compareGroup: "record",
|
|
1010
|
+
castTargets: ["record", "text"],
|
|
1011
|
+
traits: {}
|
|
1012
|
+
},
|
|
1013
|
+
array: {
|
|
1014
|
+
compareGroup: "array",
|
|
1015
|
+
castTargets: ["array", "text"],
|
|
1016
|
+
traits: {}
|
|
1017
|
+
},
|
|
1018
|
+
money: {
|
|
1019
|
+
compareGroup: "money",
|
|
1020
|
+
castTargets: ["money", "text", "numeric"],
|
|
1021
|
+
traits: {
|
|
1022
|
+
ordered: true
|
|
1023
|
+
}
|
|
1024
|
+
},
|
|
1025
|
+
null: {
|
|
1026
|
+
compareGroup: "null",
|
|
1027
|
+
castTargets: [
|
|
1028
|
+
"text",
|
|
1029
|
+
"numeric",
|
|
1030
|
+
"boolean",
|
|
1031
|
+
"date",
|
|
1032
|
+
"time",
|
|
1033
|
+
"timestamp",
|
|
1034
|
+
"interval",
|
|
1035
|
+
"binary",
|
|
1036
|
+
"uuid",
|
|
1037
|
+
"json",
|
|
1038
|
+
"xml",
|
|
1039
|
+
"bit",
|
|
1040
|
+
"oid",
|
|
1041
|
+
"identifier",
|
|
1042
|
+
"network",
|
|
1043
|
+
"spatial",
|
|
1044
|
+
"textsearch",
|
|
1045
|
+
"range",
|
|
1046
|
+
"multirange",
|
|
1047
|
+
"array",
|
|
1048
|
+
"money",
|
|
1049
|
+
"null"
|
|
1050
|
+
],
|
|
1051
|
+
traits: {}
|
|
1052
|
+
}
|
|
1053
|
+
};
|
|
1054
|
+
var postgresDatatypeKinds = {
|
|
1055
|
+
text: { family: "text", runtime: "string" },
|
|
1056
|
+
varchar: { family: "text", runtime: "string" },
|
|
1057
|
+
char: { family: "text", runtime: "string" },
|
|
1058
|
+
citext: { family: "text", runtime: "string" },
|
|
1059
|
+
name: { family: "text", runtime: "string" },
|
|
1060
|
+
uuid: { family: "uuid", runtime: "string" },
|
|
1061
|
+
int2: { family: "numeric", runtime: "number" },
|
|
1062
|
+
int4: { family: "numeric", runtime: "number" },
|
|
1063
|
+
int8: { family: "numeric", runtime: "bigintString" },
|
|
1064
|
+
numeric: { family: "numeric", runtime: "decimalString" },
|
|
1065
|
+
float4: { family: "numeric", runtime: "number" },
|
|
1066
|
+
float8: { family: "numeric", runtime: "number" },
|
|
1067
|
+
money: { family: "money", runtime: "number" },
|
|
1068
|
+
bool: { family: "boolean", runtime: "boolean" },
|
|
1069
|
+
date: { family: "date", runtime: "localDate" },
|
|
1070
|
+
time: { family: "time", runtime: "localTime" },
|
|
1071
|
+
timetz: { family: "time", runtime: "offsetTime" },
|
|
1072
|
+
timestamp: { family: "timestamp", runtime: "localDateTime" },
|
|
1073
|
+
timestamptz: { family: "timestamp", runtime: "instant" },
|
|
1074
|
+
interval: { family: "interval", runtime: "string" },
|
|
1075
|
+
bytea: { family: "binary", runtime: "bytes" },
|
|
1076
|
+
json: { family: "json", runtime: "json" },
|
|
1077
|
+
jsonb: { family: "json", runtime: "json" },
|
|
1078
|
+
xml: { family: "xml", runtime: "string" },
|
|
1079
|
+
bit: { family: "bit", runtime: "string" },
|
|
1080
|
+
varbit: { family: "bit", runtime: "string" },
|
|
1081
|
+
oid: { family: "oid", runtime: "number" },
|
|
1082
|
+
xid: { family: "oid", runtime: "number" },
|
|
1083
|
+
xid8: { family: "oid", runtime: "bigintString" },
|
|
1084
|
+
cid: { family: "oid", runtime: "number" },
|
|
1085
|
+
tid: { family: "identifier", runtime: "string" },
|
|
1086
|
+
regclass: { family: "identifier", runtime: "string" },
|
|
1087
|
+
regtype: { family: "identifier", runtime: "string" },
|
|
1088
|
+
regproc: { family: "identifier", runtime: "string" },
|
|
1089
|
+
regprocedure: { family: "identifier", runtime: "string" },
|
|
1090
|
+
regoper: { family: "identifier", runtime: "string" },
|
|
1091
|
+
regoperator: { family: "identifier", runtime: "string" },
|
|
1092
|
+
regconfig: { family: "identifier", runtime: "string" },
|
|
1093
|
+
regdictionary: { family: "identifier", runtime: "string" },
|
|
1094
|
+
pg_lsn: { family: "identifier", runtime: "string" },
|
|
1095
|
+
txid_snapshot: { family: "identifier", runtime: "string" },
|
|
1096
|
+
inet: { family: "network", runtime: "string" },
|
|
1097
|
+
cidr: { family: "network", runtime: "string" },
|
|
1098
|
+
macaddr: { family: "network", runtime: "string" },
|
|
1099
|
+
macaddr8: { family: "network", runtime: "string" },
|
|
1100
|
+
point: { family: "spatial", runtime: "unknown" },
|
|
1101
|
+
line: { family: "spatial", runtime: "unknown" },
|
|
1102
|
+
lseg: { family: "spatial", runtime: "unknown" },
|
|
1103
|
+
box: { family: "spatial", runtime: "unknown" },
|
|
1104
|
+
path: { family: "spatial", runtime: "unknown" },
|
|
1105
|
+
polygon: { family: "spatial", runtime: "unknown" },
|
|
1106
|
+
circle: { family: "spatial", runtime: "unknown" },
|
|
1107
|
+
tsvector: { family: "textsearch", runtime: "string" },
|
|
1108
|
+
tsquery: { family: "textsearch", runtime: "string" },
|
|
1109
|
+
int4range: { family: "range", runtime: "unknown" },
|
|
1110
|
+
int8range: { family: "range", runtime: "unknown" },
|
|
1111
|
+
numrange: { family: "range", runtime: "unknown" },
|
|
1112
|
+
tsrange: { family: "range", runtime: "unknown" },
|
|
1113
|
+
tstzrange: { family: "range", runtime: "unknown" },
|
|
1114
|
+
daterange: { family: "range", runtime: "unknown" },
|
|
1115
|
+
int4multirange: { family: "multirange", runtime: "unknown" },
|
|
1116
|
+
int8multirange: { family: "multirange", runtime: "unknown" },
|
|
1117
|
+
nummultirange: { family: "multirange", runtime: "unknown" },
|
|
1118
|
+
tsmultirange: { family: "multirange", runtime: "unknown" },
|
|
1119
|
+
tstzmultirange: { family: "multirange", runtime: "unknown" },
|
|
1120
|
+
datemultirange: { family: "multirange", runtime: "unknown" }
|
|
1121
|
+
};
|
|
1122
|
+
var postgresSpecificDatatypeKeys = [
|
|
1123
|
+
"int2",
|
|
1124
|
+
"int4",
|
|
1125
|
+
"int8",
|
|
1126
|
+
"float4",
|
|
1127
|
+
"float8",
|
|
1128
|
+
"money",
|
|
1129
|
+
"bool",
|
|
1130
|
+
"timetz",
|
|
1131
|
+
"timestamptz",
|
|
1132
|
+
"interval",
|
|
1133
|
+
"bytea",
|
|
1134
|
+
"citext",
|
|
1135
|
+
"name",
|
|
1136
|
+
"jsonb",
|
|
1137
|
+
"xml",
|
|
1138
|
+
"bit",
|
|
1139
|
+
"varbit",
|
|
1140
|
+
"oid",
|
|
1141
|
+
"xid",
|
|
1142
|
+
"xid8",
|
|
1143
|
+
"cid",
|
|
1144
|
+
"tid",
|
|
1145
|
+
"regclass",
|
|
1146
|
+
"regtype",
|
|
1147
|
+
"regproc",
|
|
1148
|
+
"regprocedure",
|
|
1149
|
+
"regoper",
|
|
1150
|
+
"regoperator",
|
|
1151
|
+
"regconfig",
|
|
1152
|
+
"regdictionary",
|
|
1153
|
+
"pg_lsn",
|
|
1154
|
+
"txid_snapshot",
|
|
1155
|
+
"inet",
|
|
1156
|
+
"cidr",
|
|
1157
|
+
"macaddr",
|
|
1158
|
+
"macaddr8",
|
|
1159
|
+
"point",
|
|
1160
|
+
"line",
|
|
1161
|
+
"lseg",
|
|
1162
|
+
"box",
|
|
1163
|
+
"path",
|
|
1164
|
+
"polygon",
|
|
1165
|
+
"circle",
|
|
1166
|
+
"tsvector",
|
|
1167
|
+
"tsquery",
|
|
1168
|
+
"int4range",
|
|
1169
|
+
"int8range",
|
|
1170
|
+
"numrange",
|
|
1171
|
+
"tsrange",
|
|
1172
|
+
"tstzrange",
|
|
1173
|
+
"daterange",
|
|
1174
|
+
"int4multirange",
|
|
1175
|
+
"int8multirange",
|
|
1176
|
+
"nummultirange",
|
|
1177
|
+
"tsmultirange",
|
|
1178
|
+
"tstzmultirange",
|
|
1179
|
+
"datemultirange"
|
|
1180
|
+
];
|
|
1181
|
+
var mysqlDatatypeFamilies = {
|
|
1182
|
+
text: {
|
|
1183
|
+
compareGroup: "text",
|
|
1184
|
+
castTargets: [
|
|
1185
|
+
"text",
|
|
1186
|
+
"numeric",
|
|
1187
|
+
"boolean",
|
|
1188
|
+
"date",
|
|
1189
|
+
"time",
|
|
1190
|
+
"datetime",
|
|
1191
|
+
"timestamp",
|
|
1192
|
+
"year",
|
|
1193
|
+
"binary",
|
|
1194
|
+
"json",
|
|
1195
|
+
"bit",
|
|
1196
|
+
"enum",
|
|
1197
|
+
"set",
|
|
1198
|
+
"null"
|
|
1199
|
+
],
|
|
1200
|
+
traits: {
|
|
1201
|
+
textual: true,
|
|
1202
|
+
ordered: true
|
|
1203
|
+
}
|
|
1204
|
+
},
|
|
1205
|
+
numeric: {
|
|
1206
|
+
compareGroup: "numeric",
|
|
1207
|
+
castTargets: ["numeric", "text", "boolean", "date", "time", "datetime", "timestamp", "year", "bit"],
|
|
1208
|
+
traits: {
|
|
1209
|
+
ordered: true
|
|
1210
|
+
}
|
|
1211
|
+
},
|
|
1212
|
+
boolean: {
|
|
1213
|
+
compareGroup: "boolean",
|
|
1214
|
+
castTargets: ["boolean", "text", "numeric"],
|
|
1215
|
+
traits: {}
|
|
1216
|
+
},
|
|
1217
|
+
bit: {
|
|
1218
|
+
compareGroup: "bit",
|
|
1219
|
+
castTargets: ["bit", "text", "numeric"],
|
|
1220
|
+
traits: {}
|
|
1221
|
+
},
|
|
1222
|
+
date: {
|
|
1223
|
+
compareGroup: "date",
|
|
1224
|
+
castTargets: ["date", "datetime", "timestamp", "text"],
|
|
1225
|
+
traits: {
|
|
1226
|
+
ordered: true
|
|
1227
|
+
}
|
|
1228
|
+
},
|
|
1229
|
+
time: {
|
|
1230
|
+
compareGroup: "time",
|
|
1231
|
+
castTargets: ["time", "datetime", "timestamp", "text"],
|
|
1232
|
+
traits: {
|
|
1233
|
+
ordered: true
|
|
1234
|
+
}
|
|
1235
|
+
},
|
|
1236
|
+
datetime: {
|
|
1237
|
+
compareGroup: "datetime",
|
|
1238
|
+
castTargets: ["datetime", "timestamp", "date", "text"],
|
|
1239
|
+
traits: {
|
|
1240
|
+
ordered: true
|
|
1241
|
+
}
|
|
1242
|
+
},
|
|
1243
|
+
timestamp: {
|
|
1244
|
+
compareGroup: "timestamp",
|
|
1245
|
+
castTargets: ["timestamp", "datetime", "date", "text"],
|
|
1246
|
+
traits: {
|
|
1247
|
+
ordered: true
|
|
1248
|
+
}
|
|
1249
|
+
},
|
|
1250
|
+
year: {
|
|
1251
|
+
compareGroup: "year",
|
|
1252
|
+
castTargets: ["year", "text", "numeric"],
|
|
1253
|
+
traits: {
|
|
1254
|
+
ordered: true
|
|
1255
|
+
}
|
|
1256
|
+
},
|
|
1257
|
+
binary: {
|
|
1258
|
+
compareGroup: "binary",
|
|
1259
|
+
castTargets: ["binary", "text"],
|
|
1260
|
+
traits: {}
|
|
1261
|
+
},
|
|
1262
|
+
json: {
|
|
1263
|
+
compareGroup: "json",
|
|
1264
|
+
castTargets: ["json", "text"],
|
|
1265
|
+
traits: {}
|
|
1266
|
+
},
|
|
1267
|
+
spatial: {
|
|
1268
|
+
compareGroup: "spatial",
|
|
1269
|
+
castTargets: ["spatial", "text"],
|
|
1270
|
+
traits: {}
|
|
1271
|
+
},
|
|
1272
|
+
enum: {
|
|
1273
|
+
compareGroup: "enum",
|
|
1274
|
+
castTargets: ["enum", "text"],
|
|
1275
|
+
traits: {
|
|
1276
|
+
textual: true,
|
|
1277
|
+
ordered: true
|
|
1278
|
+
}
|
|
1279
|
+
},
|
|
1280
|
+
set: {
|
|
1281
|
+
compareGroup: "set",
|
|
1282
|
+
castTargets: ["set", "text"],
|
|
1283
|
+
traits: {
|
|
1284
|
+
textual: true
|
|
1285
|
+
}
|
|
1286
|
+
},
|
|
1287
|
+
null: {
|
|
1288
|
+
compareGroup: "null",
|
|
1289
|
+
castTargets: [
|
|
1290
|
+
"text",
|
|
1291
|
+
"numeric",
|
|
1292
|
+
"boolean",
|
|
1293
|
+
"bit",
|
|
1294
|
+
"date",
|
|
1295
|
+
"time",
|
|
1296
|
+
"datetime",
|
|
1297
|
+
"timestamp",
|
|
1298
|
+
"year",
|
|
1299
|
+
"binary",
|
|
1300
|
+
"json",
|
|
1301
|
+
"spatial",
|
|
1302
|
+
"enum",
|
|
1303
|
+
"set",
|
|
1304
|
+
"null"
|
|
1305
|
+
],
|
|
1306
|
+
traits: {}
|
|
1307
|
+
}
|
|
1308
|
+
};
|
|
1309
|
+
var mysqlDatatypeKinds = {
|
|
1310
|
+
char: { family: "text", runtime: "string" },
|
|
1311
|
+
varchar: { family: "text", runtime: "string" },
|
|
1312
|
+
tinytext: { family: "text", runtime: "string" },
|
|
1313
|
+
text: { family: "text", runtime: "string" },
|
|
1314
|
+
mediumtext: { family: "text", runtime: "string" },
|
|
1315
|
+
longtext: { family: "text", runtime: "string" },
|
|
1316
|
+
tinyint: { family: "numeric", runtime: "number" },
|
|
1317
|
+
smallint: { family: "numeric", runtime: "number" },
|
|
1318
|
+
mediumint: { family: "numeric", runtime: "number" },
|
|
1319
|
+
int: { family: "numeric", runtime: "number" },
|
|
1320
|
+
integer: { family: "numeric", runtime: "number" },
|
|
1321
|
+
bigint: { family: "numeric", runtime: "bigintString" },
|
|
1322
|
+
decimal: { family: "numeric", runtime: "decimalString" },
|
|
1323
|
+
dec: { family: "numeric", runtime: "decimalString" },
|
|
1324
|
+
numeric: { family: "numeric", runtime: "decimalString" },
|
|
1325
|
+
fixed: { family: "numeric", runtime: "decimalString" },
|
|
1326
|
+
float: { family: "numeric", runtime: "number" },
|
|
1327
|
+
double: { family: "numeric", runtime: "number" },
|
|
1328
|
+
real: { family: "numeric", runtime: "number" },
|
|
1329
|
+
bool: { family: "boolean", runtime: "boolean" },
|
|
1330
|
+
boolean: { family: "boolean", runtime: "boolean" },
|
|
1331
|
+
bit: { family: "bit", runtime: "string" },
|
|
1332
|
+
date: { family: "date", runtime: "localDate" },
|
|
1333
|
+
time: { family: "time", runtime: "localTime" },
|
|
1334
|
+
datetime: { family: "datetime", runtime: "localDateTime" },
|
|
1335
|
+
timestamp: { family: "timestamp", runtime: "localDateTime" },
|
|
1336
|
+
year: { family: "year", runtime: "year" },
|
|
1337
|
+
binary: { family: "binary", runtime: "bytes" },
|
|
1338
|
+
varbinary: { family: "binary", runtime: "bytes" },
|
|
1339
|
+
tinyblob: { family: "binary", runtime: "bytes" },
|
|
1340
|
+
blob: { family: "binary", runtime: "bytes" },
|
|
1341
|
+
mediumblob: { family: "binary", runtime: "bytes" },
|
|
1342
|
+
longblob: { family: "binary", runtime: "bytes" },
|
|
1343
|
+
json: { family: "json", runtime: "json" },
|
|
1344
|
+
geometry: { family: "spatial", runtime: "unknown" },
|
|
1345
|
+
point: { family: "spatial", runtime: "unknown" },
|
|
1346
|
+
linestring: { family: "spatial", runtime: "unknown" },
|
|
1347
|
+
polygon: { family: "spatial", runtime: "unknown" },
|
|
1348
|
+
multipoint: { family: "spatial", runtime: "unknown" },
|
|
1349
|
+
multilinestring: { family: "spatial", runtime: "unknown" },
|
|
1350
|
+
multipolygon: { family: "spatial", runtime: "unknown" },
|
|
1351
|
+
geometrycollection: { family: "spatial", runtime: "unknown" },
|
|
1352
|
+
enum: { family: "enum", runtime: "string" },
|
|
1353
|
+
set: { family: "set", runtime: "string" }
|
|
1354
|
+
};
|
|
1355
|
+
var mysqlSpecificDatatypeKeys = [
|
|
1356
|
+
"tinytext",
|
|
1357
|
+
"mediumtext",
|
|
1358
|
+
"longtext",
|
|
1359
|
+
"tinyint",
|
|
1360
|
+
"smallint",
|
|
1361
|
+
"mediumint",
|
|
1362
|
+
"dec",
|
|
1363
|
+
"fixed",
|
|
1364
|
+
"float",
|
|
1365
|
+
"double",
|
|
1366
|
+
"bool",
|
|
1367
|
+
"bit",
|
|
1368
|
+
"year",
|
|
1369
|
+
"binary",
|
|
1370
|
+
"varbinary",
|
|
1371
|
+
"tinyblob",
|
|
1372
|
+
"mediumblob",
|
|
1373
|
+
"longblob",
|
|
1374
|
+
"geometry",
|
|
1375
|
+
"point",
|
|
1376
|
+
"linestring",
|
|
1377
|
+
"polygon",
|
|
1378
|
+
"multipoint",
|
|
1379
|
+
"multilinestring",
|
|
1380
|
+
"multipolygon",
|
|
1381
|
+
"geometrycollection"
|
|
1382
|
+
];
|
|
1383
|
+
var sqliteDatatypeFamilies = {
|
|
447
1384
|
text: {
|
|
448
1385
|
compareGroup: "text",
|
|
449
1386
|
castTargets: ["text", "numeric", "integer", "real", "boolean", "date", "time", "datetime", "json", "blob", "null"],
|
|
@@ -515,7 +1452,7 @@ var standardDatatypeFamilies = {
|
|
|
515
1452
|
traits: {}
|
|
516
1453
|
}
|
|
517
1454
|
};
|
|
518
|
-
var
|
|
1455
|
+
var sqliteDatatypeKinds = {
|
|
519
1456
|
text: { family: "text", runtime: "string" },
|
|
520
1457
|
varchar: { family: "text", runtime: "string" },
|
|
521
1458
|
char: { family: "text", runtime: "string" },
|
|
@@ -535,6 +1472,15 @@ var standardDatatypeKinds = {
|
|
|
535
1472
|
json: { family: "json", runtime: "json" },
|
|
536
1473
|
blob: { family: "blob", runtime: "bytes" }
|
|
537
1474
|
};
|
|
1475
|
+
var sqliteSpecificDatatypeKeys = [
|
|
1476
|
+
"clob",
|
|
1477
|
+
"double"
|
|
1478
|
+
];
|
|
1479
|
+
var pickDatatypeConstructors = (module, keys) => Object.fromEntries(keys.map((key2) => [key2, module[key2]]));
|
|
1480
|
+
|
|
1481
|
+
// src/standard/datatypes/spec.ts
|
|
1482
|
+
var standardDatatypeFamilies = portableDatatypeFamilies;
|
|
1483
|
+
var standardDatatypeKinds = portableDatatypeKinds;
|
|
538
1484
|
|
|
539
1485
|
// src/standard/datatypes/index.ts
|
|
540
1486
|
var withMetadata = (kind) => {
|
|
@@ -547,6 +1493,7 @@ var withMetadata = (kind) => {
|
|
|
547
1493
|
runtime: kindSpec.runtime,
|
|
548
1494
|
compareGroup: familySpec?.compareGroup,
|
|
549
1495
|
castTargets: familySpec?.castTargets,
|
|
1496
|
+
implicitTargets: familySpec.implicitTargets,
|
|
550
1497
|
traits: familySpec?.traits
|
|
551
1498
|
};
|
|
552
1499
|
};
|
|
@@ -577,8 +1524,7 @@ standardDatatypeModule.json = () => ({
|
|
|
577
1524
|
}
|
|
578
1525
|
});
|
|
579
1526
|
var standardDatatypes = {
|
|
580
|
-
...standardDatatypeModule
|
|
581
|
-
float8: () => withMetadata("real")
|
|
1527
|
+
...standardDatatypeModule
|
|
582
1528
|
};
|
|
583
1529
|
|
|
584
1530
|
// src/standard/column.ts
|
|
@@ -597,8 +1543,8 @@ var renderNumericDdlType = (kind, options) => {
|
|
|
597
1543
|
}
|
|
598
1544
|
return options.scale === undefined ? `${kind}(${options.precision})` : `${kind}(${options.precision},${options.scale})`;
|
|
599
1545
|
};
|
|
600
|
-
var boundedString = (length) => length === undefined ? Schema4.String : Schema4.String.
|
|
601
|
-
var finiteNumber = Schema4.Number.
|
|
1546
|
+
var boundedString = (length) => length === undefined ? Schema4.String : Schema4.String.check(Schema4.isMaxLength(length));
|
|
1547
|
+
var finiteNumber = Schema4.Number.check(Schema4.isFinite());
|
|
602
1548
|
var custom = (schema2, dbType) => makeColumnDefinition(schema2, {
|
|
603
1549
|
dbType: enrichDbType(standardDatatypes, dbType),
|
|
604
1550
|
nullable: false,
|
|
@@ -610,7 +1556,7 @@ var custom = (schema2, dbType) => makeColumnDefinition(schema2, {
|
|
|
610
1556
|
ddlType: undefined,
|
|
611
1557
|
identity: undefined
|
|
612
1558
|
});
|
|
613
|
-
var uuid = () => primitive(Schema4.
|
|
1559
|
+
var uuid = () => primitive(Schema4.String.check(Schema4.isUUID()), standardDatatypes.uuid());
|
|
614
1560
|
var text = () => primitive(Schema4.String, standardDatatypes.text());
|
|
615
1561
|
var varchar = (length) => makeColumnDefinition(boundedString(length), {
|
|
616
1562
|
dbType: standardDatatypes.varchar(),
|
|
@@ -620,7 +1566,7 @@ var varchar = (length) => makeColumnDefinition(boundedString(length), {
|
|
|
620
1566
|
primaryKey: false,
|
|
621
1567
|
unique: false,
|
|
622
1568
|
references: undefined,
|
|
623
|
-
ddlType: length === undefined ?
|
|
1569
|
+
ddlType: length === undefined ? undefined : `varchar(${length})`,
|
|
624
1570
|
identity: undefined
|
|
625
1571
|
});
|
|
626
1572
|
var char = (length = 1) => makeColumnDefinition(boundedString(length), {
|
|
@@ -653,7 +1599,7 @@ var date = () => primitive(LocalDateStringSchema, standardDatatypes.date());
|
|
|
653
1599
|
var time = () => primitive(LocalTimeStringSchema, standardDatatypes.time());
|
|
654
1600
|
var datetime = () => primitive(LocalDateTimeStringSchema, standardDatatypes.datetime());
|
|
655
1601
|
var timestamp = () => primitive(LocalDateTimeStringSchema, standardDatatypes.timestamp());
|
|
656
|
-
var blob = () => primitive(Schema4.
|
|
1602
|
+
var blob = () => primitive(Schema4.Uint8Array, standardDatatypes.blob());
|
|
657
1603
|
var json = (schema2) => makeColumnDefinition(schema2, {
|
|
658
1604
|
dbType: { ...standardDatatypes.json(), variant: "json" },
|
|
659
1605
|
nullable: false,
|
|
@@ -674,165 +1620,33 @@ var generated2 = generated;
|
|
|
674
1620
|
var driverValueMapping2 = driverValueMapping;
|
|
675
1621
|
var references2 = references;
|
|
676
1622
|
var schema2 = schema;
|
|
677
|
-
// src/standard/
|
|
678
|
-
var
|
|
679
|
-
__export(
|
|
680
|
-
|
|
681
|
-
upper: () => upper,
|
|
682
|
-
temporal: () => exports_temporal,
|
|
683
|
-
string: () => exports_string,
|
|
684
|
-
rowNumber: () => rowNumber,
|
|
685
|
-
rank: () => rank,
|
|
686
|
-
over: () => over,
|
|
687
|
-
now: () => now,
|
|
688
|
-
min: () => min,
|
|
689
|
-
max: () => max,
|
|
690
|
-
lower: () => lower,
|
|
691
|
-
localTimestamp: () => localTimestamp,
|
|
692
|
-
localTime: () => localTime,
|
|
693
|
-
denseRank: () => denseRank,
|
|
694
|
-
currentTimestamp: () => currentTimestamp,
|
|
695
|
-
currentTime: () => currentTime,
|
|
696
|
-
currentDate: () => currentDate,
|
|
697
|
-
count: () => count,
|
|
698
|
-
core: () => exports_core,
|
|
699
|
-
concat: () => concat,
|
|
700
|
-
coalesce: () => coalesce,
|
|
701
|
-
call: () => call,
|
|
702
|
-
aggregate: () => exports_aggregate
|
|
703
|
-
});
|
|
704
|
-
|
|
705
|
-
// src/standard/function/core.ts
|
|
706
|
-
var exports_core = {};
|
|
707
|
-
__export(exports_core, {
|
|
708
|
-
coalesce: () => coalesce,
|
|
709
|
-
call: () => call
|
|
710
|
-
});
|
|
711
|
-
|
|
712
|
-
// src/standard/query.ts
|
|
713
|
-
var exports_query = {};
|
|
714
|
-
__export(exports_query, {
|
|
715
|
-
withRecursive: () => withRecursive_,
|
|
716
|
-
with: () => with_,
|
|
717
|
-
where: () => where,
|
|
718
|
-
values: () => exportedValues,
|
|
719
|
-
upsert: () => upsert,
|
|
720
|
-
upper: () => upper,
|
|
721
|
-
update: () => update,
|
|
722
|
-
unnest: () => exportedUnnest,
|
|
723
|
-
union_query_capabilities: () => union_query_capabilities,
|
|
724
|
-
unionAll: () => unionAll,
|
|
725
|
-
union: () => union,
|
|
726
|
-
type: () => type,
|
|
727
|
-
truncate: () => truncate,
|
|
728
|
-
transaction: () => transaction,
|
|
729
|
-
select: () => exportedSelect,
|
|
730
|
-
scalar: () => scalar,
|
|
731
|
-
savepoint: () => savepoint,
|
|
732
|
-
rowNumber: () => rowNumber,
|
|
733
|
-
rollbackTo: () => rollbackTo,
|
|
734
|
-
rollback: () => rollback,
|
|
735
|
-
rightJoin: () => rightJoin,
|
|
736
|
-
returning: () => returning,
|
|
737
|
-
releaseSavepoint: () => releaseSavepoint,
|
|
738
|
-
regexNotMatch: () => regexNotMatch,
|
|
739
|
-
regexNotIMatch: () => regexNotIMatch,
|
|
740
|
-
regexMatch: () => regexMatch,
|
|
741
|
-
regexIMatch: () => regexIMatch,
|
|
742
|
-
rank: () => rank,
|
|
743
|
-
overlaps: () => overlaps,
|
|
744
|
-
over: () => over,
|
|
745
|
-
orderBy: () => orderBy,
|
|
746
|
-
or: () => or,
|
|
747
|
-
onConflict: () => onConflict,
|
|
748
|
-
offset: () => offset,
|
|
749
|
-
notIn: () => notIn,
|
|
750
|
-
not: () => not,
|
|
751
|
-
neq: () => neq,
|
|
752
|
-
min: () => min,
|
|
753
|
-
merge: () => merge2,
|
|
754
|
-
max: () => max,
|
|
755
|
-
match: () => match,
|
|
756
|
-
lte: () => lte,
|
|
757
|
-
lt: () => lt,
|
|
758
|
-
lower: () => lower,
|
|
759
|
-
lock: () => lock,
|
|
760
|
-
literal: () => literal,
|
|
761
|
-
limit: () => limit,
|
|
762
|
-
like: () => like,
|
|
763
|
-
leftJoin: () => leftJoin,
|
|
764
|
-
lateral: () => lateral,
|
|
765
|
-
isNull: () => isNull,
|
|
766
|
-
isNotNull: () => isNotNull,
|
|
767
|
-
isNotDistinctFrom: () => isNotDistinctFrom,
|
|
768
|
-
isDistinctFrom: () => isDistinctFrom,
|
|
769
|
-
intersectAll: () => intersectAll,
|
|
770
|
-
intersect: () => intersect,
|
|
771
|
-
insert: () => exportedInsert,
|
|
772
|
-
innerJoin: () => innerJoin,
|
|
773
|
-
inSubquery: () => inSubquery,
|
|
774
|
-
in: () => in_,
|
|
775
|
-
ilike: () => ilike,
|
|
776
|
-
having: () => having,
|
|
777
|
-
gte: () => gte,
|
|
778
|
-
gt: () => gt,
|
|
779
|
-
groupBy: () => groupBy,
|
|
780
|
-
fullJoin: () => fullJoin,
|
|
781
|
-
from: () => exportedFrom,
|
|
782
|
-
exists: () => exists,
|
|
783
|
-
excluded: () => excluded,
|
|
784
|
-
exceptAll: () => exceptAll,
|
|
785
|
-
except: () => except,
|
|
786
|
-
eq: () => eq,
|
|
787
|
-
dropTable: () => dropTable,
|
|
788
|
-
dropIndex: () => dropIndex,
|
|
789
|
-
distinct: () => distinct,
|
|
790
|
-
denseRank: () => denseRank,
|
|
791
|
-
delete: () => delete_,
|
|
792
|
-
crossJoin: () => crossJoin,
|
|
793
|
-
createTable: () => createTable,
|
|
794
|
-
createIndex: () => createIndex,
|
|
795
|
-
count: () => count,
|
|
796
|
-
contains: () => contains,
|
|
797
|
-
containedBy: () => containedBy,
|
|
798
|
-
concat: () => concat,
|
|
799
|
-
compareAny: () => compareAny,
|
|
800
|
-
compareAll: () => compareAll,
|
|
801
|
-
commit: () => commit,
|
|
802
|
-
column: () => column,
|
|
803
|
-
collate: () => collate,
|
|
804
|
-
coalesce: () => coalesce,
|
|
805
|
-
cast: () => cast,
|
|
806
|
-
case: () => case_,
|
|
807
|
-
call: () => call,
|
|
808
|
-
between: () => between,
|
|
809
|
-
as: () => as,
|
|
810
|
-
any: () => any_,
|
|
811
|
-
and: () => and,
|
|
812
|
-
all: () => all_
|
|
1623
|
+
// src/standard/cast.ts
|
|
1624
|
+
var exports_cast = {};
|
|
1625
|
+
__export(exports_cast, {
|
|
1626
|
+
to: () => to
|
|
813
1627
|
});
|
|
814
1628
|
|
|
815
1629
|
// src/internal/standard-dsl.ts
|
|
816
|
-
import { pipeArguments as
|
|
1630
|
+
import { pipeArguments as pipeArguments7 } from "effect/Pipeable";
|
|
817
1631
|
import * as Schema6 from "effect/Schema";
|
|
818
1632
|
|
|
819
1633
|
// src/internal/row-set.ts
|
|
820
1634
|
var exports_row_set = {};
|
|
821
1635
|
__export(exports_row_set, {
|
|
822
|
-
TypeId: () =>
|
|
1636
|
+
TypeId: () => TypeId4
|
|
823
1637
|
});
|
|
824
|
-
var
|
|
1638
|
+
var TypeId4 = Symbol.for("effect-qb/Plan");
|
|
825
1639
|
|
|
826
1640
|
// src/internal/table.ts
|
|
827
|
-
import { pipeArguments as
|
|
1641
|
+
import { pipeArguments as pipeArguments4 } from "effect/Pipeable";
|
|
828
1642
|
|
|
829
1643
|
// src/internal/schema-expression.ts
|
|
830
1644
|
import { parse, toSql } from "pgsql-ast-parser";
|
|
831
|
-
import { pipeArguments as
|
|
832
|
-
var
|
|
1645
|
+
import { pipeArguments as pipeArguments3 } from "effect/Pipeable";
|
|
1646
|
+
var TypeId5 = Symbol.for("effect-qb/SchemaExpression");
|
|
833
1647
|
var SchemaExpressionProto = {
|
|
834
1648
|
pipe() {
|
|
835
|
-
return
|
|
1649
|
+
return pipeArguments3(this, arguments);
|
|
836
1650
|
}
|
|
837
1651
|
};
|
|
838
1652
|
var attachPipe2 = (value) => {
|
|
@@ -840,35 +1654,35 @@ var attachPipe2 = (value) => {
|
|
|
840
1654
|
configurable: true,
|
|
841
1655
|
writable: true,
|
|
842
1656
|
value: function() {
|
|
843
|
-
return
|
|
1657
|
+
return pipeArguments3(value, arguments);
|
|
844
1658
|
}
|
|
845
1659
|
});
|
|
846
1660
|
return value;
|
|
847
1661
|
};
|
|
848
|
-
var isSchemaExpression = (value) => typeof value === "object" && value !== null && (
|
|
1662
|
+
var isSchemaExpression = (value) => typeof value === "object" && value !== null && (TypeId5 in value);
|
|
849
1663
|
var fromAst = (ast) => {
|
|
850
1664
|
const expression = attachPipe2(Object.create(SchemaExpressionProto));
|
|
851
|
-
expression[
|
|
1665
|
+
expression[TypeId5] = {
|
|
852
1666
|
ast
|
|
853
1667
|
};
|
|
854
1668
|
return expression;
|
|
855
1669
|
};
|
|
856
1670
|
var fromSql = (sql) => {
|
|
857
1671
|
const expression = attachPipe2(Object.create(SchemaExpressionProto));
|
|
858
|
-
expression[
|
|
1672
|
+
expression[TypeId5] = {
|
|
859
1673
|
sql: sql.trim()
|
|
860
1674
|
};
|
|
861
1675
|
return expression;
|
|
862
1676
|
};
|
|
863
1677
|
var parseExpression = (sql) => fromAst(parse(sql, "expr"));
|
|
864
1678
|
var toAst = (expression) => {
|
|
865
|
-
const ast = expression[
|
|
1679
|
+
const ast = expression[TypeId5].ast;
|
|
866
1680
|
if (ast !== undefined) {
|
|
867
1681
|
return ast;
|
|
868
1682
|
}
|
|
869
1683
|
return parse(render(expression), "expr");
|
|
870
1684
|
};
|
|
871
|
-
var render = (expression) => expression[
|
|
1685
|
+
var render = (expression) => expression[TypeId5].sql ?? toSql.expr(toAst(expression));
|
|
872
1686
|
var normalize = (expression) => (() => {
|
|
873
1687
|
const sql = render(expression);
|
|
874
1688
|
try {
|
|
@@ -963,7 +1777,7 @@ var collectInlineOptions = (fields) => {
|
|
|
963
1777
|
return options;
|
|
964
1778
|
};
|
|
965
1779
|
var resolvePrimaryKeyColumns = (fields, declaredOptions) => {
|
|
966
|
-
const inline = Object.entries(fields).filter(([, column]) => column.metadata.primaryKey).map(([
|
|
1780
|
+
const inline = Object.entries(fields).filter(([, column]) => column.metadata.primaryKey).map(([key2]) => key2);
|
|
967
1781
|
const explicit = declaredOptions.flatMap((option) => {
|
|
968
1782
|
if (typeof option !== "object" || option === null || !("kind" in option) || option.kind !== "primaryKey") {
|
|
969
1783
|
return [];
|
|
@@ -989,8 +1803,8 @@ var validateOptions = (tableName, fields, options) => {
|
|
|
989
1803
|
case "foreignKey": {
|
|
990
1804
|
if (option.kind === "index") {
|
|
991
1805
|
const keys = Array.isArray(option.keys) ? option.keys : [];
|
|
992
|
-
for (const
|
|
993
|
-
if (typeof
|
|
1806
|
+
for (const key2 of keys) {
|
|
1807
|
+
if (typeof key2 !== "object" || key2 === null || !("kind" in key2)) {
|
|
994
1808
|
continue;
|
|
995
1809
|
}
|
|
996
1810
|
}
|
|
@@ -1037,10 +1851,10 @@ var fieldSchemaForVariant = (variant, column, tableName, columnName, primaryKeyS
|
|
|
1037
1851
|
var deriveSchema = (variant, tableName, fields, primaryKeyColumns) => {
|
|
1038
1852
|
const primaryKeySet = new Set(primaryKeyColumns);
|
|
1039
1853
|
const structFields = {};
|
|
1040
|
-
for (const [
|
|
1041
|
-
const schema3 = fieldSchemaForVariant(variant, column, tableName,
|
|
1854
|
+
for (const [key2, column] of Object.entries(fields)) {
|
|
1855
|
+
const schema3 = fieldSchemaForVariant(variant, column, tableName, key2, primaryKeySet);
|
|
1042
1856
|
if (schema3 !== undefined) {
|
|
1043
|
-
structFields[
|
|
1857
|
+
structFields[key2] = schema3;
|
|
1044
1858
|
}
|
|
1045
1859
|
}
|
|
1046
1860
|
return Schema5.Struct(structFields);
|
|
@@ -1050,7 +1864,7 @@ var deriveInsertSchema = (tableName, fields, primaryKeyColumns) => deriveSchema(
|
|
|
1050
1864
|
var deriveUpdateSchema = (tableName, fields, primaryKeyColumns) => deriveSchema("update", tableName, fields, primaryKeyColumns);
|
|
1051
1865
|
|
|
1052
1866
|
// src/internal/casing.ts
|
|
1053
|
-
var
|
|
1867
|
+
var TypeId6 = Symbol.for("effect-qb/Casing");
|
|
1054
1868
|
var merge = (base, override) => {
|
|
1055
1869
|
if (base === undefined) {
|
|
1056
1870
|
return override;
|
|
@@ -1091,15 +1905,16 @@ var apply = (style, name) => {
|
|
|
1091
1905
|
var applyCategory = (options, category, name) => apply(options?.[category], name);
|
|
1092
1906
|
|
|
1093
1907
|
// src/internal/table.ts
|
|
1094
|
-
var
|
|
1908
|
+
var TypeId7 = Symbol.for("effect-qb/Table");
|
|
1095
1909
|
var OptionsSymbol = Symbol.for("effect-qb/Table/normalizedOptions");
|
|
1096
1910
|
var options = Symbol.for("effect-qb/Table/declaredOptions");
|
|
1097
1911
|
var CacheSymbol = Symbol.for("effect-qb/Table/cache");
|
|
1098
1912
|
var SchemaCacheSymbol = Symbol.for("effect-qb/Table/schemaCache");
|
|
1099
1913
|
var DeclaredOptionsSymbol = Symbol.for("effect-qb/Table/factoryDeclaredOptions");
|
|
1914
|
+
var ResolveOptionSymbol = Symbol.for("effect-qb/Table/resolveOption");
|
|
1100
1915
|
var TableProto = {
|
|
1101
1916
|
pipe() {
|
|
1102
|
-
return
|
|
1917
|
+
return pipeArguments4(this, arguments);
|
|
1103
1918
|
}
|
|
1104
1919
|
};
|
|
1105
1920
|
var attachPipe3 = (value) => {
|
|
@@ -1107,21 +1922,50 @@ var attachPipe3 = (value) => {
|
|
|
1107
1922
|
configurable: true,
|
|
1108
1923
|
writable: true,
|
|
1109
1924
|
value: function() {
|
|
1110
|
-
return
|
|
1925
|
+
return pipeArguments4(value, arguments);
|
|
1111
1926
|
}
|
|
1112
1927
|
});
|
|
1113
1928
|
return value;
|
|
1114
1929
|
};
|
|
1930
|
+
var conflictArbitersFromOptions = (options2) => options2.flatMap((option) => {
|
|
1931
|
+
if (typeof option !== "object" || option === null) {
|
|
1932
|
+
return [];
|
|
1933
|
+
}
|
|
1934
|
+
if (!("columns" in option) || !Array.isArray(option.columns) || option.columns.length === 0) {
|
|
1935
|
+
return [];
|
|
1936
|
+
}
|
|
1937
|
+
switch (option.kind) {
|
|
1938
|
+
case "primaryKey":
|
|
1939
|
+
case "unique":
|
|
1940
|
+
return [{
|
|
1941
|
+
columns: option.columns,
|
|
1942
|
+
scope: "unconditional",
|
|
1943
|
+
name: option.name,
|
|
1944
|
+
constraint: true
|
|
1945
|
+
}];
|
|
1946
|
+
case "index":
|
|
1947
|
+
return option.unique === true ? [{
|
|
1948
|
+
columns: option.columns,
|
|
1949
|
+
scope: option.predicate === undefined ? "unconditional" : "partial",
|
|
1950
|
+
name: option.name,
|
|
1951
|
+
constraint: false
|
|
1952
|
+
}] : [];
|
|
1953
|
+
default:
|
|
1954
|
+
return [];
|
|
1955
|
+
}
|
|
1956
|
+
});
|
|
1115
1957
|
var buildArtifacts = (name, fields, declaredOptions, schemaName, casing) => {
|
|
1116
1958
|
const normalizedOptions = [...collectInlineOptions(fields), ...declaredOptions];
|
|
1117
1959
|
validateFieldDialects(name, fields);
|
|
1118
1960
|
validateOptions(name, fields, declaredOptions);
|
|
1119
1961
|
const primaryKey3 = resolvePrimaryKeyColumns(fields, declaredOptions);
|
|
1120
|
-
const
|
|
1962
|
+
const conflictArbiters = conflictArbitersFromOptions(normalizedOptions);
|
|
1963
|
+
const columns = Object.fromEntries(Object.entries(fields).map(([key2, column]) => [key2, bindColumn(name, key2, column, name, schemaName, casing)]));
|
|
1121
1964
|
return {
|
|
1122
1965
|
columns,
|
|
1123
1966
|
normalizedOptions,
|
|
1124
|
-
primaryKey: primaryKey3
|
|
1967
|
+
primaryKey: primaryKey3,
|
|
1968
|
+
conflictArbiters
|
|
1125
1969
|
};
|
|
1126
1970
|
};
|
|
1127
1971
|
var getSchemaCache = (table) => {
|
|
@@ -1137,7 +1981,7 @@ var getSchemaCache = (table) => {
|
|
|
1137
1981
|
return cache;
|
|
1138
1982
|
};
|
|
1139
1983
|
var deriveTableSchema = (table, variant) => {
|
|
1140
|
-
const state = table[
|
|
1984
|
+
const state = table[TypeId7];
|
|
1141
1985
|
switch (variant) {
|
|
1142
1986
|
case "select":
|
|
1143
1987
|
return deriveSelectSchema(state.name, state.fields, state.primaryKey);
|
|
@@ -1206,16 +2050,17 @@ var makeTable = (name, fields, declaredOptions, baseName = name, kind = "schema"
|
|
|
1206
2050
|
table.name = name;
|
|
1207
2051
|
table.columns = artifacts.columns;
|
|
1208
2052
|
defineSchemasGetter(table);
|
|
1209
|
-
table[
|
|
2053
|
+
table[TypeId7] = {
|
|
1210
2054
|
name,
|
|
1211
2055
|
baseName,
|
|
1212
2056
|
schemaName: resolvedSchemaName,
|
|
1213
2057
|
fields,
|
|
1214
2058
|
primaryKey: artifacts.primaryKey,
|
|
2059
|
+
conflictArbiters: artifacts.conflictArbiters,
|
|
1215
2060
|
kind,
|
|
1216
2061
|
casing
|
|
1217
2062
|
};
|
|
1218
|
-
table[
|
|
2063
|
+
table[TypeId4] = {
|
|
1219
2064
|
selection: artifacts.columns,
|
|
1220
2065
|
required: undefined,
|
|
1221
2066
|
available: {
|
|
@@ -1229,8 +2074,8 @@ var makeTable = (name, fields, declaredOptions, baseName = name, kind = "schema"
|
|
|
1229
2074
|
};
|
|
1230
2075
|
table[OptionsSymbol] = artifacts.normalizedOptions;
|
|
1231
2076
|
table[DeclaredOptionsSymbol] = declaredOptions;
|
|
1232
|
-
for (const [
|
|
1233
|
-
Object.defineProperty(table,
|
|
2077
|
+
for (const [key2, value] of Object.entries(artifacts.columns)) {
|
|
2078
|
+
Object.defineProperty(table, key2, {
|
|
1234
2079
|
enumerable: true,
|
|
1235
2080
|
value
|
|
1236
2081
|
});
|
|
@@ -1268,13 +2113,14 @@ var ensureClassArtifacts = (self) => {
|
|
|
1268
2113
|
if (cached) {
|
|
1269
2114
|
return cached;
|
|
1270
2115
|
}
|
|
1271
|
-
const state = self[
|
|
2116
|
+
const state = self[TypeId7];
|
|
1272
2117
|
const classOptions = self[options];
|
|
1273
2118
|
const table = applyDeclaredOptions(makeTable(state.name, state.fields, [], state.name, "schema", state.schemaName, state.schemaName === undefined || state.schemaName === "public" ? "default" : "explicit", state.casing), classOptions);
|
|
1274
2119
|
const artifacts = {
|
|
1275
2120
|
columns: table.columns,
|
|
1276
2121
|
normalizedOptions: table[OptionsSymbol],
|
|
1277
|
-
primaryKey: table[
|
|
2122
|
+
primaryKey: table[TypeId7].primaryKey,
|
|
2123
|
+
conflictArbiters: table[TypeId7].conflictArbiters
|
|
1278
2124
|
};
|
|
1279
2125
|
Object.defineProperty(self, CacheSymbol, {
|
|
1280
2126
|
configurable: true,
|
|
@@ -1283,42 +2129,58 @@ var ensureClassArtifacts = (self) => {
|
|
|
1283
2129
|
return artifacts;
|
|
1284
2130
|
};
|
|
1285
2131
|
var appendOption = (table, option) => {
|
|
1286
|
-
const state = table[
|
|
2132
|
+
const state = table[TypeId7];
|
|
1287
2133
|
return makeTable(state.name, state.fields, [...table[DeclaredOptionsSymbol], option], state.baseName, state.kind, state.schemaName, "explicit", state.casing);
|
|
1288
2134
|
};
|
|
1289
2135
|
var makeOption = (option) => {
|
|
1290
2136
|
return attachPipe3(Object.assign((table, ..._validation) => appendOption(table, option), { option }));
|
|
1291
2137
|
};
|
|
2138
|
+
var makeResolvedOption = (option, resolve) => {
|
|
2139
|
+
return attachPipe3(Object.assign((table, ..._validation) => appendOption(table, resolve(table)), {
|
|
2140
|
+
option,
|
|
2141
|
+
[ResolveOptionSymbol]: resolve
|
|
2142
|
+
}));
|
|
2143
|
+
};
|
|
1292
2144
|
var option = (spec) => makeOption(spec);
|
|
2145
|
+
var optionFromTable = (spec, resolve) => makeResolvedOption(spec, resolve);
|
|
2146
|
+
var resolveOption = (option2, table) => {
|
|
2147
|
+
const resolve = option2[ResolveOptionSymbol];
|
|
2148
|
+
return resolve === undefined ? option2.option : resolve(table);
|
|
2149
|
+
};
|
|
2150
|
+
var mapOption = (option2, map) => {
|
|
2151
|
+
const resolve = option2[ResolveOptionSymbol];
|
|
2152
|
+
return resolve === undefined ? makeOption(map(option2.option)) : makeResolvedOption(map(option2.option), (table) => map(resolve(table)));
|
|
2153
|
+
};
|
|
1293
2154
|
function make(name, fields, schemaName) {
|
|
1294
2155
|
const resolvedSchemaName = arguments.length >= 3 ? schemaName : "public";
|
|
1295
2156
|
return makeTable(name, fields, [], name, "schema", resolvedSchemaName, arguments.length >= 3 ? "explicit" : "default");
|
|
1296
2157
|
}
|
|
1297
2158
|
var withCasing = (table, casing) => {
|
|
1298
|
-
const state = table[
|
|
2159
|
+
const state = table[TypeId7];
|
|
1299
2160
|
return makeTable(state.name, state.fields, table[DeclaredOptionsSymbol], state.baseName, state.kind, state.schemaName, "explicit", merge(state.casing, casing));
|
|
1300
2161
|
};
|
|
1301
2162
|
var withSchema = (table, schemaName, schemaCasing) => {
|
|
1302
|
-
const state = table[
|
|
2163
|
+
const state = table[TypeId7];
|
|
1303
2164
|
return makeTable(state.name, state.fields, table[DeclaredOptionsSymbol], state.baseName, state.kind, schemaName, "explicit", merge(schemaCasing, state.casing));
|
|
1304
2165
|
};
|
|
1305
2166
|
var alias = (table, aliasName) => {
|
|
1306
|
-
const state = table[
|
|
1307
|
-
const columns = Object.fromEntries(Object.entries(state.fields).map(([
|
|
2167
|
+
const state = table[TypeId7];
|
|
2168
|
+
const columns = Object.fromEntries(Object.entries(state.fields).map(([key2, column]) => [key2, bindColumn(aliasName, key2, column, state.baseName, state.schemaName, state.casing)]));
|
|
1308
2169
|
const aliased = attachPipe3(Object.create(TableProto));
|
|
1309
2170
|
aliased.name = aliasName;
|
|
1310
2171
|
aliased.columns = columns;
|
|
1311
2172
|
defineSchemasGetter(aliased);
|
|
1312
|
-
aliased[
|
|
2173
|
+
aliased[TypeId7] = {
|
|
1313
2174
|
name: aliasName,
|
|
1314
2175
|
baseName: state.baseName,
|
|
1315
2176
|
schemaName: state.schemaName,
|
|
1316
2177
|
fields: state.fields,
|
|
1317
2178
|
primaryKey: state.primaryKey,
|
|
2179
|
+
conflictArbiters: state.conflictArbiters,
|
|
1318
2180
|
kind: "alias",
|
|
1319
2181
|
casing: state.casing
|
|
1320
2182
|
};
|
|
1321
|
-
aliased[
|
|
2183
|
+
aliased[TypeId4] = {
|
|
1322
2184
|
selection: columns,
|
|
1323
2185
|
required: undefined,
|
|
1324
2186
|
available: {
|
|
@@ -1328,12 +2190,12 @@ var alias = (table, aliasName) => {
|
|
|
1328
2190
|
baseName: state.baseName
|
|
1329
2191
|
}
|
|
1330
2192
|
},
|
|
1331
|
-
dialect: table[
|
|
2193
|
+
dialect: table[TypeId4].dialect
|
|
1332
2194
|
};
|
|
1333
2195
|
aliased[OptionsSymbol] = table[OptionsSymbol];
|
|
1334
2196
|
aliased[DeclaredOptionsSymbol] = table[DeclaredOptionsSymbol];
|
|
1335
|
-
for (const [
|
|
1336
|
-
Object.defineProperty(aliased,
|
|
2197
|
+
for (const [key2, value] of Object.entries(columns)) {
|
|
2198
|
+
Object.defineProperty(aliased, key2, {
|
|
1337
2199
|
enumerable: true,
|
|
1338
2200
|
value
|
|
1339
2201
|
});
|
|
@@ -1352,18 +2214,20 @@ function Class(name, schemaName) {
|
|
|
1352
2214
|
static get schemas() {
|
|
1353
2215
|
return schemasFor(this);
|
|
1354
2216
|
}
|
|
1355
|
-
static get [
|
|
2217
|
+
static get [TypeId7]() {
|
|
1356
2218
|
const declaredOptions = extractDeclaredOptions(this[options]);
|
|
2219
|
+
const normalizedOptions = [...collectInlineOptions(fields), ...declaredOptions];
|
|
1357
2220
|
return {
|
|
1358
2221
|
name,
|
|
1359
2222
|
baseName: name,
|
|
1360
2223
|
schemaName: resolvedSchemaName,
|
|
1361
2224
|
fields,
|
|
1362
2225
|
primaryKey: resolvePrimaryKeyColumns(fields, collectInlineOptions(fields)),
|
|
2226
|
+
conflictArbiters: conflictArbitersFromOptions(normalizedOptions),
|
|
1363
2227
|
kind: "schema"
|
|
1364
2228
|
};
|
|
1365
2229
|
}
|
|
1366
|
-
static get [
|
|
2230
|
+
static get [TypeId4]() {
|
|
1367
2231
|
const artifacts = ensureClassArtifacts(this);
|
|
1368
2232
|
return {
|
|
1369
2233
|
selection: artifacts.columns,
|
|
@@ -1382,49 +2246,83 @@ function Class(name, schemaName) {
|
|
|
1382
2246
|
return ensureClassArtifacts(this).normalizedOptions;
|
|
1383
2247
|
}
|
|
1384
2248
|
static pipe() {
|
|
1385
|
-
return
|
|
2249
|
+
return pipeArguments4(this, arguments);
|
|
1386
2250
|
}
|
|
1387
2251
|
}
|
|
1388
|
-
for (const
|
|
1389
|
-
Object.defineProperty(TableClassBase,
|
|
2252
|
+
for (const key2 of Object.keys(fields)) {
|
|
2253
|
+
Object.defineProperty(TableClassBase, key2, {
|
|
1390
2254
|
enumerable: true,
|
|
1391
2255
|
configurable: true,
|
|
1392
2256
|
get() {
|
|
1393
|
-
return ensureClassArtifacts(this).columns[
|
|
2257
|
+
return ensureClassArtifacts(this).columns[key2];
|
|
1394
2258
|
}
|
|
1395
2259
|
});
|
|
1396
2260
|
}
|
|
1397
2261
|
return TableClassBase;
|
|
1398
2262
|
};
|
|
1399
2263
|
}
|
|
1400
|
-
var
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
}
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
columns:
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
2264
|
+
var selectionArray = (selection) => Array.isArray(selection) ? selection : [selection];
|
|
2265
|
+
var selectedColumnList = (selection) => selectionArray(selection).map((column) => column[BoundColumnTypeId].columnName);
|
|
2266
|
+
var referenceFromSelection = (selection) => {
|
|
2267
|
+
const columns = selectionArray(selection);
|
|
2268
|
+
const first = columns[0];
|
|
2269
|
+
const bound = first[BoundColumnTypeId];
|
|
2270
|
+
return {
|
|
2271
|
+
tableName: bound.baseTableName,
|
|
2272
|
+
schemaName: bound.schemaName,
|
|
2273
|
+
casing: bound.casing,
|
|
2274
|
+
columns: columns.map((column) => column[BoundColumnTypeId].columnName)
|
|
2275
|
+
};
|
|
2276
|
+
};
|
|
2277
|
+
function primaryKey3(columns) {
|
|
2278
|
+
return makeResolvedOption({
|
|
2279
|
+
kind: "primaryKey",
|
|
2280
|
+
columns: []
|
|
2281
|
+
}, (table) => ({
|
|
2282
|
+
kind: "primaryKey",
|
|
2283
|
+
columns: selectedColumnList(columns(table))
|
|
2284
|
+
}));
|
|
2285
|
+
}
|
|
2286
|
+
function unique3(columns) {
|
|
2287
|
+
return makeResolvedOption({
|
|
2288
|
+
kind: "unique",
|
|
2289
|
+
columns: []
|
|
2290
|
+
}, (table) => ({
|
|
2291
|
+
kind: "unique",
|
|
2292
|
+
columns: selectedColumnList(columns(table))
|
|
2293
|
+
}));
|
|
2294
|
+
}
|
|
2295
|
+
function index3(columns) {
|
|
2296
|
+
return makeResolvedOption({
|
|
2297
|
+
kind: "index",
|
|
2298
|
+
columns: []
|
|
2299
|
+
}, (table) => ({
|
|
2300
|
+
kind: "index",
|
|
2301
|
+
columns: selectedColumnList(columns(table))
|
|
2302
|
+
}));
|
|
2303
|
+
}
|
|
2304
|
+
function foreignKey2(columns, target) {
|
|
2305
|
+
return makeResolvedOption({
|
|
2306
|
+
kind: "foreignKey",
|
|
2307
|
+
columns: [],
|
|
2308
|
+
references: () => referenceFromSelection(target())
|
|
2309
|
+
}, (table) => ({
|
|
2310
|
+
kind: "foreignKey",
|
|
2311
|
+
columns: selectedColumnList(columns(table)),
|
|
2312
|
+
references: () => referenceFromSelection(target())
|
|
2313
|
+
}));
|
|
2314
|
+
}
|
|
2315
|
+
function check2(name, predicate) {
|
|
2316
|
+
const spec = {
|
|
2317
|
+
kind: "check",
|
|
2318
|
+
name,
|
|
2319
|
+
predicate
|
|
2320
|
+
};
|
|
2321
|
+
return typeof predicate === "function" ? makeResolvedOption(spec, (table) => ({
|
|
2322
|
+
...spec,
|
|
2323
|
+
predicate: predicate(table)
|
|
2324
|
+
})) : makeOption(spec);
|
|
2325
|
+
}
|
|
1428
2326
|
|
|
1429
2327
|
// src/internal/runtime/normalize.ts
|
|
1430
2328
|
var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -1677,9 +2575,9 @@ var normalizeDbValue = (dbType, value) => {
|
|
|
1677
2575
|
throw new Error("Expected a record value");
|
|
1678
2576
|
}
|
|
1679
2577
|
const normalized = {};
|
|
1680
|
-
for (const [
|
|
1681
|
-
if (
|
|
1682
|
-
normalized[
|
|
2578
|
+
for (const [key2, fieldDbType] of Object.entries(dbType.fields)) {
|
|
2579
|
+
if (key2 in value) {
|
|
2580
|
+
normalized[key2] = normalizeDbValue(fieldDbType, value[key2]);
|
|
1683
2581
|
}
|
|
1684
2582
|
}
|
|
1685
2583
|
return normalized;
|
|
@@ -1736,10 +2634,10 @@ var normalizeDbValue = (dbType, value) => {
|
|
|
1736
2634
|
};
|
|
1737
2635
|
|
|
1738
2636
|
// src/internal/query.ts
|
|
1739
|
-
import { pipeArguments as
|
|
2637
|
+
import { pipeArguments as pipeArguments5 } from "effect/Pipeable";
|
|
1740
2638
|
|
|
1741
2639
|
// src/internal/query-ast.ts
|
|
1742
|
-
var
|
|
2640
|
+
var TypeId8 = Symbol.for("effect-qb/QueryAst");
|
|
1743
2641
|
|
|
1744
2642
|
// src/internal/predicate/runtime.ts
|
|
1745
2643
|
var trueFormula = () => ({ kind: "true" });
|
|
@@ -1764,17 +2662,17 @@ var cloneContext = (context) => ({
|
|
|
1764
2662
|
nonNullKeys: new Set(context.nonNullKeys),
|
|
1765
2663
|
nullKeys: new Set(context.nullKeys),
|
|
1766
2664
|
eqLiterals: new Map(context.eqLiterals),
|
|
1767
|
-
neqLiterals: new Map(Array.from(context.neqLiterals.entries(), ([
|
|
1768
|
-
literalSets: new Map(Array.from(context.literalSets.entries(), ([
|
|
2665
|
+
neqLiterals: new Map(Array.from(context.neqLiterals.entries(), ([key2, values]) => [key2, new Set(values)])),
|
|
2666
|
+
literalSets: new Map(Array.from(context.literalSets.entries(), ([key2, values]) => [key2, new Set(values)])),
|
|
1769
2667
|
sourceNames: new Set(context.sourceNames),
|
|
1770
2668
|
contradiction: context.contradiction,
|
|
1771
2669
|
unknown: context.unknown
|
|
1772
2670
|
});
|
|
1773
2671
|
var freezeContext = (context) => context;
|
|
1774
2672
|
var columnPredicateKey = (tableName, columnName) => JSON.stringify([tableName, columnName]);
|
|
1775
|
-
var columnPredicateKeyParts = (
|
|
1776
|
-
const jsonSeparator =
|
|
1777
|
-
const columnKey = jsonSeparator === -1 ?
|
|
2673
|
+
var columnPredicateKeyParts = (key2) => {
|
|
2674
|
+
const jsonSeparator = key2.indexOf("#json:");
|
|
2675
|
+
const columnKey = jsonSeparator === -1 ? key2 : key2.slice(0, jsonSeparator);
|
|
1778
2676
|
try {
|
|
1779
2677
|
const parsed = JSON.parse(columnKey);
|
|
1780
2678
|
return Array.isArray(parsed) && parsed.length === 2 && typeof parsed[0] === "string" && typeof parsed[1] === "string" ? [parsed[0], parsed[1]] : undefined;
|
|
@@ -1782,59 +2680,59 @@ var columnPredicateKeyParts = (key) => {
|
|
|
1782
2680
|
return;
|
|
1783
2681
|
}
|
|
1784
2682
|
};
|
|
1785
|
-
var sourceNameOfKey = (
|
|
1786
|
-
var addSourceName = (context,
|
|
1787
|
-
context.sourceNames.add(sourceNameOfKey(
|
|
2683
|
+
var sourceNameOfKey = (key2) => columnPredicateKeyParts(key2)?.[0] ?? key2.split(".", 1)[0] ?? key2;
|
|
2684
|
+
var addSourceName = (context, key2) => {
|
|
2685
|
+
context.sourceNames.add(sourceNameOfKey(key2));
|
|
1788
2686
|
};
|
|
1789
|
-
var addNonNull = (context,
|
|
1790
|
-
addSourceName(context,
|
|
1791
|
-
if (context.nullKeys.has(
|
|
2687
|
+
var addNonNull = (context, key2) => {
|
|
2688
|
+
addSourceName(context, key2);
|
|
2689
|
+
if (context.nullKeys.has(key2)) {
|
|
1792
2690
|
context.contradiction = true;
|
|
1793
2691
|
}
|
|
1794
|
-
context.nonNullKeys.add(
|
|
2692
|
+
context.nonNullKeys.add(key2);
|
|
1795
2693
|
};
|
|
1796
|
-
var addNull = (context,
|
|
1797
|
-
addSourceName(context,
|
|
1798
|
-
if (context.nonNullKeys.has(
|
|
2694
|
+
var addNull = (context, key2) => {
|
|
2695
|
+
addSourceName(context, key2);
|
|
2696
|
+
if (context.nonNullKeys.has(key2)) {
|
|
1799
2697
|
context.contradiction = true;
|
|
1800
2698
|
}
|
|
1801
|
-
context.nullKeys.add(
|
|
2699
|
+
context.nullKeys.add(key2);
|
|
1802
2700
|
};
|
|
1803
|
-
var addEqLiteral = (context,
|
|
1804
|
-
addNonNull(context,
|
|
1805
|
-
const existing = context.eqLiterals.get(
|
|
2701
|
+
var addEqLiteral = (context, key2, value) => {
|
|
2702
|
+
addNonNull(context, key2);
|
|
2703
|
+
const existing = context.eqLiterals.get(key2);
|
|
1806
2704
|
if (existing !== undefined && existing !== value) {
|
|
1807
2705
|
context.contradiction = true;
|
|
1808
2706
|
}
|
|
1809
|
-
const neqValues = context.neqLiterals.get(
|
|
2707
|
+
const neqValues = context.neqLiterals.get(key2);
|
|
1810
2708
|
if (neqValues?.has(value)) {
|
|
1811
2709
|
context.contradiction = true;
|
|
1812
2710
|
}
|
|
1813
|
-
const existingSet = context.literalSets.get(
|
|
2711
|
+
const existingSet = context.literalSets.get(key2);
|
|
1814
2712
|
if (existingSet !== undefined && !existingSet.has(value)) {
|
|
1815
2713
|
context.contradiction = true;
|
|
1816
2714
|
}
|
|
1817
|
-
context.eqLiterals.set(
|
|
1818
|
-
context.literalSets.set(
|
|
2715
|
+
context.eqLiterals.set(key2, value);
|
|
2716
|
+
context.literalSets.set(key2, new Set([value]));
|
|
1819
2717
|
};
|
|
1820
|
-
var addNeqLiteral = (context,
|
|
1821
|
-
addNonNull(context,
|
|
1822
|
-
if (context.eqLiterals.get(
|
|
2718
|
+
var addNeqLiteral = (context, key2, value) => {
|
|
2719
|
+
addNonNull(context, key2);
|
|
2720
|
+
if (context.eqLiterals.get(key2) === value) {
|
|
1823
2721
|
context.contradiction = true;
|
|
1824
2722
|
}
|
|
1825
|
-
const values = context.neqLiterals.get(
|
|
2723
|
+
const values = context.neqLiterals.get(key2) ?? new Set;
|
|
1826
2724
|
values.add(value);
|
|
1827
|
-
context.neqLiterals.set(
|
|
2725
|
+
context.neqLiterals.set(key2, values);
|
|
1828
2726
|
};
|
|
1829
|
-
var addLiteralSet = (context,
|
|
1830
|
-
addNonNull(context,
|
|
1831
|
-
const existingEq = context.eqLiterals.get(
|
|
2727
|
+
var addLiteralSet = (context, key2, values) => {
|
|
2728
|
+
addNonNull(context, key2);
|
|
2729
|
+
const existingEq = context.eqLiterals.get(key2);
|
|
1832
2730
|
if (existingEq !== undefined && !values.has(existingEq)) {
|
|
1833
2731
|
context.contradiction = true;
|
|
1834
2732
|
}
|
|
1835
|
-
const existing = context.literalSets.get(
|
|
1836
|
-
context.literalSets.set(
|
|
1837
|
-
if (context.literalSets.get(
|
|
2733
|
+
const existing = context.literalSets.get(key2);
|
|
2734
|
+
context.literalSets.set(key2, existing === undefined ? new Set(values) : new Set(Array.from(existing).filter((value) => values.has(value))));
|
|
2735
|
+
if (context.literalSets.get(key2)?.size === 0) {
|
|
1838
2736
|
context.contradiction = true;
|
|
1839
2737
|
}
|
|
1840
2738
|
};
|
|
@@ -1916,35 +2814,35 @@ var applyNegativeAtom = (context, atom) => {
|
|
|
1916
2814
|
};
|
|
1917
2815
|
var intersectEqLiterals = (left, right) => {
|
|
1918
2816
|
const result = new Map;
|
|
1919
|
-
for (const [
|
|
1920
|
-
if (right.get(
|
|
1921
|
-
result.set(
|
|
2817
|
+
for (const [key2, value] of left) {
|
|
2818
|
+
if (right.get(key2) === value) {
|
|
2819
|
+
result.set(key2, value);
|
|
1922
2820
|
}
|
|
1923
2821
|
}
|
|
1924
2822
|
return result;
|
|
1925
2823
|
};
|
|
1926
2824
|
var intersectNeqLiterals = (left, right) => {
|
|
1927
2825
|
const result = new Map;
|
|
1928
|
-
for (const [
|
|
1929
|
-
const rightValues = right.get(
|
|
2826
|
+
for (const [key2, leftValues] of left) {
|
|
2827
|
+
const rightValues = right.get(key2);
|
|
1930
2828
|
if (rightValues === undefined) {
|
|
1931
2829
|
continue;
|
|
1932
2830
|
}
|
|
1933
2831
|
const next = new Set(Array.from(leftValues).filter((value) => rightValues.has(value)));
|
|
1934
2832
|
if (next.size > 0) {
|
|
1935
|
-
result.set(
|
|
2833
|
+
result.set(key2, next);
|
|
1936
2834
|
}
|
|
1937
2835
|
}
|
|
1938
2836
|
return result;
|
|
1939
2837
|
};
|
|
1940
2838
|
var unionLiteralSets = (left, right) => {
|
|
1941
2839
|
const result = new Map;
|
|
1942
|
-
for (const [
|
|
1943
|
-
const rightValues = right.get(
|
|
2840
|
+
for (const [key2, leftValues] of left) {
|
|
2841
|
+
const rightValues = right.get(key2);
|
|
1944
2842
|
if (rightValues === undefined) {
|
|
1945
2843
|
continue;
|
|
1946
2844
|
}
|
|
1947
|
-
result.set(
|
|
2845
|
+
result.set(key2, new Set([...leftValues, ...rightValues]));
|
|
1948
2846
|
}
|
|
1949
2847
|
return result;
|
|
1950
2848
|
};
|
|
@@ -1956,8 +2854,8 @@ var intersectContexts = (left, right) => {
|
|
|
1956
2854
|
return cloneContext(left);
|
|
1957
2855
|
}
|
|
1958
2856
|
return {
|
|
1959
|
-
nonNullKeys: new Set(Array.from(left.nonNullKeys).filter((
|
|
1960
|
-
nullKeys: new Set(Array.from(left.nullKeys).filter((
|
|
2857
|
+
nonNullKeys: new Set(Array.from(left.nonNullKeys).filter((key2) => right.nonNullKeys.has(key2))),
|
|
2858
|
+
nullKeys: new Set(Array.from(left.nullKeys).filter((key2) => right.nullKeys.has(key2))),
|
|
1961
2859
|
eqLiterals: intersectEqLiterals(left.eqLiterals, right.eqLiterals),
|
|
1962
2860
|
neqLiterals: intersectNeqLiterals(left.neqLiterals, right.neqLiterals),
|
|
1963
2861
|
literalSets: unionLiteralSets(left.literalSets, right.literalSets),
|
|
@@ -2048,18 +2946,18 @@ var jsonPathPredicateKeyOfExpression = (value) => {
|
|
|
2048
2946
|
if (segments.length === 0 || segments.length > 8) {
|
|
2049
2947
|
return;
|
|
2050
2948
|
}
|
|
2051
|
-
const
|
|
2949
|
+
const path2 = [];
|
|
2052
2950
|
for (const segment of segments) {
|
|
2053
2951
|
if (typeof segment !== "object" || segment === null || segment.kind !== "key") {
|
|
2054
2952
|
return;
|
|
2055
2953
|
}
|
|
2056
|
-
|
|
2954
|
+
path2.push(segment.key);
|
|
2057
2955
|
}
|
|
2058
|
-
if (
|
|
2956
|
+
if (path2.length === 0) {
|
|
2059
2957
|
return;
|
|
2060
2958
|
}
|
|
2061
2959
|
const baseKey = columnKeyOfExpression(jsonAst.base);
|
|
2062
|
-
return baseKey === undefined ? undefined : `${baseKey}#json:${
|
|
2960
|
+
return baseKey === undefined ? undefined : `${baseKey}#json:${path2.map(escapeJsonPathPredicateKeySegment).join(".")}`;
|
|
2063
2961
|
}
|
|
2064
2962
|
default:
|
|
2065
2963
|
return;
|
|
@@ -2096,8 +2994,8 @@ var valueKeyOfLiteral = (value) => {
|
|
|
2096
2994
|
return "unknown";
|
|
2097
2995
|
};
|
|
2098
2996
|
var nonNullFactsOfExpression = (value) => {
|
|
2099
|
-
const
|
|
2100
|
-
return
|
|
2997
|
+
const key2 = predicateKeyOfExpression(value);
|
|
2998
|
+
return key2 === undefined ? undefined : atomFormula({ kind: "is-not-null", key: key2 });
|
|
2101
2999
|
};
|
|
2102
3000
|
var combineFacts = (left, right) => {
|
|
2103
3001
|
if (left === undefined) {
|
|
@@ -2308,12 +3206,12 @@ var formulaOfExpression = (value) => {
|
|
|
2308
3206
|
}
|
|
2309
3207
|
return unknownTag("literal:non-boolean");
|
|
2310
3208
|
case "isNull": {
|
|
2311
|
-
const
|
|
2312
|
-
return
|
|
3209
|
+
const key2 = predicateKeyOfExpression(ast.value);
|
|
3210
|
+
return key2 === undefined ? unknownTag("isNull:unsupported") : atomFormula({ kind: "is-null", key: key2 });
|
|
2313
3211
|
}
|
|
2314
3212
|
case "isNotNull": {
|
|
2315
|
-
const
|
|
2316
|
-
return
|
|
3213
|
+
const key2 = predicateKeyOfExpression(ast.value);
|
|
3214
|
+
return key2 === undefined ? unknownTag("isNotNull:unsupported") : atomFormula({ kind: "is-not-null", key: key2 });
|
|
2317
3215
|
}
|
|
2318
3216
|
case "not":
|
|
2319
3217
|
return notFormula(formulaOfExpression(ast.value));
|
|
@@ -2334,12 +3232,12 @@ var formulaOfExpression = (value) => {
|
|
|
2334
3232
|
if (left === undefined) {
|
|
2335
3233
|
return falseFormula();
|
|
2336
3234
|
}
|
|
2337
|
-
const
|
|
3235
|
+
const key2 = predicateKeyOfExpression(left);
|
|
2338
3236
|
const literalValues = rest.map((entry) => {
|
|
2339
3237
|
const entryAst = astOf(entry);
|
|
2340
3238
|
return entryAst.kind === "literal" && entryAst.value !== null ? valueKeyOfLiteral(entryAst.value) : undefined;
|
|
2341
3239
|
});
|
|
2342
|
-
return
|
|
3240
|
+
return key2 !== undefined && literalValues.every((entry) => entry !== undefined) ? atomFormula({ kind: "literal-set", key: key2, values: literalValues }) : anyFormula(rest.map((value2) => formulaOfEq(left, value2)));
|
|
2343
3241
|
}
|
|
2344
3242
|
case "notIn": {
|
|
2345
3243
|
const [left, ...rest] = ast.values;
|
|
@@ -2376,12 +3274,12 @@ var union_query_capabilities = (...values) => [...new Set(values.flatMap((value)
|
|
|
2376
3274
|
// src/internal/query.ts
|
|
2377
3275
|
var ExpressionProto = {
|
|
2378
3276
|
pipe() {
|
|
2379
|
-
return
|
|
3277
|
+
return pipeArguments5(this, arguments);
|
|
2380
3278
|
}
|
|
2381
3279
|
};
|
|
2382
3280
|
var PlanProto = {
|
|
2383
3281
|
pipe() {
|
|
2384
|
-
return
|
|
3282
|
+
return pipeArguments5(this, arguments);
|
|
2385
3283
|
}
|
|
2386
3284
|
};
|
|
2387
3285
|
var QueryTypeId = Symbol.for("effect-qb/Query/internal");
|
|
@@ -2394,13 +3292,13 @@ var mergeAggregationManyRuntime = (values) => values.reduce((current, value) =>
|
|
|
2394
3292
|
var mergeNullabilityRuntime = (left, right = "never") => left === "always" || right === "always" ? "always" : left === "maybe" || right === "maybe" ? "maybe" : "never";
|
|
2395
3293
|
var mergeNullabilityManyRuntime = (values) => values.reduce((current, value) => mergeNullabilityRuntime(current, value[TypeId].nullability), "never");
|
|
2396
3294
|
var mergeManyDependencies = (values) => values.reduce((current, value) => mergeDependencies(current, value[TypeId].dependencies), {});
|
|
2397
|
-
var
|
|
3295
|
+
var makeExpression2 = (state, ast) => {
|
|
2398
3296
|
const expression = Object.create(ExpressionProto);
|
|
2399
3297
|
Object.defineProperty(expression, "pipe", {
|
|
2400
3298
|
configurable: true,
|
|
2401
3299
|
writable: true,
|
|
2402
3300
|
value: function() {
|
|
2403
|
-
return
|
|
3301
|
+
return pipeArguments5(expression, arguments);
|
|
2404
3302
|
}
|
|
2405
3303
|
});
|
|
2406
3304
|
expression[TypeId] = {
|
|
@@ -2422,11 +3320,11 @@ var makePlan = (state, ast, _assumptions, _capabilities, _statement, _target, _i
|
|
|
2422
3320
|
configurable: true,
|
|
2423
3321
|
writable: true,
|
|
2424
3322
|
value: function() {
|
|
2425
|
-
return
|
|
3323
|
+
return pipeArguments5(plan, arguments);
|
|
2426
3324
|
}
|
|
2427
3325
|
});
|
|
2428
|
-
plan[
|
|
2429
|
-
plan[
|
|
3326
|
+
plan[TypeId4] = state;
|
|
3327
|
+
plan[TypeId8] = ast;
|
|
2430
3328
|
plan[QueryTypeId] = {
|
|
2431
3329
|
required: undefined,
|
|
2432
3330
|
availableNames: undefined,
|
|
@@ -2440,7 +3338,7 @@ var makePlan = (state, ast, _assumptions, _capabilities, _statement, _target, _i
|
|
|
2440
3338
|
};
|
|
2441
3339
|
return plan;
|
|
2442
3340
|
};
|
|
2443
|
-
var getAst = (plan) => plan[
|
|
3341
|
+
var getAst = (plan) => plan[TypeId8];
|
|
2444
3342
|
var getQueryState = (plan) => plan[QueryTypeId];
|
|
2445
3343
|
var extractRequiredRuntime = (selection) => {
|
|
2446
3344
|
const required = new Set;
|
|
@@ -2487,8 +3385,8 @@ var presenceWitnessesOfSourceLike = (source) => {
|
|
|
2487
3385
|
if (typeof source !== "object" || source === null) {
|
|
2488
3386
|
return [];
|
|
2489
3387
|
}
|
|
2490
|
-
if (
|
|
2491
|
-
collectPresenceWitnesses(source[
|
|
3388
|
+
if (TypeId7 in source) {
|
|
3389
|
+
collectPresenceWitnesses(source[TypeId4].selection, output);
|
|
2492
3390
|
return [...output];
|
|
2493
3391
|
}
|
|
2494
3392
|
if ("columns" in source) {
|
|
@@ -2500,7 +3398,7 @@ var directAbsentSourceNames = (available, assumptions) => {
|
|
|
2500
3398
|
const nullKeys = guaranteedNullKeys(assumptions);
|
|
2501
3399
|
const absent = new Set;
|
|
2502
3400
|
for (const [name, source] of Object.entries(available)) {
|
|
2503
|
-
if (source._presenceWitnesses?.some((
|
|
3401
|
+
if (source._presenceWitnesses?.some((key2) => nullKeys.has(key2))) {
|
|
2504
3402
|
absent.add(name);
|
|
2505
3403
|
continue;
|
|
2506
3404
|
}
|
|
@@ -2577,51 +3475,6 @@ var resolveImplicationScope = (available, initialAssumptions) => {
|
|
|
2577
3475
|
};
|
|
2578
3476
|
};
|
|
2579
3477
|
|
|
2580
|
-
// src/internal/json/path.ts
|
|
2581
|
-
var SegmentTypeId = Symbol.for("effect-qb/JsonPathSegment");
|
|
2582
|
-
var TypeId8 = Symbol.for("effect-qb/JsonPath");
|
|
2583
|
-
var makeSegment = (segment) => segment;
|
|
2584
|
-
var key = (value) => makeSegment({
|
|
2585
|
-
[SegmentTypeId]: {
|
|
2586
|
-
kind: "key"
|
|
2587
|
-
},
|
|
2588
|
-
kind: "key",
|
|
2589
|
-
key: value
|
|
2590
|
-
});
|
|
2591
|
-
var index3 = (value) => makeSegment({
|
|
2592
|
-
[SegmentTypeId]: {
|
|
2593
|
-
kind: "index"
|
|
2594
|
-
},
|
|
2595
|
-
kind: "index",
|
|
2596
|
-
index: value
|
|
2597
|
-
});
|
|
2598
|
-
var wildcard = () => makeSegment({
|
|
2599
|
-
[SegmentTypeId]: {
|
|
2600
|
-
kind: "wildcard"
|
|
2601
|
-
},
|
|
2602
|
-
kind: "wildcard"
|
|
2603
|
-
});
|
|
2604
|
-
var slice = (start, end) => makeSegment({
|
|
2605
|
-
[SegmentTypeId]: {
|
|
2606
|
-
kind: "slice"
|
|
2607
|
-
},
|
|
2608
|
-
kind: "slice",
|
|
2609
|
-
start,
|
|
2610
|
-
end
|
|
2611
|
-
});
|
|
2612
|
-
var descend = () => makeSegment({
|
|
2613
|
-
[SegmentTypeId]: {
|
|
2614
|
-
kind: "descend"
|
|
2615
|
-
},
|
|
2616
|
-
kind: "descend"
|
|
2617
|
-
});
|
|
2618
|
-
var path = (...segments) => ({
|
|
2619
|
-
[TypeId8]: {
|
|
2620
|
-
segments
|
|
2621
|
-
},
|
|
2622
|
-
segments
|
|
2623
|
-
});
|
|
2624
|
-
|
|
2625
3478
|
// src/internal/grouping-key.ts
|
|
2626
3479
|
var subqueryPlanIds = new WeakMap;
|
|
2627
3480
|
var nextSubqueryPlanId = 0;
|
|
@@ -2655,8 +3508,8 @@ var literalGroupingKey = (value) => {
|
|
|
2655
3508
|
return `literal:${JSON.stringify(value)}`;
|
|
2656
3509
|
}
|
|
2657
3510
|
};
|
|
2658
|
-
var
|
|
2659
|
-
var expressionGroupingKey = (value) =>
|
|
3511
|
+
var isExpression2 = (value) => value !== null && typeof value === "object" && (TypeId in value);
|
|
3512
|
+
var expressionGroupingKey = (value) => isExpression2(value) ? groupingKeyOfExpression(value) : "missing";
|
|
2660
3513
|
var requiredExpressionGroupingKey = (_functionName, value) => groupingKeyOfExpression(value);
|
|
2661
3514
|
var requiredBinaryExpressionGroupingKey = (_functionName, left, right) => `${groupingKeyOfExpression(left)},${groupingKeyOfExpression(right)}`;
|
|
2662
3515
|
var functionCallArgsGroupingKey = (args) => args.map(groupingKeyOfExpression).join(",");
|
|
@@ -2712,7 +3565,7 @@ var jsonPathGroupingKey = (segments) => {
|
|
|
2712
3565
|
}
|
|
2713
3566
|
return segments.map(jsonSegmentGroupingKey).join(",");
|
|
2714
3567
|
};
|
|
2715
|
-
var isJsonPath = (value) => value !== null && typeof value === "object" && (
|
|
3568
|
+
var isJsonPath = (value) => value !== null && typeof value === "object" && (TypeId3 in value);
|
|
2716
3569
|
var jsonOpaquePathGroupingKey = (value) => {
|
|
2717
3570
|
if (isJsonPath(value)) {
|
|
2718
3571
|
return `jsonpath:${jsonPathGroupingKey(value.segments)}`;
|
|
@@ -2720,7 +3573,7 @@ var jsonOpaquePathGroupingKey = (value) => {
|
|
|
2720
3573
|
if (typeof value === "string") {
|
|
2721
3574
|
return `jsonpath:${escapeGroupingText(value)}`;
|
|
2722
3575
|
}
|
|
2723
|
-
if (
|
|
3576
|
+
if (isExpression2(value)) {
|
|
2724
3577
|
return `jsonpath:${groupingKeyOfExpression(value)}`;
|
|
2725
3578
|
}
|
|
2726
3579
|
return "jsonpath:unknown";
|
|
@@ -2983,7 +3836,7 @@ var makeDslTransactionDdlRuntime = (ctx) => {
|
|
|
2983
3836
|
selection: {},
|
|
2984
3837
|
required: [],
|
|
2985
3838
|
available: {},
|
|
2986
|
-
dialect: target[
|
|
3839
|
+
dialect: target[TypeId4].dialect
|
|
2987
3840
|
}, {
|
|
2988
3841
|
kind: "createTable",
|
|
2989
3842
|
select: {},
|
|
@@ -3011,7 +3864,7 @@ var makeDslTransactionDdlRuntime = (ctx) => {
|
|
|
3011
3864
|
selection: {},
|
|
3012
3865
|
required: [],
|
|
3013
3866
|
available: {},
|
|
3014
|
-
dialect: target[
|
|
3867
|
+
dialect: target[TypeId4].dialect
|
|
3015
3868
|
}, {
|
|
3016
3869
|
kind: "dropTable",
|
|
3017
3870
|
select: {},
|
|
@@ -3042,7 +3895,7 @@ var makeDslTransactionDdlRuntime = (ctx) => {
|
|
|
3042
3895
|
selection: {},
|
|
3043
3896
|
required: [],
|
|
3044
3897
|
available: {},
|
|
3045
|
-
dialect: target[
|
|
3898
|
+
dialect: target[TypeId4].dialect
|
|
3046
3899
|
}, {
|
|
3047
3900
|
kind: "createIndex",
|
|
3048
3901
|
select: {},
|
|
@@ -3075,7 +3928,7 @@ var makeDslTransactionDdlRuntime = (ctx) => {
|
|
|
3075
3928
|
selection: {},
|
|
3076
3929
|
required: [],
|
|
3077
3930
|
available: {},
|
|
3078
|
-
dialect: target[
|
|
3931
|
+
dialect: target[TypeId4].dialect
|
|
3079
3932
|
}, {
|
|
3080
3933
|
kind: "dropIndex",
|
|
3081
3934
|
select: {},
|
|
@@ -3129,7 +3982,7 @@ var makeDslMutationRuntime = (ctx) => {
|
|
|
3129
3982
|
baseName: sourceBaseName
|
|
3130
3983
|
}
|
|
3131
3984
|
},
|
|
3132
|
-
dialect: target[
|
|
3985
|
+
dialect: target[TypeId4].dialect
|
|
3133
3986
|
}, {
|
|
3134
3987
|
kind: "insert",
|
|
3135
3988
|
select: {},
|
|
@@ -3149,7 +4002,7 @@ var makeDslMutationRuntime = (ctx) => {
|
|
|
3149
4002
|
}, undefined, "write", "insert", target, insertState);
|
|
3150
4003
|
};
|
|
3151
4004
|
const attachInsertSource = (plan, source) => {
|
|
3152
|
-
const current = plan[
|
|
4005
|
+
const current = plan[TypeId4];
|
|
3153
4006
|
const currentAst = ctx.getAst(plan);
|
|
3154
4007
|
const currentQuery = ctx.getQueryState(plan);
|
|
3155
4008
|
const target = currentQuery.target;
|
|
@@ -3189,11 +4042,11 @@ var makeDslMutationRuntime = (ctx) => {
|
|
|
3189
4042
|
}, currentQuery.assumptions, currentQuery.capabilities, currentQuery.statement, currentQuery.target, "ready");
|
|
3190
4043
|
}
|
|
3191
4044
|
const sourcePlan = source;
|
|
3192
|
-
const selection = sourcePlan[
|
|
4045
|
+
const selection = sourcePlan[TypeId4].selection;
|
|
3193
4046
|
const columns = ctx.normalizeInsertSelectColumns(selection);
|
|
3194
4047
|
return ctx.makePlan({
|
|
3195
4048
|
selection: current.selection,
|
|
3196
|
-
required: ctx.currentRequiredList(sourcePlan[
|
|
4049
|
+
required: ctx.currentRequiredList(sourcePlan[TypeId4].required),
|
|
3197
4050
|
available: current.available,
|
|
3198
4051
|
dialect: current.dialect
|
|
3199
4052
|
}, {
|
|
@@ -3207,7 +4060,7 @@ var makeDslMutationRuntime = (ctx) => {
|
|
|
3207
4060
|
}, currentQuery.assumptions, currentQuery.capabilities, currentQuery.statement, currentQuery.target, "ready");
|
|
3208
4061
|
};
|
|
3209
4062
|
const onConflict = (target, options2 = {}) => (plan) => {
|
|
3210
|
-
const current = plan[
|
|
4063
|
+
const current = plan[TypeId4];
|
|
3211
4064
|
const currentAst = ctx.getAst(plan);
|
|
3212
4065
|
const currentQuery = ctx.getQueryState(plan);
|
|
3213
4066
|
const insertTarget = currentAst.into.source;
|
|
@@ -3251,7 +4104,7 @@ var makeDslMutationRuntime = (ctx) => {
|
|
|
3251
4104
|
selection: {},
|
|
3252
4105
|
required,
|
|
3253
4106
|
available: ctx.mutationAvailableSources(target),
|
|
3254
|
-
dialect: primaryTarget.source[
|
|
4107
|
+
dialect: primaryTarget.source[TypeId4].dialect
|
|
3255
4108
|
}, {
|
|
3256
4109
|
kind: "update",
|
|
3257
4110
|
select: {},
|
|
@@ -3283,7 +4136,7 @@ var makeDslMutationRuntime = (ctx) => {
|
|
|
3283
4136
|
baseName: sourceBaseName
|
|
3284
4137
|
}
|
|
3285
4138
|
},
|
|
3286
|
-
dialect: target[
|
|
4139
|
+
dialect: target[TypeId4].dialect
|
|
3287
4140
|
}, {
|
|
3288
4141
|
kind: "insert",
|
|
3289
4142
|
select: {},
|
|
@@ -3317,7 +4170,7 @@ var makeDslMutationRuntime = (ctx) => {
|
|
|
3317
4170
|
selection: {},
|
|
3318
4171
|
required: [],
|
|
3319
4172
|
available: ctx.mutationAvailableSources(target),
|
|
3320
|
-
dialect: primaryTarget.source[
|
|
4173
|
+
dialect: primaryTarget.source[TypeId4].dialect
|
|
3321
4174
|
}, {
|
|
3322
4175
|
kind: "delete",
|
|
3323
4176
|
select: {},
|
|
@@ -3338,7 +4191,7 @@ var makeDslMutationRuntime = (ctx) => {
|
|
|
3338
4191
|
selection: {},
|
|
3339
4192
|
required: [],
|
|
3340
4193
|
available: {},
|
|
3341
|
-
dialect: target[
|
|
4194
|
+
dialect: target[TypeId4].dialect
|
|
3342
4195
|
}, {
|
|
3343
4196
|
kind: "truncate",
|
|
3344
4197
|
select: {},
|
|
@@ -3392,7 +4245,7 @@ var makeDslMutationRuntime = (ctx) => {
|
|
|
3392
4245
|
baseName: usingBaseName
|
|
3393
4246
|
}
|
|
3394
4247
|
},
|
|
3395
|
-
dialect: target[
|
|
4248
|
+
dialect: target[TypeId4].dialect
|
|
3396
4249
|
}, {
|
|
3397
4250
|
kind: "merge",
|
|
3398
4251
|
select: {},
|
|
@@ -3455,7 +4308,7 @@ var renderMysqlMutationLockMode = (mode, _statement) => {
|
|
|
3455
4308
|
var makeDslPlanRuntime = (ctx) => {
|
|
3456
4309
|
const sourceRequiredList = (source) => typeof source === "object" && source !== null && ("required" in source) ? ctx.currentRequiredList(source.required) : [];
|
|
3457
4310
|
const buildSetOperation = (kind, all, left, right) => {
|
|
3458
|
-
const leftState = left[
|
|
4311
|
+
const leftState = left[TypeId4];
|
|
3459
4312
|
const leftAst = ctx.getAst(left);
|
|
3460
4313
|
const basePlan = leftAst.kind === "set" ? leftAst.setBase ?? left : left;
|
|
3461
4314
|
const leftOperations = leftAst.kind === "set" ? [...leftAst.setOperations ?? []] : [];
|
|
@@ -3463,7 +4316,7 @@ var makeDslPlanRuntime = (ctx) => {
|
|
|
3463
4316
|
selection: leftState.selection,
|
|
3464
4317
|
required: undefined,
|
|
3465
4318
|
available: {},
|
|
3466
|
-
dialect: leftState.dialect ?? right[
|
|
4319
|
+
dialect: leftState.dialect ?? right[TypeId4].dialect
|
|
3467
4320
|
}, {
|
|
3468
4321
|
kind: "set",
|
|
3469
4322
|
select: leftState.selection,
|
|
@@ -3484,7 +4337,7 @@ var makeDslPlanRuntime = (ctx) => {
|
|
|
3484
4337
|
}, undefined, undefined, "set");
|
|
3485
4338
|
};
|
|
3486
4339
|
const where = (predicate) => (plan) => {
|
|
3487
|
-
const current = plan[
|
|
4340
|
+
const current = plan[TypeId4];
|
|
3488
4341
|
const currentAst = ctx.getAst(plan);
|
|
3489
4342
|
const currentQuery = ctx.getQueryState(plan);
|
|
3490
4343
|
const predicateExpression = ctx.toDialectExpression(predicate);
|
|
@@ -3503,7 +4356,7 @@ var makeDslPlanRuntime = (ctx) => {
|
|
|
3503
4356
|
}, ctx.assumeFormulaTrue(currentQuery.assumptions, ctx.formulaOfExpressionRuntime(predicateExpression)), currentQuery.capabilities, currentQuery.statement);
|
|
3504
4357
|
};
|
|
3505
4358
|
const from = (source) => (plan) => {
|
|
3506
|
-
const current = plan[
|
|
4359
|
+
const current = plan[TypeId4];
|
|
3507
4360
|
const currentAst = ctx.getAst(plan);
|
|
3508
4361
|
const currentQuery = ctx.getQueryState(plan);
|
|
3509
4362
|
if (currentQuery.statement === "insert") {
|
|
@@ -3570,7 +4423,7 @@ var makeDslPlanRuntime = (ctx) => {
|
|
|
3570
4423
|
return plan;
|
|
3571
4424
|
};
|
|
3572
4425
|
const having = (predicate) => (plan) => {
|
|
3573
|
-
const current = plan[
|
|
4426
|
+
const current = plan[TypeId4];
|
|
3574
4427
|
const currentAst = ctx.getAst(plan);
|
|
3575
4428
|
const currentQuery = ctx.getQueryState(plan);
|
|
3576
4429
|
const predicateExpression = ctx.toDialectExpression(predicate);
|
|
@@ -3589,7 +4442,7 @@ var makeDslPlanRuntime = (ctx) => {
|
|
|
3589
4442
|
}, ctx.assumeFormulaTrue(currentQuery.assumptions, ctx.formulaOfExpressionRuntime(predicateExpression)), currentQuery.capabilities, currentQuery.statement);
|
|
3590
4443
|
};
|
|
3591
4444
|
const crossJoin = (table) => (plan) => {
|
|
3592
|
-
const current = plan[
|
|
4445
|
+
const current = plan[TypeId4];
|
|
3593
4446
|
const currentAst = ctx.getAst(plan);
|
|
3594
4447
|
const currentQuery = ctx.getQueryState(plan);
|
|
3595
4448
|
const { sourceName, sourceBaseName } = ctx.sourceDetails(table);
|
|
@@ -3609,7 +4462,7 @@ var makeDslPlanRuntime = (ctx) => {
|
|
|
3609
4462
|
selection: current.selection,
|
|
3610
4463
|
required: [...ctx.currentRequiredList(current.required), ...sourceRequired].filter((name, index4, values) => !(name in nextAvailable) && values.indexOf(name) === index4),
|
|
3611
4464
|
available: nextAvailable,
|
|
3612
|
-
dialect: current.dialect ?? table[
|
|
4465
|
+
dialect: current.dialect ?? table[TypeId4]?.dialect ?? table.dialect
|
|
3613
4466
|
}, {
|
|
3614
4467
|
...currentAst,
|
|
3615
4468
|
joins: [...currentAst.joins, {
|
|
@@ -3621,7 +4474,7 @@ var makeDslPlanRuntime = (ctx) => {
|
|
|
3621
4474
|
}, currentQuery.assumptions, currentQuery.capabilities, currentQuery.statement);
|
|
3622
4475
|
};
|
|
3623
4476
|
const join = (kind, table, on) => (plan) => {
|
|
3624
|
-
const current = plan[
|
|
4477
|
+
const current = plan[TypeId4];
|
|
3625
4478
|
const currentAst = ctx.getAst(plan);
|
|
3626
4479
|
const currentQuery = ctx.getQueryState(plan);
|
|
3627
4480
|
const onExpression = ctx.toDialectExpression(on);
|
|
@@ -3663,7 +4516,7 @@ var makeDslPlanRuntime = (ctx) => {
|
|
|
3663
4516
|
}, kind === "inner" ? ctx.assumeFormulaTrue(currentQuery.assumptions, onFormula) : currentQuery.assumptions, currentQuery.capabilities, currentQuery.statement);
|
|
3664
4517
|
};
|
|
3665
4518
|
const orderBy = (value, direction = "asc") => (plan) => {
|
|
3666
|
-
const current = plan[
|
|
4519
|
+
const current = plan[TypeId4];
|
|
3667
4520
|
const currentAst = ctx.getAst(plan);
|
|
3668
4521
|
const currentQuery = ctx.getQueryState(plan);
|
|
3669
4522
|
const expression = ctx.toDialectExpression(value);
|
|
@@ -3683,7 +4536,7 @@ var makeDslPlanRuntime = (ctx) => {
|
|
|
3683
4536
|
}, currentQuery.assumptions, currentQuery.capabilities, currentQuery.statement);
|
|
3684
4537
|
};
|
|
3685
4538
|
const lock = (mode, options2 = {}) => (plan) => {
|
|
3686
|
-
const current = plan[
|
|
4539
|
+
const current = plan[TypeId4];
|
|
3687
4540
|
const currentAst = ctx.getAst(plan);
|
|
3688
4541
|
const currentQuery = ctx.getQueryState(plan);
|
|
3689
4542
|
return ctx.makePlan({
|
|
@@ -3702,7 +4555,7 @@ var makeDslPlanRuntime = (ctx) => {
|
|
|
3702
4555
|
}, currentQuery.assumptions, currentQuery.capabilities, currentQuery.statement);
|
|
3703
4556
|
};
|
|
3704
4557
|
const distinct = () => (plan) => {
|
|
3705
|
-
const current = plan[
|
|
4558
|
+
const current = plan[TypeId4];
|
|
3706
4559
|
const currentAst = ctx.getAst(plan);
|
|
3707
4560
|
const currentQuery = ctx.getQueryState(plan);
|
|
3708
4561
|
return ctx.makePlan({
|
|
@@ -3716,7 +4569,7 @@ var makeDslPlanRuntime = (ctx) => {
|
|
|
3716
4569
|
}, currentQuery.assumptions, currentQuery.capabilities, currentQuery.statement);
|
|
3717
4570
|
};
|
|
3718
4571
|
const limit = (value) => (plan) => {
|
|
3719
|
-
const current = plan[
|
|
4572
|
+
const current = plan[TypeId4];
|
|
3720
4573
|
const currentAst = ctx.getAst(plan);
|
|
3721
4574
|
const currentQuery = ctx.getQueryState(plan);
|
|
3722
4575
|
const expression = ctx.toDialectNumericExpression(value);
|
|
@@ -3732,7 +4585,7 @@ var makeDslPlanRuntime = (ctx) => {
|
|
|
3732
4585
|
}, currentQuery.assumptions, currentQuery.capabilities, currentQuery.statement);
|
|
3733
4586
|
};
|
|
3734
4587
|
const offset = (value) => (plan) => {
|
|
3735
|
-
const current = plan[
|
|
4588
|
+
const current = plan[TypeId4];
|
|
3736
4589
|
const currentAst = ctx.getAst(plan);
|
|
3737
4590
|
const currentQuery = ctx.getQueryState(plan);
|
|
3738
4591
|
const expression = ctx.toDialectNumericExpression(value);
|
|
@@ -3830,7 +4683,7 @@ var makeDslQueryRuntime = (ctx) => {
|
|
|
3830
4683
|
}, undefined, "read", "select");
|
|
3831
4684
|
};
|
|
3832
4685
|
const groupBy = (...values2) => (plan) => {
|
|
3833
|
-
const current = plan[
|
|
4686
|
+
const current = plan[TypeId4];
|
|
3834
4687
|
const currentAst = ctx.getAst(plan);
|
|
3835
4688
|
const currentQuery = ctx.getQueryState(plan);
|
|
3836
4689
|
const required = [...values2.flatMap((value) => Object.keys(value[TypeId].dependencies))].filter((name, index4, list) => !(name in current.available) && list.indexOf(name) === index4);
|
|
@@ -3846,7 +4699,7 @@ var makeDslQueryRuntime = (ctx) => {
|
|
|
3846
4699
|
};
|
|
3847
4700
|
const returning = (selection) => {
|
|
3848
4701
|
return (plan) => {
|
|
3849
|
-
const current = plan[
|
|
4702
|
+
const current = plan[TypeId4];
|
|
3850
4703
|
const currentAst = ctx.getAst(plan);
|
|
3851
4704
|
const currentQuery = ctx.getQueryState(plan);
|
|
3852
4705
|
return ctx.makePlan({
|
|
@@ -3871,14 +4724,14 @@ var makeDslQueryRuntime = (ctx) => {
|
|
|
3871
4724
|
};
|
|
3872
4725
|
|
|
3873
4726
|
// src/internal/derived-table.ts
|
|
3874
|
-
import { pipeArguments as
|
|
4727
|
+
import { pipeArguments as pipeArguments6 } from "effect/Pipeable";
|
|
3875
4728
|
|
|
3876
4729
|
// src/internal/projection-alias.ts
|
|
3877
4730
|
var TypeId9 = Symbol.for("effect-qb/ProjectionAlias");
|
|
3878
4731
|
|
|
3879
4732
|
// src/internal/projections.ts
|
|
3880
4733
|
var aliasFromPath = (path2) => path2.join("__");
|
|
3881
|
-
var
|
|
4734
|
+
var isExpression3 = (value) => typeof value === "object" && value !== null && (TypeId in value);
|
|
3882
4735
|
var projectionAliasOf = (expression) => (TypeId9 in expression) ? expression[TypeId9].alias : undefined;
|
|
3883
4736
|
var pathKeyOf = (path2) => JSON.stringify(path2);
|
|
3884
4737
|
var formatProjectionPath = (path2) => path2.join(".");
|
|
@@ -3887,7 +4740,7 @@ var flattenSelection = (selection, path2 = []) => {
|
|
|
3887
4740
|
const fields = [];
|
|
3888
4741
|
for (const [key2, value] of Object.entries(selection)) {
|
|
3889
4742
|
const nextPath = [...path2, key2];
|
|
3890
|
-
if (
|
|
4743
|
+
if (isExpression3(value)) {
|
|
3891
4744
|
fields.push({
|
|
3892
4745
|
path: nextPath,
|
|
3893
4746
|
expression: value,
|
|
@@ -3927,7 +4780,7 @@ var validateProjections = (projections) => {
|
|
|
3927
4780
|
// src/internal/derived-table.ts
|
|
3928
4781
|
var DerivedProto = {
|
|
3929
4782
|
pipe() {
|
|
3930
|
-
return
|
|
4783
|
+
return pipeArguments6(this, arguments);
|
|
3931
4784
|
}
|
|
3932
4785
|
};
|
|
3933
4786
|
var attachPipe4 = (value) => {
|
|
@@ -3935,7 +4788,7 @@ var attachPipe4 = (value) => {
|
|
|
3935
4788
|
configurable: true,
|
|
3936
4789
|
writable: true,
|
|
3937
4790
|
value: function() {
|
|
3938
|
-
return
|
|
4791
|
+
return pipeArguments6(value, arguments);
|
|
3939
4792
|
}
|
|
3940
4793
|
});
|
|
3941
4794
|
return value;
|
|
@@ -3961,7 +4814,7 @@ var reboundedColumns = (plan, alias2) => {
|
|
|
3961
4814
|
const projections = flattenSelection(ast.select);
|
|
3962
4815
|
for (const projection of projections) {
|
|
3963
4816
|
const expression = projection.expression;
|
|
3964
|
-
setPath(selection, projection.path,
|
|
4817
|
+
setPath(selection, projection.path, makeExpression2({
|
|
3965
4818
|
runtime: undefined,
|
|
3966
4819
|
dbType: expression[TypeId].dbType,
|
|
3967
4820
|
runtimeSchema: expression[TypeId].runtimeSchema,
|
|
@@ -3986,7 +4839,7 @@ var makeDerivedSource = (plan, alias2) => {
|
|
|
3986
4839
|
derived.kind = "derived";
|
|
3987
4840
|
derived.name = alias2;
|
|
3988
4841
|
derived.baseName = alias2;
|
|
3989
|
-
derived.dialect = plan[
|
|
4842
|
+
derived.dialect = plan[TypeId4].dialect;
|
|
3990
4843
|
derived.plan = plan;
|
|
3991
4844
|
derived.required = undefined;
|
|
3992
4845
|
derived.columns = columns;
|
|
@@ -3999,7 +4852,7 @@ var makeCteSource = (plan, alias2, recursive = false) => {
|
|
|
3999
4852
|
cte.kind = "cte";
|
|
4000
4853
|
cte.name = alias2;
|
|
4001
4854
|
cte.baseName = alias2;
|
|
4002
|
-
cte.dialect = plan[
|
|
4855
|
+
cte.dialect = plan[TypeId4].dialect;
|
|
4003
4856
|
cte.plan = plan;
|
|
4004
4857
|
cte.recursive = recursive;
|
|
4005
4858
|
cte.required = undefined;
|
|
@@ -4013,9 +4866,9 @@ var makeLateralSource = (plan, alias2) => {
|
|
|
4013
4866
|
lateral.kind = "lateral";
|
|
4014
4867
|
lateral.name = alias2;
|
|
4015
4868
|
lateral.baseName = alias2;
|
|
4016
|
-
lateral.dialect = plan[
|
|
4869
|
+
lateral.dialect = plan[TypeId4].dialect;
|
|
4017
4870
|
lateral.plan = plan;
|
|
4018
|
-
lateral.required = currentRequiredList(plan[
|
|
4871
|
+
lateral.required = currentRequiredList(plan[TypeId4].required);
|
|
4019
4872
|
lateral.columns = columns;
|
|
4020
4873
|
return lateral;
|
|
4021
4874
|
};
|
|
@@ -4024,7 +4877,7 @@ var makeLateralSource = (plan, alias2) => {
|
|
|
4024
4877
|
var profile = {
|
|
4025
4878
|
dialect: "standard",
|
|
4026
4879
|
textDb: standardDatatypes.text(),
|
|
4027
|
-
numericDb: standardDatatypes.
|
|
4880
|
+
numericDb: standardDatatypes.real(),
|
|
4028
4881
|
boolDb: standardDatatypes.boolean(),
|
|
4029
4882
|
timestampDb: standardDatatypes.timestamp(),
|
|
4030
4883
|
nullDb: {
|
|
@@ -4039,16 +4892,19 @@ var profile = {
|
|
|
4039
4892
|
};
|
|
4040
4893
|
var ValuesInputProto = {
|
|
4041
4894
|
pipe() {
|
|
4042
|
-
return
|
|
4895
|
+
return pipeArguments7(this, arguments);
|
|
4043
4896
|
}
|
|
4044
4897
|
};
|
|
4045
4898
|
var literalSchemaOf = (value) => {
|
|
4046
4899
|
if (value === null || value instanceof Date) {
|
|
4047
4900
|
return;
|
|
4048
4901
|
}
|
|
4902
|
+
if (typeof value === "number" && !Number.isFinite(value)) {
|
|
4903
|
+
return;
|
|
4904
|
+
}
|
|
4049
4905
|
return Schema6.Literal(value);
|
|
4050
4906
|
};
|
|
4051
|
-
var literal = (value) =>
|
|
4907
|
+
var literal = (value) => makeExpression2({
|
|
4052
4908
|
runtime: undefined,
|
|
4053
4909
|
dbType: value === null ? profile.nullDb : value instanceof Date ? profile.timestampDb : typeof value === "string" ? profile.textDb : typeof value === "number" ? profile.numericDb : profile.boolDb,
|
|
4054
4910
|
runtimeSchema: literalSchemaOf(value),
|
|
@@ -4060,7 +4916,7 @@ var literal = (value) => makeExpression({
|
|
|
4060
4916
|
kind: "literal",
|
|
4061
4917
|
value
|
|
4062
4918
|
});
|
|
4063
|
-
var column = (name, dbType, nullable3 = false) =>
|
|
4919
|
+
var column = (name, dbType, nullable3 = false) => makeExpression2({
|
|
4064
4920
|
runtime: undefined,
|
|
4065
4921
|
dbType,
|
|
4066
4922
|
nullability: nullable3 ? "maybe" : "never",
|
|
@@ -4084,7 +4940,7 @@ var retargetLiteralExpression = (value, target) => {
|
|
|
4084
4940
|
return value;
|
|
4085
4941
|
}
|
|
4086
4942
|
const targetState = target[TypeId];
|
|
4087
|
-
return
|
|
4943
|
+
return makeExpression2({
|
|
4088
4944
|
runtime: value[TypeId].runtime,
|
|
4089
4945
|
dbType: targetState.dbType,
|
|
4090
4946
|
runtimeSchema: targetState.runtimeSchema,
|
|
@@ -4122,7 +4978,7 @@ var flattenVariadicBooleanExpressions = (kind, values) => {
|
|
|
4122
4978
|
};
|
|
4123
4979
|
var makeVariadicBooleanExpression = (kind, values) => {
|
|
4124
4980
|
const expressions = flattenVariadicBooleanExpressions(kind, values);
|
|
4125
|
-
const expression =
|
|
4981
|
+
const expression = makeExpression2({
|
|
4126
4982
|
runtime: true,
|
|
4127
4983
|
dbType: profile.boolDb,
|
|
4128
4984
|
nullability: mergeNullabilityManyRuntime(expressions),
|
|
@@ -4146,7 +5002,7 @@ var makeVariadicBooleanExpression = (kind, values) => {
|
|
|
4146
5002
|
return makeVariadicBooleanExpression(kind, [...expressions, ...appended]);
|
|
4147
5003
|
}
|
|
4148
5004
|
if (operations.every((operation) => typeof operation === "function")) {
|
|
4149
|
-
return
|
|
5005
|
+
return pipeArguments7(this, arguments);
|
|
4150
5006
|
}
|
|
4151
5007
|
const valuesForMixedPipe = (value) => {
|
|
4152
5008
|
if (typeof value !== "object" || value === null || !(TypeId in value)) {
|
|
@@ -4197,7 +5053,7 @@ var extractRequiredFromDialectNumericInputRuntime = (value) => {
|
|
|
4197
5053
|
};
|
|
4198
5054
|
var buildBinaryPredicate = (left, right, kind, nullability = "maybe") => {
|
|
4199
5055
|
const [leftExpression, rightExpression] = alignBinaryPredicateExpressions(toDialectExpression(left), toDialectExpression(right));
|
|
4200
|
-
return
|
|
5056
|
+
return makeExpression2({
|
|
4201
5057
|
runtime: true,
|
|
4202
5058
|
dbType: profile.boolDb,
|
|
4203
5059
|
nullability,
|
|
@@ -4214,7 +5070,7 @@ var buildVariadicPredicate = (values, kind) => {
|
|
|
4214
5070
|
const expressions = values.map((value) => toDialectExpression(value));
|
|
4215
5071
|
const [head, ...tail] = expressions;
|
|
4216
5072
|
const alignedExpressions = head !== undefined && (kind === "in" || kind === "notIn" || kind === "between") ? [head, ...tail.map((value) => retargetLiteralExpression(value, head))] : expressions;
|
|
4217
|
-
return
|
|
5073
|
+
return makeExpression2({
|
|
4218
5074
|
runtime: true,
|
|
4219
5075
|
dbType: profile.boolDb,
|
|
4220
5076
|
nullability: "maybe",
|
|
@@ -4298,7 +5154,7 @@ var isNotDistinctFrom = (...args) => {
|
|
|
4298
5154
|
};
|
|
4299
5155
|
var isNull = (value) => {
|
|
4300
5156
|
const expression = toDialectExpression(value);
|
|
4301
|
-
return
|
|
5157
|
+
return makeExpression2({
|
|
4302
5158
|
runtime: true,
|
|
4303
5159
|
dbType: profile.boolDb,
|
|
4304
5160
|
nullability: "never",
|
|
@@ -4312,7 +5168,7 @@ var isNull = (value) => {
|
|
|
4312
5168
|
};
|
|
4313
5169
|
var isNotNull = (value) => {
|
|
4314
5170
|
const expression = toDialectExpression(value);
|
|
4315
|
-
return
|
|
5171
|
+
return makeExpression2({
|
|
4316
5172
|
runtime: true,
|
|
4317
5173
|
dbType: profile.boolDb,
|
|
4318
5174
|
nullability: "never",
|
|
@@ -4326,7 +5182,7 @@ var isNotNull = (value) => {
|
|
|
4326
5182
|
};
|
|
4327
5183
|
var upper = (value) => {
|
|
4328
5184
|
const expression = toDialectStringExpression(value);
|
|
4329
|
-
return
|
|
5185
|
+
return makeExpression2({
|
|
4330
5186
|
runtime: "",
|
|
4331
5187
|
dbType: profile.textDb,
|
|
4332
5188
|
nullability: expression[TypeId].nullability,
|
|
@@ -4340,7 +5196,7 @@ var upper = (value) => {
|
|
|
4340
5196
|
};
|
|
4341
5197
|
var lower = (value) => {
|
|
4342
5198
|
const expression = toDialectStringExpression(value);
|
|
4343
|
-
return
|
|
5199
|
+
return makeExpression2({
|
|
4344
5200
|
runtime: "",
|
|
4345
5201
|
dbType: profile.textDb,
|
|
4346
5202
|
nullability: expression[TypeId].nullability,
|
|
@@ -4355,7 +5211,7 @@ var lower = (value) => {
|
|
|
4355
5211
|
var collate = (value, collation) => {
|
|
4356
5212
|
const expression = toDialectStringExpression(value);
|
|
4357
5213
|
const normalizedCollation = typeof collation === "string" ? [collation] : collation;
|
|
4358
|
-
return
|
|
5214
|
+
return makeExpression2({
|
|
4359
5215
|
runtime: expression[TypeId].runtime,
|
|
4360
5216
|
dbType: expression[TypeId].dbType,
|
|
4361
5217
|
nullability: expression[TypeId].nullability,
|
|
@@ -4370,7 +5226,7 @@ var collate = (value, collation) => {
|
|
|
4370
5226
|
};
|
|
4371
5227
|
var cast = (value, target) => {
|
|
4372
5228
|
const expression = toDialectExpression(value);
|
|
4373
|
-
return
|
|
5229
|
+
return makeExpression2({
|
|
4374
5230
|
runtime: undefined,
|
|
4375
5231
|
dbType: target,
|
|
4376
5232
|
runtimeSchema: undefined,
|
|
@@ -4385,41 +5241,6 @@ var cast = (value, target) => {
|
|
|
4385
5241
|
target
|
|
4386
5242
|
});
|
|
4387
5243
|
};
|
|
4388
|
-
var array2 = (element) => ({
|
|
4389
|
-
dialect: profile.dialect,
|
|
4390
|
-
kind: `${element.kind}[]`,
|
|
4391
|
-
element
|
|
4392
|
-
});
|
|
4393
|
-
var range = (kind, subtype) => ({
|
|
4394
|
-
dialect: profile.dialect,
|
|
4395
|
-
kind,
|
|
4396
|
-
subtype
|
|
4397
|
-
});
|
|
4398
|
-
var multirange = (kind, subtype) => ({
|
|
4399
|
-
dialect: profile.dialect,
|
|
4400
|
-
kind,
|
|
4401
|
-
subtype
|
|
4402
|
-
});
|
|
4403
|
-
var record = (kind, fields) => ({
|
|
4404
|
-
dialect: profile.dialect,
|
|
4405
|
-
kind,
|
|
4406
|
-
fields
|
|
4407
|
-
});
|
|
4408
|
-
var domain = (kind, base) => ({
|
|
4409
|
-
dialect: profile.dialect,
|
|
4410
|
-
kind,
|
|
4411
|
-
base
|
|
4412
|
-
});
|
|
4413
|
-
var enum_ = (kind) => ({
|
|
4414
|
-
dialect: profile.dialect,
|
|
4415
|
-
kind,
|
|
4416
|
-
variant: "enum"
|
|
4417
|
-
});
|
|
4418
|
-
var set = (kind) => ({
|
|
4419
|
-
dialect: profile.dialect,
|
|
4420
|
-
kind,
|
|
4421
|
-
variant: "set"
|
|
4422
|
-
});
|
|
4423
5244
|
var custom2 = (kind) => ({
|
|
4424
5245
|
dialect: profile.dialect,
|
|
4425
5246
|
kind
|
|
@@ -4430,13 +5251,6 @@ var driverValueMapping3 = (dbType, mapping) => ({
|
|
|
4430
5251
|
});
|
|
4431
5252
|
var type = {
|
|
4432
5253
|
...profile.type,
|
|
4433
|
-
array: array2,
|
|
4434
|
-
range,
|
|
4435
|
-
multirange,
|
|
4436
|
-
record,
|
|
4437
|
-
domain,
|
|
4438
|
-
enum: enum_,
|
|
4439
|
-
set,
|
|
4440
5254
|
custom: custom2,
|
|
4441
5255
|
driverValueMapping: driverValueMapping3
|
|
4442
5256
|
};
|
|
@@ -4452,21 +5266,21 @@ var isJsonExpressionValue = (value) => isExpressionValue(value) && (() => {
|
|
|
4452
5266
|
const dbType = value[TypeId].dbType;
|
|
4453
5267
|
return dbType.variant === "json" || dbType.kind === "json" || dbType.kind === "jsonb";
|
|
4454
5268
|
})();
|
|
4455
|
-
var isJsonPathValue = (value) => value !== null && typeof value === "object" && (
|
|
5269
|
+
var isJsonPathValue = (value) => value !== null && typeof value === "object" && (TypeId3 in value);
|
|
4456
5270
|
var normalizeJsonPathInput = (value) => isJsonPathValue(value) ? value.segments : [value];
|
|
4457
5271
|
var isExactJsonSegmentValue = (segment) => segment.kind === "key" || segment.kind === "index";
|
|
4458
5272
|
var isExactJsonPathValue = (segments) => segments.every(isExactJsonSegmentValue);
|
|
4459
|
-
var buildJsonNodeExpression = (expressions, state, ast) =>
|
|
5273
|
+
var buildJsonNodeExpression = (expressions, state, ast) => withJsonPathAccess(makeExpression2({
|
|
4460
5274
|
runtime: state.runtime,
|
|
4461
5275
|
dbType: state.dbType,
|
|
4462
5276
|
nullability: state.nullability,
|
|
4463
5277
|
dialect: expressions.find((expression) => expression[TypeId].dialect !== undefined)?.[TypeId].dialect ?? profile.dialect,
|
|
4464
5278
|
kind: mergeAggregationManyRuntime(expressions),
|
|
4465
5279
|
dependencies: mergeManyDependencies(expressions)
|
|
4466
|
-
}, ast);
|
|
5280
|
+
}, ast));
|
|
4467
5281
|
var jsonDbTypeOf = (base) => base[TypeId].dbType;
|
|
4468
5282
|
var resolveJsonMergeDbType = (..._values) => jsonbDb;
|
|
4469
|
-
var makeJsonLiteralExpression = (value, dbType = jsonDb) =>
|
|
5283
|
+
var makeJsonLiteralExpression = (value, dbType = jsonDb) => withJsonPathAccess(makeExpression2({
|
|
4470
5284
|
runtime: value,
|
|
4471
5285
|
dbType,
|
|
4472
5286
|
nullability: value === null ? "always" : "never",
|
|
@@ -4476,7 +5290,7 @@ var makeJsonLiteralExpression = (value, dbType = jsonDb) => makeExpression({
|
|
|
4476
5290
|
}, {
|
|
4477
5291
|
kind: "literal",
|
|
4478
5292
|
value
|
|
4479
|
-
});
|
|
5293
|
+
}));
|
|
4480
5294
|
var wrapJsonExpression = (value, kind, dbType) => buildJsonNodeExpression([value], {
|
|
4481
5295
|
runtime: undefined,
|
|
4482
5296
|
dbType,
|
|
@@ -4719,6 +5533,7 @@ var jsonBuildObject = jsonBuildObjectAs(jsonDb);
|
|
|
4719
5533
|
var jsonBuildArray = jsonBuildArrayAs(jsonDb);
|
|
4720
5534
|
var jsonbBuildObject = jsonBuildObjectAs(jsonbDb);
|
|
4721
5535
|
var jsonbBuildArray = jsonBuildArrayAs(jsonbDb);
|
|
5536
|
+
var jsonToJson = (value) => toJsonValueExpression(value, "jsonToJson", jsonDb);
|
|
4722
5537
|
var jsonToJsonb = (value) => toJsonValueExpression(value, "jsonToJsonb", jsonbDb);
|
|
4723
5538
|
var jsonTypeOf = (base) => buildJsonNodeExpression([base], {
|
|
4724
5539
|
runtime: undefined,
|
|
@@ -4798,9 +5613,45 @@ var jsonPathMatch = (base, query) => {
|
|
|
4798
5613
|
query: queryExpression
|
|
4799
5614
|
});
|
|
4800
5615
|
};
|
|
5616
|
+
var json2 = {
|
|
5617
|
+
key,
|
|
5618
|
+
index,
|
|
5619
|
+
wildcard,
|
|
5620
|
+
slice,
|
|
5621
|
+
descend,
|
|
5622
|
+
path,
|
|
5623
|
+
get: jsonGet,
|
|
5624
|
+
access: jsonAccess,
|
|
5625
|
+
traverse: jsonTraverse,
|
|
5626
|
+
text: jsonText,
|
|
5627
|
+
accessText: jsonAccessText,
|
|
5628
|
+
traverseText: jsonTraverseText,
|
|
5629
|
+
contains: jsonContains,
|
|
5630
|
+
containedBy: jsonContainedBy,
|
|
5631
|
+
hasKey: jsonHasKey,
|
|
5632
|
+
keyExists: jsonKeyExists,
|
|
5633
|
+
hasAnyKeys: jsonHasAnyKeys,
|
|
5634
|
+
hasAllKeys: jsonHasAllKeys,
|
|
5635
|
+
delete: jsonDelete,
|
|
5636
|
+
remove: jsonRemove,
|
|
5637
|
+
set: jsonSet,
|
|
5638
|
+
insert: jsonInsert,
|
|
5639
|
+
concat: jsonConcat,
|
|
5640
|
+
merge: jsonMerge,
|
|
5641
|
+
buildObject: jsonBuildObject,
|
|
5642
|
+
buildArray: jsonBuildArray,
|
|
5643
|
+
toJson: jsonToJson,
|
|
5644
|
+
toJsonb: jsonToJsonb,
|
|
5645
|
+
typeOf: jsonTypeOf,
|
|
5646
|
+
length: jsonLength,
|
|
5647
|
+
keys: jsonKeys,
|
|
5648
|
+
stripNulls: jsonStripNulls,
|
|
5649
|
+
pathExists: jsonPathExists,
|
|
5650
|
+
pathMatch: jsonPathMatch
|
|
5651
|
+
};
|
|
4801
5652
|
var jsonb = {
|
|
4802
5653
|
key,
|
|
4803
|
-
index
|
|
5654
|
+
index,
|
|
4804
5655
|
wildcard,
|
|
4805
5656
|
slice,
|
|
4806
5657
|
descend,
|
|
@@ -4837,7 +5688,7 @@ var and = (...values) => makeVariadicBooleanExpression("and", values.map((value)
|
|
|
4837
5688
|
var or = (...values) => makeVariadicBooleanExpression("or", values.map((value) => toDialectExpression(value)));
|
|
4838
5689
|
var not = (value) => {
|
|
4839
5690
|
const expression = toDialectExpression(value);
|
|
4840
|
-
return
|
|
5691
|
+
return makeExpression2({
|
|
4841
5692
|
runtime: true,
|
|
4842
5693
|
dbType: profile.boolDb,
|
|
4843
5694
|
nullability: expression[TypeId].nullability,
|
|
@@ -4869,7 +5720,7 @@ var overlaps = (...args) => {
|
|
|
4869
5720
|
};
|
|
4870
5721
|
var concat = (...values) => {
|
|
4871
5722
|
const expressions = values.map((value) => toDialectStringExpression(value));
|
|
4872
|
-
return
|
|
5723
|
+
return makeExpression2({
|
|
4873
5724
|
runtime: "",
|
|
4874
5725
|
dbType: profile.textDb,
|
|
4875
5726
|
nullability: mergeNullabilityManyRuntime(expressions),
|
|
@@ -4885,7 +5736,7 @@ var all_ = (...values) => and(...values);
|
|
|
4885
5736
|
var any_ = (...values) => or(...values);
|
|
4886
5737
|
var count = (value) => {
|
|
4887
5738
|
const expression = toDialectExpression(value);
|
|
4888
|
-
return
|
|
5739
|
+
return makeExpression2({
|
|
4889
5740
|
runtime: 0,
|
|
4890
5741
|
dbType: profile.numericDb,
|
|
4891
5742
|
nullability: "never",
|
|
@@ -4898,8 +5749,8 @@ var count = (value) => {
|
|
|
4898
5749
|
});
|
|
4899
5750
|
};
|
|
4900
5751
|
var exists = (plan) => {
|
|
4901
|
-
const dependencies = Object.fromEntries(currentRequiredList(plan[
|
|
4902
|
-
return
|
|
5752
|
+
const dependencies = Object.fromEntries(currentRequiredList(plan[TypeId4].required).map((name) => [name, true]));
|
|
5753
|
+
return makeExpression2({
|
|
4903
5754
|
runtime: true,
|
|
4904
5755
|
dbType: profile.boolDb,
|
|
4905
5756
|
nullability: "never",
|
|
@@ -4912,9 +5763,9 @@ var exists = (plan) => {
|
|
|
4912
5763
|
});
|
|
4913
5764
|
};
|
|
4914
5765
|
var scalar = (plan) => {
|
|
4915
|
-
const dependencies = Object.fromEntries(currentRequiredList(plan[
|
|
4916
|
-
const expression = extractSingleSelectedExpressionRuntime(plan[
|
|
4917
|
-
return
|
|
5766
|
+
const dependencies = Object.fromEntries(currentRequiredList(plan[TypeId4].required).map((name) => [name, true]));
|
|
5767
|
+
const expression = extractSingleSelectedExpressionRuntime(plan[TypeId4].selection);
|
|
5768
|
+
return makeExpression2({
|
|
4918
5769
|
runtime: undefined,
|
|
4919
5770
|
dbType: expression[TypeId].dbType,
|
|
4920
5771
|
runtimeSchema: expression[TypeId].runtimeSchema,
|
|
@@ -4930,8 +5781,8 @@ var scalar = (plan) => {
|
|
|
4930
5781
|
};
|
|
4931
5782
|
var inSubquery = (left, plan) => {
|
|
4932
5783
|
const leftExpression = toDialectExpression(left);
|
|
4933
|
-
const dependencies = Object.fromEntries(currentRequiredList(plan[
|
|
4934
|
-
return
|
|
5784
|
+
const dependencies = Object.fromEntries(currentRequiredList(plan[TypeId4].required).map((name) => [name, true]));
|
|
5785
|
+
return makeExpression2({
|
|
4935
5786
|
runtime: true,
|
|
4936
5787
|
dbType: profile.boolDb,
|
|
4937
5788
|
nullability: "maybe",
|
|
@@ -4946,8 +5797,8 @@ var inSubquery = (left, plan) => {
|
|
|
4946
5797
|
};
|
|
4947
5798
|
var quantifiedComparison = (left, plan, operator, quantifier) => {
|
|
4948
5799
|
const leftExpression = toDialectExpression(left);
|
|
4949
|
-
const dependencies = Object.fromEntries(currentRequiredList(plan[
|
|
4950
|
-
return
|
|
5800
|
+
const dependencies = Object.fromEntries(currentRequiredList(plan[TypeId4].required).map((name) => [name, true]));
|
|
5801
|
+
return makeExpression2({
|
|
4951
5802
|
runtime: true,
|
|
4952
5803
|
dbType: profile.boolDb,
|
|
4953
5804
|
nullability: "maybe",
|
|
@@ -4961,7 +5812,7 @@ var compareAll = (left, plan, operator) => quantifiedComparison(left, plan, oper
|
|
|
4961
5812
|
var over = (value, spec = {}) => {
|
|
4962
5813
|
const normalized = normalizeWindowSpec(spec);
|
|
4963
5814
|
const expressions = mergeWindowExpressions(value, normalized.partitionBy, normalized.orderBy);
|
|
4964
|
-
return
|
|
5815
|
+
return makeExpression2({
|
|
4965
5816
|
runtime: undefined,
|
|
4966
5817
|
dbType: value[TypeId].dbType,
|
|
4967
5818
|
nullability: value[TypeId].nullability,
|
|
@@ -4979,7 +5830,7 @@ var over = (value, spec = {}) => {
|
|
|
4979
5830
|
var buildNumberWindow = (kind, spec) => {
|
|
4980
5831
|
const normalized = normalizeWindowSpec(spec);
|
|
4981
5832
|
const expressions = mergeWindowExpressions(undefined, normalized.partitionBy, normalized.orderBy);
|
|
4982
|
-
return
|
|
5833
|
+
return makeExpression2({
|
|
4983
5834
|
runtime: 0,
|
|
4984
5835
|
dbType: profile.numericDb,
|
|
4985
5836
|
nullability: "never",
|
|
@@ -4996,7 +5847,7 @@ var buildNumberWindow = (kind, spec) => {
|
|
|
4996
5847
|
var rowNumber = (spec) => buildNumberWindow("rowNumber", spec);
|
|
4997
5848
|
var rank = (spec) => buildNumberWindow("rank", spec);
|
|
4998
5849
|
var denseRank = (spec) => buildNumberWindow("denseRank", spec);
|
|
4999
|
-
var max = (value) =>
|
|
5850
|
+
var max = (value) => makeExpression2({
|
|
5000
5851
|
runtime: undefined,
|
|
5001
5852
|
dbType: value[TypeId].dbType,
|
|
5002
5853
|
nullability: "maybe",
|
|
@@ -5007,7 +5858,7 @@ var max = (value) => makeExpression({
|
|
|
5007
5858
|
kind: "max",
|
|
5008
5859
|
value
|
|
5009
5860
|
});
|
|
5010
|
-
var min = (value) =>
|
|
5861
|
+
var min = (value) => makeExpression2({
|
|
5011
5862
|
runtime: undefined,
|
|
5012
5863
|
dbType: value[TypeId].dbType,
|
|
5013
5864
|
nullability: "maybe",
|
|
@@ -5022,7 +5873,7 @@ var resolveCoalesceNullabilityRuntime = (values) => values.some((value) => value
|
|
|
5022
5873
|
var coalesce = (...values) => {
|
|
5023
5874
|
const expressions = values.map((value) => toDialectExpression(value));
|
|
5024
5875
|
const representative = expressions.find((value) => value[TypeId].nullability !== "always") ?? expressions[0];
|
|
5025
|
-
return
|
|
5876
|
+
return makeExpression2({
|
|
5026
5877
|
runtime: undefined,
|
|
5027
5878
|
dbType: representative[TypeId].dbType,
|
|
5028
5879
|
nullability: resolveCoalesceNullabilityRuntime(expressions),
|
|
@@ -5036,7 +5887,7 @@ var coalesce = (...values) => {
|
|
|
5036
5887
|
};
|
|
5037
5888
|
var call = (name, ...args) => {
|
|
5038
5889
|
const expressions = args.map((value) => toDialectExpression(value));
|
|
5039
|
-
return
|
|
5890
|
+
return makeExpression2({
|
|
5040
5891
|
runtime: undefined,
|
|
5041
5892
|
dbType: profile.textDb,
|
|
5042
5893
|
nullability: "maybe",
|
|
@@ -5072,7 +5923,7 @@ var finalizeCase = (branches, fallback) => {
|
|
|
5072
5923
|
const resultExpressions = [...branches.map((branch) => branch.then), fallback];
|
|
5073
5924
|
const allExpressions = [...branches.flatMap((branch) => [branch.when, branch.then]), fallback];
|
|
5074
5925
|
const representative = resultExpressions.find((value) => value[TypeId].nullability !== "always") ?? fallback;
|
|
5075
|
-
return
|
|
5926
|
+
return makeExpression2({
|
|
5076
5927
|
runtime: undefined,
|
|
5077
5928
|
dbType: representative[TypeId].dbType,
|
|
5078
5929
|
nullability: resolveCaseNullabilityRuntime(resultExpressions),
|
|
@@ -5140,7 +5991,7 @@ var match = (value) => {
|
|
|
5140
5991
|
};
|
|
5141
5992
|
var excluded = (value) => {
|
|
5142
5993
|
const ast = value[TypeId2];
|
|
5143
|
-
return
|
|
5994
|
+
return makeExpression2({
|
|
5144
5995
|
runtime: undefined,
|
|
5145
5996
|
dbType: value[TypeId].dbType,
|
|
5146
5997
|
runtimeSchema: value[TypeId].runtimeSchema,
|
|
@@ -5172,7 +6023,7 @@ var toMutationValueExpression = (value, column2) => {
|
|
|
5172
6023
|
const ast = expression[TypeId2];
|
|
5173
6024
|
if (ast.kind === "literal") {
|
|
5174
6025
|
const normalizedValue2 = normalizeMutationValue(ast.value);
|
|
5175
|
-
return
|
|
6026
|
+
return makeExpression2({
|
|
5176
6027
|
runtime: normalizedValue2,
|
|
5177
6028
|
dbType: columnState.dbType,
|
|
5178
6029
|
runtimeSchema: columnState.runtimeSchema,
|
|
@@ -5189,7 +6040,7 @@ var toMutationValueExpression = (value, column2) => {
|
|
|
5189
6040
|
return retargetLiteralExpression(value, column2);
|
|
5190
6041
|
}
|
|
5191
6042
|
const normalizedValue = normalizeMutationValue(value);
|
|
5192
|
-
return
|
|
6043
|
+
return makeExpression2({
|
|
5193
6044
|
runtime: normalizedValue,
|
|
5194
6045
|
dbType: columnState.dbType,
|
|
5195
6046
|
runtimeSchema: columnState.runtimeSchema,
|
|
@@ -5210,28 +6061,28 @@ var renderQuantifiedComparisonAst = (left, plan, operator, quantifier) => ({
|
|
|
5210
6061
|
plan
|
|
5211
6062
|
});
|
|
5212
6063
|
var targetSourceDetails = (table) => {
|
|
5213
|
-
const sourceName = table[
|
|
5214
|
-
const sourceBaseName = table[
|
|
6064
|
+
const sourceName = table[TypeId7].name;
|
|
6065
|
+
const sourceBaseName = table[TypeId7].baseName;
|
|
5215
6066
|
return {
|
|
5216
6067
|
sourceName,
|
|
5217
6068
|
sourceBaseName
|
|
5218
6069
|
};
|
|
5219
6070
|
};
|
|
5220
6071
|
var sourceDetails = (source) => {
|
|
5221
|
-
if (
|
|
6072
|
+
if (TypeId7 in source) {
|
|
5222
6073
|
return targetSourceDetails(source);
|
|
5223
6074
|
}
|
|
5224
|
-
const
|
|
6075
|
+
const record = source;
|
|
5225
6076
|
return {
|
|
5226
|
-
sourceName:
|
|
5227
|
-
sourceBaseName:
|
|
6077
|
+
sourceName: record.name,
|
|
6078
|
+
sourceBaseName: record.baseName
|
|
5228
6079
|
};
|
|
5229
6080
|
};
|
|
5230
6081
|
var makeColumnReferenceSelection = (alias2, selection) => {
|
|
5231
6082
|
const columns = {};
|
|
5232
6083
|
for (const [columnName, expression] of Object.entries(selection)) {
|
|
5233
6084
|
const state = expression[TypeId];
|
|
5234
|
-
columns[columnName] =
|
|
6085
|
+
columns[columnName] = makeExpression2({
|
|
5235
6086
|
runtime: undefined,
|
|
5236
6087
|
dbType: state.dbType,
|
|
5237
6088
|
runtimeSchema: state.runtimeSchema,
|
|
@@ -5297,7 +6148,7 @@ var buildMutationAssignments = (target, values) => {
|
|
|
5297
6148
|
}
|
|
5298
6149
|
const valueMap = values;
|
|
5299
6150
|
return targets.flatMap((table) => {
|
|
5300
|
-
const targetName = table[
|
|
6151
|
+
const targetName = table[TypeId7].name;
|
|
5301
6152
|
const scopedValues = valueMap[targetName] ?? {};
|
|
5302
6153
|
const columns = table;
|
|
5303
6154
|
return Object.entries(scopedValues).map(([columnName, value]) => ({
|
|
@@ -5535,6 +6386,146 @@ var {
|
|
|
5535
6386
|
from,
|
|
5536
6387
|
insert
|
|
5537
6388
|
};
|
|
6389
|
+
|
|
6390
|
+
// src/standard/cast.ts
|
|
6391
|
+
var to = (...args) => args.length === 1 ? (value) => cast(value, args[0]) : cast(args[0], args[1]);
|
|
6392
|
+
// src/standard/function/index.ts
|
|
6393
|
+
var exports_function = {};
|
|
6394
|
+
__export(exports_function, {
|
|
6395
|
+
window: () => exports_window,
|
|
6396
|
+
upper: () => upper,
|
|
6397
|
+
temporal: () => exports_temporal,
|
|
6398
|
+
string: () => exports_string,
|
|
6399
|
+
rowNumber: () => rowNumber,
|
|
6400
|
+
rank: () => rank,
|
|
6401
|
+
over: () => over,
|
|
6402
|
+
now: () => now,
|
|
6403
|
+
min: () => min,
|
|
6404
|
+
max: () => max,
|
|
6405
|
+
lower: () => lower,
|
|
6406
|
+
localTimestamp: () => localTimestamp,
|
|
6407
|
+
localTime: () => localTime,
|
|
6408
|
+
denseRank: () => denseRank,
|
|
6409
|
+
currentTimestamp: () => currentTimestamp,
|
|
6410
|
+
currentTime: () => currentTime,
|
|
6411
|
+
currentDate: () => currentDate,
|
|
6412
|
+
count: () => count,
|
|
6413
|
+
core: () => exports_core,
|
|
6414
|
+
concat: () => concat,
|
|
6415
|
+
coalesce: () => coalesce,
|
|
6416
|
+
call: () => call,
|
|
6417
|
+
aggregate: () => exports_aggregate
|
|
6418
|
+
});
|
|
6419
|
+
|
|
6420
|
+
// src/standard/function/core.ts
|
|
6421
|
+
var exports_core = {};
|
|
6422
|
+
__export(exports_core, {
|
|
6423
|
+
coalesce: () => coalesce,
|
|
6424
|
+
call: () => call
|
|
6425
|
+
});
|
|
6426
|
+
|
|
6427
|
+
// src/standard/query.ts
|
|
6428
|
+
var exports_query = {};
|
|
6429
|
+
__export(exports_query, {
|
|
6430
|
+
withRecursive: () => withRecursive_,
|
|
6431
|
+
with: () => with_,
|
|
6432
|
+
where: () => where,
|
|
6433
|
+
values: () => exportedValues,
|
|
6434
|
+
upsert: () => upsert,
|
|
6435
|
+
upper: () => upper,
|
|
6436
|
+
update: () => update,
|
|
6437
|
+
unnest: () => exportedUnnest,
|
|
6438
|
+
union_query_capabilities: () => union_query_capabilities,
|
|
6439
|
+
unionAll: () => unionAll,
|
|
6440
|
+
union: () => union,
|
|
6441
|
+
type: () => type,
|
|
6442
|
+
truncate: () => truncate,
|
|
6443
|
+
transaction: () => transaction,
|
|
6444
|
+
select: () => exportedSelect,
|
|
6445
|
+
scalar: () => scalar,
|
|
6446
|
+
savepoint: () => savepoint,
|
|
6447
|
+
rowNumber: () => rowNumber,
|
|
6448
|
+
rollbackTo: () => rollbackTo,
|
|
6449
|
+
rollback: () => rollback,
|
|
6450
|
+
rightJoin: () => rightJoin,
|
|
6451
|
+
returning: () => returning,
|
|
6452
|
+
releaseSavepoint: () => releaseSavepoint,
|
|
6453
|
+
regexNotMatch: () => regexNotMatch,
|
|
6454
|
+
regexNotIMatch: () => regexNotIMatch,
|
|
6455
|
+
regexMatch: () => regexMatch,
|
|
6456
|
+
regexIMatch: () => regexIMatch,
|
|
6457
|
+
rank: () => rank,
|
|
6458
|
+
overlaps: () => overlaps,
|
|
6459
|
+
over: () => over,
|
|
6460
|
+
orderBy: () => orderBy,
|
|
6461
|
+
or: () => or,
|
|
6462
|
+
onConflict: () => onConflict,
|
|
6463
|
+
offset: () => offset,
|
|
6464
|
+
notIn: () => notIn,
|
|
6465
|
+
not: () => not,
|
|
6466
|
+
neq: () => neq,
|
|
6467
|
+
min: () => min,
|
|
6468
|
+
merge: () => merge2,
|
|
6469
|
+
max: () => max,
|
|
6470
|
+
match: () => match,
|
|
6471
|
+
lte: () => lte,
|
|
6472
|
+
lt: () => lt,
|
|
6473
|
+
lower: () => lower,
|
|
6474
|
+
lock: () => lock,
|
|
6475
|
+
literal: () => literal,
|
|
6476
|
+
limit: () => limit,
|
|
6477
|
+
like: () => like,
|
|
6478
|
+
leftJoin: () => leftJoin,
|
|
6479
|
+
lateral: () => lateral,
|
|
6480
|
+
isNull: () => isNull,
|
|
6481
|
+
isNotNull: () => isNotNull,
|
|
6482
|
+
isNotDistinctFrom: () => isNotDistinctFrom,
|
|
6483
|
+
isDistinctFrom: () => isDistinctFrom,
|
|
6484
|
+
intersectAll: () => intersectAll,
|
|
6485
|
+
intersect: () => intersect,
|
|
6486
|
+
insert: () => exportedInsert,
|
|
6487
|
+
innerJoin: () => innerJoin,
|
|
6488
|
+
inSubquery: () => inSubquery,
|
|
6489
|
+
in: () => in_,
|
|
6490
|
+
ilike: () => ilike,
|
|
6491
|
+
having: () => having,
|
|
6492
|
+
gte: () => gte,
|
|
6493
|
+
gt: () => gt,
|
|
6494
|
+
groupBy: () => groupBy,
|
|
6495
|
+
fullJoin: () => fullJoin,
|
|
6496
|
+
from: () => exportedFrom,
|
|
6497
|
+
exists: () => exists,
|
|
6498
|
+
excluded: () => excluded,
|
|
6499
|
+
exceptAll: () => exceptAll,
|
|
6500
|
+
except: () => except,
|
|
6501
|
+
eq: () => eq,
|
|
6502
|
+
dropTable: () => dropTable,
|
|
6503
|
+
dropIndex: () => dropIndex,
|
|
6504
|
+
distinct: () => distinct,
|
|
6505
|
+
denseRank: () => denseRank,
|
|
6506
|
+
delete: () => delete_,
|
|
6507
|
+
crossJoin: () => crossJoin,
|
|
6508
|
+
createTable: () => createTable,
|
|
6509
|
+
createIndex: () => createIndex,
|
|
6510
|
+
count: () => count,
|
|
6511
|
+
contains: () => contains,
|
|
6512
|
+
containedBy: () => containedBy,
|
|
6513
|
+
concat: () => concat,
|
|
6514
|
+
compareAny: () => compareAny,
|
|
6515
|
+
compareAll: () => compareAll,
|
|
6516
|
+
commit: () => commit,
|
|
6517
|
+
column: () => column,
|
|
6518
|
+
collate: () => collate,
|
|
6519
|
+
coalesce: () => coalesce,
|
|
6520
|
+
cast: () => cast,
|
|
6521
|
+
case: () => case_,
|
|
6522
|
+
call: () => call,
|
|
6523
|
+
between: () => between,
|
|
6524
|
+
as: () => as,
|
|
6525
|
+
any: () => any_,
|
|
6526
|
+
and: () => and,
|
|
6527
|
+
all: () => all_
|
|
6528
|
+
});
|
|
5538
6529
|
// src/standard/function/string.ts
|
|
5539
6530
|
var exports_string = {};
|
|
5540
6531
|
__export(exports_string, {
|
|
@@ -5567,7 +6558,7 @@ __export(exports_temporal, {
|
|
|
5567
6558
|
currentTime: () => currentTime,
|
|
5568
6559
|
currentDate: () => currentDate
|
|
5569
6560
|
});
|
|
5570
|
-
var makeTemporal = (name, dbType, runtimeSchema) =>
|
|
6561
|
+
var makeTemporal = (name, dbType, runtimeSchema) => makeExpression2({
|
|
5571
6562
|
runtime: undefined,
|
|
5572
6563
|
dbType,
|
|
5573
6564
|
runtimeSchema,
|
|
@@ -5586,11 +6577,240 @@ var currentTime = () => makeTemporal("current_time", standardDatatypes.time(), L
|
|
|
5586
6577
|
var currentTimestamp = () => makeTemporal("current_timestamp", standardDatatypes.timestamp(), LocalDateTimeStringSchema);
|
|
5587
6578
|
var localTime = () => makeTemporal("localtime", standardDatatypes.time(), LocalTimeStringSchema);
|
|
5588
6579
|
var localTimestamp = () => makeTemporal("localtimestamp", standardDatatypes.timestamp(), LocalDateTimeStringSchema);
|
|
6580
|
+
// src/standard/json.ts
|
|
6581
|
+
var exports_json = {};
|
|
6582
|
+
__export(exports_json, {
|
|
6583
|
+
wildcard: () => wildcard2,
|
|
6584
|
+
typeOf: () => typeOf,
|
|
6585
|
+
traverseText: () => traverseText,
|
|
6586
|
+
traverse: () => traverse,
|
|
6587
|
+
toJsonb: () => toJsonb,
|
|
6588
|
+
toJson: () => toJson,
|
|
6589
|
+
text: () => text2,
|
|
6590
|
+
slice: () => slice2,
|
|
6591
|
+
set: () => set,
|
|
6592
|
+
remove: () => remove,
|
|
6593
|
+
pathExists: () => pathExists,
|
|
6594
|
+
merge: () => merge3,
|
|
6595
|
+
length: () => length,
|
|
6596
|
+
keys: () => keys,
|
|
6597
|
+
keyExists: () => keyExists,
|
|
6598
|
+
key: () => key2,
|
|
6599
|
+
insert: () => insert2,
|
|
6600
|
+
index: () => index4,
|
|
6601
|
+
hasKey: () => hasKey,
|
|
6602
|
+
hasAnyKeys: () => hasAnyKeys,
|
|
6603
|
+
hasAllKeys: () => hasAllKeys,
|
|
6604
|
+
get: () => get,
|
|
6605
|
+
descend: () => descend2,
|
|
6606
|
+
delete_: () => delete_2,
|
|
6607
|
+
delete: () => delete_2,
|
|
6608
|
+
contains: () => contains2,
|
|
6609
|
+
containedBy: () => containedBy2,
|
|
6610
|
+
concat: () => concat2,
|
|
6611
|
+
buildObject: () => buildObject,
|
|
6612
|
+
buildArray: () => buildArray,
|
|
6613
|
+
accessText: () => accessText,
|
|
6614
|
+
access: () => access
|
|
6615
|
+
});
|
|
6616
|
+
var emptyPath = path();
|
|
6617
|
+
var isObjectLike2 = (value) => (typeof value === "object" || typeof value === "function") && value !== null;
|
|
6618
|
+
var isExpression4 = (value) => isObjectLike2(value) && (TypeId in value);
|
|
6619
|
+
var isPath = (value) => isObjectLike2(value) && (TypeId3 in value);
|
|
6620
|
+
var isSegment = (value) => isObjectLike2(value) && (SegmentTypeId in value);
|
|
6621
|
+
var isTarget = (value) => isPath(value) || isSegment(value);
|
|
6622
|
+
var normalizeSegment2 = (segment) => {
|
|
6623
|
+
switch (segment.kind) {
|
|
6624
|
+
case "key":
|
|
6625
|
+
return key(segment.key);
|
|
6626
|
+
case "index":
|
|
6627
|
+
return index(segment.index);
|
|
6628
|
+
case "wildcard":
|
|
6629
|
+
return wildcard();
|
|
6630
|
+
case "slice":
|
|
6631
|
+
return slice(segment.start, segment.end);
|
|
6632
|
+
case "descend":
|
|
6633
|
+
return descend();
|
|
6634
|
+
}
|
|
6635
|
+
};
|
|
6636
|
+
var normalizeTarget = (target) => isPath(target) ? path(...target.segments.map(normalizeSegment2)) : normalizeSegment2(target);
|
|
6637
|
+
var normalizeTargetPath = (target) => isPath(target) ? path(...target.segments.map(normalizeSegment2)) : path(normalizeSegment2(target));
|
|
6638
|
+
var accessKinds2 = new Set([
|
|
6639
|
+
"jsonGet",
|
|
6640
|
+
"jsonPath",
|
|
6641
|
+
"jsonAccess",
|
|
6642
|
+
"jsonTraverse",
|
|
6643
|
+
"jsonGetText",
|
|
6644
|
+
"jsonPathText",
|
|
6645
|
+
"jsonAccessText",
|
|
6646
|
+
"jsonTraverseText"
|
|
6647
|
+
]);
|
|
6648
|
+
var accessPathOf2 = (value) => {
|
|
6649
|
+
const segments = [];
|
|
6650
|
+
let base = value;
|
|
6651
|
+
while (isExpression4(base)) {
|
|
6652
|
+
const ast = base[TypeId2];
|
|
6653
|
+
if (typeof ast.kind !== "string" || !accessKinds2.has(ast.kind) || !isExpression4(ast.base) || !Array.isArray(ast.segments)) {
|
|
6654
|
+
break;
|
|
6655
|
+
}
|
|
6656
|
+
segments.unshift(...ast.segments.map(normalizeSegment2));
|
|
6657
|
+
base = ast.base;
|
|
6658
|
+
}
|
|
6659
|
+
return segments.length === 0 ? undefined : {
|
|
6660
|
+
base,
|
|
6661
|
+
path: path(...segments)
|
|
6662
|
+
};
|
|
6663
|
+
};
|
|
6664
|
+
var targetOrAccessPath = (value) => isExpression4(value) ? accessPathOf2(value) : undefined;
|
|
6665
|
+
var segmentOperation = (segment) => Object.assign((base) => json2.get(base, segment), segment);
|
|
6666
|
+
var key2 = (value) => segmentOperation(key(value));
|
|
6667
|
+
var index4 = (value) => segmentOperation(index(value));
|
|
6668
|
+
var wildcard2 = () => segmentOperation(wildcard());
|
|
6669
|
+
var slice2 = (start, end) => segmentOperation(slice(start, end));
|
|
6670
|
+
var descend2 = () => segmentOperation(descend());
|
|
6671
|
+
var get = (...args) => {
|
|
6672
|
+
if (args.length === 1) {
|
|
6673
|
+
const [first] = args;
|
|
6674
|
+
if (isTarget(first)) {
|
|
6675
|
+
return (base2) => json2.get(base2, normalizeTarget(first));
|
|
6676
|
+
}
|
|
6677
|
+
const access = targetOrAccessPath(first);
|
|
6678
|
+
return access === undefined ? first : json2.get(access.base, access.path);
|
|
6679
|
+
}
|
|
6680
|
+
const [base, target] = args;
|
|
6681
|
+
return json2.get(base, normalizeTarget(target));
|
|
6682
|
+
};
|
|
6683
|
+
var text2 = (...args) => {
|
|
6684
|
+
if (args.length === 1) {
|
|
6685
|
+
const [first] = args;
|
|
6686
|
+
if (isTarget(first)) {
|
|
6687
|
+
return (base2) => json2.text(base2, normalizeTarget(first));
|
|
6688
|
+
}
|
|
6689
|
+
const access = targetOrAccessPath(first);
|
|
6690
|
+
return access === undefined ? json2.text(first, emptyPath) : json2.text(access.base, access.path);
|
|
6691
|
+
}
|
|
6692
|
+
const [base, target] = args;
|
|
6693
|
+
return json2.text(base, normalizeTarget(target));
|
|
6694
|
+
};
|
|
6695
|
+
var delete_2 = (...args) => {
|
|
6696
|
+
if (args.length === 1) {
|
|
6697
|
+
const [first] = args;
|
|
6698
|
+
if (isTarget(first)) {
|
|
6699
|
+
return (base2) => json2.delete(base2, normalizeTarget(first));
|
|
6700
|
+
}
|
|
6701
|
+
const access = targetOrAccessPath(first);
|
|
6702
|
+
if (access === undefined) {
|
|
6703
|
+
throw new Error("Json.delete requires a piped JSON path or an explicit target");
|
|
6704
|
+
}
|
|
6705
|
+
return json2.delete(access.base, access.path);
|
|
6706
|
+
}
|
|
6707
|
+
const [base, target] = args;
|
|
6708
|
+
return json2.delete(base, normalizeTarget(target));
|
|
6709
|
+
};
|
|
6710
|
+
var access = json2.access;
|
|
6711
|
+
var traverse = json2.traverse;
|
|
6712
|
+
var accessText = json2.accessText;
|
|
6713
|
+
var traverseText = json2.traverseText;
|
|
6714
|
+
var contains2 = json2.contains;
|
|
6715
|
+
var containedBy2 = json2.containedBy;
|
|
6716
|
+
var hasKey = (...args) => {
|
|
6717
|
+
if (args.length === 1) {
|
|
6718
|
+
const [key4] = args;
|
|
6719
|
+
return (base2) => json2.hasKey(base2, key4);
|
|
6720
|
+
}
|
|
6721
|
+
const [base, key3] = args;
|
|
6722
|
+
return json2.hasKey(base, key3);
|
|
6723
|
+
};
|
|
6724
|
+
var keyExists = hasKey;
|
|
6725
|
+
var hasAnyKeys = (base, ...keys) => json2.hasAnyKeys(base, ...keys);
|
|
6726
|
+
var hasAllKeys = (base, ...keys) => json2.hasAllKeys(base, ...keys);
|
|
6727
|
+
var remove = (...args) => {
|
|
6728
|
+
if (args.length === 1) {
|
|
6729
|
+
const [first] = args;
|
|
6730
|
+
if (isTarget(first)) {
|
|
6731
|
+
return (base2) => json2.remove(base2, normalizeTarget(first));
|
|
6732
|
+
}
|
|
6733
|
+
const access2 = targetOrAccessPath(first);
|
|
6734
|
+
if (access2 === undefined) {
|
|
6735
|
+
throw new Error("Json.remove requires a piped JSON path or an explicit target");
|
|
6736
|
+
}
|
|
6737
|
+
return json2.remove(access2.base, access2.path);
|
|
6738
|
+
}
|
|
6739
|
+
const [base, target] = args;
|
|
6740
|
+
return json2.remove(base, normalizeTarget(target));
|
|
6741
|
+
};
|
|
6742
|
+
var set = (...args) => {
|
|
6743
|
+
if (args.length === 1 || args.length === 2 && !isExpression4(args[0])) {
|
|
6744
|
+
const [next2, options3] = args;
|
|
6745
|
+
return (base2) => {
|
|
6746
|
+
const access2 = accessPathOf2(base2);
|
|
6747
|
+
if (access2 === undefined) {
|
|
6748
|
+
throw new Error("Json.set requires a piped JSON path or an explicit target");
|
|
6749
|
+
}
|
|
6750
|
+
return json2.set(access2.base, access2.path, next2, options3);
|
|
6751
|
+
};
|
|
6752
|
+
}
|
|
6753
|
+
if ((args.length === 2 || args.length === 3) && isExpression4(args[0]) && !isTarget(args[1])) {
|
|
6754
|
+
const [base2, next2, options3] = args;
|
|
6755
|
+
const access2 = accessPathOf2(base2);
|
|
6756
|
+
if (access2 === undefined) {
|
|
6757
|
+
throw new Error("Json.set requires a piped JSON path or an explicit target");
|
|
6758
|
+
}
|
|
6759
|
+
return json2.set(access2.base, access2.path, next2, options3);
|
|
6760
|
+
}
|
|
6761
|
+
const [base, target, next, options2] = args;
|
|
6762
|
+
return json2.set(base, normalizeTarget(target), next, options2);
|
|
6763
|
+
};
|
|
6764
|
+
var insert2 = (...args) => {
|
|
6765
|
+
if (args.length === 1 || args.length === 2 && !isExpression4(args[0])) {
|
|
6766
|
+
const [next2, options3] = args;
|
|
6767
|
+
return (base2) => {
|
|
6768
|
+
const access2 = accessPathOf2(base2);
|
|
6769
|
+
if (access2 === undefined) {
|
|
6770
|
+
throw new Error("Json.insert requires a piped JSON path or an explicit target");
|
|
6771
|
+
}
|
|
6772
|
+
return json2.insert(access2.base, access2.path, next2, options3);
|
|
6773
|
+
};
|
|
6774
|
+
}
|
|
6775
|
+
if ((args.length === 2 || args.length === 3) && isExpression4(args[0]) && !isTarget(args[1])) {
|
|
6776
|
+
const [base2, next2, options3] = args;
|
|
6777
|
+
const access2 = accessPathOf2(base2);
|
|
6778
|
+
if (access2 === undefined) {
|
|
6779
|
+
throw new Error("Json.insert requires a piped JSON path or an explicit target");
|
|
6780
|
+
}
|
|
6781
|
+
return json2.insert(access2.base, access2.path, next2, options3);
|
|
6782
|
+
}
|
|
6783
|
+
const [base, target, next, options2] = args;
|
|
6784
|
+
return json2.insert(base, normalizeTarget(target), next, options2);
|
|
6785
|
+
};
|
|
6786
|
+
var concat2 = json2.concat;
|
|
6787
|
+
var merge3 = json2.merge;
|
|
6788
|
+
var buildObject = json2.buildObject;
|
|
6789
|
+
var buildArray = json2.buildArray;
|
|
6790
|
+
var toJson = json2.toJson;
|
|
6791
|
+
var toJsonb = json2.toJsonb;
|
|
6792
|
+
var typeOf = json2.typeOf;
|
|
6793
|
+
var length = json2.length;
|
|
6794
|
+
var keys = json2.keys;
|
|
6795
|
+
var pathExists = (...args) => {
|
|
6796
|
+
if (args.length === 1) {
|
|
6797
|
+
const [first] = args;
|
|
6798
|
+
if (isTarget(first) || typeof first === "string") {
|
|
6799
|
+
return (base2) => json2.pathExists(base2, isTarget(first) ? normalizeTargetPath(first) : first);
|
|
6800
|
+
}
|
|
6801
|
+
const access2 = targetOrAccessPath(first);
|
|
6802
|
+
if (access2 === undefined) {
|
|
6803
|
+
throw new Error("Json.pathExists requires a piped JSON path or an explicit query");
|
|
6804
|
+
}
|
|
6805
|
+
return json2.pathExists(access2.base, access2.path);
|
|
6806
|
+
}
|
|
6807
|
+
const [base, query] = args;
|
|
6808
|
+
return json2.pathExists(base, isTarget(query) ? normalizeTargetPath(query) : query);
|
|
6809
|
+
};
|
|
5589
6810
|
// src/internal/executor.ts
|
|
5590
6811
|
var exports_executor = {};
|
|
5591
6812
|
__export(exports_executor, {
|
|
5592
6813
|
withTransaction: () => withTransaction,
|
|
5593
|
-
withSavepoint: () => withSavepoint,
|
|
5594
6814
|
streamFromSqlClient: () => streamFromSqlClient,
|
|
5595
6815
|
remapRows: () => remapRows,
|
|
5596
6816
|
makeRowDecoder: () => makeRowDecoder,
|
|
@@ -5604,9 +6824,10 @@ __export(exports_executor, {
|
|
|
5604
6824
|
});
|
|
5605
6825
|
import * as Chunk from "effect/Chunk";
|
|
5606
6826
|
import * as Effect from "effect/Effect";
|
|
6827
|
+
import * as Exit from "effect/Exit";
|
|
5607
6828
|
import * as Option from "effect/Option";
|
|
5608
6829
|
import * as Schema9 from "effect/Schema";
|
|
5609
|
-
import * as SqlClient from "
|
|
6830
|
+
import * as SqlClient from "effect/unstable/sql/SqlClient";
|
|
5610
6831
|
import * as Stream from "effect/Stream";
|
|
5611
6832
|
|
|
5612
6833
|
// src/internal/runtime/driver-value-mapping.ts
|
|
@@ -5653,9 +6874,9 @@ var mappingCandidates = (context) => {
|
|
|
5653
6874
|
runtimeTag === undefined ? undefined : context.valueMappings?.[runtimeTag]
|
|
5654
6875
|
];
|
|
5655
6876
|
};
|
|
5656
|
-
var findMapping = (context,
|
|
6877
|
+
var findMapping = (context, key3) => {
|
|
5657
6878
|
for (const candidate of mappingCandidates(context)) {
|
|
5658
|
-
const value = candidate?.[
|
|
6879
|
+
const value = candidate?.[key3];
|
|
5659
6880
|
if (value !== undefined) {
|
|
5660
6881
|
return value;
|
|
5661
6882
|
}
|
|
@@ -5783,7 +7004,7 @@ var renderJsonSelectSql = (sql, context) => {
|
|
|
5783
7004
|
import * as Schema8 from "effect/Schema";
|
|
5784
7005
|
import * as SchemaAST from "effect/SchemaAST";
|
|
5785
7006
|
var schemaCache = new WeakMap;
|
|
5786
|
-
var FiniteNumberSchema = Schema8.Number.
|
|
7007
|
+
var FiniteNumberSchema = Schema8.Number.check(Schema8.isFinite());
|
|
5787
7008
|
var runtimeSchemaForTag = (tag) => {
|
|
5788
7009
|
switch (tag) {
|
|
5789
7010
|
case "string":
|
|
@@ -5811,14 +7032,11 @@ var runtimeSchemaForTag = (tag) => {
|
|
|
5811
7032
|
case "decimalString":
|
|
5812
7033
|
return DecimalStringSchema;
|
|
5813
7034
|
case "bytes":
|
|
5814
|
-
return Schema8.
|
|
7035
|
+
return Schema8.Uint8Array;
|
|
5815
7036
|
case "array":
|
|
5816
7037
|
return Schema8.Array(Schema8.Unknown);
|
|
5817
7038
|
case "record":
|
|
5818
|
-
return Schema8.Record(
|
|
5819
|
-
key: Schema8.String,
|
|
5820
|
-
value: Schema8.Unknown
|
|
5821
|
-
});
|
|
7039
|
+
return Schema8.Record(Schema8.String, Schema8.Unknown);
|
|
5822
7040
|
case "null":
|
|
5823
7041
|
return Schema8.Null;
|
|
5824
7042
|
case "unknown":
|
|
@@ -5836,7 +7054,7 @@ var runtimeSchemaForDbType = (dbType) => {
|
|
|
5836
7054
|
return Schema8.Array(runtimeSchemaForDbType(dbType.element) ?? Schema8.Unknown);
|
|
5837
7055
|
}
|
|
5838
7056
|
if ("fields" in dbType) {
|
|
5839
|
-
const fields = Object.fromEntries(Object.entries(dbType.fields).map(([
|
|
7057
|
+
const fields = Object.fromEntries(Object.entries(dbType.fields).map(([key3, field]) => [key3, runtimeSchemaForDbType(field) ?? Schema8.Unknown]));
|
|
5840
7058
|
return Schema8.Struct(fields);
|
|
5841
7059
|
}
|
|
5842
7060
|
if ("variant" in dbType && dbType.variant === "json") {
|
|
@@ -5856,27 +7074,23 @@ var unionAst = (asts) => {
|
|
|
5856
7074
|
if (asts.length === 1) {
|
|
5857
7075
|
return asts[0];
|
|
5858
7076
|
}
|
|
5859
|
-
return SchemaAST.Union
|
|
7077
|
+
return new SchemaAST.Union(asts, "anyOf");
|
|
5860
7078
|
};
|
|
5861
|
-
var propertyAstOf = (ast,
|
|
7079
|
+
var propertyAstOf = (ast, key3) => {
|
|
5862
7080
|
switch (ast._tag) {
|
|
5863
|
-
case "Transformation":
|
|
5864
|
-
return propertyAstOf(SchemaAST.typeAST(ast), key2);
|
|
5865
|
-
case "Refinement":
|
|
5866
|
-
return propertyAstOf(ast.from, key2);
|
|
5867
7081
|
case "Suspend":
|
|
5868
|
-
return propertyAstOf(ast.
|
|
5869
|
-
case "
|
|
5870
|
-
const property = ast.propertySignatures.find((entry) => entry.name ===
|
|
7082
|
+
return propertyAstOf(ast.thunk(), key3);
|
|
7083
|
+
case "Objects": {
|
|
7084
|
+
const property = ast.propertySignatures.find((entry) => entry.name === key3);
|
|
5871
7085
|
if (property !== undefined) {
|
|
5872
7086
|
return property.type;
|
|
5873
7087
|
}
|
|
5874
|
-
const
|
|
5875
|
-
return
|
|
7088
|
+
const index5 = ast.indexSignatures.find((entry) => entry.parameter._tag === "String");
|
|
7089
|
+
return index5?.type;
|
|
5876
7090
|
}
|
|
5877
7091
|
case "Union": {
|
|
5878
7092
|
const values2 = ast.types.flatMap((member) => {
|
|
5879
|
-
const next = propertyAstOf(member,
|
|
7093
|
+
const next = propertyAstOf(member, key3);
|
|
5880
7094
|
return next === undefined ? [] : [next];
|
|
5881
7095
|
});
|
|
5882
7096
|
return unionAst(values2);
|
|
@@ -5885,27 +7099,23 @@ var propertyAstOf = (ast, key2) => {
|
|
|
5885
7099
|
return;
|
|
5886
7100
|
}
|
|
5887
7101
|
};
|
|
5888
|
-
var numberAstOf = (ast,
|
|
7102
|
+
var numberAstOf = (ast, index5) => {
|
|
5889
7103
|
switch (ast._tag) {
|
|
5890
|
-
case "Transformation":
|
|
5891
|
-
return numberAstOf(SchemaAST.typeAST(ast), index4);
|
|
5892
|
-
case "Refinement":
|
|
5893
|
-
return numberAstOf(ast.from, index4);
|
|
5894
7104
|
case "Suspend":
|
|
5895
|
-
return numberAstOf(ast.
|
|
5896
|
-
case "
|
|
5897
|
-
const element = ast.elements[
|
|
7105
|
+
return numberAstOf(ast.thunk(), index5);
|
|
7106
|
+
case "Arrays": {
|
|
7107
|
+
const element = ast.elements[index5];
|
|
5898
7108
|
if (element !== undefined) {
|
|
5899
|
-
return element
|
|
7109
|
+
return element;
|
|
5900
7110
|
}
|
|
5901
7111
|
if (ast.rest.length === 0) {
|
|
5902
7112
|
return;
|
|
5903
7113
|
}
|
|
5904
|
-
return unionAst(ast.rest
|
|
7114
|
+
return unionAst(ast.rest);
|
|
5905
7115
|
}
|
|
5906
7116
|
case "Union": {
|
|
5907
7117
|
const values2 = ast.types.flatMap((member) => {
|
|
5908
|
-
const next = numberAstOf(member,
|
|
7118
|
+
const next = numberAstOf(member, index5);
|
|
5909
7119
|
return next === undefined ? [] : [next];
|
|
5910
7120
|
});
|
|
5911
7121
|
return unionAst(values2);
|
|
@@ -5916,7 +7126,7 @@ var numberAstOf = (ast, index4) => {
|
|
|
5916
7126
|
};
|
|
5917
7127
|
var exactJsonSegments = (segments) => segments.every((segment) => segment.kind === "key" || segment.kind === "index");
|
|
5918
7128
|
var schemaAstAtExactJsonPath = (schema3, segments) => {
|
|
5919
|
-
let current =
|
|
7129
|
+
let current = schema3.ast;
|
|
5920
7130
|
for (const segment of segments) {
|
|
5921
7131
|
if (segment.kind === "key") {
|
|
5922
7132
|
const property = propertyAstOf(current, segment.key);
|
|
@@ -5946,28 +7156,28 @@ var unionSchemas = (schemas) => {
|
|
|
5946
7156
|
if (resolved.length === 1) {
|
|
5947
7157
|
return resolved[0];
|
|
5948
7158
|
}
|
|
5949
|
-
return Schema8.Union(
|
|
7159
|
+
return Schema8.Union(resolved);
|
|
5950
7160
|
};
|
|
5951
7161
|
var firstSelectedExpression = (plan) => {
|
|
5952
7162
|
const selection = getAst(plan).select;
|
|
5953
7163
|
return flattenSelection(selection)[0]?.expression;
|
|
5954
7164
|
};
|
|
5955
7165
|
var isJsonCompatibleAst = (ast) => {
|
|
7166
|
+
ast = SchemaAST.toType(ast);
|
|
5956
7167
|
switch (ast._tag) {
|
|
5957
|
-
case "
|
|
5958
|
-
case "
|
|
5959
|
-
case "
|
|
5960
|
-
case "
|
|
5961
|
-
case "
|
|
7168
|
+
case "String":
|
|
7169
|
+
case "Number":
|
|
7170
|
+
case "Boolean":
|
|
7171
|
+
case "Null":
|
|
7172
|
+
case "Arrays":
|
|
7173
|
+
case "Objects":
|
|
5962
7174
|
return true;
|
|
5963
7175
|
case "Literal":
|
|
5964
|
-
return
|
|
7176
|
+
return typeof ast.literal === "string" || typeof ast.literal === "number" || typeof ast.literal === "boolean";
|
|
5965
7177
|
case "Union":
|
|
5966
7178
|
return ast.types.every(isJsonCompatibleAst);
|
|
5967
|
-
case "Transformation":
|
|
5968
|
-
return isJsonCompatibleAst(SchemaAST.typeAST(ast));
|
|
5969
7179
|
case "Suspend":
|
|
5970
|
-
return isJsonCompatibleAst(ast.
|
|
7180
|
+
return isJsonCompatibleAst(ast.thunk());
|
|
5971
7181
|
default:
|
|
5972
7182
|
return false;
|
|
5973
7183
|
}
|
|
@@ -5976,14 +7186,14 @@ var jsonCompatibleSchema = (schema3) => {
|
|
|
5976
7186
|
if (schema3 === undefined) {
|
|
5977
7187
|
return;
|
|
5978
7188
|
}
|
|
5979
|
-
const ast = SchemaAST.
|
|
7189
|
+
const ast = SchemaAST.toType(schema3.ast);
|
|
5980
7190
|
return isJsonCompatibleAst(ast) ? schema3 : JsonValueSchema;
|
|
5981
7191
|
};
|
|
5982
7192
|
var buildStructSchema = (entries, context) => {
|
|
5983
7193
|
const fields = Object.fromEntries(entries.map((entry) => [entry.key, expressionRuntimeSchema(entry.value, context) ?? JsonValueSchema]));
|
|
5984
7194
|
return Schema8.Struct(fields);
|
|
5985
7195
|
};
|
|
5986
|
-
var buildTupleSchema = (values2, context) => Schema8.Tuple(
|
|
7196
|
+
var buildTupleSchema = (values2, context) => Schema8.Tuple(values2.map((value) => expressionRuntimeSchema(value, context) ?? JsonValueSchema));
|
|
5987
7197
|
var deriveCaseSchema = (ast, context) => {
|
|
5988
7198
|
if (context === undefined) {
|
|
5989
7199
|
return unionSchemas([
|
|
@@ -6138,15 +7348,15 @@ var expressionRuntimeSchema = (expression, context) => {
|
|
|
6138
7348
|
// src/internal/executor.ts
|
|
6139
7349
|
var setPath2 = (target, path2, value) => {
|
|
6140
7350
|
let current = target;
|
|
6141
|
-
for (let
|
|
6142
|
-
const
|
|
6143
|
-
const existing = current[
|
|
7351
|
+
for (let index5 = 0;index5 < path2.length - 1; index5++) {
|
|
7352
|
+
const key3 = path2[index5];
|
|
7353
|
+
const existing = current[key3];
|
|
6144
7354
|
if (typeof existing === "object" && existing !== null && !Array.isArray(existing)) {
|
|
6145
7355
|
current = existing;
|
|
6146
7356
|
continue;
|
|
6147
7357
|
}
|
|
6148
7358
|
const next = {};
|
|
6149
|
-
current[
|
|
7359
|
+
current[key3] = next;
|
|
6150
7360
|
current = next;
|
|
6151
7361
|
}
|
|
6152
7362
|
current[path2[path2.length - 1]] = value;
|
|
@@ -6189,24 +7399,31 @@ var remapRows = (query, rows) => rows.map((row) => {
|
|
|
6189
7399
|
}
|
|
6190
7400
|
return decoded;
|
|
6191
7401
|
});
|
|
6192
|
-
var makeRowDecodeError = (rendered, projection, expression, raw, stage, cause, normalized) =>
|
|
6193
|
-
|
|
6194
|
-
|
|
6195
|
-
|
|
6196
|
-
|
|
6197
|
-
|
|
6198
|
-
|
|
6199
|
-
|
|
6200
|
-
|
|
6201
|
-
|
|
6202
|
-
|
|
6203
|
-
|
|
6204
|
-
|
|
6205
|
-
|
|
6206
|
-
|
|
6207
|
-
|
|
6208
|
-
|
|
6209
|
-
|
|
7402
|
+
var makeRowDecodeError = (rendered, projection, expression, raw, stage, cause, normalized) => {
|
|
7403
|
+
const schemaError = Schema9.isSchemaError(cause) ? {
|
|
7404
|
+
message: cause.message,
|
|
7405
|
+
issue: cause.issue
|
|
7406
|
+
} : undefined;
|
|
7407
|
+
return {
|
|
7408
|
+
_tag: "RowDecodeError",
|
|
7409
|
+
message: stage === "normalize" ? `Failed to normalize projection '${projection.alias}'` : `Failed to decode projection '${projection.alias}' against its runtime schema`,
|
|
7410
|
+
dialect: rendered.dialect,
|
|
7411
|
+
query: {
|
|
7412
|
+
sql: rendered.sql,
|
|
7413
|
+
params: rendered.params
|
|
7414
|
+
},
|
|
7415
|
+
projection: {
|
|
7416
|
+
alias: projection.alias,
|
|
7417
|
+
path: projection.path
|
|
7418
|
+
},
|
|
7419
|
+
dbType: expression[TypeId].dbType,
|
|
7420
|
+
raw,
|
|
7421
|
+
normalized,
|
|
7422
|
+
stage,
|
|
7423
|
+
cause,
|
|
7424
|
+
...schemaError === undefined ? {} : { schemaError }
|
|
7425
|
+
};
|
|
7426
|
+
};
|
|
6210
7427
|
var hasOptionalSourceDependency = (expression, scope) => {
|
|
6211
7428
|
const state = expression[TypeId];
|
|
6212
7429
|
return Object.keys(state.dependencies).some((sourceName) => !scope.absentSourceNames.has(sourceName) && scope.sourceModes.get(sourceName) === "optional");
|
|
@@ -6218,11 +7435,11 @@ var effectiveRuntimeNullability = (expression, scope) => {
|
|
|
6218
7435
|
return "always";
|
|
6219
7436
|
}
|
|
6220
7437
|
if (ast.kind === "column") {
|
|
6221
|
-
const
|
|
6222
|
-
if (scope.absentSourceNames.has(ast.tableName) || scope.nullKeys.has(
|
|
7438
|
+
const key3 = columnPredicateKey(ast.tableName, ast.columnName);
|
|
7439
|
+
if (scope.absentSourceNames.has(ast.tableName) || scope.nullKeys.has(key3)) {
|
|
6223
7440
|
return "always";
|
|
6224
7441
|
}
|
|
6225
|
-
if (scope.nonNullKeys.has(
|
|
7442
|
+
if (scope.nonNullKeys.has(key3)) {
|
|
6226
7443
|
return "never";
|
|
6227
7444
|
}
|
|
6228
7445
|
}
|
|
@@ -6249,8 +7466,8 @@ var decodeProjectionValue = (rendered, projection, expression, raw, scope, drive
|
|
|
6249
7466
|
driverValueMapping: expression[TypeId].driverValueMapping,
|
|
6250
7467
|
valueMappings
|
|
6251
7468
|
});
|
|
6252
|
-
} catch (
|
|
6253
|
-
throw makeRowDecodeError(rendered, projection, expression, raw, "normalize",
|
|
7469
|
+
} catch (cause2) {
|
|
7470
|
+
throw makeRowDecodeError(rendered, projection, expression, raw, "normalize", cause2);
|
|
6254
7471
|
}
|
|
6255
7472
|
}
|
|
6256
7473
|
const nullability = effectiveRuntimeNullability(expression, scope);
|
|
@@ -6276,18 +7493,22 @@ var decodeProjectionValue = (rendered, projection, expression, raw, scope, drive
|
|
|
6276
7493
|
if (Schema9.is(schema3)(normalized)) {
|
|
6277
7494
|
return normalized;
|
|
6278
7495
|
}
|
|
6279
|
-
|
|
6280
|
-
|
|
6281
|
-
|
|
6282
|
-
throw makeRowDecodeError(rendered, projection, expression, raw, "schema", cause, normalized);
|
|
7496
|
+
const decoded = Schema9.decodeUnknownExit(schema3)(normalized);
|
|
7497
|
+
if (Exit.isSuccess(decoded)) {
|
|
7498
|
+
return decoded.value;
|
|
6283
7499
|
}
|
|
7500
|
+
const cause = Option.match(Exit.findErrorOption(decoded), {
|
|
7501
|
+
onNone: () => decoded.cause,
|
|
7502
|
+
onSome: (schemaError) => schemaError
|
|
7503
|
+
});
|
|
7504
|
+
throw makeRowDecodeError(rendered, projection, expression, raw, "schema", cause, normalized);
|
|
6284
7505
|
};
|
|
6285
7506
|
var makeRowDecoder = (rendered, plan, options2 = {}) => {
|
|
6286
7507
|
const projections = flattenSelection(getAst(plan).select);
|
|
6287
7508
|
const byPath = new Map(projections.map((projection) => [JSON.stringify(projection.path), projection.expression]));
|
|
6288
7509
|
const driverMode = options2.driverMode ?? "raw";
|
|
6289
7510
|
const valueMappings = options2.valueMappings ?? rendered.valueMappings;
|
|
6290
|
-
const scope = resolveImplicationScope(plan[
|
|
7511
|
+
const scope = resolveImplicationScope(plan[TypeId4].available, getQueryState(plan).assumptions);
|
|
6291
7512
|
return (row) => {
|
|
6292
7513
|
const decoded = {};
|
|
6293
7514
|
for (const projection of rendered.projections) {
|
|
@@ -6305,7 +7526,7 @@ var makeRowDecoder = (rendered, plan, options2 = {}) => {
|
|
|
6305
7526
|
};
|
|
6306
7527
|
var decodeChunk = (rendered, plan, rows, options2 = {}) => {
|
|
6307
7528
|
const decodeRow = makeRowDecoder(rendered, plan, options2);
|
|
6308
|
-
return Chunk.
|
|
7529
|
+
return Chunk.fromIterable(Chunk.toReadonlyArray(rows).map((row) => decodeRow(row)));
|
|
6309
7530
|
};
|
|
6310
7531
|
var decodeRows = (rendered, plan, rows, options2 = {}) => {
|
|
6311
7532
|
const decodeRow = makeRowDecoder(rendered, plan, options2);
|
|
@@ -6343,12 +7564,12 @@ var fromDriver = (renderer, sqlDriver) => {
|
|
|
6343
7564
|
},
|
|
6344
7565
|
stream(plan) {
|
|
6345
7566
|
const rendered = renderer.render(plan);
|
|
6346
|
-
return Stream.
|
|
7567
|
+
return Stream.mapArray(sqlDriver.stream(rendered), (rows) => remapRows(rendered, rows));
|
|
6347
7568
|
}
|
|
6348
7569
|
};
|
|
6349
7570
|
return executor;
|
|
6350
7571
|
};
|
|
6351
|
-
var streamFromSqlClient = (query) => Stream.
|
|
7572
|
+
var streamFromSqlClient = (query) => Stream.unwrap(Effect.flatMap(SqlClient.SqlClient, (sql) => Effect.flatMap(Effect.serviceOption(sql.transactionService), Option.match({
|
|
6352
7573
|
onNone: () => sql.reserve,
|
|
6353
7574
|
onSome: ([connection]) => Effect.succeed(connection)
|
|
6354
7575
|
})).pipe(Effect.map((connection) => connection.executeStream(query.sql, [...query.params], undefined)))));
|
|
@@ -6357,7 +7578,6 @@ var fromSqlClient = (renderer) => fromDriver(renderer, driver(renderer.dialect,
|
|
|
6357
7578
|
stream: (query) => streamFromSqlClient(query)
|
|
6358
7579
|
}));
|
|
6359
7580
|
var withTransaction = (effect) => Effect.flatMap(SqlClient.SqlClient, (sql) => sql.withTransaction(effect));
|
|
6360
|
-
var withSavepoint = (effect) => Effect.flatMap(SqlClient.SqlClient, (sql) => sql.withTransaction(effect));
|
|
6361
7581
|
// src/standard/table.ts
|
|
6362
7582
|
var exports_table2 = {};
|
|
6363
7583
|
__export(exports_table2, {
|
|
@@ -6369,15 +7589,15 @@ __export(exports_table2, {
|
|
|
6369
7589
|
option: () => option2,
|
|
6370
7590
|
make: () => make4,
|
|
6371
7591
|
insertSchema: () => insertSchema3,
|
|
6372
|
-
index: () =>
|
|
7592
|
+
index: () => index5,
|
|
6373
7593
|
foreignKey: () => foreignKey3,
|
|
6374
|
-
check: () =>
|
|
7594
|
+
check: () => check3,
|
|
6375
7595
|
alias: () => alias2,
|
|
6376
7596
|
TypeId: () => TypeId10,
|
|
6377
7597
|
OptionsSymbol: () => OptionsSymbol2,
|
|
6378
7598
|
Class: () => Class2
|
|
6379
7599
|
});
|
|
6380
|
-
var TypeId10 =
|
|
7600
|
+
var TypeId10 = TypeId7;
|
|
6381
7601
|
var OptionsSymbol2 = OptionsSymbol;
|
|
6382
7602
|
var options2 = options;
|
|
6383
7603
|
var option2 = option;
|
|
@@ -6391,17 +7611,83 @@ var Class2 = (name, schemaName = undefined) => {
|
|
|
6391
7611
|
};
|
|
6392
7612
|
var primaryKey4 = primaryKey3;
|
|
6393
7613
|
var unique4 = unique3;
|
|
6394
|
-
var
|
|
6395
|
-
var foreignKey3 =
|
|
6396
|
-
var
|
|
7614
|
+
var index5 = index3;
|
|
7615
|
+
var foreignKey3 = foreignKey2;
|
|
7616
|
+
var check3 = check2;
|
|
6397
7617
|
var selectSchema3 = selectSchema2;
|
|
6398
7618
|
var insertSchema3 = insertSchema2;
|
|
6399
7619
|
var updateSchema3 = updateSchema2;
|
|
7620
|
+
// src/standard/primary-key.ts
|
|
7621
|
+
var exports_primary_key = {};
|
|
7622
|
+
__export(exports_primary_key, {
|
|
7623
|
+
named: () => named,
|
|
7624
|
+
make: () => make5
|
|
7625
|
+
});
|
|
7626
|
+
var make5 = primaryKey3;
|
|
7627
|
+
var named = (name) => (option3) => mapOption(option3, (spec) => ({
|
|
7628
|
+
...spec,
|
|
7629
|
+
name
|
|
7630
|
+
}));
|
|
7631
|
+
// src/standard/unique.ts
|
|
7632
|
+
var exports_unique = {};
|
|
7633
|
+
__export(exports_unique, {
|
|
7634
|
+
named: () => named2,
|
|
7635
|
+
make: () => make6
|
|
7636
|
+
});
|
|
7637
|
+
var make6 = unique3;
|
|
7638
|
+
var named2 = (name) => (option3) => mapOption(option3, (spec) => ({
|
|
7639
|
+
...spec,
|
|
7640
|
+
name
|
|
7641
|
+
}));
|
|
7642
|
+
// src/standard/index.ts
|
|
7643
|
+
var exports_standard = {};
|
|
7644
|
+
__export(exports_standard, {
|
|
7645
|
+
named: () => named3,
|
|
7646
|
+
make: () => make7
|
|
7647
|
+
});
|
|
7648
|
+
var make7 = index3;
|
|
7649
|
+
var named3 = (name) => (option3) => mapOption(option3, (spec) => ({
|
|
7650
|
+
...spec,
|
|
7651
|
+
name
|
|
7652
|
+
}));
|
|
7653
|
+
// src/standard/foreign-key.ts
|
|
7654
|
+
var exports_foreign_key = {};
|
|
7655
|
+
__export(exports_foreign_key, {
|
|
7656
|
+
onUpdate: () => onUpdate,
|
|
7657
|
+
onDelete: () => onDelete,
|
|
7658
|
+
named: () => named4,
|
|
7659
|
+
make: () => make8
|
|
7660
|
+
});
|
|
7661
|
+
var make8 = foreignKey2;
|
|
7662
|
+
var named4 = (name) => (option3) => mapOption(option3, (spec) => ({
|
|
7663
|
+
...spec,
|
|
7664
|
+
name
|
|
7665
|
+
}));
|
|
7666
|
+
var onDelete = (action) => (option3) => mapOption(option3, (spec) => ({
|
|
7667
|
+
...spec,
|
|
7668
|
+
onDelete: action
|
|
7669
|
+
}));
|
|
7670
|
+
var onUpdate = (action) => (option3) => mapOption(option3, (spec) => ({
|
|
7671
|
+
...spec,
|
|
7672
|
+
onUpdate: action
|
|
7673
|
+
}));
|
|
7674
|
+
// src/standard/check.ts
|
|
7675
|
+
var exports_check = {};
|
|
7676
|
+
__export(exports_check, {
|
|
7677
|
+
named: () => named5,
|
|
7678
|
+
make: () => make9
|
|
7679
|
+
});
|
|
7680
|
+
var make9 = check2;
|
|
7681
|
+
var named5 = (name) => (option3) => mapOption(option3, (spec) => ({
|
|
7682
|
+
...spec,
|
|
7683
|
+
name
|
|
7684
|
+
}));
|
|
6400
7685
|
// src/standard/renderer.ts
|
|
6401
7686
|
var exports_renderer = {};
|
|
6402
7687
|
__export(exports_renderer, {
|
|
6403
|
-
make: () =>
|
|
7688
|
+
make: () => make10
|
|
6404
7689
|
});
|
|
7690
|
+
import { pipeArguments as pipeArguments8 } from "effect/Pipeable";
|
|
6405
7691
|
|
|
6406
7692
|
// src/internal/renderer.ts
|
|
6407
7693
|
var TypeId11 = Symbol.for("effect-qb/Renderer");
|
|
@@ -6473,14 +7759,15 @@ var renderDbTypeName = (value) => value;
|
|
|
6473
7759
|
// src/internal/dialect-renderers/postgres.ts
|
|
6474
7760
|
import * as Schema10 from "effect/Schema";
|
|
6475
7761
|
var renderDbType = (dialect, dbType) => {
|
|
6476
|
-
|
|
6477
|
-
return "bytea";
|
|
6478
|
-
}
|
|
6479
|
-
return renderDbTypeName(dbType.kind);
|
|
7762
|
+
return renderDbTypeName(renderPortableDatatypeDdlType(dialect.name, dbType.kind) ?? dbType.kind);
|
|
6480
7763
|
};
|
|
6481
7764
|
var isArrayDbType = (dbType) => ("element" in dbType);
|
|
6482
7765
|
var renderCastType = (dialect, dbType) => {
|
|
6483
7766
|
const kind = dbType?.kind;
|
|
7767
|
+
const portableType = renderPortableDatatypeCastType(dialect.name, kind);
|
|
7768
|
+
if (portableType !== undefined) {
|
|
7769
|
+
return renderDbTypeName(portableType);
|
|
7770
|
+
}
|
|
6484
7771
|
if (dialect.name !== "mysql") {
|
|
6485
7772
|
return renderDbTypeName(kind);
|
|
6486
7773
|
}
|
|
@@ -6502,13 +7789,13 @@ var renderCastType = (dialect, dbType) => {
|
|
|
6502
7789
|
return renderDbTypeName(kind);
|
|
6503
7790
|
}
|
|
6504
7791
|
};
|
|
6505
|
-
var casingForTable = (table, state) => merge(state.casing, table[
|
|
7792
|
+
var casingForTable = (table, state) => merge(state.casing, table[TypeId7].casing);
|
|
6506
7793
|
var casedTableName = (table, state) => {
|
|
6507
|
-
const tableState = table[
|
|
7794
|
+
const tableState = table[TypeId7];
|
|
6508
7795
|
return applyCategory(casingForTable(table, state), "tables", tableState.baseName);
|
|
6509
7796
|
};
|
|
6510
7797
|
var casedSchemaName = (table, state) => {
|
|
6511
|
-
const schemaName = table[
|
|
7798
|
+
const schemaName = table[TypeId7].schemaName;
|
|
6512
7799
|
return schemaName === undefined ? undefined : applyCategory(casingForTable(table, state), "schemas", schemaName);
|
|
6513
7800
|
};
|
|
6514
7801
|
var casedColumnName = (columnName, state, tableName) => {
|
|
@@ -6522,7 +7809,7 @@ var casedColumnName = (columnName, state, tableName) => {
|
|
|
6522
7809
|
};
|
|
6523
7810
|
var casedTableReferenceName = (tableName, state) => state.sourceNames?.get(tableName)?.tableName ?? applyCategory(state.casing, "tables", tableName);
|
|
6524
7811
|
var quoteColumn = (columnName, state, dialect, tableName) => dialect.quoteIdentifier(casedColumnName(columnName, state, tableName));
|
|
6525
|
-
var stateWithTableCasing = (state, source) => typeof source === "object" && source !== null && (
|
|
7812
|
+
var stateWithTableCasing = (state, source) => typeof source === "object" && source !== null && (TypeId7 in source) ? { ...state, casing: casingForTable(source, state) } : state;
|
|
6526
7813
|
var referenceCasing = (reference, state) => merge(state.casing, reference.casing);
|
|
6527
7814
|
var renderReferenceTable = (reference, state, dialect) => {
|
|
6528
7815
|
const casing = referenceCasing(reference, state);
|
|
@@ -6535,9 +7822,9 @@ var registerSourceReference = (source, tableName, state) => {
|
|
|
6535
7822
|
if (typeof source !== "object" || source === null) {
|
|
6536
7823
|
return;
|
|
6537
7824
|
}
|
|
6538
|
-
if (
|
|
7825
|
+
if (TypeId7 in source) {
|
|
6539
7826
|
const table = source;
|
|
6540
|
-
const tableState = table[
|
|
7827
|
+
const tableState = table[TypeId7];
|
|
6541
7828
|
const casing = casingForTable(table, state);
|
|
6542
7829
|
const renderedTableName = tableState.kind === "alias" ? tableName : applyCategory(casing, "tables", tableState.baseName);
|
|
6543
7830
|
const columns = new Map(Object.keys(tableState.fields).map((columnName) => [
|
|
@@ -6651,11 +7938,11 @@ var renderCreateTableSql = (targetSource, state, dialect, ifNotExists) => {
|
|
|
6651
7938
|
}
|
|
6652
7939
|
const table = targetSource.source;
|
|
6653
7940
|
const tableCasing = casingForTable(table, state);
|
|
6654
|
-
const fields = table[
|
|
7941
|
+
const fields = table[TypeId7].fields;
|
|
6655
7942
|
const definitions = Object.entries(fields).map(([columnName, column2]) => renderColumnDefinition(dialect, state, columnName, column2, targetSource.tableName, tableCasing));
|
|
6656
7943
|
const options3 = table[OptionsSymbol];
|
|
6657
7944
|
const tableOptions = Array.isArray(options3) ? options3 : [options3];
|
|
6658
|
-
validateOptions(table[
|
|
7945
|
+
validateOptions(table[TypeId7].name, fields, tableOptions);
|
|
6659
7946
|
for (const option3 of tableOptions) {
|
|
6660
7947
|
if (typeof option3 !== "object" || option3 === null || !("kind" in option3)) {
|
|
6661
7948
|
continue;
|
|
@@ -6714,8 +8001,8 @@ var renderDropIndexSql = (targetSource, ddl, state, dialect) => {
|
|
|
6714
8001
|
throw new Error(`Unsupported ${dialect.name} drop index options`);
|
|
6715
8002
|
}
|
|
6716
8003
|
if (dialect.name === "postgres") {
|
|
6717
|
-
const table2 = typeof targetSource.source === "object" && targetSource.source !== null &&
|
|
6718
|
-
const schemaName = table2?.[
|
|
8004
|
+
const table2 = typeof targetSource.source === "object" && targetSource.source !== null && TypeId7 in targetSource.source ? targetSource.source : undefined;
|
|
8005
|
+
const schemaName = table2?.[TypeId7].schemaName;
|
|
6719
8006
|
const tableCasing2 = table2 === undefined ? state.casing : casingForTable(table2, state);
|
|
6720
8007
|
const renderedSchemaName = table2 === undefined ? schemaName : casedSchemaName(table2, state);
|
|
6721
8008
|
const renderedIndexName = applyCategory(tableCasing2, "indexes", name);
|
|
@@ -6726,7 +8013,7 @@ var renderDropIndexSql = (targetSource, ddl, state, dialect) => {
|
|
|
6726
8013
|
const tableCasing = casingForTable(table, state);
|
|
6727
8014
|
return `drop index ${dialect.quoteIdentifier(applyCategory(tableCasing, "indexes", name))} on ${renderSourceReference(targetSource.source, targetSource.tableName, targetSource.baseTableName, state, dialect)}`;
|
|
6728
8015
|
};
|
|
6729
|
-
var
|
|
8016
|
+
var isExpression5 = (value) => value !== null && typeof value === "object" && (TypeId in value);
|
|
6730
8017
|
var isJsonDbType2 = (dbType) => {
|
|
6731
8018
|
if (dbType.kind === "jsonb" || dbType.kind === "json") {
|
|
6732
8019
|
return true;
|
|
@@ -6737,7 +8024,7 @@ var isJsonDbType2 = (dbType) => {
|
|
|
6737
8024
|
const variant = dbType.variant;
|
|
6738
8025
|
return variant === "json" || variant === "jsonb";
|
|
6739
8026
|
};
|
|
6740
|
-
var
|
|
8027
|
+
var isJsonExpression2 = (value) => isExpression5(value) && isJsonDbType2(value[TypeId].dbType);
|
|
6741
8028
|
var expectValueExpression = (_functionName, value) => value;
|
|
6742
8029
|
var expectBinaryExpressions = (_functionName, left, right) => [left, right];
|
|
6743
8030
|
var renderBinaryExpression = (functionName, operator, left, right, state, dialect) => {
|
|
@@ -6784,7 +8071,7 @@ var unsupportedJsonFeature = (dialect, feature) => {
|
|
|
6784
8071
|
throw error;
|
|
6785
8072
|
};
|
|
6786
8073
|
var extractJsonBase = (node) => node.value ?? node.base ?? node.input ?? node.left ?? node.target;
|
|
6787
|
-
var isJsonPathValue2 = (value) => value !== null && typeof value === "object" && (
|
|
8074
|
+
var isJsonPathValue2 = (value) => value !== null && typeof value === "object" && (TypeId3 in value);
|
|
6788
8075
|
var isOptionalJsonPathNumber = (value) => value === undefined || typeof value === "number" && Number.isFinite(value);
|
|
6789
8076
|
var isJsonPathSegment = (segment) => {
|
|
6790
8077
|
if (typeof segment === "string") {
|
|
@@ -6800,8 +8087,8 @@ var isJsonPathSegment = (segment) => {
|
|
|
6800
8087
|
case "key":
|
|
6801
8088
|
return typeof segment.key === "string";
|
|
6802
8089
|
case "index": {
|
|
6803
|
-
const
|
|
6804
|
-
return typeof
|
|
8090
|
+
const index6 = segment.index;
|
|
8091
|
+
return typeof index6 === "number" && Number.isFinite(index6);
|
|
6805
8092
|
}
|
|
6806
8093
|
case "wildcard":
|
|
6807
8094
|
case "descend":
|
|
@@ -6841,7 +8128,7 @@ var extractJsonPathSegments = (node) => {
|
|
|
6841
8128
|
return [key(segment)];
|
|
6842
8129
|
}
|
|
6843
8130
|
if (typeof segment === "number") {
|
|
6844
|
-
return [
|
|
8131
|
+
return [index(segment)];
|
|
6845
8132
|
}
|
|
6846
8133
|
if (segment !== null && typeof segment === "object" && SegmentTypeId in segment) {
|
|
6847
8134
|
return [segment];
|
|
@@ -6914,7 +8201,7 @@ var renderPostgresJsonAccessStep = (segment, textMode, state, dialect) => {
|
|
|
6914
8201
|
}
|
|
6915
8202
|
};
|
|
6916
8203
|
var renderPostgresJsonValue = (value, state, dialect) => {
|
|
6917
|
-
if (!
|
|
8204
|
+
if (!isExpression5(value)) {
|
|
6918
8205
|
throw new Error("Expected a JSON expression");
|
|
6919
8206
|
}
|
|
6920
8207
|
const rendered = renderExpression2(value, state, dialect);
|
|
@@ -6958,7 +8245,7 @@ var renderJsonOpaquePath = (value, state, dialect) => {
|
|
|
6958
8245
|
}
|
|
6959
8246
|
return dialect.renderLiteral(value, state);
|
|
6960
8247
|
}
|
|
6961
|
-
if (
|
|
8248
|
+
if (isExpression5(value)) {
|
|
6962
8249
|
const ast = value[TypeId2];
|
|
6963
8250
|
if (ast.kind === "literal" && typeof ast.value === "string" && ast.value.trim().length === 0) {
|
|
6964
8251
|
throw new Error("SQL/JSON path input must be a non-empty string");
|
|
@@ -7008,8 +8295,8 @@ var renderJsonExpression = (expression, ast, state, dialect) => {
|
|
|
7008
8295
|
const base = extractJsonBase(ast);
|
|
7009
8296
|
const segments = extractJsonPathSegments(ast);
|
|
7010
8297
|
const exact = segments.every((segment) => segment.kind === "key" || segment.kind === "index");
|
|
7011
|
-
const postgresExpressionKind = dialect.name === "postgres" &&
|
|
7012
|
-
const postgresBaseKind = dialect.name === "postgres" &&
|
|
8298
|
+
const postgresExpressionKind = dialect.name === "postgres" && isJsonExpression2(expression) ? renderPostgresJsonKind(expression) : undefined;
|
|
8299
|
+
const postgresBaseKind = dialect.name === "postgres" && isJsonExpression2(base) ? renderPostgresJsonKind(base) : undefined;
|
|
7013
8300
|
switch (kind) {
|
|
7014
8301
|
case "jsonGet":
|
|
7015
8302
|
case "jsonPath":
|
|
@@ -7019,7 +8306,7 @@ var renderJsonExpression = (expression, ast, state, dialect) => {
|
|
|
7019
8306
|
case "jsonPathText":
|
|
7020
8307
|
case "jsonAccessText":
|
|
7021
8308
|
case "jsonTraverseText": {
|
|
7022
|
-
if (!
|
|
8309
|
+
if (!isExpression5(base) || segments.length === 0) {
|
|
7023
8310
|
return;
|
|
7024
8311
|
}
|
|
7025
8312
|
const baseSql = renderExpression2(base, state, dialect);
|
|
@@ -7042,24 +8329,24 @@ var renderJsonExpression = (expression, ast, state, dialect) => {
|
|
|
7042
8329
|
case "jsonKeyExists":
|
|
7043
8330
|
case "jsonHasAnyKeys":
|
|
7044
8331
|
case "jsonHasAllKeys": {
|
|
7045
|
-
if (!
|
|
8332
|
+
if (!isExpression5(base)) {
|
|
7046
8333
|
return;
|
|
7047
8334
|
}
|
|
7048
8335
|
const baseSql = dialect.name === "postgres" ? renderPostgresJsonValue(base, state, dialect) : renderExpression2(base, state, dialect);
|
|
7049
|
-
const
|
|
7050
|
-
if (
|
|
8336
|
+
const keys2 = extractJsonKeys(ast, segments);
|
|
8337
|
+
if (keys2.length === 0) {
|
|
7051
8338
|
return;
|
|
7052
8339
|
}
|
|
7053
|
-
if (
|
|
8340
|
+
if (keys2.some((key3) => typeof key3 !== "string" || key3.length === 0)) {
|
|
7054
8341
|
throw new Error("json key predicates require string keys");
|
|
7055
8342
|
}
|
|
7056
|
-
const keyNames =
|
|
8343
|
+
const keyNames = keys2;
|
|
7057
8344
|
if (dialect.name === "postgres") {
|
|
7058
8345
|
if (kind === "jsonHasAnyKeys") {
|
|
7059
|
-
return `(${baseSql} ?| array[${keyNames.map((
|
|
8346
|
+
return `(${baseSql} ?| array[${keyNames.map((key3) => renderPostgresTextLiteral(key3, state, dialect)).join(", ")}])`;
|
|
7060
8347
|
}
|
|
7061
8348
|
if (kind === "jsonHasAllKeys") {
|
|
7062
|
-
return `(${baseSql} ?& array[${keyNames.map((
|
|
8349
|
+
return `(${baseSql} ?& array[${keyNames.map((key3) => renderPostgresTextLiteral(key3, state, dialect)).join(", ")}])`;
|
|
7063
8350
|
}
|
|
7064
8351
|
return `(${baseSql} ? ${renderPostgresTextLiteral(keyNames[0], state, dialect)})`;
|
|
7065
8352
|
}
|
|
@@ -7072,7 +8359,7 @@ var renderJsonExpression = (expression, ast, state, dialect) => {
|
|
|
7072
8359
|
}
|
|
7073
8360
|
case "jsonConcat":
|
|
7074
8361
|
case "jsonMerge": {
|
|
7075
|
-
if (!
|
|
8362
|
+
if (!isExpression5(ast.left) || !isExpression5(ast.right)) {
|
|
7076
8363
|
return;
|
|
7077
8364
|
}
|
|
7078
8365
|
if (dialect.name === "postgres") {
|
|
@@ -7109,7 +8396,7 @@ var renderJsonExpression = (expression, ast, state, dialect) => {
|
|
|
7109
8396
|
return;
|
|
7110
8397
|
}
|
|
7111
8398
|
case "jsonToJson":
|
|
7112
|
-
if (!
|
|
8399
|
+
if (!isExpression5(base)) {
|
|
7113
8400
|
return;
|
|
7114
8401
|
}
|
|
7115
8402
|
if (dialect.name === "postgres") {
|
|
@@ -7120,7 +8407,7 @@ var renderJsonExpression = (expression, ast, state, dialect) => {
|
|
|
7120
8407
|
}
|
|
7121
8408
|
return;
|
|
7122
8409
|
case "jsonToJsonb":
|
|
7123
|
-
if (!
|
|
8410
|
+
if (!isExpression5(base)) {
|
|
7124
8411
|
return;
|
|
7125
8412
|
}
|
|
7126
8413
|
if (dialect.name === "postgres") {
|
|
@@ -7131,7 +8418,7 @@ var renderJsonExpression = (expression, ast, state, dialect) => {
|
|
|
7131
8418
|
}
|
|
7132
8419
|
return;
|
|
7133
8420
|
case "jsonTypeOf":
|
|
7134
|
-
if (!
|
|
8421
|
+
if (!isExpression5(base)) {
|
|
7135
8422
|
return;
|
|
7136
8423
|
}
|
|
7137
8424
|
if (dialect.name === "postgres") {
|
|
@@ -7143,36 +8430,36 @@ var renderJsonExpression = (expression, ast, state, dialect) => {
|
|
|
7143
8430
|
}
|
|
7144
8431
|
return;
|
|
7145
8432
|
case "jsonLength":
|
|
7146
|
-
if (!
|
|
8433
|
+
if (!isExpression5(base)) {
|
|
7147
8434
|
return;
|
|
7148
8435
|
}
|
|
7149
8436
|
if (dialect.name === "postgres") {
|
|
7150
8437
|
const baseSql = renderExpression2(base, state, dialect);
|
|
7151
|
-
const
|
|
8438
|
+
const typeOf2 = `${postgresBaseKind === "jsonb" ? "jsonb" : "json"}_typeof`;
|
|
7152
8439
|
const arrayLength = `${postgresBaseKind === "jsonb" ? "jsonb" : "json"}_array_length`;
|
|
7153
8440
|
const objectKeys = `${postgresBaseKind === "jsonb" ? "jsonb" : "json"}_object_keys`;
|
|
7154
|
-
return `(case when ${
|
|
8441
|
+
return `(case when ${typeOf2}(${baseSql}) = 'array' then ${arrayLength}(${baseSql}) when ${typeOf2}(${baseSql}) = 'object' then (select count(*)::int from ${objectKeys}(${baseSql})) else null end)`;
|
|
7155
8442
|
}
|
|
7156
8443
|
if (dialect.name === "mysql") {
|
|
7157
8444
|
return `json_length(${renderExpression2(base, state, dialect)})`;
|
|
7158
8445
|
}
|
|
7159
8446
|
return;
|
|
7160
8447
|
case "jsonKeys":
|
|
7161
|
-
if (!
|
|
8448
|
+
if (!isExpression5(base)) {
|
|
7162
8449
|
return;
|
|
7163
8450
|
}
|
|
7164
8451
|
if (dialect.name === "postgres") {
|
|
7165
8452
|
const baseSql = renderExpression2(base, state, dialect);
|
|
7166
|
-
const
|
|
8453
|
+
const typeOf2 = `${postgresBaseKind === "jsonb" ? "jsonb" : "json"}_typeof`;
|
|
7167
8454
|
const objectKeys = `${postgresBaseKind === "jsonb" ? "jsonb" : "json"}_object_keys`;
|
|
7168
|
-
return `(case when ${
|
|
8455
|
+
return `(case when ${typeOf2}(${baseSql}) = 'object' then to_json(array(select ${objectKeys}(${baseSql}))) else null end)`;
|
|
7169
8456
|
}
|
|
7170
8457
|
if (dialect.name === "mysql") {
|
|
7171
8458
|
return `json_keys(${renderExpression2(base, state, dialect)})`;
|
|
7172
8459
|
}
|
|
7173
8460
|
return;
|
|
7174
8461
|
case "jsonStripNulls":
|
|
7175
|
-
if (!
|
|
8462
|
+
if (!isExpression5(base)) {
|
|
7176
8463
|
return;
|
|
7177
8464
|
}
|
|
7178
8465
|
if (dialect.name === "postgres") {
|
|
@@ -7183,7 +8470,7 @@ var renderJsonExpression = (expression, ast, state, dialect) => {
|
|
|
7183
8470
|
case "jsonDelete":
|
|
7184
8471
|
case "jsonDeletePath":
|
|
7185
8472
|
case "jsonRemove": {
|
|
7186
|
-
if (!
|
|
8473
|
+
if (!isExpression5(base) || segments.length === 0) {
|
|
7187
8474
|
return;
|
|
7188
8475
|
}
|
|
7189
8476
|
if (dialect.name === "postgres") {
|
|
@@ -7201,11 +8488,11 @@ var renderJsonExpression = (expression, ast, state, dialect) => {
|
|
|
7201
8488
|
}
|
|
7202
8489
|
case "jsonSet":
|
|
7203
8490
|
case "jsonInsert": {
|
|
7204
|
-
if (!
|
|
8491
|
+
if (!isExpression5(base) || segments.length === 0) {
|
|
7205
8492
|
return;
|
|
7206
8493
|
}
|
|
7207
8494
|
const nextValue = extractJsonValue(ast);
|
|
7208
|
-
if (!
|
|
8495
|
+
if (!isExpression5(nextValue)) {
|
|
7209
8496
|
return;
|
|
7210
8497
|
}
|
|
7211
8498
|
const createMissing = ast.createMissing === true;
|
|
@@ -7222,7 +8509,7 @@ var renderJsonExpression = (expression, ast, state, dialect) => {
|
|
|
7222
8509
|
return;
|
|
7223
8510
|
}
|
|
7224
8511
|
case "jsonPathExists": {
|
|
7225
|
-
if (!
|
|
8512
|
+
if (!isExpression5(base)) {
|
|
7226
8513
|
return;
|
|
7227
8514
|
}
|
|
7228
8515
|
const path2 = ast.path ?? ast.query ?? ast.right;
|
|
@@ -7238,7 +8525,7 @@ var renderJsonExpression = (expression, ast, state, dialect) => {
|
|
|
7238
8525
|
return;
|
|
7239
8526
|
}
|
|
7240
8527
|
case "jsonPathMatch": {
|
|
7241
|
-
if (!
|
|
8528
|
+
if (!isExpression5(base)) {
|
|
7242
8529
|
return;
|
|
7243
8530
|
}
|
|
7244
8531
|
const path2 = ast.path ?? ast.query ?? ast.right;
|
|
@@ -7335,9 +8622,9 @@ var validateDistinctOnOrdering = (distinctOn2, orderBy2) => {
|
|
|
7335
8622
|
}
|
|
7336
8623
|
const remainingDistinctKeys = new Set(distinctOn2.map(groupingKeyOfExpression));
|
|
7337
8624
|
for (const order of orderBy2) {
|
|
7338
|
-
const
|
|
7339
|
-
if (remainingDistinctKeys.has(
|
|
7340
|
-
remainingDistinctKeys.delete(
|
|
8625
|
+
const key3 = groupingKeyOfExpression(order.value);
|
|
8626
|
+
if (remainingDistinctKeys.has(key3)) {
|
|
8627
|
+
remainingDistinctKeys.delete(key3);
|
|
7341
8628
|
continue;
|
|
7342
8629
|
}
|
|
7343
8630
|
if (remainingDistinctKeys.size > 0) {
|
|
@@ -7432,12 +8719,12 @@ var renderQueryAst2 = (ast, state, dialect, options3 = {}) => {
|
|
|
7432
8719
|
const columns = insertSource.columns.map((column2) => quoteColumn(column2, state, dialect, targetSource.tableName)).join(", ");
|
|
7433
8720
|
if (dialect.name === "postgres") {
|
|
7434
8721
|
const table = targetSource.source;
|
|
7435
|
-
const fields = table[
|
|
8722
|
+
const fields = table[TypeId7].fields;
|
|
7436
8723
|
const rendered = insertSource.values.map((entry) => `cast(${dialect.renderLiteral(encodeArrayValues(entry.values, fields[entry.columnName], state, dialect), state)} as ${renderCastType(dialect, fields[entry.columnName].metadata.dbType)}[])`).join(", ");
|
|
7437
8724
|
sql += ` (${columns}) select * from unnest(${rendered})`;
|
|
7438
8725
|
} else {
|
|
7439
8726
|
const rowCount = insertSource.values[0]?.values.length ?? 0;
|
|
7440
|
-
const rows = Array.from({ length: rowCount }, (_,
|
|
8727
|
+
const rows = Array.from({ length: rowCount }, (_, index6) => `(${insertSource.values.map((entry) => dialect.renderLiteral(entry.values[index6], state, targetSource.source[TypeId7].fields[entry.columnName][TypeId])).join(", ")})`).join(", ");
|
|
7441
8728
|
sql += ` (${columns}) values ${rows}`;
|
|
7442
8729
|
}
|
|
7443
8730
|
} else {
|
|
@@ -7591,27 +8878,27 @@ var renderQueryAst2 = (ast, state, dialect, options3 = {}) => {
|
|
|
7591
8878
|
const mergeAst = ast;
|
|
7592
8879
|
const targetSource = mergeAst.target;
|
|
7593
8880
|
const usingSource = mergeAst.using;
|
|
7594
|
-
const
|
|
7595
|
-
sql = `merge into ${renderSourceReference(targetSource.source, targetSource.tableName, targetSource.baseTableName, state, dialect)} using ${renderSourceReference(usingSource.source, usingSource.tableName, usingSource.baseTableName, state, dialect)} on ${renderExpression2(
|
|
7596
|
-
if (
|
|
7597
|
-
const matchedKind =
|
|
8881
|
+
const merge4 = mergeAst.merge;
|
|
8882
|
+
sql = `merge into ${renderSourceReference(targetSource.source, targetSource.tableName, targetSource.baseTableName, state, dialect)} using ${renderSourceReference(usingSource.source, usingSource.tableName, usingSource.baseTableName, state, dialect)} on ${renderExpression2(merge4.on, state, dialect)}`;
|
|
8883
|
+
if (merge4.whenMatched) {
|
|
8884
|
+
const matchedKind = merge4.whenMatched.kind === "delete" ? "delete" : "update";
|
|
7598
8885
|
sql += " when matched";
|
|
7599
|
-
if (
|
|
7600
|
-
sql += ` and ${renderExpression2(
|
|
8886
|
+
if (merge4.whenMatched.predicate) {
|
|
8887
|
+
sql += ` and ${renderExpression2(merge4.whenMatched.predicate, state, dialect)}`;
|
|
7601
8888
|
}
|
|
7602
8889
|
if (matchedKind === "delete") {
|
|
7603
8890
|
sql += " then delete";
|
|
7604
8891
|
} else {
|
|
7605
|
-
const matchedUpdate =
|
|
8892
|
+
const matchedUpdate = merge4.whenMatched;
|
|
7606
8893
|
sql += ` then update set ${matchedUpdate.values.map((entry) => `${quoteColumn(entry.columnName, state, dialect, targetSource.tableName)} = ${renderExpression2(entry.value, state, dialect)}`).join(", ")}`;
|
|
7607
8894
|
}
|
|
7608
8895
|
}
|
|
7609
|
-
if (
|
|
8896
|
+
if (merge4.whenNotMatched) {
|
|
7610
8897
|
sql += " when not matched";
|
|
7611
|
-
if (
|
|
7612
|
-
sql += ` and ${renderExpression2(
|
|
8898
|
+
if (merge4.whenNotMatched.predicate) {
|
|
8899
|
+
sql += ` and ${renderExpression2(merge4.whenNotMatched.predicate, state, dialect)}`;
|
|
7613
8900
|
}
|
|
7614
|
-
sql += ` then insert (${
|
|
8901
|
+
sql += ` then insert (${merge4.whenNotMatched.values.map((entry) => quoteColumn(entry.columnName, state, dialect, targetSource.tableName)).join(", ")}) values (${merge4.whenNotMatched.values.map((entry) => renderExpression2(entry.value, state, dialect)).join(", ")})`;
|
|
7615
8902
|
}
|
|
7616
8903
|
break;
|
|
7617
8904
|
}
|
|
@@ -7675,7 +8962,7 @@ var renderSourceReference = (source, tableName, baseTableName, state, dialect) =
|
|
|
7675
8962
|
};
|
|
7676
8963
|
const renderUnnestRows = (arrays, columnNames) => {
|
|
7677
8964
|
const rowCount = arrays[columnNames[0]].length;
|
|
7678
|
-
const rows = Array.from({ length: rowCount }, (_,
|
|
8965
|
+
const rows = Array.from({ length: rowCount }, (_, index6) => Object.fromEntries(columnNames.map((columnName) => [columnName, arrays[columnName][index6]])));
|
|
7679
8966
|
return renderSelectRows(rows, columnNames);
|
|
7680
8967
|
};
|
|
7681
8968
|
if (typeof source === "object" && source !== null && "kind" in source && source.kind === "cte") {
|
|
@@ -7725,11 +9012,11 @@ var renderSourceReference = (source, tableName, baseTableName, state, dialect) =
|
|
|
7725
9012
|
const columnNames = Object.keys(tableFunction.columns);
|
|
7726
9013
|
return `${functionName}(${tableFunction.args.map((arg) => renderExpression2(arg, state, dialect)).join(", ")}) as ${dialect.quoteIdentifier(tableFunction.name)}(${columnNames.map((columnName) => dialect.quoteIdentifier(columnName)).join(", ")})`;
|
|
7727
9014
|
}
|
|
7728
|
-
const schemaName = typeof source === "object" && source !== null &&
|
|
7729
|
-
if (typeof source === "object" && source !== null &&
|
|
9015
|
+
const schemaName = typeof source === "object" && source !== null && TypeId7 in source ? casedSchemaName(source, state) : undefined;
|
|
9016
|
+
if (typeof source === "object" && source !== null && TypeId7 in source) {
|
|
7730
9017
|
const table = source;
|
|
7731
9018
|
const renderedBaseName = casedTableName(table, state);
|
|
7732
|
-
const renderedTableName = table[
|
|
9019
|
+
const renderedTableName = table[TypeId7].kind === "alias" ? tableName : renderedBaseName;
|
|
7733
9020
|
return dialect.renderTableReference(renderedTableName, renderedBaseName, schemaName);
|
|
7734
9021
|
}
|
|
7735
9022
|
return dialect.renderTableReference(applyCategory(state.casing, "tables", tableName), applyCategory(state.casing, "tables", baseTableName), schemaName);
|
|
@@ -7836,11 +9123,11 @@ var renderExpression2 = (expression, state, dialect) => {
|
|
|
7836
9123
|
const [leftExpression, rightExpression] = expectBinaryExpressions("contains", ast.left, ast.right);
|
|
7837
9124
|
if (dialect.name === "postgres") {
|
|
7838
9125
|
assertCompatiblePostgresRangeOperands(leftExpression, rightExpression);
|
|
7839
|
-
const left =
|
|
7840
|
-
const right =
|
|
9126
|
+
const left = isJsonExpression2(leftExpression) ? renderPostgresJsonValue(leftExpression, state, dialect) : renderExpression2(leftExpression, state, dialect);
|
|
9127
|
+
const right = isJsonExpression2(rightExpression) ? renderPostgresJsonValue(rightExpression, state, dialect) : renderExpression2(rightExpression, state, dialect);
|
|
7841
9128
|
return `(${left} @> ${right})`;
|
|
7842
9129
|
}
|
|
7843
|
-
if (dialect.name === "mysql" &&
|
|
9130
|
+
if (dialect.name === "mysql" && isJsonExpression2(leftExpression) && isJsonExpression2(rightExpression)) {
|
|
7844
9131
|
return `json_contains(${renderExpression2(leftExpression, state, dialect)}, ${renderExpression2(rightExpression, state, dialect)})`;
|
|
7845
9132
|
}
|
|
7846
9133
|
throw new Error("Unsupported container operator for SQL rendering");
|
|
@@ -7849,11 +9136,11 @@ var renderExpression2 = (expression, state, dialect) => {
|
|
|
7849
9136
|
const [leftExpression, rightExpression] = expectBinaryExpressions("containedBy", ast.left, ast.right);
|
|
7850
9137
|
if (dialect.name === "postgres") {
|
|
7851
9138
|
assertCompatiblePostgresRangeOperands(leftExpression, rightExpression);
|
|
7852
|
-
const left =
|
|
7853
|
-
const right =
|
|
9139
|
+
const left = isJsonExpression2(leftExpression) ? renderPostgresJsonValue(leftExpression, state, dialect) : renderExpression2(leftExpression, state, dialect);
|
|
9140
|
+
const right = isJsonExpression2(rightExpression) ? renderPostgresJsonValue(rightExpression, state, dialect) : renderExpression2(rightExpression, state, dialect);
|
|
7854
9141
|
return `(${left} <@ ${right})`;
|
|
7855
9142
|
}
|
|
7856
|
-
if (dialect.name === "mysql" &&
|
|
9143
|
+
if (dialect.name === "mysql" && isJsonExpression2(leftExpression) && isJsonExpression2(rightExpression)) {
|
|
7857
9144
|
return `json_contains(${renderExpression2(rightExpression, state, dialect)}, ${renderExpression2(leftExpression, state, dialect)})`;
|
|
7858
9145
|
}
|
|
7859
9146
|
throw new Error("Unsupported container operator for SQL rendering");
|
|
@@ -7862,11 +9149,11 @@ var renderExpression2 = (expression, state, dialect) => {
|
|
|
7862
9149
|
const [leftExpression, rightExpression] = expectBinaryExpressions("overlaps", ast.left, ast.right);
|
|
7863
9150
|
if (dialect.name === "postgres") {
|
|
7864
9151
|
assertCompatiblePostgresRangeOperands(leftExpression, rightExpression);
|
|
7865
|
-
const left =
|
|
7866
|
-
const right =
|
|
9152
|
+
const left = isJsonExpression2(leftExpression) ? renderPostgresJsonValue(leftExpression, state, dialect) : renderExpression2(leftExpression, state, dialect);
|
|
9153
|
+
const right = isJsonExpression2(rightExpression) ? renderPostgresJsonValue(rightExpression, state, dialect) : renderExpression2(rightExpression, state, dialect);
|
|
7867
9154
|
return `(${left} && ${right})`;
|
|
7868
9155
|
}
|
|
7869
|
-
if (dialect.name === "mysql" &&
|
|
9156
|
+
if (dialect.name === "mysql" && isJsonExpression2(leftExpression) && isJsonExpression2(rightExpression)) {
|
|
7870
9157
|
return `json_overlaps(${renderExpression2(leftExpression, state, dialect)}, ${renderExpression2(rightExpression, state, dialect)})`;
|
|
7871
9158
|
}
|
|
7872
9159
|
throw new Error("Unsupported container operator for SQL rendering");
|
|
@@ -8005,15 +9292,39 @@ var renderStandardPlan = (plan, options3 = {}) => {
|
|
|
8005
9292
|
};
|
|
8006
9293
|
|
|
8007
9294
|
// src/standard/renderer.ts
|
|
8008
|
-
var
|
|
9295
|
+
var RendererProto = {
|
|
9296
|
+
pipe() {
|
|
9297
|
+
return pipeArguments8(this, arguments);
|
|
9298
|
+
}
|
|
9299
|
+
};
|
|
9300
|
+
var makeWithState = (state = {}) => {
|
|
9301
|
+
const renderer = makeTrusted("standard", (plan) => renderStandardPlan(plan, state));
|
|
9302
|
+
return Object.assign(Object.create(RendererProto), renderer, {
|
|
9303
|
+
[TypeId6]: {
|
|
9304
|
+
casing: state.casing
|
|
9305
|
+
},
|
|
9306
|
+
withCasing: (override) => makeWithState({
|
|
9307
|
+
...state,
|
|
9308
|
+
casing: merge(state.casing, override)
|
|
9309
|
+
})
|
|
9310
|
+
});
|
|
9311
|
+
};
|
|
9312
|
+
var make10 = (options3 = {}) => makeWithState({ valueMappings: options3.valueMappings });
|
|
8009
9313
|
export {
|
|
9314
|
+
exports_unique as Unique,
|
|
8010
9315
|
exports_table2 as Table,
|
|
8011
9316
|
exports_scalar as Scalar,
|
|
8012
9317
|
exports_row_set as RowSet,
|
|
8013
9318
|
exports_renderer as Renderer,
|
|
8014
9319
|
exports_query as Query,
|
|
9320
|
+
exports_primary_key as PrimaryKey,
|
|
9321
|
+
exports_json as Json,
|
|
9322
|
+
exports_standard as Index,
|
|
8015
9323
|
exports_function as Function,
|
|
9324
|
+
exports_foreign_key as ForeignKey,
|
|
8016
9325
|
exports_executor as Executor,
|
|
8017
9326
|
exports_datatypes as Datatypes,
|
|
8018
|
-
exports_column as Column
|
|
9327
|
+
exports_column as Column,
|
|
9328
|
+
exports_check as Check,
|
|
9329
|
+
exports_cast as Cast
|
|
8019
9330
|
};
|