effect-qb 0.19.0 → 0.21.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 +3 -6
- 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/sqlite.js
CHANGED
|
@@ -22,7 +22,7 @@ import * as Schema4 from "effect/Schema";
|
|
|
22
22
|
import * as Schema2 from "effect/Schema";
|
|
23
23
|
|
|
24
24
|
// src/internal/column-state.ts
|
|
25
|
-
import { pipeArguments } from "effect/Pipeable";
|
|
25
|
+
import { pipeArguments as pipeArguments2 } from "effect/Pipeable";
|
|
26
26
|
import * as Schema from "effect/Schema";
|
|
27
27
|
|
|
28
28
|
// src/internal/scalar.ts
|
|
@@ -35,12 +35,181 @@ var TypeId = Symbol.for("effect-qb/Expression");
|
|
|
35
35
|
// src/internal/expression-ast.ts
|
|
36
36
|
var TypeId2 = Symbol.for("effect-qb/ExpressionAst");
|
|
37
37
|
|
|
38
|
+
// src/internal/json/path-access.ts
|
|
39
|
+
import { pipeArguments } from "effect/Pipeable";
|
|
40
|
+
|
|
41
|
+
// src/internal/json/path.ts
|
|
42
|
+
var SegmentTypeId = Symbol.for("effect-qb/JsonPathSegment");
|
|
43
|
+
var TypeId3 = Symbol.for("effect-qb/JsonPath");
|
|
44
|
+
var makeSegment = (segment) => segment;
|
|
45
|
+
var key = (value) => makeSegment({
|
|
46
|
+
[SegmentTypeId]: {
|
|
47
|
+
kind: "key"
|
|
48
|
+
},
|
|
49
|
+
kind: "key",
|
|
50
|
+
key: value
|
|
51
|
+
});
|
|
52
|
+
var index = (value) => makeSegment({
|
|
53
|
+
[SegmentTypeId]: {
|
|
54
|
+
kind: "index"
|
|
55
|
+
},
|
|
56
|
+
kind: "index",
|
|
57
|
+
index: value
|
|
58
|
+
});
|
|
59
|
+
var wildcard = () => makeSegment({
|
|
60
|
+
[SegmentTypeId]: {
|
|
61
|
+
kind: "wildcard"
|
|
62
|
+
},
|
|
63
|
+
kind: "wildcard"
|
|
64
|
+
});
|
|
65
|
+
var slice = (start, end) => makeSegment({
|
|
66
|
+
[SegmentTypeId]: {
|
|
67
|
+
kind: "slice"
|
|
68
|
+
},
|
|
69
|
+
kind: "slice",
|
|
70
|
+
start,
|
|
71
|
+
end
|
|
72
|
+
});
|
|
73
|
+
var descend = () => makeSegment({
|
|
74
|
+
[SegmentTypeId]: {
|
|
75
|
+
kind: "descend"
|
|
76
|
+
},
|
|
77
|
+
kind: "descend"
|
|
78
|
+
});
|
|
79
|
+
var path = (...segments) => ({
|
|
80
|
+
[TypeId3]: {
|
|
81
|
+
segments
|
|
82
|
+
},
|
|
83
|
+
segments
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
// src/internal/json/path-access.ts
|
|
87
|
+
var WrappedTypeId = Symbol.for("effect-qb/JsonPathAccess");
|
|
88
|
+
var accessKinds = new Set([
|
|
89
|
+
"jsonGet",
|
|
90
|
+
"jsonPath",
|
|
91
|
+
"jsonAccess",
|
|
92
|
+
"jsonTraverse",
|
|
93
|
+
"jsonGetText",
|
|
94
|
+
"jsonPathText",
|
|
95
|
+
"jsonAccessText",
|
|
96
|
+
"jsonTraverseText"
|
|
97
|
+
]);
|
|
98
|
+
var reservedKeys = new Set([
|
|
99
|
+
"pipe",
|
|
100
|
+
"then",
|
|
101
|
+
"toString",
|
|
102
|
+
"toJSON",
|
|
103
|
+
"valueOf",
|
|
104
|
+
"constructor",
|
|
105
|
+
"__proto__",
|
|
106
|
+
"prototype",
|
|
107
|
+
"inspect",
|
|
108
|
+
"schema",
|
|
109
|
+
"metadata",
|
|
110
|
+
"columns",
|
|
111
|
+
"name"
|
|
112
|
+
]);
|
|
113
|
+
var isObjectLike = (value) => (typeof value === "object" || typeof value === "function") && value !== null;
|
|
114
|
+
var isExpression = (value) => isObjectLike(value) && (TypeId in value);
|
|
115
|
+
var isJsonExpression = (value) => {
|
|
116
|
+
if (!isExpression(value)) {
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
const dbType = value[TypeId].dbType;
|
|
120
|
+
return dbType.kind === "json" || dbType.kind === "jsonb" || dbType.variant === "json" || dbType.variant === "jsonb";
|
|
121
|
+
};
|
|
122
|
+
var isWrapped = (value) => value[WrappedTypeId] === true;
|
|
123
|
+
var normalizeSegment = (segment) => {
|
|
124
|
+
switch (segment.kind) {
|
|
125
|
+
case "key":
|
|
126
|
+
return key(segment.key);
|
|
127
|
+
case "index":
|
|
128
|
+
return index(segment.index);
|
|
129
|
+
case "wildcard":
|
|
130
|
+
return wildcard();
|
|
131
|
+
case "slice":
|
|
132
|
+
return slice(segment.start, segment.end);
|
|
133
|
+
case "descend":
|
|
134
|
+
return descend();
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
var accessPathOf = (value) => {
|
|
138
|
+
const segments = [];
|
|
139
|
+
let base = value;
|
|
140
|
+
while (isExpression(base)) {
|
|
141
|
+
const ast = base[TypeId2];
|
|
142
|
+
if (ast === undefined || typeof ast.kind !== "string" || !accessKinds.has(ast.kind) || !isExpression(ast.base) || !Array.isArray(ast.segments)) {
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
segments.unshift(...ast.segments.map(normalizeSegment));
|
|
146
|
+
base = ast.base;
|
|
147
|
+
}
|
|
148
|
+
return { base, segments };
|
|
149
|
+
};
|
|
150
|
+
var isIntegerProperty = (property) => /^(?:-?(?:0|[1-9][0-9]*))$/.test(property);
|
|
151
|
+
var jsonAccessKind = (segments) => segments.every((segment) => segment.kind === "key" || segment.kind === "index") ? segments.length === 1 ? "jsonGet" : "jsonPath" : "jsonTraverse";
|
|
152
|
+
var makeExpression = (state, ast) => {
|
|
153
|
+
const expression = Object.create(null);
|
|
154
|
+
Object.defineProperty(expression, "pipe", {
|
|
155
|
+
configurable: true,
|
|
156
|
+
writable: true,
|
|
157
|
+
value: function() {
|
|
158
|
+
return pipeArguments(expression, arguments);
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
expression[TypeId] = state;
|
|
162
|
+
expression[TypeId2] = ast;
|
|
163
|
+
return expression;
|
|
164
|
+
};
|
|
165
|
+
var makePathExpression = (value, segment) => {
|
|
166
|
+
const access = accessPathOf(value);
|
|
167
|
+
const segments = [...access.segments, normalizeSegment(segment)];
|
|
168
|
+
const base = access.base;
|
|
169
|
+
const baseState = base[TypeId];
|
|
170
|
+
return withJsonPathAccess(makeExpression({
|
|
171
|
+
...baseState,
|
|
172
|
+
runtime: undefined,
|
|
173
|
+
nullability: undefined
|
|
174
|
+
}, {
|
|
175
|
+
kind: jsonAccessKind(segments),
|
|
176
|
+
base,
|
|
177
|
+
segments
|
|
178
|
+
}));
|
|
179
|
+
};
|
|
180
|
+
var pathProxyHandler = {
|
|
181
|
+
get(target, property, receiver) {
|
|
182
|
+
if (typeof property === "symbol") {
|
|
183
|
+
return Reflect.get(target, property, receiver);
|
|
184
|
+
}
|
|
185
|
+
if (Reflect.has(target, property) || reservedKeys.has(property)) {
|
|
186
|
+
return Reflect.get(target, property, receiver);
|
|
187
|
+
}
|
|
188
|
+
const segment = isIntegerProperty(property) ? index(Number(property)) : key(property);
|
|
189
|
+
return makePathExpression(target, segment);
|
|
190
|
+
},
|
|
191
|
+
has(target, property) {
|
|
192
|
+
return Reflect.has(target, property);
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
var withJsonPathAccess = (value) => {
|
|
196
|
+
if (!isObjectLike(value) || !isJsonExpression(value) || isWrapped(value)) {
|
|
197
|
+
return value;
|
|
198
|
+
}
|
|
199
|
+
const proxy = new Proxy(value, pathProxyHandler);
|
|
200
|
+
Object.defineProperty(proxy, WrappedTypeId, {
|
|
201
|
+
configurable: false,
|
|
202
|
+
value: true
|
|
203
|
+
});
|
|
204
|
+
return proxy;
|
|
205
|
+
};
|
|
206
|
+
|
|
38
207
|
// src/internal/column-state.ts
|
|
39
208
|
var ColumnTypeId = Symbol.for("effect-qb/Column");
|
|
40
209
|
var BoundColumnTypeId = Symbol.for("effect-qb/BoundColumn");
|
|
41
210
|
var ColumnProto = {
|
|
42
211
|
pipe() {
|
|
43
|
-
return
|
|
212
|
+
return pipeArguments2(this, arguments);
|
|
44
213
|
}
|
|
45
214
|
};
|
|
46
215
|
var attachPipe = (value) => {
|
|
@@ -48,7 +217,7 @@ var attachPipe = (value) => {
|
|
|
48
217
|
configurable: true,
|
|
49
218
|
writable: true,
|
|
50
219
|
value: function() {
|
|
51
|
-
return
|
|
220
|
+
return pipeArguments2(value, arguments);
|
|
52
221
|
}
|
|
53
222
|
});
|
|
54
223
|
return value;
|
|
@@ -85,7 +254,7 @@ var makeColumnDefinition = (schema, metadata) => {
|
|
|
85
254
|
identity: metadata.identity,
|
|
86
255
|
enum: metadata.enum
|
|
87
256
|
};
|
|
88
|
-
return column;
|
|
257
|
+
return withJsonPathAccess(column);
|
|
89
258
|
};
|
|
90
259
|
var remapColumnDefinition = (column, options = {}) => {
|
|
91
260
|
const schema = options.schema ?? column.schema;
|
|
@@ -127,7 +296,7 @@ var remapColumnDefinition = (column, options = {}) => {
|
|
|
127
296
|
if (BoundColumnTypeId in column) {
|
|
128
297
|
next[BoundColumnTypeId] = column[BoundColumnTypeId];
|
|
129
298
|
}
|
|
130
|
-
return next;
|
|
299
|
+
return withJsonPathAccess(next);
|
|
131
300
|
};
|
|
132
301
|
var bindColumn = (tableName, columnName, column, baseTableName, schemaName, casing) => {
|
|
133
302
|
const brandName = `${tableName}.${columnName}`;
|
|
@@ -160,7 +329,7 @@ var bindColumn = (tableName, columnName, column, baseTableName, schemaName, casi
|
|
|
160
329
|
schemaName,
|
|
161
330
|
casing
|
|
162
331
|
};
|
|
163
|
-
return bound;
|
|
332
|
+
return withJsonPathAccess(bound);
|
|
164
333
|
};
|
|
165
334
|
|
|
166
335
|
// src/internal/column.ts
|
|
@@ -245,7 +414,7 @@ var array = (options) => (column) => remapColumnDefinition(column, {
|
|
|
245
414
|
ddlType: `${column.metadata.ddlType ?? column.metadata.dbType.kind}[]`
|
|
246
415
|
}
|
|
247
416
|
});
|
|
248
|
-
function
|
|
417
|
+
function index2(arg) {
|
|
249
418
|
if (isColumnDefinitionValue(arg)) {
|
|
250
419
|
return mapColumn(arg, {
|
|
251
420
|
...arg.metadata,
|
|
@@ -309,7 +478,7 @@ var enrichDbType = (datatypes, dbType) => {
|
|
|
309
478
|
|
|
310
479
|
// src/internal/runtime/value.ts
|
|
311
480
|
import * as Schema3 from "effect/Schema";
|
|
312
|
-
var brandString = (
|
|
481
|
+
var brandString = (pattern, brand5) => Schema3.String.pipe(Schema3.check(Schema3.isPattern(pattern)), Schema3.brand(brand5));
|
|
313
482
|
var localDatePattern = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
314
483
|
var isValidLocalDateString = (value) => {
|
|
315
484
|
const match = localDatePattern.exec(value);
|
|
@@ -362,11 +531,11 @@ var isValidInstantString = (value) => {
|
|
|
362
531
|
const match = instantPattern.exec(value);
|
|
363
532
|
return match !== null && isValidLocalDateString(match[1]) && isValidLocalTimeString(match[2]) && isValidOffset(match[3]);
|
|
364
533
|
};
|
|
365
|
-
var LocalDateStringSchema = Schema3.String.pipe(Schema3.
|
|
366
|
-
var LocalTimeStringSchema = Schema3.String.pipe(Schema3.
|
|
367
|
-
var OffsetTimeStringSchema = Schema3.String.pipe(Schema3.
|
|
368
|
-
var LocalDateTimeStringSchema = Schema3.String.pipe(Schema3.
|
|
369
|
-
var InstantStringSchema = Schema3.String.pipe(Schema3.
|
|
534
|
+
var LocalDateStringSchema = Schema3.String.pipe(Schema3.check(Schema3.isPattern(localDatePattern)), Schema3.check(Schema3.makeFilter((value) => isValidLocalDateString(value))), Schema3.brand("LocalDateString"));
|
|
535
|
+
var LocalTimeStringSchema = Schema3.String.pipe(Schema3.check(Schema3.isPattern(localTimePattern)), Schema3.check(Schema3.makeFilter((value) => isValidLocalTimeString(value))), Schema3.brand("LocalTimeString"));
|
|
536
|
+
var OffsetTimeStringSchema = Schema3.String.pipe(Schema3.check(Schema3.isPattern(offsetTimePattern)), Schema3.check(Schema3.makeFilter((value) => isValidOffsetTimeString(value))), Schema3.brand("OffsetTimeString"));
|
|
537
|
+
var LocalDateTimeStringSchema = Schema3.String.pipe(Schema3.check(Schema3.isPattern(localDateTimePattern)), Schema3.check(Schema3.makeFilter((value) => isValidLocalDateTimeString(value))), Schema3.brand("LocalDateTimeString"));
|
|
538
|
+
var InstantStringSchema = Schema3.String.pipe(Schema3.check(Schema3.isPattern(instantPattern)), Schema3.check(Schema3.makeFilter((value) => isValidInstantString(value))), Schema3.brand("InstantString"));
|
|
370
539
|
var YearStringSchema = brandString(/^\d{4}$/, "YearString");
|
|
371
540
|
var canonicalizeBigIntString = (input) => {
|
|
372
541
|
const trimmed = input.trim();
|
|
@@ -395,32 +564,800 @@ var canonicalizeDecimalString = (input) => {
|
|
|
395
564
|
if (integer === "0") {
|
|
396
565
|
return "0";
|
|
397
566
|
}
|
|
398
|
-
return `${sign}${integer}`;
|
|
399
|
-
}
|
|
400
|
-
return `${sign}${integer}.${fraction}`;
|
|
401
|
-
};
|
|
402
|
-
var isCanonicalDecimalString = (value) => {
|
|
403
|
-
try {
|
|
404
|
-
return canonicalizeDecimalString(value) === value;
|
|
405
|
-
} catch {
|
|
406
|
-
return false;
|
|
567
|
+
return `${sign}${integer}`;
|
|
568
|
+
}
|
|
569
|
+
return `${sign}${integer}.${fraction}`;
|
|
570
|
+
};
|
|
571
|
+
var isCanonicalDecimalString = (value) => {
|
|
572
|
+
try {
|
|
573
|
+
return canonicalizeDecimalString(value) === value;
|
|
574
|
+
} catch {
|
|
575
|
+
return false;
|
|
576
|
+
}
|
|
577
|
+
};
|
|
578
|
+
var BigIntStringSchema = Schema3.String.pipe(Schema3.check(Schema3.makeFilter((value) => isCanonicalBigIntString(value))), Schema3.brand("BigIntString"));
|
|
579
|
+
var DecimalStringSchema = Schema3.String.pipe(Schema3.check(Schema3.makeFilter((value) => isCanonicalDecimalString(value))), Schema3.brand("DecimalString"));
|
|
580
|
+
var JsonValueSchema = Schema3.suspend(() => Schema3.Union([
|
|
581
|
+
Schema3.String,
|
|
582
|
+
Schema3.Number.check(Schema3.isFinite()),
|
|
583
|
+
Schema3.Boolean,
|
|
584
|
+
Schema3.Null,
|
|
585
|
+
Schema3.Array(JsonValueSchema),
|
|
586
|
+
Schema3.Record(Schema3.String, JsonValueSchema)
|
|
587
|
+
]));
|
|
588
|
+
var JsonPrimitiveSchema = Schema3.Union([
|
|
589
|
+
Schema3.String,
|
|
590
|
+
Schema3.Number.check(Schema3.isFinite()),
|
|
591
|
+
Schema3.Boolean,
|
|
592
|
+
Schema3.Null
|
|
593
|
+
]);
|
|
594
|
+
|
|
595
|
+
// src/sqlite/datatypes/index.ts
|
|
596
|
+
var exports_datatypes = {};
|
|
597
|
+
__export(exports_datatypes, {
|
|
598
|
+
sqliteDatatypes: () => sqliteDatatypes
|
|
599
|
+
});
|
|
600
|
+
|
|
601
|
+
// src/internal/datatypes/matrix.ts
|
|
602
|
+
var portableDatatypeFamilies = {
|
|
603
|
+
uuid: {
|
|
604
|
+
compareGroup: "uuid",
|
|
605
|
+
castTargets: ["uuid", "char", "varchar", "text"],
|
|
606
|
+
traits: {
|
|
607
|
+
textual: true
|
|
608
|
+
}
|
|
609
|
+
},
|
|
610
|
+
text: {
|
|
611
|
+
compareGroup: "text",
|
|
612
|
+
castTargets: [
|
|
613
|
+
"text",
|
|
614
|
+
"numeric",
|
|
615
|
+
"integer",
|
|
616
|
+
"real",
|
|
617
|
+
"boolean",
|
|
618
|
+
"date",
|
|
619
|
+
"time",
|
|
620
|
+
"datetime",
|
|
621
|
+
"interval",
|
|
622
|
+
"uuid",
|
|
623
|
+
"json",
|
|
624
|
+
"blob",
|
|
625
|
+
"binary",
|
|
626
|
+
"array",
|
|
627
|
+
"range",
|
|
628
|
+
"multirange",
|
|
629
|
+
"record",
|
|
630
|
+
"enum",
|
|
631
|
+
"set",
|
|
632
|
+
"money",
|
|
633
|
+
"null"
|
|
634
|
+
],
|
|
635
|
+
traits: {
|
|
636
|
+
textual: true,
|
|
637
|
+
ordered: true
|
|
638
|
+
}
|
|
639
|
+
},
|
|
640
|
+
numeric: {
|
|
641
|
+
compareGroup: "numeric",
|
|
642
|
+
castTargets: ["numeric", "integer", "real", "text", "boolean", "date", "time", "datetime"],
|
|
643
|
+
traits: {
|
|
644
|
+
ordered: true
|
|
645
|
+
}
|
|
646
|
+
},
|
|
647
|
+
integer: {
|
|
648
|
+
compareGroup: "numeric",
|
|
649
|
+
castTargets: ["integer", "numeric", "real", "text", "boolean", "date", "time", "datetime"],
|
|
650
|
+
traits: {
|
|
651
|
+
ordered: true
|
|
652
|
+
}
|
|
653
|
+
},
|
|
654
|
+
real: {
|
|
655
|
+
compareGroup: "numeric",
|
|
656
|
+
castTargets: ["real", "numeric", "integer", "text", "boolean"],
|
|
657
|
+
traits: {
|
|
658
|
+
ordered: true
|
|
659
|
+
}
|
|
660
|
+
},
|
|
661
|
+
boolean: {
|
|
662
|
+
compareGroup: "boolean",
|
|
663
|
+
castTargets: ["boolean", "integer", "numeric", "text"],
|
|
664
|
+
traits: {}
|
|
665
|
+
},
|
|
666
|
+
date: {
|
|
667
|
+
compareGroup: "date",
|
|
668
|
+
castTargets: ["date", "time", "datetime", "text", "numeric", "integer"],
|
|
669
|
+
traits: {
|
|
670
|
+
ordered: true
|
|
671
|
+
}
|
|
672
|
+
},
|
|
673
|
+
time: {
|
|
674
|
+
compareGroup: "time",
|
|
675
|
+
castTargets: ["time", "date", "datetime", "text", "numeric", "integer"],
|
|
676
|
+
traits: {
|
|
677
|
+
ordered: true
|
|
678
|
+
}
|
|
679
|
+
},
|
|
680
|
+
datetime: {
|
|
681
|
+
compareGroup: "datetime",
|
|
682
|
+
castTargets: ["datetime", "date", "time", "text", "numeric", "integer"],
|
|
683
|
+
traits: {
|
|
684
|
+
ordered: true
|
|
685
|
+
}
|
|
686
|
+
},
|
|
687
|
+
json: {
|
|
688
|
+
compareGroup: "json",
|
|
689
|
+
castTargets: ["json", "text"],
|
|
690
|
+
traits: {}
|
|
691
|
+
},
|
|
692
|
+
blob: {
|
|
693
|
+
compareGroup: "blob",
|
|
694
|
+
castTargets: ["blob", "text"],
|
|
695
|
+
traits: {}
|
|
696
|
+
},
|
|
697
|
+
null: {
|
|
698
|
+
compareGroup: "null",
|
|
699
|
+
castTargets: ["uuid", "text", "numeric", "integer", "real", "boolean", "date", "time", "datetime", "json", "blob", "null"],
|
|
700
|
+
traits: {}
|
|
701
|
+
}
|
|
702
|
+
};
|
|
703
|
+
var portableDatatypeKinds = {
|
|
704
|
+
uuid: { family: "uuid", runtime: "string" },
|
|
705
|
+
text: { family: "text", runtime: "string" },
|
|
706
|
+
varchar: { family: "text", runtime: "string" },
|
|
707
|
+
char: { family: "text", runtime: "string" },
|
|
708
|
+
int: { family: "integer", runtime: "number" },
|
|
709
|
+
integer: { family: "integer", runtime: "number" },
|
|
710
|
+
bigint: { family: "integer", runtime: "bigintString" },
|
|
711
|
+
numeric: { family: "numeric", runtime: "decimalString" },
|
|
712
|
+
decimal: { family: "numeric", runtime: "decimalString" },
|
|
713
|
+
real: { family: "real", runtime: "number" },
|
|
714
|
+
boolean: { family: "boolean", runtime: "boolean" },
|
|
715
|
+
date: { family: "date", runtime: "localDate" },
|
|
716
|
+
time: { family: "time", runtime: "localTime" },
|
|
717
|
+
datetime: { family: "datetime", runtime: "localDateTime" },
|
|
718
|
+
timestamp: { family: "datetime", runtime: "localDateTime" },
|
|
719
|
+
json: { family: "json", runtime: "json" },
|
|
720
|
+
blob: { family: "blob", runtime: "bytes" }
|
|
721
|
+
};
|
|
722
|
+
var portableDatatypeKeys = Object.keys(portableDatatypeKinds);
|
|
723
|
+
var portableDatatypeDdlTypeByDialect = {
|
|
724
|
+
standard: {
|
|
725
|
+
uuid: "uuid",
|
|
726
|
+
text: "text",
|
|
727
|
+
varchar: "varchar",
|
|
728
|
+
char: "char",
|
|
729
|
+
int: "int",
|
|
730
|
+
integer: "integer",
|
|
731
|
+
bigint: "bigint",
|
|
732
|
+
numeric: "numeric",
|
|
733
|
+
decimal: "decimal",
|
|
734
|
+
real: "real",
|
|
735
|
+
boolean: "boolean",
|
|
736
|
+
date: "date",
|
|
737
|
+
time: "time",
|
|
738
|
+
datetime: "datetime",
|
|
739
|
+
timestamp: "timestamp",
|
|
740
|
+
json: "json",
|
|
741
|
+
blob: "blob"
|
|
742
|
+
},
|
|
743
|
+
postgres: {
|
|
744
|
+
uuid: "uuid",
|
|
745
|
+
text: "text",
|
|
746
|
+
varchar: "varchar",
|
|
747
|
+
char: "char",
|
|
748
|
+
int: "int",
|
|
749
|
+
integer: "integer",
|
|
750
|
+
bigint: "bigint",
|
|
751
|
+
numeric: "numeric",
|
|
752
|
+
decimal: "decimal",
|
|
753
|
+
real: "real",
|
|
754
|
+
boolean: "boolean",
|
|
755
|
+
date: "date",
|
|
756
|
+
time: "time",
|
|
757
|
+
datetime: "timestamp",
|
|
758
|
+
timestamp: "timestamp",
|
|
759
|
+
json: "json",
|
|
760
|
+
blob: "bytea"
|
|
761
|
+
},
|
|
762
|
+
mysql: {
|
|
763
|
+
uuid: "char(36)",
|
|
764
|
+
text: "text",
|
|
765
|
+
varchar: "varchar(255)",
|
|
766
|
+
char: "char",
|
|
767
|
+
int: "int",
|
|
768
|
+
integer: "integer",
|
|
769
|
+
bigint: "bigint",
|
|
770
|
+
numeric: "numeric",
|
|
771
|
+
decimal: "decimal",
|
|
772
|
+
real: "real",
|
|
773
|
+
boolean: "boolean",
|
|
774
|
+
date: "date",
|
|
775
|
+
time: "time",
|
|
776
|
+
datetime: "datetime",
|
|
777
|
+
timestamp: "timestamp",
|
|
778
|
+
json: "json",
|
|
779
|
+
blob: "blob"
|
|
780
|
+
},
|
|
781
|
+
sqlite: {
|
|
782
|
+
uuid: "text",
|
|
783
|
+
text: "text",
|
|
784
|
+
varchar: "varchar",
|
|
785
|
+
char: "char",
|
|
786
|
+
int: "int",
|
|
787
|
+
integer: "integer",
|
|
788
|
+
bigint: "bigint",
|
|
789
|
+
numeric: "numeric",
|
|
790
|
+
decimal: "decimal",
|
|
791
|
+
real: "real",
|
|
792
|
+
boolean: "boolean",
|
|
793
|
+
date: "date",
|
|
794
|
+
time: "time",
|
|
795
|
+
datetime: "datetime",
|
|
796
|
+
timestamp: "datetime",
|
|
797
|
+
json: "json",
|
|
798
|
+
blob: "blob"
|
|
799
|
+
}
|
|
800
|
+
};
|
|
801
|
+
var portableDatatypeCastTypeByDialect = {
|
|
802
|
+
standard: portableDatatypeDdlTypeByDialect.standard,
|
|
803
|
+
postgres: portableDatatypeDdlTypeByDialect.postgres,
|
|
804
|
+
mysql: {
|
|
805
|
+
...portableDatatypeDdlTypeByDialect.mysql,
|
|
806
|
+
uuid: "char(36)",
|
|
807
|
+
text: "char",
|
|
808
|
+
varchar: "char",
|
|
809
|
+
char: "char",
|
|
810
|
+
int: "signed",
|
|
811
|
+
integer: "signed",
|
|
812
|
+
bigint: "signed",
|
|
813
|
+
numeric: "decimal",
|
|
814
|
+
decimal: "decimal",
|
|
815
|
+
boolean: "unsigned",
|
|
816
|
+
datetime: "datetime",
|
|
817
|
+
timestamp: "datetime",
|
|
818
|
+
blob: "binary"
|
|
819
|
+
},
|
|
820
|
+
sqlite: {
|
|
821
|
+
...portableDatatypeDdlTypeByDialect.sqlite,
|
|
822
|
+
uuid: "text",
|
|
823
|
+
int: "integer",
|
|
824
|
+
timestamp: "datetime"
|
|
825
|
+
}
|
|
826
|
+
};
|
|
827
|
+
var hasOwn = (value, key2) => Object.prototype.hasOwnProperty.call(value, key2);
|
|
828
|
+
var renderPortableDatatypeDdlType = (dialect, kind) => {
|
|
829
|
+
if (!hasOwn(portableDatatypeDdlTypeByDialect, dialect)) {
|
|
830
|
+
return;
|
|
831
|
+
}
|
|
832
|
+
const byKind = portableDatatypeDdlTypeByDialect[dialect];
|
|
833
|
+
return hasOwn(byKind, kind) ? byKind[kind] : undefined;
|
|
834
|
+
};
|
|
835
|
+
var renderPortableDatatypeCastType = (dialect, kind) => {
|
|
836
|
+
if (!hasOwn(portableDatatypeCastTypeByDialect, dialect)) {
|
|
837
|
+
return;
|
|
838
|
+
}
|
|
839
|
+
const byKind = portableDatatypeCastTypeByDialect[dialect];
|
|
840
|
+
return hasOwn(byKind, kind) ? byKind[kind] : undefined;
|
|
841
|
+
};
|
|
842
|
+
var postgresDatatypeFamilies = {
|
|
843
|
+
text: {
|
|
844
|
+
compareGroup: "text",
|
|
845
|
+
castTargets: [
|
|
846
|
+
"text",
|
|
847
|
+
"numeric",
|
|
848
|
+
"boolean",
|
|
849
|
+
"date",
|
|
850
|
+
"time",
|
|
851
|
+
"timestamp",
|
|
852
|
+
"interval",
|
|
853
|
+
"binary",
|
|
854
|
+
"uuid",
|
|
855
|
+
"json",
|
|
856
|
+
"xml",
|
|
857
|
+
"bit",
|
|
858
|
+
"oid",
|
|
859
|
+
"identifier",
|
|
860
|
+
"network",
|
|
861
|
+
"spatial",
|
|
862
|
+
"textsearch",
|
|
863
|
+
"range",
|
|
864
|
+
"multirange",
|
|
865
|
+
"array",
|
|
866
|
+
"money",
|
|
867
|
+
"null"
|
|
868
|
+
],
|
|
869
|
+
traits: {
|
|
870
|
+
textual: true,
|
|
871
|
+
ordered: true
|
|
872
|
+
}
|
|
873
|
+
},
|
|
874
|
+
numeric: {
|
|
875
|
+
compareGroup: "numeric",
|
|
876
|
+
castTargets: ["numeric", "text", "boolean", "date", "time", "timestamp", "interval", "uuid", "bit", "oid", "money"],
|
|
877
|
+
traits: {
|
|
878
|
+
ordered: true
|
|
879
|
+
}
|
|
880
|
+
},
|
|
881
|
+
boolean: {
|
|
882
|
+
compareGroup: "boolean",
|
|
883
|
+
castTargets: ["boolean", "text", "numeric"],
|
|
884
|
+
traits: {}
|
|
885
|
+
},
|
|
886
|
+
date: {
|
|
887
|
+
compareGroup: "date",
|
|
888
|
+
castTargets: ["date", "timestamp", "text"],
|
|
889
|
+
traits: {
|
|
890
|
+
ordered: true
|
|
891
|
+
}
|
|
892
|
+
},
|
|
893
|
+
time: {
|
|
894
|
+
compareGroup: "time",
|
|
895
|
+
castTargets: ["time", "timestamp", "text"],
|
|
896
|
+
traits: {
|
|
897
|
+
ordered: true
|
|
898
|
+
}
|
|
899
|
+
},
|
|
900
|
+
timestamp: {
|
|
901
|
+
compareGroup: "timestamp",
|
|
902
|
+
castTargets: ["timestamp", "date", "text"],
|
|
903
|
+
traits: {
|
|
904
|
+
ordered: true
|
|
905
|
+
}
|
|
906
|
+
},
|
|
907
|
+
interval: {
|
|
908
|
+
compareGroup: "interval",
|
|
909
|
+
castTargets: ["interval", "text"],
|
|
910
|
+
traits: {
|
|
911
|
+
ordered: true
|
|
912
|
+
}
|
|
913
|
+
},
|
|
914
|
+
binary: {
|
|
915
|
+
compareGroup: "binary",
|
|
916
|
+
castTargets: ["binary", "text"],
|
|
917
|
+
traits: {}
|
|
918
|
+
},
|
|
919
|
+
uuid: {
|
|
920
|
+
compareGroup: "uuid",
|
|
921
|
+
castTargets: ["uuid", "text"],
|
|
922
|
+
traits: {
|
|
923
|
+
ordered: true
|
|
924
|
+
}
|
|
925
|
+
},
|
|
926
|
+
json: {
|
|
927
|
+
compareGroup: "json",
|
|
928
|
+
castTargets: ["json", "text"],
|
|
929
|
+
traits: {}
|
|
930
|
+
},
|
|
931
|
+
xml: {
|
|
932
|
+
compareGroup: "xml",
|
|
933
|
+
castTargets: ["xml", "text"],
|
|
934
|
+
traits: {}
|
|
935
|
+
},
|
|
936
|
+
bit: {
|
|
937
|
+
compareGroup: "bit",
|
|
938
|
+
castTargets: ["bit", "text", "numeric"],
|
|
939
|
+
traits: {}
|
|
940
|
+
},
|
|
941
|
+
oid: {
|
|
942
|
+
compareGroup: "oid",
|
|
943
|
+
castTargets: ["oid", "text", "numeric"],
|
|
944
|
+
traits: {
|
|
945
|
+
ordered: true
|
|
946
|
+
}
|
|
947
|
+
},
|
|
948
|
+
identifier: {
|
|
949
|
+
compareGroup: "identifier",
|
|
950
|
+
castTargets: ["identifier", "text"],
|
|
951
|
+
traits: {}
|
|
952
|
+
},
|
|
953
|
+
network: {
|
|
954
|
+
compareGroup: "network",
|
|
955
|
+
castTargets: ["network", "text"],
|
|
956
|
+
traits: {}
|
|
957
|
+
},
|
|
958
|
+
spatial: {
|
|
959
|
+
compareGroup: "spatial",
|
|
960
|
+
castTargets: ["spatial", "text"],
|
|
961
|
+
traits: {}
|
|
962
|
+
},
|
|
963
|
+
textsearch: {
|
|
964
|
+
compareGroup: "textsearch",
|
|
965
|
+
castTargets: ["textsearch", "text"],
|
|
966
|
+
traits: {}
|
|
967
|
+
},
|
|
968
|
+
range: {
|
|
969
|
+
compareGroup: "range",
|
|
970
|
+
castTargets: ["range", "text"],
|
|
971
|
+
traits: {}
|
|
972
|
+
},
|
|
973
|
+
multirange: {
|
|
974
|
+
compareGroup: "multirange",
|
|
975
|
+
castTargets: ["multirange", "text"],
|
|
976
|
+
traits: {}
|
|
977
|
+
},
|
|
978
|
+
enum: {
|
|
979
|
+
compareGroup: "enum",
|
|
980
|
+
castTargets: ["enum", "text"],
|
|
981
|
+
traits: {
|
|
982
|
+
textual: true,
|
|
983
|
+
ordered: true
|
|
984
|
+
}
|
|
985
|
+
},
|
|
986
|
+
record: {
|
|
987
|
+
compareGroup: "record",
|
|
988
|
+
castTargets: ["record", "text"],
|
|
989
|
+
traits: {}
|
|
990
|
+
},
|
|
991
|
+
array: {
|
|
992
|
+
compareGroup: "array",
|
|
993
|
+
castTargets: ["array", "text"],
|
|
994
|
+
traits: {}
|
|
995
|
+
},
|
|
996
|
+
money: {
|
|
997
|
+
compareGroup: "money",
|
|
998
|
+
castTargets: ["money", "text", "numeric"],
|
|
999
|
+
traits: {
|
|
1000
|
+
ordered: true
|
|
1001
|
+
}
|
|
1002
|
+
},
|
|
1003
|
+
null: {
|
|
1004
|
+
compareGroup: "null",
|
|
1005
|
+
castTargets: [
|
|
1006
|
+
"text",
|
|
1007
|
+
"numeric",
|
|
1008
|
+
"boolean",
|
|
1009
|
+
"date",
|
|
1010
|
+
"time",
|
|
1011
|
+
"timestamp",
|
|
1012
|
+
"interval",
|
|
1013
|
+
"binary",
|
|
1014
|
+
"uuid",
|
|
1015
|
+
"json",
|
|
1016
|
+
"xml",
|
|
1017
|
+
"bit",
|
|
1018
|
+
"oid",
|
|
1019
|
+
"identifier",
|
|
1020
|
+
"network",
|
|
1021
|
+
"spatial",
|
|
1022
|
+
"textsearch",
|
|
1023
|
+
"range",
|
|
1024
|
+
"multirange",
|
|
1025
|
+
"array",
|
|
1026
|
+
"money",
|
|
1027
|
+
"null"
|
|
1028
|
+
],
|
|
1029
|
+
traits: {}
|
|
1030
|
+
}
|
|
1031
|
+
};
|
|
1032
|
+
var postgresDatatypeKinds = {
|
|
1033
|
+
text: { family: "text", runtime: "string" },
|
|
1034
|
+
varchar: { family: "text", runtime: "string" },
|
|
1035
|
+
char: { family: "text", runtime: "string" },
|
|
1036
|
+
citext: { family: "text", runtime: "string" },
|
|
1037
|
+
name: { family: "text", runtime: "string" },
|
|
1038
|
+
uuid: { family: "uuid", runtime: "string" },
|
|
1039
|
+
int2: { family: "numeric", runtime: "number" },
|
|
1040
|
+
int4: { family: "numeric", runtime: "number" },
|
|
1041
|
+
int8: { family: "numeric", runtime: "bigintString" },
|
|
1042
|
+
numeric: { family: "numeric", runtime: "decimalString" },
|
|
1043
|
+
float4: { family: "numeric", runtime: "number" },
|
|
1044
|
+
float8: { family: "numeric", runtime: "number" },
|
|
1045
|
+
money: { family: "money", runtime: "number" },
|
|
1046
|
+
bool: { family: "boolean", runtime: "boolean" },
|
|
1047
|
+
date: { family: "date", runtime: "localDate" },
|
|
1048
|
+
time: { family: "time", runtime: "localTime" },
|
|
1049
|
+
timetz: { family: "time", runtime: "offsetTime" },
|
|
1050
|
+
timestamp: { family: "timestamp", runtime: "localDateTime" },
|
|
1051
|
+
timestamptz: { family: "timestamp", runtime: "instant" },
|
|
1052
|
+
interval: { family: "interval", runtime: "string" },
|
|
1053
|
+
bytea: { family: "binary", runtime: "bytes" },
|
|
1054
|
+
json: { family: "json", runtime: "json" },
|
|
1055
|
+
jsonb: { family: "json", runtime: "json" },
|
|
1056
|
+
xml: { family: "xml", runtime: "string" },
|
|
1057
|
+
bit: { family: "bit", runtime: "string" },
|
|
1058
|
+
varbit: { family: "bit", runtime: "string" },
|
|
1059
|
+
oid: { family: "oid", runtime: "number" },
|
|
1060
|
+
xid: { family: "oid", runtime: "number" },
|
|
1061
|
+
xid8: { family: "oid", runtime: "bigintString" },
|
|
1062
|
+
cid: { family: "oid", runtime: "number" },
|
|
1063
|
+
tid: { family: "identifier", runtime: "string" },
|
|
1064
|
+
regclass: { family: "identifier", runtime: "string" },
|
|
1065
|
+
regtype: { family: "identifier", runtime: "string" },
|
|
1066
|
+
regproc: { family: "identifier", runtime: "string" },
|
|
1067
|
+
regprocedure: { family: "identifier", runtime: "string" },
|
|
1068
|
+
regoper: { family: "identifier", runtime: "string" },
|
|
1069
|
+
regoperator: { family: "identifier", runtime: "string" },
|
|
1070
|
+
regconfig: { family: "identifier", runtime: "string" },
|
|
1071
|
+
regdictionary: { family: "identifier", runtime: "string" },
|
|
1072
|
+
pg_lsn: { family: "identifier", runtime: "string" },
|
|
1073
|
+
txid_snapshot: { family: "identifier", runtime: "string" },
|
|
1074
|
+
inet: { family: "network", runtime: "string" },
|
|
1075
|
+
cidr: { family: "network", runtime: "string" },
|
|
1076
|
+
macaddr: { family: "network", runtime: "string" },
|
|
1077
|
+
macaddr8: { family: "network", runtime: "string" },
|
|
1078
|
+
point: { family: "spatial", runtime: "unknown" },
|
|
1079
|
+
line: { family: "spatial", runtime: "unknown" },
|
|
1080
|
+
lseg: { family: "spatial", runtime: "unknown" },
|
|
1081
|
+
box: { family: "spatial", runtime: "unknown" },
|
|
1082
|
+
path: { family: "spatial", runtime: "unknown" },
|
|
1083
|
+
polygon: { family: "spatial", runtime: "unknown" },
|
|
1084
|
+
circle: { family: "spatial", runtime: "unknown" },
|
|
1085
|
+
tsvector: { family: "textsearch", runtime: "string" },
|
|
1086
|
+
tsquery: { family: "textsearch", runtime: "string" },
|
|
1087
|
+
int4range: { family: "range", runtime: "unknown" },
|
|
1088
|
+
int8range: { family: "range", runtime: "unknown" },
|
|
1089
|
+
numrange: { family: "range", runtime: "unknown" },
|
|
1090
|
+
tsrange: { family: "range", runtime: "unknown" },
|
|
1091
|
+
tstzrange: { family: "range", runtime: "unknown" },
|
|
1092
|
+
daterange: { family: "range", runtime: "unknown" },
|
|
1093
|
+
int4multirange: { family: "multirange", runtime: "unknown" },
|
|
1094
|
+
int8multirange: { family: "multirange", runtime: "unknown" },
|
|
1095
|
+
nummultirange: { family: "multirange", runtime: "unknown" },
|
|
1096
|
+
tsmultirange: { family: "multirange", runtime: "unknown" },
|
|
1097
|
+
tstzmultirange: { family: "multirange", runtime: "unknown" },
|
|
1098
|
+
datemultirange: { family: "multirange", runtime: "unknown" }
|
|
1099
|
+
};
|
|
1100
|
+
var postgresSpecificDatatypeKeys = [
|
|
1101
|
+
"int2",
|
|
1102
|
+
"int4",
|
|
1103
|
+
"int8",
|
|
1104
|
+
"float4",
|
|
1105
|
+
"float8",
|
|
1106
|
+
"money",
|
|
1107
|
+
"bool",
|
|
1108
|
+
"timetz",
|
|
1109
|
+
"timestamptz",
|
|
1110
|
+
"interval",
|
|
1111
|
+
"bytea",
|
|
1112
|
+
"citext",
|
|
1113
|
+
"name",
|
|
1114
|
+
"jsonb",
|
|
1115
|
+
"xml",
|
|
1116
|
+
"bit",
|
|
1117
|
+
"varbit",
|
|
1118
|
+
"oid",
|
|
1119
|
+
"xid",
|
|
1120
|
+
"xid8",
|
|
1121
|
+
"cid",
|
|
1122
|
+
"tid",
|
|
1123
|
+
"regclass",
|
|
1124
|
+
"regtype",
|
|
1125
|
+
"regproc",
|
|
1126
|
+
"regprocedure",
|
|
1127
|
+
"regoper",
|
|
1128
|
+
"regoperator",
|
|
1129
|
+
"regconfig",
|
|
1130
|
+
"regdictionary",
|
|
1131
|
+
"pg_lsn",
|
|
1132
|
+
"txid_snapshot",
|
|
1133
|
+
"inet",
|
|
1134
|
+
"cidr",
|
|
1135
|
+
"macaddr",
|
|
1136
|
+
"macaddr8",
|
|
1137
|
+
"point",
|
|
1138
|
+
"line",
|
|
1139
|
+
"lseg",
|
|
1140
|
+
"box",
|
|
1141
|
+
"path",
|
|
1142
|
+
"polygon",
|
|
1143
|
+
"circle",
|
|
1144
|
+
"tsvector",
|
|
1145
|
+
"tsquery",
|
|
1146
|
+
"int4range",
|
|
1147
|
+
"int8range",
|
|
1148
|
+
"numrange",
|
|
1149
|
+
"tsrange",
|
|
1150
|
+
"tstzrange",
|
|
1151
|
+
"daterange",
|
|
1152
|
+
"int4multirange",
|
|
1153
|
+
"int8multirange",
|
|
1154
|
+
"nummultirange",
|
|
1155
|
+
"tsmultirange",
|
|
1156
|
+
"tstzmultirange",
|
|
1157
|
+
"datemultirange"
|
|
1158
|
+
];
|
|
1159
|
+
var mysqlDatatypeFamilies = {
|
|
1160
|
+
text: {
|
|
1161
|
+
compareGroup: "text",
|
|
1162
|
+
castTargets: [
|
|
1163
|
+
"text",
|
|
1164
|
+
"numeric",
|
|
1165
|
+
"boolean",
|
|
1166
|
+
"date",
|
|
1167
|
+
"time",
|
|
1168
|
+
"datetime",
|
|
1169
|
+
"timestamp",
|
|
1170
|
+
"year",
|
|
1171
|
+
"binary",
|
|
1172
|
+
"json",
|
|
1173
|
+
"bit",
|
|
1174
|
+
"enum",
|
|
1175
|
+
"set",
|
|
1176
|
+
"null"
|
|
1177
|
+
],
|
|
1178
|
+
traits: {
|
|
1179
|
+
textual: true,
|
|
1180
|
+
ordered: true
|
|
1181
|
+
}
|
|
1182
|
+
},
|
|
1183
|
+
numeric: {
|
|
1184
|
+
compareGroup: "numeric",
|
|
1185
|
+
castTargets: ["numeric", "text", "boolean", "date", "time", "datetime", "timestamp", "year", "bit"],
|
|
1186
|
+
traits: {
|
|
1187
|
+
ordered: true
|
|
1188
|
+
}
|
|
1189
|
+
},
|
|
1190
|
+
boolean: {
|
|
1191
|
+
compareGroup: "boolean",
|
|
1192
|
+
castTargets: ["boolean", "text", "numeric"],
|
|
1193
|
+
traits: {}
|
|
1194
|
+
},
|
|
1195
|
+
bit: {
|
|
1196
|
+
compareGroup: "bit",
|
|
1197
|
+
castTargets: ["bit", "text", "numeric"],
|
|
1198
|
+
traits: {}
|
|
1199
|
+
},
|
|
1200
|
+
date: {
|
|
1201
|
+
compareGroup: "date",
|
|
1202
|
+
castTargets: ["date", "datetime", "timestamp", "text"],
|
|
1203
|
+
traits: {
|
|
1204
|
+
ordered: true
|
|
1205
|
+
}
|
|
1206
|
+
},
|
|
1207
|
+
time: {
|
|
1208
|
+
compareGroup: "time",
|
|
1209
|
+
castTargets: ["time", "datetime", "timestamp", "text"],
|
|
1210
|
+
traits: {
|
|
1211
|
+
ordered: true
|
|
1212
|
+
}
|
|
1213
|
+
},
|
|
1214
|
+
datetime: {
|
|
1215
|
+
compareGroup: "datetime",
|
|
1216
|
+
castTargets: ["datetime", "timestamp", "date", "text"],
|
|
1217
|
+
traits: {
|
|
1218
|
+
ordered: true
|
|
1219
|
+
}
|
|
1220
|
+
},
|
|
1221
|
+
timestamp: {
|
|
1222
|
+
compareGroup: "timestamp",
|
|
1223
|
+
castTargets: ["timestamp", "datetime", "date", "text"],
|
|
1224
|
+
traits: {
|
|
1225
|
+
ordered: true
|
|
1226
|
+
}
|
|
1227
|
+
},
|
|
1228
|
+
year: {
|
|
1229
|
+
compareGroup: "year",
|
|
1230
|
+
castTargets: ["year", "text", "numeric"],
|
|
1231
|
+
traits: {
|
|
1232
|
+
ordered: true
|
|
1233
|
+
}
|
|
1234
|
+
},
|
|
1235
|
+
binary: {
|
|
1236
|
+
compareGroup: "binary",
|
|
1237
|
+
castTargets: ["binary", "text"],
|
|
1238
|
+
traits: {}
|
|
1239
|
+
},
|
|
1240
|
+
json: {
|
|
1241
|
+
compareGroup: "json",
|
|
1242
|
+
castTargets: ["json", "text"],
|
|
1243
|
+
traits: {}
|
|
1244
|
+
},
|
|
1245
|
+
spatial: {
|
|
1246
|
+
compareGroup: "spatial",
|
|
1247
|
+
castTargets: ["spatial", "text"],
|
|
1248
|
+
traits: {}
|
|
1249
|
+
},
|
|
1250
|
+
enum: {
|
|
1251
|
+
compareGroup: "enum",
|
|
1252
|
+
castTargets: ["enum", "text"],
|
|
1253
|
+
traits: {
|
|
1254
|
+
textual: true,
|
|
1255
|
+
ordered: true
|
|
1256
|
+
}
|
|
1257
|
+
},
|
|
1258
|
+
set: {
|
|
1259
|
+
compareGroup: "set",
|
|
1260
|
+
castTargets: ["set", "text"],
|
|
1261
|
+
traits: {
|
|
1262
|
+
textual: true
|
|
1263
|
+
}
|
|
1264
|
+
},
|
|
1265
|
+
null: {
|
|
1266
|
+
compareGroup: "null",
|
|
1267
|
+
castTargets: [
|
|
1268
|
+
"text",
|
|
1269
|
+
"numeric",
|
|
1270
|
+
"boolean",
|
|
1271
|
+
"bit",
|
|
1272
|
+
"date",
|
|
1273
|
+
"time",
|
|
1274
|
+
"datetime",
|
|
1275
|
+
"timestamp",
|
|
1276
|
+
"year",
|
|
1277
|
+
"binary",
|
|
1278
|
+
"json",
|
|
1279
|
+
"spatial",
|
|
1280
|
+
"enum",
|
|
1281
|
+
"set",
|
|
1282
|
+
"null"
|
|
1283
|
+
],
|
|
1284
|
+
traits: {}
|
|
407
1285
|
}
|
|
408
1286
|
};
|
|
409
|
-
var
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
|
|
1287
|
+
var mysqlDatatypeKinds = {
|
|
1288
|
+
char: { family: "text", runtime: "string" },
|
|
1289
|
+
varchar: { family: "text", runtime: "string" },
|
|
1290
|
+
tinytext: { family: "text", runtime: "string" },
|
|
1291
|
+
text: { family: "text", runtime: "string" },
|
|
1292
|
+
mediumtext: { family: "text", runtime: "string" },
|
|
1293
|
+
longtext: { family: "text", runtime: "string" },
|
|
1294
|
+
tinyint: { family: "numeric", runtime: "number" },
|
|
1295
|
+
smallint: { family: "numeric", runtime: "number" },
|
|
1296
|
+
mediumint: { family: "numeric", runtime: "number" },
|
|
1297
|
+
int: { family: "numeric", runtime: "number" },
|
|
1298
|
+
integer: { family: "numeric", runtime: "number" },
|
|
1299
|
+
bigint: { family: "numeric", runtime: "bigintString" },
|
|
1300
|
+
decimal: { family: "numeric", runtime: "decimalString" },
|
|
1301
|
+
dec: { family: "numeric", runtime: "decimalString" },
|
|
1302
|
+
numeric: { family: "numeric", runtime: "decimalString" },
|
|
1303
|
+
fixed: { family: "numeric", runtime: "decimalString" },
|
|
1304
|
+
float: { family: "numeric", runtime: "number" },
|
|
1305
|
+
double: { family: "numeric", runtime: "number" },
|
|
1306
|
+
real: { family: "numeric", runtime: "number" },
|
|
1307
|
+
bool: { family: "boolean", runtime: "boolean" },
|
|
1308
|
+
boolean: { family: "boolean", runtime: "boolean" },
|
|
1309
|
+
bit: { family: "bit", runtime: "string" },
|
|
1310
|
+
date: { family: "date", runtime: "localDate" },
|
|
1311
|
+
time: { family: "time", runtime: "localTime" },
|
|
1312
|
+
datetime: { family: "datetime", runtime: "localDateTime" },
|
|
1313
|
+
timestamp: { family: "timestamp", runtime: "localDateTime" },
|
|
1314
|
+
year: { family: "year", runtime: "year" },
|
|
1315
|
+
binary: { family: "binary", runtime: "bytes" },
|
|
1316
|
+
varbinary: { family: "binary", runtime: "bytes" },
|
|
1317
|
+
tinyblob: { family: "binary", runtime: "bytes" },
|
|
1318
|
+
blob: { family: "binary", runtime: "bytes" },
|
|
1319
|
+
mediumblob: { family: "binary", runtime: "bytes" },
|
|
1320
|
+
longblob: { family: "binary", runtime: "bytes" },
|
|
1321
|
+
json: { family: "json", runtime: "json" },
|
|
1322
|
+
geometry: { family: "spatial", runtime: "unknown" },
|
|
1323
|
+
point: { family: "spatial", runtime: "unknown" },
|
|
1324
|
+
linestring: { family: "spatial", runtime: "unknown" },
|
|
1325
|
+
polygon: { family: "spatial", runtime: "unknown" },
|
|
1326
|
+
multipoint: { family: "spatial", runtime: "unknown" },
|
|
1327
|
+
multilinestring: { family: "spatial", runtime: "unknown" },
|
|
1328
|
+
multipolygon: { family: "spatial", runtime: "unknown" },
|
|
1329
|
+
geometrycollection: { family: "spatial", runtime: "unknown" },
|
|
1330
|
+
enum: { family: "enum", runtime: "string" },
|
|
1331
|
+
set: { family: "set", runtime: "string" }
|
|
1332
|
+
};
|
|
1333
|
+
var mysqlSpecificDatatypeKeys = [
|
|
1334
|
+
"tinytext",
|
|
1335
|
+
"mediumtext",
|
|
1336
|
+
"longtext",
|
|
1337
|
+
"tinyint",
|
|
1338
|
+
"smallint",
|
|
1339
|
+
"mediumint",
|
|
1340
|
+
"dec",
|
|
1341
|
+
"fixed",
|
|
1342
|
+
"float",
|
|
1343
|
+
"double",
|
|
1344
|
+
"bool",
|
|
1345
|
+
"bit",
|
|
1346
|
+
"year",
|
|
1347
|
+
"binary",
|
|
1348
|
+
"varbinary",
|
|
1349
|
+
"tinyblob",
|
|
1350
|
+
"mediumblob",
|
|
1351
|
+
"longblob",
|
|
1352
|
+
"geometry",
|
|
1353
|
+
"point",
|
|
1354
|
+
"linestring",
|
|
1355
|
+
"polygon",
|
|
1356
|
+
"multipoint",
|
|
1357
|
+
"multilinestring",
|
|
1358
|
+
"multipolygon",
|
|
1359
|
+
"geometrycollection"
|
|
1360
|
+
];
|
|
424
1361
|
var sqliteDatatypeFamilies = {
|
|
425
1362
|
text: {
|
|
426
1363
|
compareGroup: "text",
|
|
@@ -513,11 +1450,20 @@ var sqliteDatatypeKinds = {
|
|
|
513
1450
|
json: { family: "json", runtime: "json" },
|
|
514
1451
|
blob: { family: "blob", runtime: "bytes" }
|
|
515
1452
|
};
|
|
1453
|
+
var sqliteSpecificDatatypeKeys = [
|
|
1454
|
+
"clob",
|
|
1455
|
+
"double"
|
|
1456
|
+
];
|
|
1457
|
+
var pickDatatypeConstructors = (module, keys) => Object.fromEntries(keys.map((key2) => [key2, module[key2]]));
|
|
1458
|
+
|
|
1459
|
+
// src/sqlite/datatypes/spec.ts
|
|
1460
|
+
var sqliteDatatypeFamilies2 = sqliteDatatypeFamilies;
|
|
1461
|
+
var sqliteDatatypeKinds2 = sqliteDatatypeKinds;
|
|
516
1462
|
|
|
517
1463
|
// src/sqlite/datatypes/index.ts
|
|
518
1464
|
var withMetadata = (kind) => {
|
|
519
|
-
const kindSpec =
|
|
520
|
-
const familySpec =
|
|
1465
|
+
const kindSpec = sqliteDatatypeKinds2[kind];
|
|
1466
|
+
const familySpec = sqliteDatatypeFamilies2[kindSpec.family];
|
|
521
1467
|
return {
|
|
522
1468
|
dialect: "sqlite",
|
|
523
1469
|
kind,
|
|
@@ -525,6 +1471,7 @@ var withMetadata = (kind) => {
|
|
|
525
1471
|
runtime: kindSpec.runtime,
|
|
526
1472
|
compareGroup: familySpec?.compareGroup,
|
|
527
1473
|
castTargets: familySpec?.castTargets,
|
|
1474
|
+
implicitTargets: familySpec.implicitTargets,
|
|
528
1475
|
traits: familySpec?.traits
|
|
529
1476
|
};
|
|
530
1477
|
};
|
|
@@ -545,7 +1492,7 @@ var sqliteDatatypeModule = {
|
|
|
545
1492
|
}
|
|
546
1493
|
})
|
|
547
1494
|
};
|
|
548
|
-
for (const kind of Object.keys(
|
|
1495
|
+
for (const kind of Object.keys(sqliteDatatypeKinds2)) {
|
|
549
1496
|
sqliteDatatypeModule[kind] = () => withMetadata(kind);
|
|
550
1497
|
}
|
|
551
1498
|
sqliteDatatypeModule.json = () => ({
|
|
@@ -655,7 +1602,7 @@ var findSqliteErrorDescriptorsByNumberLoose = (number) => isSqliteErrorNumber(nu
|
|
|
655
1602
|
var isRecord = (value) => typeof value === "object" && value !== null;
|
|
656
1603
|
var unwrapSqliteDriverCause = (cause) => {
|
|
657
1604
|
let current = cause;
|
|
658
|
-
while (isRecord(current) && "_tag" in current &&
|
|
1605
|
+
while (isRecord(current) && "_tag" in current && "cause" in current) {
|
|
659
1606
|
current = current.cause;
|
|
660
1607
|
}
|
|
661
1608
|
return current;
|
|
@@ -808,65 +1755,34 @@ var narrowSqliteDriverErrorForReadQuery = (error) => {
|
|
|
808
1755
|
// src/sqlite/json.ts
|
|
809
1756
|
var exports_json = {};
|
|
810
1757
|
__export(exports_json, {
|
|
811
|
-
wildcard: () => wildcard2,
|
|
812
1758
|
typeOf: () => typeOf,
|
|
813
|
-
traverseText: () => traverseText,
|
|
814
|
-
traverse: () => traverse,
|
|
815
|
-
toJsonb: () => toJsonb,
|
|
816
|
-
toJson: () => toJson,
|
|
817
|
-
text: () => text,
|
|
818
1759
|
stripNulls: () => stripNulls,
|
|
819
|
-
slice: () => slice2,
|
|
820
|
-
set: () => set2,
|
|
821
|
-
remove: () => remove,
|
|
822
1760
|
pathMatch: () => pathMatch,
|
|
823
|
-
pathExists: () => pathExists,
|
|
824
|
-
path: () => path2,
|
|
825
|
-
merge: () => merge2,
|
|
826
1761
|
length: () => length,
|
|
827
|
-
|
|
828
|
-
keyExists: () => keyExists,
|
|
829
|
-
key: () => key2,
|
|
830
|
-
json: () => json,
|
|
831
|
-
insert: () => insert,
|
|
832
|
-
index: () => index4,
|
|
833
|
-
hasKey: () => hasKey,
|
|
834
|
-
hasAnyKeys: () => hasAnyKeys,
|
|
835
|
-
hasAllKeys: () => hasAllKeys,
|
|
836
|
-
get: () => get,
|
|
837
|
-
descend: () => descend2,
|
|
838
|
-
delete_: () => delete_,
|
|
839
|
-
delete: () => delete_,
|
|
840
|
-
contains: () => contains,
|
|
841
|
-
containedBy: () => containedBy,
|
|
842
|
-
concat: () => concat,
|
|
843
|
-
buildObject: () => buildObject,
|
|
844
|
-
buildArray: () => buildArray,
|
|
845
|
-
accessText: () => accessText,
|
|
846
|
-
access: () => access
|
|
1762
|
+
insert: () => insert
|
|
847
1763
|
});
|
|
848
1764
|
|
|
849
1765
|
// src/sqlite/internal/dsl.ts
|
|
850
|
-
import { pipeArguments as
|
|
1766
|
+
import { pipeArguments as pipeArguments7 } from "effect/Pipeable";
|
|
851
1767
|
import * as Schema6 from "effect/Schema";
|
|
852
1768
|
|
|
853
1769
|
// src/internal/row-set.ts
|
|
854
1770
|
var exports_row_set = {};
|
|
855
1771
|
__export(exports_row_set, {
|
|
856
|
-
TypeId: () =>
|
|
1772
|
+
TypeId: () => TypeId4
|
|
857
1773
|
});
|
|
858
|
-
var
|
|
1774
|
+
var TypeId4 = Symbol.for("effect-qb/Plan");
|
|
859
1775
|
|
|
860
1776
|
// src/internal/table.ts
|
|
861
|
-
import { pipeArguments as
|
|
1777
|
+
import { pipeArguments as pipeArguments4 } from "effect/Pipeable";
|
|
862
1778
|
|
|
863
1779
|
// src/internal/schema-expression.ts
|
|
864
1780
|
import { parse, toSql } from "pgsql-ast-parser";
|
|
865
|
-
import { pipeArguments as
|
|
866
|
-
var
|
|
1781
|
+
import { pipeArguments as pipeArguments3 } from "effect/Pipeable";
|
|
1782
|
+
var TypeId5 = Symbol.for("effect-qb/SchemaExpression");
|
|
867
1783
|
var SchemaExpressionProto = {
|
|
868
1784
|
pipe() {
|
|
869
|
-
return
|
|
1785
|
+
return pipeArguments3(this, arguments);
|
|
870
1786
|
}
|
|
871
1787
|
};
|
|
872
1788
|
var attachPipe2 = (value) => {
|
|
@@ -874,35 +1790,35 @@ var attachPipe2 = (value) => {
|
|
|
874
1790
|
configurable: true,
|
|
875
1791
|
writable: true,
|
|
876
1792
|
value: function() {
|
|
877
|
-
return
|
|
1793
|
+
return pipeArguments3(value, arguments);
|
|
878
1794
|
}
|
|
879
1795
|
});
|
|
880
1796
|
return value;
|
|
881
1797
|
};
|
|
882
|
-
var isSchemaExpression = (value) => typeof value === "object" && value !== null && (
|
|
1798
|
+
var isSchemaExpression = (value) => typeof value === "object" && value !== null && (TypeId5 in value);
|
|
883
1799
|
var fromAst = (ast) => {
|
|
884
1800
|
const expression = attachPipe2(Object.create(SchemaExpressionProto));
|
|
885
|
-
expression[
|
|
1801
|
+
expression[TypeId5] = {
|
|
886
1802
|
ast
|
|
887
1803
|
};
|
|
888
1804
|
return expression;
|
|
889
1805
|
};
|
|
890
1806
|
var fromSql = (sql) => {
|
|
891
1807
|
const expression = attachPipe2(Object.create(SchemaExpressionProto));
|
|
892
|
-
expression[
|
|
1808
|
+
expression[TypeId5] = {
|
|
893
1809
|
sql: sql.trim()
|
|
894
1810
|
};
|
|
895
1811
|
return expression;
|
|
896
1812
|
};
|
|
897
1813
|
var parseExpression = (sql) => fromAst(parse(sql, "expr"));
|
|
898
1814
|
var toAst = (expression) => {
|
|
899
|
-
const ast = expression[
|
|
1815
|
+
const ast = expression[TypeId5].ast;
|
|
900
1816
|
if (ast !== undefined) {
|
|
901
1817
|
return ast;
|
|
902
1818
|
}
|
|
903
1819
|
return parse(render(expression), "expr");
|
|
904
1820
|
};
|
|
905
|
-
var render = (expression) => expression[
|
|
1821
|
+
var render = (expression) => expression[TypeId5].sql ?? toSql.expr(toAst(expression));
|
|
906
1822
|
var normalize2 = (expression) => (() => {
|
|
907
1823
|
const sql = render(expression);
|
|
908
1824
|
try {
|
|
@@ -997,7 +1913,7 @@ var collectInlineOptions = (fields2) => {
|
|
|
997
1913
|
return options;
|
|
998
1914
|
};
|
|
999
1915
|
var resolvePrimaryKeyColumns = (fields2, declaredOptions) => {
|
|
1000
|
-
const inline = Object.entries(fields2).filter(([, column]) => column.metadata.primaryKey).map(([
|
|
1916
|
+
const inline = Object.entries(fields2).filter(([, column]) => column.metadata.primaryKey).map(([key2]) => key2);
|
|
1001
1917
|
const explicit = declaredOptions.flatMap((option) => {
|
|
1002
1918
|
if (typeof option !== "object" || option === null || !("kind" in option) || option.kind !== "primaryKey") {
|
|
1003
1919
|
return [];
|
|
@@ -1023,8 +1939,8 @@ var validateOptions = (tableName, fields2, options) => {
|
|
|
1023
1939
|
case "foreignKey": {
|
|
1024
1940
|
if (option.kind === "index") {
|
|
1025
1941
|
const keys = Array.isArray(option.keys) ? option.keys : [];
|
|
1026
|
-
for (const
|
|
1027
|
-
if (typeof
|
|
1942
|
+
for (const key2 of keys) {
|
|
1943
|
+
if (typeof key2 !== "object" || key2 === null || !("kind" in key2)) {
|
|
1028
1944
|
continue;
|
|
1029
1945
|
}
|
|
1030
1946
|
}
|
|
@@ -1071,10 +1987,10 @@ var fieldSchemaForVariant = (variant, column, tableName, columnName, primaryKeyS
|
|
|
1071
1987
|
var deriveSchema = (variant, tableName, fields2, primaryKeyColumns) => {
|
|
1072
1988
|
const primaryKeySet = new Set(primaryKeyColumns);
|
|
1073
1989
|
const structFields = {};
|
|
1074
|
-
for (const [
|
|
1075
|
-
const schema2 = fieldSchemaForVariant(variant, column, tableName,
|
|
1990
|
+
for (const [key2, column] of Object.entries(fields2)) {
|
|
1991
|
+
const schema2 = fieldSchemaForVariant(variant, column, tableName, key2, primaryKeySet);
|
|
1076
1992
|
if (schema2 !== undefined) {
|
|
1077
|
-
structFields[
|
|
1993
|
+
structFields[key2] = schema2;
|
|
1078
1994
|
}
|
|
1079
1995
|
}
|
|
1080
1996
|
return Schema5.Struct(structFields);
|
|
@@ -1084,7 +2000,7 @@ var deriveInsertSchema = (tableName, fields2, primaryKeyColumns) => deriveSchema
|
|
|
1084
2000
|
var deriveUpdateSchema = (tableName, fields2, primaryKeyColumns) => deriveSchema("update", tableName, fields2, primaryKeyColumns);
|
|
1085
2001
|
|
|
1086
2002
|
// src/internal/casing.ts
|
|
1087
|
-
var
|
|
2003
|
+
var TypeId6 = Symbol.for("effect-qb/Casing");
|
|
1088
2004
|
var merge = (base, override) => {
|
|
1089
2005
|
if (base === undefined) {
|
|
1090
2006
|
return override;
|
|
@@ -1125,15 +2041,16 @@ var apply = (style, name) => {
|
|
|
1125
2041
|
var applyCategory = (options, category, name) => apply(options?.[category], name);
|
|
1126
2042
|
|
|
1127
2043
|
// src/internal/table.ts
|
|
1128
|
-
var
|
|
2044
|
+
var TypeId7 = Symbol.for("effect-qb/Table");
|
|
1129
2045
|
var OptionsSymbol = Symbol.for("effect-qb/Table/normalizedOptions");
|
|
1130
2046
|
var options = Symbol.for("effect-qb/Table/declaredOptions");
|
|
1131
2047
|
var CacheSymbol = Symbol.for("effect-qb/Table/cache");
|
|
1132
2048
|
var SchemaCacheSymbol = Symbol.for("effect-qb/Table/schemaCache");
|
|
1133
2049
|
var DeclaredOptionsSymbol = Symbol.for("effect-qb/Table/factoryDeclaredOptions");
|
|
2050
|
+
var ResolveOptionSymbol = Symbol.for("effect-qb/Table/resolveOption");
|
|
1134
2051
|
var TableProto = {
|
|
1135
2052
|
pipe() {
|
|
1136
|
-
return
|
|
2053
|
+
return pipeArguments4(this, arguments);
|
|
1137
2054
|
}
|
|
1138
2055
|
};
|
|
1139
2056
|
var attachPipe3 = (value) => {
|
|
@@ -1141,21 +2058,50 @@ var attachPipe3 = (value) => {
|
|
|
1141
2058
|
configurable: true,
|
|
1142
2059
|
writable: true,
|
|
1143
2060
|
value: function() {
|
|
1144
|
-
return
|
|
2061
|
+
return pipeArguments4(value, arguments);
|
|
1145
2062
|
}
|
|
1146
2063
|
});
|
|
1147
2064
|
return value;
|
|
1148
2065
|
};
|
|
2066
|
+
var conflictArbitersFromOptions = (options2) => options2.flatMap((option) => {
|
|
2067
|
+
if (typeof option !== "object" || option === null) {
|
|
2068
|
+
return [];
|
|
2069
|
+
}
|
|
2070
|
+
if (!("columns" in option) || !Array.isArray(option.columns) || option.columns.length === 0) {
|
|
2071
|
+
return [];
|
|
2072
|
+
}
|
|
2073
|
+
switch (option.kind) {
|
|
2074
|
+
case "primaryKey":
|
|
2075
|
+
case "unique":
|
|
2076
|
+
return [{
|
|
2077
|
+
columns: option.columns,
|
|
2078
|
+
scope: "unconditional",
|
|
2079
|
+
name: option.name,
|
|
2080
|
+
constraint: true
|
|
2081
|
+
}];
|
|
2082
|
+
case "index":
|
|
2083
|
+
return option.unique === true ? [{
|
|
2084
|
+
columns: option.columns,
|
|
2085
|
+
scope: option.predicate === undefined ? "unconditional" : "partial",
|
|
2086
|
+
name: option.name,
|
|
2087
|
+
constraint: false
|
|
2088
|
+
}] : [];
|
|
2089
|
+
default:
|
|
2090
|
+
return [];
|
|
2091
|
+
}
|
|
2092
|
+
});
|
|
1149
2093
|
var buildArtifacts = (name, fields2, declaredOptions, schemaName, casing) => {
|
|
1150
2094
|
const normalizedOptions = [...collectInlineOptions(fields2), ...declaredOptions];
|
|
1151
2095
|
validateFieldDialects(name, fields2);
|
|
1152
2096
|
validateOptions(name, fields2, declaredOptions);
|
|
1153
2097
|
const primaryKey2 = resolvePrimaryKeyColumns(fields2, declaredOptions);
|
|
1154
|
-
const
|
|
2098
|
+
const conflictArbiters = conflictArbitersFromOptions(normalizedOptions);
|
|
2099
|
+
const columns = Object.fromEntries(Object.entries(fields2).map(([key2, column]) => [key2, bindColumn(name, key2, column, name, schemaName, casing)]));
|
|
1155
2100
|
return {
|
|
1156
2101
|
columns,
|
|
1157
2102
|
normalizedOptions,
|
|
1158
|
-
primaryKey: primaryKey2
|
|
2103
|
+
primaryKey: primaryKey2,
|
|
2104
|
+
conflictArbiters
|
|
1159
2105
|
};
|
|
1160
2106
|
};
|
|
1161
2107
|
var getSchemaCache = (table) => {
|
|
@@ -1171,7 +2117,7 @@ var getSchemaCache = (table) => {
|
|
|
1171
2117
|
return cache;
|
|
1172
2118
|
};
|
|
1173
2119
|
var deriveTableSchema = (table, variant) => {
|
|
1174
|
-
const state = table[
|
|
2120
|
+
const state = table[TypeId7];
|
|
1175
2121
|
switch (variant) {
|
|
1176
2122
|
case "select":
|
|
1177
2123
|
return deriveSelectSchema(state.name, state.fields, state.primaryKey);
|
|
@@ -1240,16 +2186,17 @@ var makeTable = (name, fields2, declaredOptions, baseName = name, kind = "schema
|
|
|
1240
2186
|
table.name = name;
|
|
1241
2187
|
table.columns = artifacts.columns;
|
|
1242
2188
|
defineSchemasGetter(table);
|
|
1243
|
-
table[
|
|
2189
|
+
table[TypeId7] = {
|
|
1244
2190
|
name,
|
|
1245
2191
|
baseName,
|
|
1246
2192
|
schemaName: resolvedSchemaName,
|
|
1247
2193
|
fields: fields2,
|
|
1248
2194
|
primaryKey: artifacts.primaryKey,
|
|
2195
|
+
conflictArbiters: artifacts.conflictArbiters,
|
|
1249
2196
|
kind,
|
|
1250
2197
|
casing
|
|
1251
2198
|
};
|
|
1252
|
-
table[
|
|
2199
|
+
table[TypeId4] = {
|
|
1253
2200
|
selection: artifacts.columns,
|
|
1254
2201
|
required: undefined,
|
|
1255
2202
|
available: {
|
|
@@ -1263,8 +2210,8 @@ var makeTable = (name, fields2, declaredOptions, baseName = name, kind = "schema
|
|
|
1263
2210
|
};
|
|
1264
2211
|
table[OptionsSymbol] = artifacts.normalizedOptions;
|
|
1265
2212
|
table[DeclaredOptionsSymbol] = declaredOptions;
|
|
1266
|
-
for (const [
|
|
1267
|
-
Object.defineProperty(table,
|
|
2213
|
+
for (const [key2, value] of Object.entries(artifacts.columns)) {
|
|
2214
|
+
Object.defineProperty(table, key2, {
|
|
1268
2215
|
enumerable: true,
|
|
1269
2216
|
value
|
|
1270
2217
|
});
|
|
@@ -1302,13 +2249,14 @@ var ensureClassArtifacts = (self) => {
|
|
|
1302
2249
|
if (cached) {
|
|
1303
2250
|
return cached;
|
|
1304
2251
|
}
|
|
1305
|
-
const state = self[
|
|
2252
|
+
const state = self[TypeId7];
|
|
1306
2253
|
const classOptions = self[options];
|
|
1307
2254
|
const table = applyDeclaredOptions(makeTable(state.name, state.fields, [], state.name, "schema", state.schemaName, state.schemaName === undefined || state.schemaName === "public" ? "default" : "explicit", state.casing), classOptions);
|
|
1308
2255
|
const artifacts = {
|
|
1309
2256
|
columns: table.columns,
|
|
1310
2257
|
normalizedOptions: table[OptionsSymbol],
|
|
1311
|
-
primaryKey: table[
|
|
2258
|
+
primaryKey: table[TypeId7].primaryKey,
|
|
2259
|
+
conflictArbiters: table[TypeId7].conflictArbiters
|
|
1312
2260
|
};
|
|
1313
2261
|
Object.defineProperty(self, CacheSymbol, {
|
|
1314
2262
|
configurable: true,
|
|
@@ -1317,42 +2265,58 @@ var ensureClassArtifacts = (self) => {
|
|
|
1317
2265
|
return artifacts;
|
|
1318
2266
|
};
|
|
1319
2267
|
var appendOption = (table, option) => {
|
|
1320
|
-
const state = table[
|
|
2268
|
+
const state = table[TypeId7];
|
|
1321
2269
|
return makeTable(state.name, state.fields, [...table[DeclaredOptionsSymbol], option], state.baseName, state.kind, state.schemaName, "explicit", state.casing);
|
|
1322
2270
|
};
|
|
1323
2271
|
var makeOption = (option) => {
|
|
1324
2272
|
return attachPipe3(Object.assign((table, ..._validation) => appendOption(table, option), { option }));
|
|
1325
2273
|
};
|
|
2274
|
+
var makeResolvedOption = (option, resolve) => {
|
|
2275
|
+
return attachPipe3(Object.assign((table, ..._validation) => appendOption(table, resolve(table)), {
|
|
2276
|
+
option,
|
|
2277
|
+
[ResolveOptionSymbol]: resolve
|
|
2278
|
+
}));
|
|
2279
|
+
};
|
|
1326
2280
|
var option = (spec) => makeOption(spec);
|
|
2281
|
+
var optionFromTable = (spec, resolve) => makeResolvedOption(spec, resolve);
|
|
2282
|
+
var resolveOption = (option2, table) => {
|
|
2283
|
+
const resolve = option2[ResolveOptionSymbol];
|
|
2284
|
+
return resolve === undefined ? option2.option : resolve(table);
|
|
2285
|
+
};
|
|
2286
|
+
var mapOption = (option2, map) => {
|
|
2287
|
+
const resolve = option2[ResolveOptionSymbol];
|
|
2288
|
+
return resolve === undefined ? makeOption(map(option2.option)) : makeResolvedOption(map(option2.option), (table) => map(resolve(table)));
|
|
2289
|
+
};
|
|
1327
2290
|
function make(name, fields2, schemaName) {
|
|
1328
2291
|
const resolvedSchemaName = arguments.length >= 3 ? schemaName : "public";
|
|
1329
2292
|
return makeTable(name, fields2, [], name, "schema", resolvedSchemaName, arguments.length >= 3 ? "explicit" : "default");
|
|
1330
2293
|
}
|
|
1331
2294
|
var withCasing = (table, casing) => {
|
|
1332
|
-
const state = table[
|
|
2295
|
+
const state = table[TypeId7];
|
|
1333
2296
|
return makeTable(state.name, state.fields, table[DeclaredOptionsSymbol], state.baseName, state.kind, state.schemaName, "explicit", merge(state.casing, casing));
|
|
1334
2297
|
};
|
|
1335
2298
|
var withSchema = (table, schemaName, schemaCasing) => {
|
|
1336
|
-
const state = table[
|
|
2299
|
+
const state = table[TypeId7];
|
|
1337
2300
|
return makeTable(state.name, state.fields, table[DeclaredOptionsSymbol], state.baseName, state.kind, schemaName, "explicit", merge(schemaCasing, state.casing));
|
|
1338
2301
|
};
|
|
1339
2302
|
var alias = (table, aliasName) => {
|
|
1340
|
-
const state = table[
|
|
1341
|
-
const columns = Object.fromEntries(Object.entries(state.fields).map(([
|
|
2303
|
+
const state = table[TypeId7];
|
|
2304
|
+
const columns = Object.fromEntries(Object.entries(state.fields).map(([key2, column]) => [key2, bindColumn(aliasName, key2, column, state.baseName, state.schemaName, state.casing)]));
|
|
1342
2305
|
const aliased = attachPipe3(Object.create(TableProto));
|
|
1343
2306
|
aliased.name = aliasName;
|
|
1344
2307
|
aliased.columns = columns;
|
|
1345
2308
|
defineSchemasGetter(aliased);
|
|
1346
|
-
aliased[
|
|
2309
|
+
aliased[TypeId7] = {
|
|
1347
2310
|
name: aliasName,
|
|
1348
2311
|
baseName: state.baseName,
|
|
1349
2312
|
schemaName: state.schemaName,
|
|
1350
2313
|
fields: state.fields,
|
|
1351
2314
|
primaryKey: state.primaryKey,
|
|
2315
|
+
conflictArbiters: state.conflictArbiters,
|
|
1352
2316
|
kind: "alias",
|
|
1353
2317
|
casing: state.casing
|
|
1354
2318
|
};
|
|
1355
|
-
aliased[
|
|
2319
|
+
aliased[TypeId4] = {
|
|
1356
2320
|
selection: columns,
|
|
1357
2321
|
required: undefined,
|
|
1358
2322
|
available: {
|
|
@@ -1362,12 +2326,12 @@ var alias = (table, aliasName) => {
|
|
|
1362
2326
|
baseName: state.baseName
|
|
1363
2327
|
}
|
|
1364
2328
|
},
|
|
1365
|
-
dialect: table[
|
|
2329
|
+
dialect: table[TypeId4].dialect
|
|
1366
2330
|
};
|
|
1367
2331
|
aliased[OptionsSymbol] = table[OptionsSymbol];
|
|
1368
2332
|
aliased[DeclaredOptionsSymbol] = table[DeclaredOptionsSymbol];
|
|
1369
|
-
for (const [
|
|
1370
|
-
Object.defineProperty(aliased,
|
|
2333
|
+
for (const [key2, value] of Object.entries(columns)) {
|
|
2334
|
+
Object.defineProperty(aliased, key2, {
|
|
1371
2335
|
enumerable: true,
|
|
1372
2336
|
value
|
|
1373
2337
|
});
|
|
@@ -1386,18 +2350,20 @@ function Class(name, schemaName) {
|
|
|
1386
2350
|
static get schemas() {
|
|
1387
2351
|
return schemasFor(this);
|
|
1388
2352
|
}
|
|
1389
|
-
static get [
|
|
2353
|
+
static get [TypeId7]() {
|
|
1390
2354
|
const declaredOptions = extractDeclaredOptions(this[options]);
|
|
2355
|
+
const normalizedOptions = [...collectInlineOptions(fields2), ...declaredOptions];
|
|
1391
2356
|
return {
|
|
1392
2357
|
name,
|
|
1393
2358
|
baseName: name,
|
|
1394
2359
|
schemaName: resolvedSchemaName,
|
|
1395
2360
|
fields: fields2,
|
|
1396
2361
|
primaryKey: resolvePrimaryKeyColumns(fields2, collectInlineOptions(fields2)),
|
|
2362
|
+
conflictArbiters: conflictArbitersFromOptions(normalizedOptions),
|
|
1397
2363
|
kind: "schema"
|
|
1398
2364
|
};
|
|
1399
2365
|
}
|
|
1400
|
-
static get [
|
|
2366
|
+
static get [TypeId4]() {
|
|
1401
2367
|
const artifacts = ensureClassArtifacts(this);
|
|
1402
2368
|
return {
|
|
1403
2369
|
selection: artifacts.columns,
|
|
@@ -1416,49 +2382,83 @@ function Class(name, schemaName) {
|
|
|
1416
2382
|
return ensureClassArtifacts(this).normalizedOptions;
|
|
1417
2383
|
}
|
|
1418
2384
|
static pipe() {
|
|
1419
|
-
return
|
|
2385
|
+
return pipeArguments4(this, arguments);
|
|
1420
2386
|
}
|
|
1421
2387
|
}
|
|
1422
|
-
for (const
|
|
1423
|
-
Object.defineProperty(TableClassBase,
|
|
2388
|
+
for (const key2 of Object.keys(fields2)) {
|
|
2389
|
+
Object.defineProperty(TableClassBase, key2, {
|
|
1424
2390
|
enumerable: true,
|
|
1425
2391
|
configurable: true,
|
|
1426
2392
|
get() {
|
|
1427
|
-
return ensureClassArtifacts(this).columns[
|
|
2393
|
+
return ensureClassArtifacts(this).columns[key2];
|
|
1428
2394
|
}
|
|
1429
2395
|
});
|
|
1430
2396
|
}
|
|
1431
2397
|
return TableClassBase;
|
|
1432
2398
|
};
|
|
1433
2399
|
}
|
|
1434
|
-
var
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
}
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
columns:
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
2400
|
+
var selectionArray = (selection) => Array.isArray(selection) ? selection : [selection];
|
|
2401
|
+
var selectedColumnList = (selection) => selectionArray(selection).map((column) => column[BoundColumnTypeId].columnName);
|
|
2402
|
+
var referenceFromSelection = (selection) => {
|
|
2403
|
+
const columns = selectionArray(selection);
|
|
2404
|
+
const first = columns[0];
|
|
2405
|
+
const bound = first[BoundColumnTypeId];
|
|
2406
|
+
return {
|
|
2407
|
+
tableName: bound.baseTableName,
|
|
2408
|
+
schemaName: bound.schemaName,
|
|
2409
|
+
casing: bound.casing,
|
|
2410
|
+
columns: columns.map((column) => column[BoundColumnTypeId].columnName)
|
|
2411
|
+
};
|
|
2412
|
+
};
|
|
2413
|
+
function primaryKey2(columns) {
|
|
2414
|
+
return makeResolvedOption({
|
|
2415
|
+
kind: "primaryKey",
|
|
2416
|
+
columns: []
|
|
2417
|
+
}, (table) => ({
|
|
2418
|
+
kind: "primaryKey",
|
|
2419
|
+
columns: selectedColumnList(columns(table))
|
|
2420
|
+
}));
|
|
2421
|
+
}
|
|
2422
|
+
function unique2(columns) {
|
|
2423
|
+
return makeResolvedOption({
|
|
2424
|
+
kind: "unique",
|
|
2425
|
+
columns: []
|
|
2426
|
+
}, (table) => ({
|
|
2427
|
+
kind: "unique",
|
|
2428
|
+
columns: selectedColumnList(columns(table))
|
|
2429
|
+
}));
|
|
2430
|
+
}
|
|
2431
|
+
function index3(columns) {
|
|
2432
|
+
return makeResolvedOption({
|
|
2433
|
+
kind: "index",
|
|
2434
|
+
columns: []
|
|
2435
|
+
}, (table) => ({
|
|
2436
|
+
kind: "index",
|
|
2437
|
+
columns: selectedColumnList(columns(table))
|
|
2438
|
+
}));
|
|
2439
|
+
}
|
|
2440
|
+
function foreignKey2(columns, target) {
|
|
2441
|
+
return makeResolvedOption({
|
|
2442
|
+
kind: "foreignKey",
|
|
2443
|
+
columns: [],
|
|
2444
|
+
references: () => referenceFromSelection(target())
|
|
2445
|
+
}, (table) => ({
|
|
2446
|
+
kind: "foreignKey",
|
|
2447
|
+
columns: selectedColumnList(columns(table)),
|
|
2448
|
+
references: () => referenceFromSelection(target())
|
|
2449
|
+
}));
|
|
2450
|
+
}
|
|
2451
|
+
function check2(name, predicate) {
|
|
2452
|
+
const spec = {
|
|
2453
|
+
kind: "check",
|
|
2454
|
+
name,
|
|
2455
|
+
predicate
|
|
2456
|
+
};
|
|
2457
|
+
return typeof predicate === "function" ? makeResolvedOption(spec, (table) => ({
|
|
2458
|
+
...spec,
|
|
2459
|
+
predicate: predicate(table)
|
|
2460
|
+
})) : makeOption(spec);
|
|
2461
|
+
}
|
|
1462
2462
|
|
|
1463
2463
|
// src/internal/runtime/normalize.ts
|
|
1464
2464
|
var isRecord2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -1711,9 +2711,9 @@ var normalizeDbValue = (dbType, value) => {
|
|
|
1711
2711
|
throw new Error("Expected a record value");
|
|
1712
2712
|
}
|
|
1713
2713
|
const normalized = {};
|
|
1714
|
-
for (const [
|
|
1715
|
-
if (
|
|
1716
|
-
normalized[
|
|
2714
|
+
for (const [key2, fieldDbType] of Object.entries(dbType.fields)) {
|
|
2715
|
+
if (key2 in value) {
|
|
2716
|
+
normalized[key2] = normalizeDbValue(fieldDbType, value[key2]);
|
|
1717
2717
|
}
|
|
1718
2718
|
}
|
|
1719
2719
|
return normalized;
|
|
@@ -1770,10 +2770,10 @@ var normalizeDbValue = (dbType, value) => {
|
|
|
1770
2770
|
};
|
|
1771
2771
|
|
|
1772
2772
|
// src/internal/query.ts
|
|
1773
|
-
import { pipeArguments as
|
|
2773
|
+
import { pipeArguments as pipeArguments5 } from "effect/Pipeable";
|
|
1774
2774
|
|
|
1775
2775
|
// src/internal/query-ast.ts
|
|
1776
|
-
var
|
|
2776
|
+
var TypeId8 = Symbol.for("effect-qb/QueryAst");
|
|
1777
2777
|
|
|
1778
2778
|
// src/internal/predicate/runtime.ts
|
|
1779
2779
|
var trueFormula = () => ({ kind: "true" });
|
|
@@ -1798,17 +2798,17 @@ var cloneContext = (context) => ({
|
|
|
1798
2798
|
nonNullKeys: new Set(context.nonNullKeys),
|
|
1799
2799
|
nullKeys: new Set(context.nullKeys),
|
|
1800
2800
|
eqLiterals: new Map(context.eqLiterals),
|
|
1801
|
-
neqLiterals: new Map(Array.from(context.neqLiterals.entries(), ([
|
|
1802
|
-
literalSets: new Map(Array.from(context.literalSets.entries(), ([
|
|
2801
|
+
neqLiterals: new Map(Array.from(context.neqLiterals.entries(), ([key2, values]) => [key2, new Set(values)])),
|
|
2802
|
+
literalSets: new Map(Array.from(context.literalSets.entries(), ([key2, values]) => [key2, new Set(values)])),
|
|
1803
2803
|
sourceNames: new Set(context.sourceNames),
|
|
1804
2804
|
contradiction: context.contradiction,
|
|
1805
2805
|
unknown: context.unknown
|
|
1806
2806
|
});
|
|
1807
2807
|
var freezeContext = (context) => context;
|
|
1808
2808
|
var columnPredicateKey = (tableName, columnName) => JSON.stringify([tableName, columnName]);
|
|
1809
|
-
var columnPredicateKeyParts = (
|
|
1810
|
-
const jsonSeparator =
|
|
1811
|
-
const columnKey = jsonSeparator === -1 ?
|
|
2809
|
+
var columnPredicateKeyParts = (key2) => {
|
|
2810
|
+
const jsonSeparator = key2.indexOf("#json:");
|
|
2811
|
+
const columnKey = jsonSeparator === -1 ? key2 : key2.slice(0, jsonSeparator);
|
|
1812
2812
|
try {
|
|
1813
2813
|
const parsed = JSON.parse(columnKey);
|
|
1814
2814
|
return Array.isArray(parsed) && parsed.length === 2 && typeof parsed[0] === "string" && typeof parsed[1] === "string" ? [parsed[0], parsed[1]] : undefined;
|
|
@@ -1816,59 +2816,59 @@ var columnPredicateKeyParts = (key) => {
|
|
|
1816
2816
|
return;
|
|
1817
2817
|
}
|
|
1818
2818
|
};
|
|
1819
|
-
var sourceNameOfKey = (
|
|
1820
|
-
var addSourceName = (context,
|
|
1821
|
-
context.sourceNames.add(sourceNameOfKey(
|
|
2819
|
+
var sourceNameOfKey = (key2) => columnPredicateKeyParts(key2)?.[0] ?? key2.split(".", 1)[0] ?? key2;
|
|
2820
|
+
var addSourceName = (context, key2) => {
|
|
2821
|
+
context.sourceNames.add(sourceNameOfKey(key2));
|
|
1822
2822
|
};
|
|
1823
|
-
var addNonNull = (context,
|
|
1824
|
-
addSourceName(context,
|
|
1825
|
-
if (context.nullKeys.has(
|
|
2823
|
+
var addNonNull = (context, key2) => {
|
|
2824
|
+
addSourceName(context, key2);
|
|
2825
|
+
if (context.nullKeys.has(key2)) {
|
|
1826
2826
|
context.contradiction = true;
|
|
1827
2827
|
}
|
|
1828
|
-
context.nonNullKeys.add(
|
|
2828
|
+
context.nonNullKeys.add(key2);
|
|
1829
2829
|
};
|
|
1830
|
-
var addNull = (context,
|
|
1831
|
-
addSourceName(context,
|
|
1832
|
-
if (context.nonNullKeys.has(
|
|
2830
|
+
var addNull = (context, key2) => {
|
|
2831
|
+
addSourceName(context, key2);
|
|
2832
|
+
if (context.nonNullKeys.has(key2)) {
|
|
1833
2833
|
context.contradiction = true;
|
|
1834
2834
|
}
|
|
1835
|
-
context.nullKeys.add(
|
|
2835
|
+
context.nullKeys.add(key2);
|
|
1836
2836
|
};
|
|
1837
|
-
var addEqLiteral = (context,
|
|
1838
|
-
addNonNull(context,
|
|
1839
|
-
const existing = context.eqLiterals.get(
|
|
2837
|
+
var addEqLiteral = (context, key2, value) => {
|
|
2838
|
+
addNonNull(context, key2);
|
|
2839
|
+
const existing = context.eqLiterals.get(key2);
|
|
1840
2840
|
if (existing !== undefined && existing !== value) {
|
|
1841
2841
|
context.contradiction = true;
|
|
1842
2842
|
}
|
|
1843
|
-
const neqValues = context.neqLiterals.get(
|
|
2843
|
+
const neqValues = context.neqLiterals.get(key2);
|
|
1844
2844
|
if (neqValues?.has(value)) {
|
|
1845
2845
|
context.contradiction = true;
|
|
1846
2846
|
}
|
|
1847
|
-
const existingSet = context.literalSets.get(
|
|
2847
|
+
const existingSet = context.literalSets.get(key2);
|
|
1848
2848
|
if (existingSet !== undefined && !existingSet.has(value)) {
|
|
1849
2849
|
context.contradiction = true;
|
|
1850
2850
|
}
|
|
1851
|
-
context.eqLiterals.set(
|
|
1852
|
-
context.literalSets.set(
|
|
2851
|
+
context.eqLiterals.set(key2, value);
|
|
2852
|
+
context.literalSets.set(key2, new Set([value]));
|
|
1853
2853
|
};
|
|
1854
|
-
var addNeqLiteral = (context,
|
|
1855
|
-
addNonNull(context,
|
|
1856
|
-
if (context.eqLiterals.get(
|
|
2854
|
+
var addNeqLiteral = (context, key2, value) => {
|
|
2855
|
+
addNonNull(context, key2);
|
|
2856
|
+
if (context.eqLiterals.get(key2) === value) {
|
|
1857
2857
|
context.contradiction = true;
|
|
1858
2858
|
}
|
|
1859
|
-
const values = context.neqLiterals.get(
|
|
2859
|
+
const values = context.neqLiterals.get(key2) ?? new Set;
|
|
1860
2860
|
values.add(value);
|
|
1861
|
-
context.neqLiterals.set(
|
|
2861
|
+
context.neqLiterals.set(key2, values);
|
|
1862
2862
|
};
|
|
1863
|
-
var addLiteralSet = (context,
|
|
1864
|
-
addNonNull(context,
|
|
1865
|
-
const existingEq = context.eqLiterals.get(
|
|
2863
|
+
var addLiteralSet = (context, key2, values) => {
|
|
2864
|
+
addNonNull(context, key2);
|
|
2865
|
+
const existingEq = context.eqLiterals.get(key2);
|
|
1866
2866
|
if (existingEq !== undefined && !values.has(existingEq)) {
|
|
1867
2867
|
context.contradiction = true;
|
|
1868
2868
|
}
|
|
1869
|
-
const existing = context.literalSets.get(
|
|
1870
|
-
context.literalSets.set(
|
|
1871
|
-
if (context.literalSets.get(
|
|
2869
|
+
const existing = context.literalSets.get(key2);
|
|
2870
|
+
context.literalSets.set(key2, existing === undefined ? new Set(values) : new Set(Array.from(existing).filter((value) => values.has(value))));
|
|
2871
|
+
if (context.literalSets.get(key2)?.size === 0) {
|
|
1872
2872
|
context.contradiction = true;
|
|
1873
2873
|
}
|
|
1874
2874
|
};
|
|
@@ -1950,35 +2950,35 @@ var applyNegativeAtom = (context, atom) => {
|
|
|
1950
2950
|
};
|
|
1951
2951
|
var intersectEqLiterals = (left, right) => {
|
|
1952
2952
|
const result = new Map;
|
|
1953
|
-
for (const [
|
|
1954
|
-
if (right.get(
|
|
1955
|
-
result.set(
|
|
2953
|
+
for (const [key2, value] of left) {
|
|
2954
|
+
if (right.get(key2) === value) {
|
|
2955
|
+
result.set(key2, value);
|
|
1956
2956
|
}
|
|
1957
2957
|
}
|
|
1958
2958
|
return result;
|
|
1959
2959
|
};
|
|
1960
2960
|
var intersectNeqLiterals = (left, right) => {
|
|
1961
2961
|
const result = new Map;
|
|
1962
|
-
for (const [
|
|
1963
|
-
const rightValues = right.get(
|
|
2962
|
+
for (const [key2, leftValues] of left) {
|
|
2963
|
+
const rightValues = right.get(key2);
|
|
1964
2964
|
if (rightValues === undefined) {
|
|
1965
2965
|
continue;
|
|
1966
2966
|
}
|
|
1967
2967
|
const next = new Set(Array.from(leftValues).filter((value) => rightValues.has(value)));
|
|
1968
2968
|
if (next.size > 0) {
|
|
1969
|
-
result.set(
|
|
2969
|
+
result.set(key2, next);
|
|
1970
2970
|
}
|
|
1971
2971
|
}
|
|
1972
2972
|
return result;
|
|
1973
2973
|
};
|
|
1974
2974
|
var unionLiteralSets = (left, right) => {
|
|
1975
2975
|
const result = new Map;
|
|
1976
|
-
for (const [
|
|
1977
|
-
const rightValues = right.get(
|
|
2976
|
+
for (const [key2, leftValues] of left) {
|
|
2977
|
+
const rightValues = right.get(key2);
|
|
1978
2978
|
if (rightValues === undefined) {
|
|
1979
2979
|
continue;
|
|
1980
2980
|
}
|
|
1981
|
-
result.set(
|
|
2981
|
+
result.set(key2, new Set([...leftValues, ...rightValues]));
|
|
1982
2982
|
}
|
|
1983
2983
|
return result;
|
|
1984
2984
|
};
|
|
@@ -1990,8 +2990,8 @@ var intersectContexts = (left, right) => {
|
|
|
1990
2990
|
return cloneContext(left);
|
|
1991
2991
|
}
|
|
1992
2992
|
return {
|
|
1993
|
-
nonNullKeys: new Set(Array.from(left.nonNullKeys).filter((
|
|
1994
|
-
nullKeys: new Set(Array.from(left.nullKeys).filter((
|
|
2993
|
+
nonNullKeys: new Set(Array.from(left.nonNullKeys).filter((key2) => right.nonNullKeys.has(key2))),
|
|
2994
|
+
nullKeys: new Set(Array.from(left.nullKeys).filter((key2) => right.nullKeys.has(key2))),
|
|
1995
2995
|
eqLiterals: intersectEqLiterals(left.eqLiterals, right.eqLiterals),
|
|
1996
2996
|
neqLiterals: intersectNeqLiterals(left.neqLiterals, right.neqLiterals),
|
|
1997
2997
|
literalSets: unionLiteralSets(left.literalSets, right.literalSets),
|
|
@@ -2082,18 +3082,18 @@ var jsonPathPredicateKeyOfExpression = (value) => {
|
|
|
2082
3082
|
if (segments.length === 0 || segments.length > 8) {
|
|
2083
3083
|
return;
|
|
2084
3084
|
}
|
|
2085
|
-
const
|
|
3085
|
+
const path2 = [];
|
|
2086
3086
|
for (const segment of segments) {
|
|
2087
3087
|
if (typeof segment !== "object" || segment === null || segment.kind !== "key") {
|
|
2088
3088
|
return;
|
|
2089
3089
|
}
|
|
2090
|
-
|
|
3090
|
+
path2.push(segment.key);
|
|
2091
3091
|
}
|
|
2092
|
-
if (
|
|
3092
|
+
if (path2.length === 0) {
|
|
2093
3093
|
return;
|
|
2094
3094
|
}
|
|
2095
3095
|
const baseKey = columnKeyOfExpression(jsonAst.base);
|
|
2096
|
-
return baseKey === undefined ? undefined : `${baseKey}#json:${
|
|
3096
|
+
return baseKey === undefined ? undefined : `${baseKey}#json:${path2.map(escapeJsonPathPredicateKeySegment).join(".")}`;
|
|
2097
3097
|
}
|
|
2098
3098
|
default:
|
|
2099
3099
|
return;
|
|
@@ -2130,8 +3130,8 @@ var valueKeyOfLiteral = (value) => {
|
|
|
2130
3130
|
return "unknown";
|
|
2131
3131
|
};
|
|
2132
3132
|
var nonNullFactsOfExpression = (value) => {
|
|
2133
|
-
const
|
|
2134
|
-
return
|
|
3133
|
+
const key2 = predicateKeyOfExpression(value);
|
|
3134
|
+
return key2 === undefined ? undefined : atomFormula({ kind: "is-not-null", key: key2 });
|
|
2135
3135
|
};
|
|
2136
3136
|
var combineFacts = (left, right) => {
|
|
2137
3137
|
if (left === undefined) {
|
|
@@ -2342,12 +3342,12 @@ var formulaOfExpression = (value) => {
|
|
|
2342
3342
|
}
|
|
2343
3343
|
return unknownTag("literal:non-boolean");
|
|
2344
3344
|
case "isNull": {
|
|
2345
|
-
const
|
|
2346
|
-
return
|
|
3345
|
+
const key2 = predicateKeyOfExpression(ast.value);
|
|
3346
|
+
return key2 === undefined ? unknownTag("isNull:unsupported") : atomFormula({ kind: "is-null", key: key2 });
|
|
2347
3347
|
}
|
|
2348
3348
|
case "isNotNull": {
|
|
2349
|
-
const
|
|
2350
|
-
return
|
|
3349
|
+
const key2 = predicateKeyOfExpression(ast.value);
|
|
3350
|
+
return key2 === undefined ? unknownTag("isNotNull:unsupported") : atomFormula({ kind: "is-not-null", key: key2 });
|
|
2351
3351
|
}
|
|
2352
3352
|
case "not":
|
|
2353
3353
|
return notFormula(formulaOfExpression(ast.value));
|
|
@@ -2368,12 +3368,12 @@ var formulaOfExpression = (value) => {
|
|
|
2368
3368
|
if (left === undefined) {
|
|
2369
3369
|
return falseFormula();
|
|
2370
3370
|
}
|
|
2371
|
-
const
|
|
3371
|
+
const key2 = predicateKeyOfExpression(left);
|
|
2372
3372
|
const literalValues = rest.map((entry) => {
|
|
2373
3373
|
const entryAst = astOf(entry);
|
|
2374
3374
|
return entryAst.kind === "literal" && entryAst.value !== null ? valueKeyOfLiteral(entryAst.value) : undefined;
|
|
2375
3375
|
});
|
|
2376
|
-
return
|
|
3376
|
+
return key2 !== undefined && literalValues.every((entry) => entry !== undefined) ? atomFormula({ kind: "literal-set", key: key2, values: literalValues }) : anyFormula(rest.map((value2) => formulaOfEq(left, value2)));
|
|
2377
3377
|
}
|
|
2378
3378
|
case "notIn": {
|
|
2379
3379
|
const [left, ...rest] = ast.values;
|
|
@@ -2406,12 +3406,12 @@ var guaranteedSourceNames = (assumptions) => analyzeFormula(assumptions).sourceN
|
|
|
2406
3406
|
// src/internal/query.ts
|
|
2407
3407
|
var ExpressionProto = {
|
|
2408
3408
|
pipe() {
|
|
2409
|
-
return
|
|
3409
|
+
return pipeArguments5(this, arguments);
|
|
2410
3410
|
}
|
|
2411
3411
|
};
|
|
2412
3412
|
var PlanProto = {
|
|
2413
3413
|
pipe() {
|
|
2414
|
-
return
|
|
3414
|
+
return pipeArguments5(this, arguments);
|
|
2415
3415
|
}
|
|
2416
3416
|
};
|
|
2417
3417
|
var QueryTypeId = Symbol.for("effect-qb/Query/internal");
|
|
@@ -2424,13 +3424,13 @@ var mergeAggregationManyRuntime = (values) => values.reduce((current, value) =>
|
|
|
2424
3424
|
var mergeNullabilityRuntime = (left, right = "never") => left === "always" || right === "always" ? "always" : left === "maybe" || right === "maybe" ? "maybe" : "never";
|
|
2425
3425
|
var mergeNullabilityManyRuntime = (values) => values.reduce((current, value) => mergeNullabilityRuntime(current, value[TypeId].nullability), "never");
|
|
2426
3426
|
var mergeManyDependencies = (values) => values.reduce((current, value) => mergeDependencies(current, value[TypeId].dependencies), {});
|
|
2427
|
-
var
|
|
3427
|
+
var makeExpression2 = (state, ast) => {
|
|
2428
3428
|
const expression = Object.create(ExpressionProto);
|
|
2429
3429
|
Object.defineProperty(expression, "pipe", {
|
|
2430
3430
|
configurable: true,
|
|
2431
3431
|
writable: true,
|
|
2432
3432
|
value: function() {
|
|
2433
|
-
return
|
|
3433
|
+
return pipeArguments5(expression, arguments);
|
|
2434
3434
|
}
|
|
2435
3435
|
});
|
|
2436
3436
|
expression[TypeId] = {
|
|
@@ -2452,11 +3452,11 @@ var makePlan = (state, ast, _assumptions, _capabilities, _statement, _target, _i
|
|
|
2452
3452
|
configurable: true,
|
|
2453
3453
|
writable: true,
|
|
2454
3454
|
value: function() {
|
|
2455
|
-
return
|
|
3455
|
+
return pipeArguments5(plan, arguments);
|
|
2456
3456
|
}
|
|
2457
3457
|
});
|
|
2458
|
-
plan[
|
|
2459
|
-
plan[
|
|
3458
|
+
plan[TypeId4] = state;
|
|
3459
|
+
plan[TypeId8] = ast;
|
|
2460
3460
|
plan[QueryTypeId] = {
|
|
2461
3461
|
required: undefined,
|
|
2462
3462
|
availableNames: undefined,
|
|
@@ -2470,7 +3470,7 @@ var makePlan = (state, ast, _assumptions, _capabilities, _statement, _target, _i
|
|
|
2470
3470
|
};
|
|
2471
3471
|
return plan;
|
|
2472
3472
|
};
|
|
2473
|
-
var getAst = (plan) => plan[
|
|
3473
|
+
var getAst = (plan) => plan[TypeId8];
|
|
2474
3474
|
var getQueryState = (plan) => plan[QueryTypeId];
|
|
2475
3475
|
var extractRequiredRuntime = (selection) => {
|
|
2476
3476
|
const required = new Set;
|
|
@@ -2517,8 +3517,8 @@ var presenceWitnessesOfSourceLike = (source) => {
|
|
|
2517
3517
|
if (typeof source !== "object" || source === null) {
|
|
2518
3518
|
return [];
|
|
2519
3519
|
}
|
|
2520
|
-
if (
|
|
2521
|
-
collectPresenceWitnesses(source[
|
|
3520
|
+
if (TypeId7 in source) {
|
|
3521
|
+
collectPresenceWitnesses(source[TypeId4].selection, output);
|
|
2522
3522
|
return [...output];
|
|
2523
3523
|
}
|
|
2524
3524
|
if ("columns" in source) {
|
|
@@ -2530,7 +3530,7 @@ var directAbsentSourceNames = (available, assumptions) => {
|
|
|
2530
3530
|
const nullKeys = guaranteedNullKeys(assumptions);
|
|
2531
3531
|
const absent = new Set;
|
|
2532
3532
|
for (const [name, source] of Object.entries(available)) {
|
|
2533
|
-
if (source._presenceWitnesses?.some((
|
|
3533
|
+
if (source._presenceWitnesses?.some((key2) => nullKeys.has(key2))) {
|
|
2534
3534
|
absent.add(name);
|
|
2535
3535
|
continue;
|
|
2536
3536
|
}
|
|
@@ -2607,51 +3607,6 @@ var resolveImplicationScope = (available, initialAssumptions) => {
|
|
|
2607
3607
|
};
|
|
2608
3608
|
};
|
|
2609
3609
|
|
|
2610
|
-
// src/internal/json/path.ts
|
|
2611
|
-
var SegmentTypeId = Symbol.for("effect-qb/JsonPathSegment");
|
|
2612
|
-
var TypeId8 = Symbol.for("effect-qb/JsonPath");
|
|
2613
|
-
var makeSegment = (segment) => segment;
|
|
2614
|
-
var key = (value) => makeSegment({
|
|
2615
|
-
[SegmentTypeId]: {
|
|
2616
|
-
kind: "key"
|
|
2617
|
-
},
|
|
2618
|
-
kind: "key",
|
|
2619
|
-
key: value
|
|
2620
|
-
});
|
|
2621
|
-
var index3 = (value) => makeSegment({
|
|
2622
|
-
[SegmentTypeId]: {
|
|
2623
|
-
kind: "index"
|
|
2624
|
-
},
|
|
2625
|
-
kind: "index",
|
|
2626
|
-
index: value
|
|
2627
|
-
});
|
|
2628
|
-
var wildcard = () => makeSegment({
|
|
2629
|
-
[SegmentTypeId]: {
|
|
2630
|
-
kind: "wildcard"
|
|
2631
|
-
},
|
|
2632
|
-
kind: "wildcard"
|
|
2633
|
-
});
|
|
2634
|
-
var slice = (start, end) => makeSegment({
|
|
2635
|
-
[SegmentTypeId]: {
|
|
2636
|
-
kind: "slice"
|
|
2637
|
-
},
|
|
2638
|
-
kind: "slice",
|
|
2639
|
-
start,
|
|
2640
|
-
end
|
|
2641
|
-
});
|
|
2642
|
-
var descend = () => makeSegment({
|
|
2643
|
-
[SegmentTypeId]: {
|
|
2644
|
-
kind: "descend"
|
|
2645
|
-
},
|
|
2646
|
-
kind: "descend"
|
|
2647
|
-
});
|
|
2648
|
-
var path = (...segments) => ({
|
|
2649
|
-
[TypeId8]: {
|
|
2650
|
-
segments
|
|
2651
|
-
},
|
|
2652
|
-
segments
|
|
2653
|
-
});
|
|
2654
|
-
|
|
2655
3610
|
// src/internal/grouping-key.ts
|
|
2656
3611
|
var subqueryPlanIds = new WeakMap;
|
|
2657
3612
|
var nextSubqueryPlanId = 0;
|
|
@@ -2685,8 +3640,8 @@ var literalGroupingKey = (value) => {
|
|
|
2685
3640
|
return `literal:${JSON.stringify(value)}`;
|
|
2686
3641
|
}
|
|
2687
3642
|
};
|
|
2688
|
-
var
|
|
2689
|
-
var expressionGroupingKey = (value) =>
|
|
3643
|
+
var isExpression2 = (value) => value !== null && typeof value === "object" && (TypeId in value);
|
|
3644
|
+
var expressionGroupingKey = (value) => isExpression2(value) ? groupingKeyOfExpression(value) : "missing";
|
|
2690
3645
|
var requiredExpressionGroupingKey = (_functionName, value) => groupingKeyOfExpression(value);
|
|
2691
3646
|
var requiredBinaryExpressionGroupingKey = (_functionName, left, right) => `${groupingKeyOfExpression(left)},${groupingKeyOfExpression(right)}`;
|
|
2692
3647
|
var functionCallArgsGroupingKey = (args) => args.map(groupingKeyOfExpression).join(",");
|
|
@@ -2742,7 +3697,7 @@ var jsonPathGroupingKey = (segments) => {
|
|
|
2742
3697
|
}
|
|
2743
3698
|
return segments.map(jsonSegmentGroupingKey).join(",");
|
|
2744
3699
|
};
|
|
2745
|
-
var isJsonPath = (value) => value !== null && typeof value === "object" && (
|
|
3700
|
+
var isJsonPath = (value) => value !== null && typeof value === "object" && (TypeId3 in value);
|
|
2746
3701
|
var jsonOpaquePathGroupingKey = (value) => {
|
|
2747
3702
|
if (isJsonPath(value)) {
|
|
2748
3703
|
return `jsonpath:${jsonPathGroupingKey(value.segments)}`;
|
|
@@ -2750,7 +3705,7 @@ var jsonOpaquePathGroupingKey = (value) => {
|
|
|
2750
3705
|
if (typeof value === "string") {
|
|
2751
3706
|
return `jsonpath:${escapeGroupingText(value)}`;
|
|
2752
3707
|
}
|
|
2753
|
-
if (
|
|
3708
|
+
if (isExpression2(value)) {
|
|
2754
3709
|
return `jsonpath:${groupingKeyOfExpression(value)}`;
|
|
2755
3710
|
}
|
|
2756
3711
|
return "jsonpath:unknown";
|
|
@@ -3013,7 +3968,7 @@ var makeDslTransactionDdlRuntime = (ctx) => {
|
|
|
3013
3968
|
selection: {},
|
|
3014
3969
|
required: [],
|
|
3015
3970
|
available: {},
|
|
3016
|
-
dialect: target[
|
|
3971
|
+
dialect: target[TypeId4].dialect
|
|
3017
3972
|
}, {
|
|
3018
3973
|
kind: "createTable",
|
|
3019
3974
|
select: {},
|
|
@@ -3041,7 +3996,7 @@ var makeDslTransactionDdlRuntime = (ctx) => {
|
|
|
3041
3996
|
selection: {},
|
|
3042
3997
|
required: [],
|
|
3043
3998
|
available: {},
|
|
3044
|
-
dialect: target[
|
|
3999
|
+
dialect: target[TypeId4].dialect
|
|
3045
4000
|
}, {
|
|
3046
4001
|
kind: "dropTable",
|
|
3047
4002
|
select: {},
|
|
@@ -3072,7 +4027,7 @@ var makeDslTransactionDdlRuntime = (ctx) => {
|
|
|
3072
4027
|
selection: {},
|
|
3073
4028
|
required: [],
|
|
3074
4029
|
available: {},
|
|
3075
|
-
dialect: target[
|
|
4030
|
+
dialect: target[TypeId4].dialect
|
|
3076
4031
|
}, {
|
|
3077
4032
|
kind: "createIndex",
|
|
3078
4033
|
select: {},
|
|
@@ -3105,7 +4060,7 @@ var makeDslTransactionDdlRuntime = (ctx) => {
|
|
|
3105
4060
|
selection: {},
|
|
3106
4061
|
required: [],
|
|
3107
4062
|
available: {},
|
|
3108
|
-
dialect: target[
|
|
4063
|
+
dialect: target[TypeId4].dialect
|
|
3109
4064
|
}, {
|
|
3110
4065
|
kind: "dropIndex",
|
|
3111
4066
|
select: {},
|
|
@@ -3159,7 +4114,7 @@ var makeDslMutationRuntime = (ctx) => {
|
|
|
3159
4114
|
baseName: sourceBaseName
|
|
3160
4115
|
}
|
|
3161
4116
|
},
|
|
3162
|
-
dialect: target[
|
|
4117
|
+
dialect: target[TypeId4].dialect
|
|
3163
4118
|
}, {
|
|
3164
4119
|
kind: "insert",
|
|
3165
4120
|
select: {},
|
|
@@ -3179,7 +4134,7 @@ var makeDslMutationRuntime = (ctx) => {
|
|
|
3179
4134
|
}, undefined, "write", "insert", target, insertState);
|
|
3180
4135
|
};
|
|
3181
4136
|
const attachInsertSource = (plan, source) => {
|
|
3182
|
-
const current = plan[
|
|
4137
|
+
const current = plan[TypeId4];
|
|
3183
4138
|
const currentAst = ctx.getAst(plan);
|
|
3184
4139
|
const currentQuery = ctx.getQueryState(plan);
|
|
3185
4140
|
const target = currentQuery.target;
|
|
@@ -3219,11 +4174,11 @@ var makeDslMutationRuntime = (ctx) => {
|
|
|
3219
4174
|
}, currentQuery.assumptions, currentQuery.capabilities, currentQuery.statement, currentQuery.target, "ready");
|
|
3220
4175
|
}
|
|
3221
4176
|
const sourcePlan = source;
|
|
3222
|
-
const selection = sourcePlan[
|
|
4177
|
+
const selection = sourcePlan[TypeId4].selection;
|
|
3223
4178
|
const columns = ctx.normalizeInsertSelectColumns(selection);
|
|
3224
4179
|
return ctx.makePlan({
|
|
3225
4180
|
selection: current.selection,
|
|
3226
|
-
required: ctx.currentRequiredList(sourcePlan[
|
|
4181
|
+
required: ctx.currentRequiredList(sourcePlan[TypeId4].required),
|
|
3227
4182
|
available: current.available,
|
|
3228
4183
|
dialect: current.dialect
|
|
3229
4184
|
}, {
|
|
@@ -3237,7 +4192,7 @@ var makeDslMutationRuntime = (ctx) => {
|
|
|
3237
4192
|
}, currentQuery.assumptions, currentQuery.capabilities, currentQuery.statement, currentQuery.target, "ready");
|
|
3238
4193
|
};
|
|
3239
4194
|
const onConflict = (target, options2 = {}) => (plan) => {
|
|
3240
|
-
const current = plan[
|
|
4195
|
+
const current = plan[TypeId4];
|
|
3241
4196
|
const currentAst = ctx.getAst(plan);
|
|
3242
4197
|
const currentQuery = ctx.getQueryState(plan);
|
|
3243
4198
|
const insertTarget = currentAst.into.source;
|
|
@@ -3281,7 +4236,7 @@ var makeDslMutationRuntime = (ctx) => {
|
|
|
3281
4236
|
selection: {},
|
|
3282
4237
|
required,
|
|
3283
4238
|
available: ctx.mutationAvailableSources(target),
|
|
3284
|
-
dialect: primaryTarget.source[
|
|
4239
|
+
dialect: primaryTarget.source[TypeId4].dialect
|
|
3285
4240
|
}, {
|
|
3286
4241
|
kind: "update",
|
|
3287
4242
|
select: {},
|
|
@@ -3313,7 +4268,7 @@ var makeDslMutationRuntime = (ctx) => {
|
|
|
3313
4268
|
baseName: sourceBaseName
|
|
3314
4269
|
}
|
|
3315
4270
|
},
|
|
3316
|
-
dialect: target[
|
|
4271
|
+
dialect: target[TypeId4].dialect
|
|
3317
4272
|
}, {
|
|
3318
4273
|
kind: "insert",
|
|
3319
4274
|
select: {},
|
|
@@ -3347,7 +4302,7 @@ var makeDslMutationRuntime = (ctx) => {
|
|
|
3347
4302
|
selection: {},
|
|
3348
4303
|
required: [],
|
|
3349
4304
|
available: ctx.mutationAvailableSources(target),
|
|
3350
|
-
dialect: primaryTarget.source[
|
|
4305
|
+
dialect: primaryTarget.source[TypeId4].dialect
|
|
3351
4306
|
}, {
|
|
3352
4307
|
kind: "delete",
|
|
3353
4308
|
select: {},
|
|
@@ -3368,7 +4323,7 @@ var makeDslMutationRuntime = (ctx) => {
|
|
|
3368
4323
|
selection: {},
|
|
3369
4324
|
required: [],
|
|
3370
4325
|
available: {},
|
|
3371
|
-
dialect: target[
|
|
4326
|
+
dialect: target[TypeId4].dialect
|
|
3372
4327
|
}, {
|
|
3373
4328
|
kind: "truncate",
|
|
3374
4329
|
select: {},
|
|
@@ -3422,7 +4377,7 @@ var makeDslMutationRuntime = (ctx) => {
|
|
|
3422
4377
|
baseName: usingBaseName
|
|
3423
4378
|
}
|
|
3424
4379
|
},
|
|
3425
|
-
dialect: target[
|
|
4380
|
+
dialect: target[TypeId4].dialect
|
|
3426
4381
|
}, {
|
|
3427
4382
|
kind: "merge",
|
|
3428
4383
|
select: {},
|
|
@@ -3485,7 +4440,7 @@ var renderMysqlMutationLockMode = (mode, _statement) => {
|
|
|
3485
4440
|
var makeDslPlanRuntime = (ctx) => {
|
|
3486
4441
|
const sourceRequiredList = (source) => typeof source === "object" && source !== null && ("required" in source) ? ctx.currentRequiredList(source.required) : [];
|
|
3487
4442
|
const buildSetOperation = (kind, all, left, right) => {
|
|
3488
|
-
const leftState = left[
|
|
4443
|
+
const leftState = left[TypeId4];
|
|
3489
4444
|
const leftAst = ctx.getAst(left);
|
|
3490
4445
|
const basePlan = leftAst.kind === "set" ? leftAst.setBase ?? left : left;
|
|
3491
4446
|
const leftOperations = leftAst.kind === "set" ? [...leftAst.setOperations ?? []] : [];
|
|
@@ -3493,7 +4448,7 @@ var makeDslPlanRuntime = (ctx) => {
|
|
|
3493
4448
|
selection: leftState.selection,
|
|
3494
4449
|
required: undefined,
|
|
3495
4450
|
available: {},
|
|
3496
|
-
dialect: leftState.dialect ?? right[
|
|
4451
|
+
dialect: leftState.dialect ?? right[TypeId4].dialect
|
|
3497
4452
|
}, {
|
|
3498
4453
|
kind: "set",
|
|
3499
4454
|
select: leftState.selection,
|
|
@@ -3514,7 +4469,7 @@ var makeDslPlanRuntime = (ctx) => {
|
|
|
3514
4469
|
}, undefined, undefined, "set");
|
|
3515
4470
|
};
|
|
3516
4471
|
const where = (predicate) => (plan) => {
|
|
3517
|
-
const current = plan[
|
|
4472
|
+
const current = plan[TypeId4];
|
|
3518
4473
|
const currentAst = ctx.getAst(plan);
|
|
3519
4474
|
const currentQuery = ctx.getQueryState(plan);
|
|
3520
4475
|
const predicateExpression = ctx.toDialectExpression(predicate);
|
|
@@ -3533,7 +4488,7 @@ var makeDslPlanRuntime = (ctx) => {
|
|
|
3533
4488
|
}, ctx.assumeFormulaTrue(currentQuery.assumptions, ctx.formulaOfExpressionRuntime(predicateExpression)), currentQuery.capabilities, currentQuery.statement);
|
|
3534
4489
|
};
|
|
3535
4490
|
const from = (source) => (plan) => {
|
|
3536
|
-
const current = plan[
|
|
4491
|
+
const current = plan[TypeId4];
|
|
3537
4492
|
const currentAst = ctx.getAst(plan);
|
|
3538
4493
|
const currentQuery = ctx.getQueryState(plan);
|
|
3539
4494
|
if (currentQuery.statement === "insert") {
|
|
@@ -3600,7 +4555,7 @@ var makeDslPlanRuntime = (ctx) => {
|
|
|
3600
4555
|
return plan;
|
|
3601
4556
|
};
|
|
3602
4557
|
const having = (predicate) => (plan) => {
|
|
3603
|
-
const current = plan[
|
|
4558
|
+
const current = plan[TypeId4];
|
|
3604
4559
|
const currentAst = ctx.getAst(plan);
|
|
3605
4560
|
const currentQuery = ctx.getQueryState(plan);
|
|
3606
4561
|
const predicateExpression = ctx.toDialectExpression(predicate);
|
|
@@ -3619,7 +4574,7 @@ var makeDslPlanRuntime = (ctx) => {
|
|
|
3619
4574
|
}, ctx.assumeFormulaTrue(currentQuery.assumptions, ctx.formulaOfExpressionRuntime(predicateExpression)), currentQuery.capabilities, currentQuery.statement);
|
|
3620
4575
|
};
|
|
3621
4576
|
const crossJoin = (table) => (plan) => {
|
|
3622
|
-
const current = plan[
|
|
4577
|
+
const current = plan[TypeId4];
|
|
3623
4578
|
const currentAst = ctx.getAst(plan);
|
|
3624
4579
|
const currentQuery = ctx.getQueryState(plan);
|
|
3625
4580
|
const { sourceName, sourceBaseName } = ctx.sourceDetails(table);
|
|
@@ -3639,7 +4594,7 @@ var makeDslPlanRuntime = (ctx) => {
|
|
|
3639
4594
|
selection: current.selection,
|
|
3640
4595
|
required: [...ctx.currentRequiredList(current.required), ...sourceRequired].filter((name, index4, values) => !(name in nextAvailable) && values.indexOf(name) === index4),
|
|
3641
4596
|
available: nextAvailable,
|
|
3642
|
-
dialect: current.dialect ?? table[
|
|
4597
|
+
dialect: current.dialect ?? table[TypeId4]?.dialect ?? table.dialect
|
|
3643
4598
|
}, {
|
|
3644
4599
|
...currentAst,
|
|
3645
4600
|
joins: [...currentAst.joins, {
|
|
@@ -3651,7 +4606,7 @@ var makeDslPlanRuntime = (ctx) => {
|
|
|
3651
4606
|
}, currentQuery.assumptions, currentQuery.capabilities, currentQuery.statement);
|
|
3652
4607
|
};
|
|
3653
4608
|
const join = (kind, table, on) => (plan) => {
|
|
3654
|
-
const current = plan[
|
|
4609
|
+
const current = plan[TypeId4];
|
|
3655
4610
|
const currentAst = ctx.getAst(plan);
|
|
3656
4611
|
const currentQuery = ctx.getQueryState(plan);
|
|
3657
4612
|
const onExpression = ctx.toDialectExpression(on);
|
|
@@ -3693,7 +4648,7 @@ var makeDslPlanRuntime = (ctx) => {
|
|
|
3693
4648
|
}, kind === "inner" ? ctx.assumeFormulaTrue(currentQuery.assumptions, onFormula) : currentQuery.assumptions, currentQuery.capabilities, currentQuery.statement);
|
|
3694
4649
|
};
|
|
3695
4650
|
const orderBy = (value, direction = "asc") => (plan) => {
|
|
3696
|
-
const current = plan[
|
|
4651
|
+
const current = plan[TypeId4];
|
|
3697
4652
|
const currentAst = ctx.getAst(plan);
|
|
3698
4653
|
const currentQuery = ctx.getQueryState(plan);
|
|
3699
4654
|
const expression = ctx.toDialectExpression(value);
|
|
@@ -3713,7 +4668,7 @@ var makeDslPlanRuntime = (ctx) => {
|
|
|
3713
4668
|
}, currentQuery.assumptions, currentQuery.capabilities, currentQuery.statement);
|
|
3714
4669
|
};
|
|
3715
4670
|
const lock = (mode, options2 = {}) => (plan) => {
|
|
3716
|
-
const current = plan[
|
|
4671
|
+
const current = plan[TypeId4];
|
|
3717
4672
|
const currentAst = ctx.getAst(plan);
|
|
3718
4673
|
const currentQuery = ctx.getQueryState(plan);
|
|
3719
4674
|
return ctx.makePlan({
|
|
@@ -3732,7 +4687,7 @@ var makeDslPlanRuntime = (ctx) => {
|
|
|
3732
4687
|
}, currentQuery.assumptions, currentQuery.capabilities, currentQuery.statement);
|
|
3733
4688
|
};
|
|
3734
4689
|
const distinct = () => (plan) => {
|
|
3735
|
-
const current = plan[
|
|
4690
|
+
const current = plan[TypeId4];
|
|
3736
4691
|
const currentAst = ctx.getAst(plan);
|
|
3737
4692
|
const currentQuery = ctx.getQueryState(plan);
|
|
3738
4693
|
return ctx.makePlan({
|
|
@@ -3746,7 +4701,7 @@ var makeDslPlanRuntime = (ctx) => {
|
|
|
3746
4701
|
}, currentQuery.assumptions, currentQuery.capabilities, currentQuery.statement);
|
|
3747
4702
|
};
|
|
3748
4703
|
const limit = (value) => (plan) => {
|
|
3749
|
-
const current = plan[
|
|
4704
|
+
const current = plan[TypeId4];
|
|
3750
4705
|
const currentAst = ctx.getAst(plan);
|
|
3751
4706
|
const currentQuery = ctx.getQueryState(plan);
|
|
3752
4707
|
const expression = ctx.toDialectNumericExpression(value);
|
|
@@ -3762,7 +4717,7 @@ var makeDslPlanRuntime = (ctx) => {
|
|
|
3762
4717
|
}, currentQuery.assumptions, currentQuery.capabilities, currentQuery.statement);
|
|
3763
4718
|
};
|
|
3764
4719
|
const offset = (value) => (plan) => {
|
|
3765
|
-
const current = plan[
|
|
4720
|
+
const current = plan[TypeId4];
|
|
3766
4721
|
const currentAst = ctx.getAst(plan);
|
|
3767
4722
|
const currentQuery = ctx.getQueryState(plan);
|
|
3768
4723
|
const expression = ctx.toDialectNumericExpression(value);
|
|
@@ -3860,7 +4815,7 @@ var makeDslQueryRuntime = (ctx) => {
|
|
|
3860
4815
|
}, undefined, "read", "select");
|
|
3861
4816
|
};
|
|
3862
4817
|
const groupBy = (...values2) => (plan) => {
|
|
3863
|
-
const current = plan[
|
|
4818
|
+
const current = plan[TypeId4];
|
|
3864
4819
|
const currentAst = ctx.getAst(plan);
|
|
3865
4820
|
const currentQuery = ctx.getQueryState(plan);
|
|
3866
4821
|
const required = [...values2.flatMap((value) => Object.keys(value[TypeId].dependencies))].filter((name, index4, list) => !(name in current.available) && list.indexOf(name) === index4);
|
|
@@ -3876,7 +4831,7 @@ var makeDslQueryRuntime = (ctx) => {
|
|
|
3876
4831
|
};
|
|
3877
4832
|
const returning = (selection) => {
|
|
3878
4833
|
return (plan) => {
|
|
3879
|
-
const current = plan[
|
|
4834
|
+
const current = plan[TypeId4];
|
|
3880
4835
|
const currentAst = ctx.getAst(plan);
|
|
3881
4836
|
const currentQuery = ctx.getQueryState(plan);
|
|
3882
4837
|
return ctx.makePlan({
|
|
@@ -3901,14 +4856,14 @@ var makeDslQueryRuntime = (ctx) => {
|
|
|
3901
4856
|
};
|
|
3902
4857
|
|
|
3903
4858
|
// src/internal/derived-table.ts
|
|
3904
|
-
import { pipeArguments as
|
|
4859
|
+
import { pipeArguments as pipeArguments6 } from "effect/Pipeable";
|
|
3905
4860
|
|
|
3906
4861
|
// src/internal/projection-alias.ts
|
|
3907
4862
|
var TypeId9 = Symbol.for("effect-qb/ProjectionAlias");
|
|
3908
4863
|
|
|
3909
4864
|
// src/internal/projections.ts
|
|
3910
4865
|
var aliasFromPath = (path2) => path2.join("__");
|
|
3911
|
-
var
|
|
4866
|
+
var isExpression3 = (value) => typeof value === "object" && value !== null && (TypeId in value);
|
|
3912
4867
|
var projectionAliasOf = (expression) => (TypeId9 in expression) ? expression[TypeId9].alias : undefined;
|
|
3913
4868
|
var pathKeyOf = (path2) => JSON.stringify(path2);
|
|
3914
4869
|
var formatProjectionPath = (path2) => path2.join(".");
|
|
@@ -3917,7 +4872,7 @@ var flattenSelection = (selection, path2 = []) => {
|
|
|
3917
4872
|
const fields2 = [];
|
|
3918
4873
|
for (const [key2, value] of Object.entries(selection)) {
|
|
3919
4874
|
const nextPath = [...path2, key2];
|
|
3920
|
-
if (
|
|
4875
|
+
if (isExpression3(value)) {
|
|
3921
4876
|
fields2.push({
|
|
3922
4877
|
path: nextPath,
|
|
3923
4878
|
expression: value,
|
|
@@ -3957,7 +4912,7 @@ var validateProjections = (projections) => {
|
|
|
3957
4912
|
// src/internal/derived-table.ts
|
|
3958
4913
|
var DerivedProto = {
|
|
3959
4914
|
pipe() {
|
|
3960
|
-
return
|
|
4915
|
+
return pipeArguments6(this, arguments);
|
|
3961
4916
|
}
|
|
3962
4917
|
};
|
|
3963
4918
|
var attachPipe4 = (value) => {
|
|
@@ -3965,7 +4920,7 @@ var attachPipe4 = (value) => {
|
|
|
3965
4920
|
configurable: true,
|
|
3966
4921
|
writable: true,
|
|
3967
4922
|
value: function() {
|
|
3968
|
-
return
|
|
4923
|
+
return pipeArguments6(value, arguments);
|
|
3969
4924
|
}
|
|
3970
4925
|
});
|
|
3971
4926
|
return value;
|
|
@@ -3991,7 +4946,7 @@ var reboundedColumns = (plan, alias2) => {
|
|
|
3991
4946
|
const projections = flattenSelection(ast.select);
|
|
3992
4947
|
for (const projection of projections) {
|
|
3993
4948
|
const expression = projection.expression;
|
|
3994
|
-
setPath(selection, projection.path,
|
|
4949
|
+
setPath(selection, projection.path, makeExpression2({
|
|
3995
4950
|
runtime: undefined,
|
|
3996
4951
|
dbType: expression[TypeId].dbType,
|
|
3997
4952
|
runtimeSchema: expression[TypeId].runtimeSchema,
|
|
@@ -4016,7 +4971,7 @@ var makeDerivedSource = (plan, alias2) => {
|
|
|
4016
4971
|
derived.kind = "derived";
|
|
4017
4972
|
derived.name = alias2;
|
|
4018
4973
|
derived.baseName = alias2;
|
|
4019
|
-
derived.dialect = plan[
|
|
4974
|
+
derived.dialect = plan[TypeId4].dialect;
|
|
4020
4975
|
derived.plan = plan;
|
|
4021
4976
|
derived.required = undefined;
|
|
4022
4977
|
derived.columns = columns;
|
|
@@ -4029,7 +4984,7 @@ var makeCteSource = (plan, alias2, recursive = false) => {
|
|
|
4029
4984
|
cte.kind = "cte";
|
|
4030
4985
|
cte.name = alias2;
|
|
4031
4986
|
cte.baseName = alias2;
|
|
4032
|
-
cte.dialect = plan[
|
|
4987
|
+
cte.dialect = plan[TypeId4].dialect;
|
|
4033
4988
|
cte.plan = plan;
|
|
4034
4989
|
cte.recursive = recursive;
|
|
4035
4990
|
cte.required = undefined;
|
|
@@ -4043,9 +4998,9 @@ var makeLateralSource = (plan, alias2) => {
|
|
|
4043
4998
|
lateral.kind = "lateral";
|
|
4044
4999
|
lateral.name = alias2;
|
|
4045
5000
|
lateral.baseName = alias2;
|
|
4046
|
-
lateral.dialect = plan[
|
|
5001
|
+
lateral.dialect = plan[TypeId4].dialect;
|
|
4047
5002
|
lateral.plan = plan;
|
|
4048
|
-
lateral.required = currentRequiredList(plan[
|
|
5003
|
+
lateral.required = currentRequiredList(plan[TypeId4].required);
|
|
4049
5004
|
lateral.columns = columns;
|
|
4050
5005
|
return lateral;
|
|
4051
5006
|
};
|
|
@@ -4069,16 +5024,19 @@ var profile = {
|
|
|
4069
5024
|
};
|
|
4070
5025
|
var ValuesInputProto = {
|
|
4071
5026
|
pipe() {
|
|
4072
|
-
return
|
|
5027
|
+
return pipeArguments7(this, arguments);
|
|
4073
5028
|
}
|
|
4074
5029
|
};
|
|
4075
5030
|
var literalSchemaOf = (value) => {
|
|
4076
5031
|
if (value === null || value instanceof Date) {
|
|
4077
5032
|
return;
|
|
4078
5033
|
}
|
|
5034
|
+
if (typeof value === "number" && !Number.isFinite(value)) {
|
|
5035
|
+
return;
|
|
5036
|
+
}
|
|
4079
5037
|
return Schema6.Literal(value);
|
|
4080
5038
|
};
|
|
4081
|
-
var literal = (value) =>
|
|
5039
|
+
var literal = (value) => makeExpression2({
|
|
4082
5040
|
runtime: undefined,
|
|
4083
5041
|
dbType: value === null ? profile.nullDb : value instanceof Date ? profile.timestampDb : typeof value === "string" ? profile.textDb : typeof value === "number" ? profile.numericDb : profile.boolDb,
|
|
4084
5042
|
runtimeSchema: literalSchemaOf(value),
|
|
@@ -4102,7 +5060,7 @@ var retargetLiteralExpression = (value, target) => {
|
|
|
4102
5060
|
return value;
|
|
4103
5061
|
}
|
|
4104
5062
|
const targetState = target[TypeId];
|
|
4105
|
-
return
|
|
5063
|
+
return makeExpression2({
|
|
4106
5064
|
runtime: value[TypeId].runtime,
|
|
4107
5065
|
dbType: targetState.dbType,
|
|
4108
5066
|
runtimeSchema: targetState.runtimeSchema,
|
|
@@ -4136,7 +5094,7 @@ var extractRequiredFromDialectNumericInputRuntime = (value) => {
|
|
|
4136
5094
|
};
|
|
4137
5095
|
var buildBinaryPredicate = (left, right, kind, nullability = "maybe") => {
|
|
4138
5096
|
const [leftExpression, rightExpression] = alignBinaryPredicateExpressions(toDialectExpression(left), toDialectExpression(right));
|
|
4139
|
-
return
|
|
5097
|
+
return makeExpression2({
|
|
4140
5098
|
runtime: true,
|
|
4141
5099
|
dbType: profile.boolDb,
|
|
4142
5100
|
nullability,
|
|
@@ -4216,11 +5174,11 @@ var isJsonExpressionValue = (value) => isExpressionValue(value) && (() => {
|
|
|
4216
5174
|
const dbType = value[TypeId].dbType;
|
|
4217
5175
|
return dbType.variant === "json" || dbType.kind === "json" || dbType.kind === "jsonb";
|
|
4218
5176
|
})();
|
|
4219
|
-
var isJsonPathValue = (value) => value !== null && typeof value === "object" && (
|
|
5177
|
+
var isJsonPathValue = (value) => value !== null && typeof value === "object" && (TypeId3 in value);
|
|
4220
5178
|
var normalizeJsonPathInput = (value) => isJsonPathValue(value) ? value.segments : [value];
|
|
4221
5179
|
var isExactJsonSegmentValue = (segment) => segment.kind === "key" || segment.kind === "index";
|
|
4222
5180
|
var isExactJsonPathValue = (segments) => segments.every(isExactJsonSegmentValue);
|
|
4223
|
-
var buildJsonNodeExpression = (expressions, state, ast) =>
|
|
5181
|
+
var buildJsonNodeExpression = (expressions, state, ast) => makeExpression2({
|
|
4224
5182
|
runtime: state.runtime,
|
|
4225
5183
|
dbType: state.dbType,
|
|
4226
5184
|
nullability: state.nullability,
|
|
@@ -4230,7 +5188,7 @@ var buildJsonNodeExpression = (expressions, state, ast) => makeExpression({
|
|
|
4230
5188
|
}, ast);
|
|
4231
5189
|
var jsonDbTypeOf = (base) => base[TypeId].dbType;
|
|
4232
5190
|
var resolveJsonMergeDbType = (...values) => values.some((value) => value[TypeId].dbType.kind === "jsonb") ? jsonbDb : jsonDb;
|
|
4233
|
-
var makeJsonLiteralExpression = (value, dbType = jsonDb) =>
|
|
5191
|
+
var makeJsonLiteralExpression = (value, dbType = jsonDb) => makeExpression2({
|
|
4234
5192
|
runtime: value,
|
|
4235
5193
|
dbType,
|
|
4236
5194
|
nullability: value === null ? "always" : "never",
|
|
@@ -4565,7 +5523,7 @@ var jsonPathMatch = (base, query) => {
|
|
|
4565
5523
|
};
|
|
4566
5524
|
var json = {
|
|
4567
5525
|
key,
|
|
4568
|
-
index
|
|
5526
|
+
index,
|
|
4569
5527
|
wildcard,
|
|
4570
5528
|
slice,
|
|
4571
5529
|
descend,
|
|
@@ -4601,7 +5559,7 @@ var json = {
|
|
|
4601
5559
|
};
|
|
4602
5560
|
var jsonb = {
|
|
4603
5561
|
key,
|
|
4604
|
-
index
|
|
5562
|
+
index,
|
|
4605
5563
|
wildcard,
|
|
4606
5564
|
slice,
|
|
4607
5565
|
descend,
|
|
@@ -4652,7 +5610,7 @@ var toMutationValueExpression = (value, column) => {
|
|
|
4652
5610
|
const ast = expression[TypeId2];
|
|
4653
5611
|
if (ast.kind === "literal") {
|
|
4654
5612
|
const normalizedValue2 = normalizeMutationValue(ast.value);
|
|
4655
|
-
return
|
|
5613
|
+
return makeExpression2({
|
|
4656
5614
|
runtime: normalizedValue2,
|
|
4657
5615
|
dbType: columnState.dbType,
|
|
4658
5616
|
runtimeSchema: columnState.runtimeSchema,
|
|
@@ -4669,7 +5627,7 @@ var toMutationValueExpression = (value, column) => {
|
|
|
4669
5627
|
return retargetLiteralExpression(value, column);
|
|
4670
5628
|
}
|
|
4671
5629
|
const normalizedValue = normalizeMutationValue(value);
|
|
4672
|
-
return
|
|
5630
|
+
return makeExpression2({
|
|
4673
5631
|
runtime: normalizedValue,
|
|
4674
5632
|
dbType: columnState.dbType,
|
|
4675
5633
|
runtimeSchema: columnState.runtimeSchema,
|
|
@@ -4684,15 +5642,15 @@ var toMutationValueExpression = (value, column) => {
|
|
|
4684
5642
|
});
|
|
4685
5643
|
};
|
|
4686
5644
|
var targetSourceDetails = (table) => {
|
|
4687
|
-
const sourceName = table[
|
|
4688
|
-
const sourceBaseName = table[
|
|
5645
|
+
const sourceName = table[TypeId7].name;
|
|
5646
|
+
const sourceBaseName = table[TypeId7].baseName;
|
|
4689
5647
|
return {
|
|
4690
5648
|
sourceName,
|
|
4691
5649
|
sourceBaseName
|
|
4692
5650
|
};
|
|
4693
5651
|
};
|
|
4694
5652
|
var sourceDetails = (source) => {
|
|
4695
|
-
if (
|
|
5653
|
+
if (TypeId7 in source) {
|
|
4696
5654
|
return targetSourceDetails(source);
|
|
4697
5655
|
}
|
|
4698
5656
|
const record2 = source;
|
|
@@ -4705,7 +5663,7 @@ var makeColumnReferenceSelection = (alias2, selection) => {
|
|
|
4705
5663
|
const columns = {};
|
|
4706
5664
|
for (const [columnName, expression] of Object.entries(selection)) {
|
|
4707
5665
|
const state = expression[TypeId];
|
|
4708
|
-
columns[columnName] =
|
|
5666
|
+
columns[columnName] = makeExpression2({
|
|
4709
5667
|
runtime: undefined,
|
|
4710
5668
|
dbType: state.dbType,
|
|
4711
5669
|
runtimeSchema: state.runtimeSchema,
|
|
@@ -4759,7 +5717,7 @@ var buildMutationAssignments = (target, values) => {
|
|
|
4759
5717
|
}
|
|
4760
5718
|
const valueMap = values;
|
|
4761
5719
|
return targets.flatMap((table) => {
|
|
4762
|
-
const targetName = table[
|
|
5720
|
+
const targetName = table[TypeId7].name;
|
|
4763
5721
|
const scopedValues = valueMap[targetName] ?? {};
|
|
4764
5722
|
const columns = table;
|
|
4765
5723
|
return Object.entries(scopedValues).map(([columnName, value]) => ({
|
|
@@ -4924,59 +5882,29 @@ var {
|
|
|
4924
5882
|
normalizeColumnList,
|
|
4925
5883
|
defaultIndexName
|
|
4926
5884
|
});
|
|
5885
|
+
|
|
4927
5886
|
// src/sqlite/json.ts
|
|
4928
|
-
var key2 = json.key;
|
|
4929
|
-
var index4 = json.index;
|
|
4930
|
-
var wildcard2 = json.wildcard;
|
|
4931
|
-
var slice2 = json.slice;
|
|
4932
|
-
var descend2 = json.descend;
|
|
4933
|
-
var path2 = json.path;
|
|
4934
|
-
var get = json.get;
|
|
4935
|
-
var access = json.access;
|
|
4936
|
-
var traverse = json.traverse;
|
|
4937
|
-
var text = json.text;
|
|
4938
|
-
var accessText = json.accessText;
|
|
4939
|
-
var traverseText = json.traverseText;
|
|
4940
|
-
var contains = json.contains;
|
|
4941
|
-
var containedBy = json.containedBy;
|
|
4942
|
-
var hasKey = json.hasKey;
|
|
4943
|
-
var keyExists = json.keyExists;
|
|
4944
|
-
var hasAnyKeys = json.hasAnyKeys;
|
|
4945
|
-
var hasAllKeys = json.hasAllKeys;
|
|
4946
|
-
var delete_ = json.delete;
|
|
4947
|
-
var remove = json.remove;
|
|
4948
|
-
var set2 = json.set;
|
|
4949
5887
|
var insert = json.insert;
|
|
4950
|
-
var concat = json.concat;
|
|
4951
|
-
var merge2 = json.merge;
|
|
4952
|
-
var buildObject = json.buildObject;
|
|
4953
|
-
var buildArray = json.buildArray;
|
|
4954
|
-
var toJson = json.toJson;
|
|
4955
|
-
var toJsonb = json.toJsonb;
|
|
4956
5888
|
var typeOf = json.typeOf;
|
|
4957
5889
|
var length = json.length;
|
|
4958
|
-
var keys = json.keys;
|
|
4959
5890
|
var stripNulls = json.stripNulls;
|
|
4960
|
-
var pathExists = json.pathExists;
|
|
4961
5891
|
var pathMatch = json.pathMatch;
|
|
4962
5892
|
// src/sqlite/executor.ts
|
|
4963
5893
|
var exports_executor2 = {};
|
|
4964
5894
|
__export(exports_executor2, {
|
|
4965
5895
|
withTransaction: () => withTransaction2,
|
|
4966
|
-
withSavepoint: () => withSavepoint2,
|
|
4967
5896
|
make: () => make4,
|
|
4968
5897
|
driver: () => driver2,
|
|
4969
5898
|
custom: () => custom3
|
|
4970
5899
|
});
|
|
4971
5900
|
import * as Effect2 from "effect/Effect";
|
|
4972
|
-
import * as SqlClient3 from "
|
|
5901
|
+
import * as SqlClient3 from "effect/unstable/sql/SqlClient";
|
|
4973
5902
|
import * as Stream2 from "effect/Stream";
|
|
4974
5903
|
|
|
4975
5904
|
// src/internal/executor.ts
|
|
4976
5905
|
var exports_executor = {};
|
|
4977
5906
|
__export(exports_executor, {
|
|
4978
5907
|
withTransaction: () => withTransaction,
|
|
4979
|
-
withSavepoint: () => withSavepoint,
|
|
4980
5908
|
streamFromSqlClient: () => streamFromSqlClient,
|
|
4981
5909
|
remapRows: () => remapRows,
|
|
4982
5910
|
makeRowDecoder: () => makeRowDecoder,
|
|
@@ -4990,9 +5918,10 @@ __export(exports_executor, {
|
|
|
4990
5918
|
});
|
|
4991
5919
|
import * as Chunk from "effect/Chunk";
|
|
4992
5920
|
import * as Effect from "effect/Effect";
|
|
5921
|
+
import * as Exit from "effect/Exit";
|
|
4993
5922
|
import * as Option from "effect/Option";
|
|
4994
5923
|
import * as Schema9 from "effect/Schema";
|
|
4995
|
-
import * as SqlClient from "
|
|
5924
|
+
import * as SqlClient from "effect/unstable/sql/SqlClient";
|
|
4996
5925
|
import * as Stream from "effect/Stream";
|
|
4997
5926
|
|
|
4998
5927
|
// src/internal/runtime/driver-value-mapping.ts
|
|
@@ -5039,9 +5968,9 @@ var mappingCandidates = (context) => {
|
|
|
5039
5968
|
runtimeTag === undefined ? undefined : context.valueMappings?.[runtimeTag]
|
|
5040
5969
|
];
|
|
5041
5970
|
};
|
|
5042
|
-
var findMapping = (context,
|
|
5971
|
+
var findMapping = (context, key2) => {
|
|
5043
5972
|
for (const candidate of mappingCandidates(context)) {
|
|
5044
|
-
const value = candidate?.[
|
|
5973
|
+
const value = candidate?.[key2];
|
|
5045
5974
|
if (value !== undefined) {
|
|
5046
5975
|
return value;
|
|
5047
5976
|
}
|
|
@@ -5169,7 +6098,7 @@ var renderJsonSelectSql = (sql, context) => {
|
|
|
5169
6098
|
import * as Schema8 from "effect/Schema";
|
|
5170
6099
|
import * as SchemaAST from "effect/SchemaAST";
|
|
5171
6100
|
var schemaCache = new WeakMap;
|
|
5172
|
-
var FiniteNumberSchema = Schema8.Number.
|
|
6101
|
+
var FiniteNumberSchema = Schema8.Number.check(Schema8.isFinite());
|
|
5173
6102
|
var runtimeSchemaForTag = (tag) => {
|
|
5174
6103
|
switch (tag) {
|
|
5175
6104
|
case "string":
|
|
@@ -5197,14 +6126,11 @@ var runtimeSchemaForTag = (tag) => {
|
|
|
5197
6126
|
case "decimalString":
|
|
5198
6127
|
return DecimalStringSchema;
|
|
5199
6128
|
case "bytes":
|
|
5200
|
-
return Schema8.
|
|
6129
|
+
return Schema8.Uint8Array;
|
|
5201
6130
|
case "array":
|
|
5202
6131
|
return Schema8.Array(Schema8.Unknown);
|
|
5203
6132
|
case "record":
|
|
5204
|
-
return Schema8.Record(
|
|
5205
|
-
key: Schema8.String,
|
|
5206
|
-
value: Schema8.Unknown
|
|
5207
|
-
});
|
|
6133
|
+
return Schema8.Record(Schema8.String, Schema8.Unknown);
|
|
5208
6134
|
case "null":
|
|
5209
6135
|
return Schema8.Null;
|
|
5210
6136
|
case "unknown":
|
|
@@ -5222,7 +6148,7 @@ var runtimeSchemaForDbType = (dbType) => {
|
|
|
5222
6148
|
return Schema8.Array(runtimeSchemaForDbType(dbType.element) ?? Schema8.Unknown);
|
|
5223
6149
|
}
|
|
5224
6150
|
if ("fields" in dbType) {
|
|
5225
|
-
const fields2 = Object.fromEntries(Object.entries(dbType.fields).map(([
|
|
6151
|
+
const fields2 = Object.fromEntries(Object.entries(dbType.fields).map(([key2, field]) => [key2, runtimeSchemaForDbType(field) ?? Schema8.Unknown]));
|
|
5226
6152
|
return Schema8.Struct(fields2);
|
|
5227
6153
|
}
|
|
5228
6154
|
if ("variant" in dbType && dbType.variant === "json") {
|
|
@@ -5242,27 +6168,23 @@ var unionAst = (asts) => {
|
|
|
5242
6168
|
if (asts.length === 1) {
|
|
5243
6169
|
return asts[0];
|
|
5244
6170
|
}
|
|
5245
|
-
return SchemaAST.Union
|
|
6171
|
+
return new SchemaAST.Union(asts, "anyOf");
|
|
5246
6172
|
};
|
|
5247
|
-
var propertyAstOf = (ast,
|
|
6173
|
+
var propertyAstOf = (ast, key2) => {
|
|
5248
6174
|
switch (ast._tag) {
|
|
5249
|
-
case "Transformation":
|
|
5250
|
-
return propertyAstOf(SchemaAST.typeAST(ast), key3);
|
|
5251
|
-
case "Refinement":
|
|
5252
|
-
return propertyAstOf(ast.from, key3);
|
|
5253
6175
|
case "Suspend":
|
|
5254
|
-
return propertyAstOf(ast.
|
|
5255
|
-
case "
|
|
5256
|
-
const property = ast.propertySignatures.find((entry) => entry.name ===
|
|
6176
|
+
return propertyAstOf(ast.thunk(), key2);
|
|
6177
|
+
case "Objects": {
|
|
6178
|
+
const property = ast.propertySignatures.find((entry) => entry.name === key2);
|
|
5257
6179
|
if (property !== undefined) {
|
|
5258
6180
|
return property.type;
|
|
5259
6181
|
}
|
|
5260
|
-
const
|
|
5261
|
-
return
|
|
6182
|
+
const index4 = ast.indexSignatures.find((entry) => entry.parameter._tag === "String");
|
|
6183
|
+
return index4?.type;
|
|
5262
6184
|
}
|
|
5263
6185
|
case "Union": {
|
|
5264
6186
|
const values2 = ast.types.flatMap((member) => {
|
|
5265
|
-
const next = propertyAstOf(member,
|
|
6187
|
+
const next = propertyAstOf(member, key2);
|
|
5266
6188
|
return next === undefined ? [] : [next];
|
|
5267
6189
|
});
|
|
5268
6190
|
return unionAst(values2);
|
|
@@ -5271,27 +6193,23 @@ var propertyAstOf = (ast, key3) => {
|
|
|
5271
6193
|
return;
|
|
5272
6194
|
}
|
|
5273
6195
|
};
|
|
5274
|
-
var numberAstOf = (ast,
|
|
6196
|
+
var numberAstOf = (ast, index4) => {
|
|
5275
6197
|
switch (ast._tag) {
|
|
5276
|
-
case "Transformation":
|
|
5277
|
-
return numberAstOf(SchemaAST.typeAST(ast), index5);
|
|
5278
|
-
case "Refinement":
|
|
5279
|
-
return numberAstOf(ast.from, index5);
|
|
5280
6198
|
case "Suspend":
|
|
5281
|
-
return numberAstOf(ast.
|
|
5282
|
-
case "
|
|
5283
|
-
const element = ast.elements[
|
|
6199
|
+
return numberAstOf(ast.thunk(), index4);
|
|
6200
|
+
case "Arrays": {
|
|
6201
|
+
const element = ast.elements[index4];
|
|
5284
6202
|
if (element !== undefined) {
|
|
5285
|
-
return element
|
|
6203
|
+
return element;
|
|
5286
6204
|
}
|
|
5287
6205
|
if (ast.rest.length === 0) {
|
|
5288
6206
|
return;
|
|
5289
6207
|
}
|
|
5290
|
-
return unionAst(ast.rest
|
|
6208
|
+
return unionAst(ast.rest);
|
|
5291
6209
|
}
|
|
5292
6210
|
case "Union": {
|
|
5293
6211
|
const values2 = ast.types.flatMap((member) => {
|
|
5294
|
-
const next = numberAstOf(member,
|
|
6212
|
+
const next = numberAstOf(member, index4);
|
|
5295
6213
|
return next === undefined ? [] : [next];
|
|
5296
6214
|
});
|
|
5297
6215
|
return unionAst(values2);
|
|
@@ -5302,7 +6220,7 @@ var numberAstOf = (ast, index5) => {
|
|
|
5302
6220
|
};
|
|
5303
6221
|
var exactJsonSegments = (segments) => segments.every((segment) => segment.kind === "key" || segment.kind === "index");
|
|
5304
6222
|
var schemaAstAtExactJsonPath = (schema2, segments) => {
|
|
5305
|
-
let current =
|
|
6223
|
+
let current = schema2.ast;
|
|
5306
6224
|
for (const segment of segments) {
|
|
5307
6225
|
if (segment.kind === "key") {
|
|
5308
6226
|
const property = propertyAstOf(current, segment.key);
|
|
@@ -5332,28 +6250,28 @@ var unionSchemas = (schemas) => {
|
|
|
5332
6250
|
if (resolved.length === 1) {
|
|
5333
6251
|
return resolved[0];
|
|
5334
6252
|
}
|
|
5335
|
-
return Schema8.Union(
|
|
6253
|
+
return Schema8.Union(resolved);
|
|
5336
6254
|
};
|
|
5337
6255
|
var firstSelectedExpression = (plan) => {
|
|
5338
6256
|
const selection = getAst(plan).select;
|
|
5339
6257
|
return flattenSelection(selection)[0]?.expression;
|
|
5340
6258
|
};
|
|
5341
6259
|
var isJsonCompatibleAst = (ast) => {
|
|
6260
|
+
ast = SchemaAST.toType(ast);
|
|
5342
6261
|
switch (ast._tag) {
|
|
5343
|
-
case "
|
|
5344
|
-
case "
|
|
5345
|
-
case "
|
|
5346
|
-
case "
|
|
5347
|
-
case "
|
|
6262
|
+
case "String":
|
|
6263
|
+
case "Number":
|
|
6264
|
+
case "Boolean":
|
|
6265
|
+
case "Null":
|
|
6266
|
+
case "Arrays":
|
|
6267
|
+
case "Objects":
|
|
5348
6268
|
return true;
|
|
5349
6269
|
case "Literal":
|
|
5350
|
-
return
|
|
6270
|
+
return typeof ast.literal === "string" || typeof ast.literal === "number" || typeof ast.literal === "boolean";
|
|
5351
6271
|
case "Union":
|
|
5352
6272
|
return ast.types.every(isJsonCompatibleAst);
|
|
5353
|
-
case "Transformation":
|
|
5354
|
-
return isJsonCompatibleAst(SchemaAST.typeAST(ast));
|
|
5355
6273
|
case "Suspend":
|
|
5356
|
-
return isJsonCompatibleAst(ast.
|
|
6274
|
+
return isJsonCompatibleAst(ast.thunk());
|
|
5357
6275
|
default:
|
|
5358
6276
|
return false;
|
|
5359
6277
|
}
|
|
@@ -5362,14 +6280,14 @@ var jsonCompatibleSchema = (schema2) => {
|
|
|
5362
6280
|
if (schema2 === undefined) {
|
|
5363
6281
|
return;
|
|
5364
6282
|
}
|
|
5365
|
-
const ast = SchemaAST.
|
|
6283
|
+
const ast = SchemaAST.toType(schema2.ast);
|
|
5366
6284
|
return isJsonCompatibleAst(ast) ? schema2 : JsonValueSchema;
|
|
5367
6285
|
};
|
|
5368
6286
|
var buildStructSchema = (entries, context) => {
|
|
5369
6287
|
const fields2 = Object.fromEntries(entries.map((entry) => [entry.key, expressionRuntimeSchema(entry.value, context) ?? JsonValueSchema]));
|
|
5370
6288
|
return Schema8.Struct(fields2);
|
|
5371
6289
|
};
|
|
5372
|
-
var buildTupleSchema = (values2, context) => Schema8.Tuple(
|
|
6290
|
+
var buildTupleSchema = (values2, context) => Schema8.Tuple(values2.map((value) => expressionRuntimeSchema(value, context) ?? JsonValueSchema));
|
|
5373
6291
|
var deriveCaseSchema = (ast, context) => {
|
|
5374
6292
|
if (context === undefined) {
|
|
5375
6293
|
return unionSchemas([
|
|
@@ -5522,20 +6440,20 @@ var expressionRuntimeSchema = (expression, context) => {
|
|
|
5522
6440
|
};
|
|
5523
6441
|
|
|
5524
6442
|
// src/internal/executor.ts
|
|
5525
|
-
var setPath2 = (target,
|
|
6443
|
+
var setPath2 = (target, path2, value) => {
|
|
5526
6444
|
let current = target;
|
|
5527
|
-
for (let
|
|
5528
|
-
const
|
|
5529
|
-
const existing = current[
|
|
6445
|
+
for (let index4 = 0;index4 < path2.length - 1; index4++) {
|
|
6446
|
+
const key2 = path2[index4];
|
|
6447
|
+
const existing = current[key2];
|
|
5530
6448
|
if (typeof existing === "object" && existing !== null && !Array.isArray(existing)) {
|
|
5531
6449
|
current = existing;
|
|
5532
6450
|
continue;
|
|
5533
6451
|
}
|
|
5534
6452
|
const next = {};
|
|
5535
|
-
current[
|
|
6453
|
+
current[key2] = next;
|
|
5536
6454
|
current = next;
|
|
5537
6455
|
}
|
|
5538
|
-
current[
|
|
6456
|
+
current[path2[path2.length - 1]] = value;
|
|
5539
6457
|
};
|
|
5540
6458
|
var hasWriteStatement = (statement) => statement === "insert" || statement === "update" || statement === "delete" || statement === "truncate" || statement === "merge" || statement === "transaction" || statement === "commit" || statement === "rollback" || statement === "savepoint" || statement === "rollbackTo" || statement === "releaseSavepoint" || statement === "createTable" || statement === "createIndex" || statement === "dropIndex" || statement === "dropTable";
|
|
5541
6459
|
var hasWriteCapabilityInSource = (source) => typeof source === "object" && source !== null && ("plan" in source) ? hasWriteCapability(source.plan) : false;
|
|
@@ -5575,24 +6493,31 @@ var remapRows = (query, rows) => rows.map((row) => {
|
|
|
5575
6493
|
}
|
|
5576
6494
|
return decoded;
|
|
5577
6495
|
});
|
|
5578
|
-
var makeRowDecodeError = (rendered, projection, expression, raw, stage, cause, normalized) =>
|
|
5579
|
-
|
|
5580
|
-
|
|
5581
|
-
|
|
5582
|
-
|
|
5583
|
-
|
|
5584
|
-
|
|
5585
|
-
|
|
5586
|
-
|
|
5587
|
-
|
|
5588
|
-
|
|
5589
|
-
|
|
5590
|
-
|
|
5591
|
-
|
|
5592
|
-
|
|
5593
|
-
|
|
5594
|
-
|
|
5595
|
-
|
|
6496
|
+
var makeRowDecodeError = (rendered, projection, expression, raw, stage, cause, normalized) => {
|
|
6497
|
+
const schemaError = Schema9.isSchemaError(cause) ? {
|
|
6498
|
+
message: cause.message,
|
|
6499
|
+
issue: cause.issue
|
|
6500
|
+
} : undefined;
|
|
6501
|
+
return {
|
|
6502
|
+
_tag: "RowDecodeError",
|
|
6503
|
+
message: stage === "normalize" ? `Failed to normalize projection '${projection.alias}'` : `Failed to decode projection '${projection.alias}' against its runtime schema`,
|
|
6504
|
+
dialect: rendered.dialect,
|
|
6505
|
+
query: {
|
|
6506
|
+
sql: rendered.sql,
|
|
6507
|
+
params: rendered.params
|
|
6508
|
+
},
|
|
6509
|
+
projection: {
|
|
6510
|
+
alias: projection.alias,
|
|
6511
|
+
path: projection.path
|
|
6512
|
+
},
|
|
6513
|
+
dbType: expression[TypeId].dbType,
|
|
6514
|
+
raw,
|
|
6515
|
+
normalized,
|
|
6516
|
+
stage,
|
|
6517
|
+
cause,
|
|
6518
|
+
...schemaError === undefined ? {} : { schemaError }
|
|
6519
|
+
};
|
|
6520
|
+
};
|
|
5596
6521
|
var hasOptionalSourceDependency = (expression, scope) => {
|
|
5597
6522
|
const state = expression[TypeId];
|
|
5598
6523
|
return Object.keys(state.dependencies).some((sourceName) => !scope.absentSourceNames.has(sourceName) && scope.sourceModes.get(sourceName) === "optional");
|
|
@@ -5604,11 +6529,11 @@ var effectiveRuntimeNullability = (expression, scope) => {
|
|
|
5604
6529
|
return "always";
|
|
5605
6530
|
}
|
|
5606
6531
|
if (ast.kind === "column") {
|
|
5607
|
-
const
|
|
5608
|
-
if (scope.absentSourceNames.has(ast.tableName) || scope.nullKeys.has(
|
|
6532
|
+
const key2 = columnPredicateKey(ast.tableName, ast.columnName);
|
|
6533
|
+
if (scope.absentSourceNames.has(ast.tableName) || scope.nullKeys.has(key2)) {
|
|
5609
6534
|
return "always";
|
|
5610
6535
|
}
|
|
5611
|
-
if (scope.nonNullKeys.has(
|
|
6536
|
+
if (scope.nonNullKeys.has(key2)) {
|
|
5612
6537
|
return "never";
|
|
5613
6538
|
}
|
|
5614
6539
|
}
|
|
@@ -5635,8 +6560,8 @@ var decodeProjectionValue = (rendered, projection, expression, raw, scope, drive
|
|
|
5635
6560
|
driverValueMapping: expression[TypeId].driverValueMapping,
|
|
5636
6561
|
valueMappings
|
|
5637
6562
|
});
|
|
5638
|
-
} catch (
|
|
5639
|
-
throw makeRowDecodeError(rendered, projection, expression, raw, "normalize",
|
|
6563
|
+
} catch (cause2) {
|
|
6564
|
+
throw makeRowDecodeError(rendered, projection, expression, raw, "normalize", cause2);
|
|
5640
6565
|
}
|
|
5641
6566
|
}
|
|
5642
6567
|
const nullability = effectiveRuntimeNullability(expression, scope);
|
|
@@ -5662,18 +6587,22 @@ var decodeProjectionValue = (rendered, projection, expression, raw, scope, drive
|
|
|
5662
6587
|
if (Schema9.is(schema2)(normalized)) {
|
|
5663
6588
|
return normalized;
|
|
5664
6589
|
}
|
|
5665
|
-
|
|
5666
|
-
|
|
5667
|
-
|
|
5668
|
-
throw makeRowDecodeError(rendered, projection, expression, raw, "schema", cause, normalized);
|
|
6590
|
+
const decoded = Schema9.decodeUnknownExit(schema2)(normalized);
|
|
6591
|
+
if (Exit.isSuccess(decoded)) {
|
|
6592
|
+
return decoded.value;
|
|
5669
6593
|
}
|
|
6594
|
+
const cause = Option.match(Exit.findErrorOption(decoded), {
|
|
6595
|
+
onNone: () => decoded.cause,
|
|
6596
|
+
onSome: (schemaError) => schemaError
|
|
6597
|
+
});
|
|
6598
|
+
throw makeRowDecodeError(rendered, projection, expression, raw, "schema", cause, normalized);
|
|
5670
6599
|
};
|
|
5671
6600
|
var makeRowDecoder = (rendered, plan, options2 = {}) => {
|
|
5672
6601
|
const projections = flattenSelection(getAst(plan).select);
|
|
5673
6602
|
const byPath = new Map(projections.map((projection) => [JSON.stringify(projection.path), projection.expression]));
|
|
5674
6603
|
const driverMode = options2.driverMode ?? "raw";
|
|
5675
6604
|
const valueMappings = options2.valueMappings ?? rendered.valueMappings;
|
|
5676
|
-
const scope = resolveImplicationScope(plan[
|
|
6605
|
+
const scope = resolveImplicationScope(plan[TypeId4].available, getQueryState(plan).assumptions);
|
|
5677
6606
|
return (row) => {
|
|
5678
6607
|
const decoded = {};
|
|
5679
6608
|
for (const projection of rendered.projections) {
|
|
@@ -5691,7 +6620,7 @@ var makeRowDecoder = (rendered, plan, options2 = {}) => {
|
|
|
5691
6620
|
};
|
|
5692
6621
|
var decodeChunk = (rendered, plan, rows, options2 = {}) => {
|
|
5693
6622
|
const decodeRow = makeRowDecoder(rendered, plan, options2);
|
|
5694
|
-
return Chunk.
|
|
6623
|
+
return Chunk.fromIterable(Chunk.toReadonlyArray(rows).map((row) => decodeRow(row)));
|
|
5695
6624
|
};
|
|
5696
6625
|
var decodeRows = (rendered, plan, rows, options2 = {}) => {
|
|
5697
6626
|
const decodeRow = makeRowDecoder(rendered, plan, options2);
|
|
@@ -5729,12 +6658,12 @@ var fromDriver = (renderer, sqlDriver) => {
|
|
|
5729
6658
|
},
|
|
5730
6659
|
stream(plan) {
|
|
5731
6660
|
const rendered = renderer.render(plan);
|
|
5732
|
-
return Stream.
|
|
6661
|
+
return Stream.mapArray(sqlDriver.stream(rendered), (rows) => remapRows(rendered, rows));
|
|
5733
6662
|
}
|
|
5734
6663
|
};
|
|
5735
6664
|
return executor;
|
|
5736
6665
|
};
|
|
5737
|
-
var streamFromSqlClient = (query) => Stream.
|
|
6666
|
+
var streamFromSqlClient = (query) => Stream.unwrap(Effect.flatMap(SqlClient.SqlClient, (sql) => Effect.flatMap(Effect.serviceOption(sql.transactionService), Option.match({
|
|
5738
6667
|
onNone: () => sql.reserve,
|
|
5739
6668
|
onSome: ([connection]) => Effect.succeed(connection)
|
|
5740
6669
|
})).pipe(Effect.map((connection) => connection.executeStream(query.sql, [...query.params], undefined)))));
|
|
@@ -5743,12 +6672,11 @@ var fromSqlClient = (renderer) => fromDriver(renderer, driver(renderer.dialect,
|
|
|
5743
6672
|
stream: (query) => streamFromSqlClient(query)
|
|
5744
6673
|
}));
|
|
5745
6674
|
var withTransaction = (effect) => Effect.flatMap(SqlClient.SqlClient, (sql) => sql.withTransaction(effect));
|
|
5746
|
-
var withSavepoint = (effect) => Effect.flatMap(SqlClient.SqlClient, (sql) => sql.withTransaction(effect));
|
|
5747
6675
|
|
|
5748
6676
|
// src/internal/renderer.ts
|
|
5749
6677
|
var TypeId10 = Symbol.for("effect-qb/Renderer");
|
|
5750
|
-
var projectionPathKey = (
|
|
5751
|
-
var formatProjectionPath2 = (
|
|
6678
|
+
var projectionPathKey = (path2) => JSON.stringify(path2);
|
|
6679
|
+
var formatProjectionPath2 = (path2) => path2.join(".");
|
|
5752
6680
|
var validateProjectionPathsMatchSelection = (plan, projections) => {
|
|
5753
6681
|
const expected = flattenSelection(getAst(plan).select);
|
|
5754
6682
|
const expectedPaths = new Set(expected.map((projection) => projectionPathKey(projection.path)));
|
|
@@ -5807,14 +6735,15 @@ var renderDbTypeName = (value) => value;
|
|
|
5807
6735
|
// src/internal/dialect-renderers/sqlite.ts
|
|
5808
6736
|
import * as Schema10 from "effect/Schema";
|
|
5809
6737
|
var renderDbType = (dialect, dbType) => {
|
|
5810
|
-
|
|
5811
|
-
return "text";
|
|
5812
|
-
}
|
|
5813
|
-
return renderDbTypeName(dbType.kind);
|
|
6738
|
+
return renderDbTypeName(renderPortableDatatypeDdlType(dialect.name, dbType.kind) ?? dbType.kind);
|
|
5814
6739
|
};
|
|
5815
6740
|
var isArrayDbType = (dbType) => ("element" in dbType);
|
|
5816
6741
|
var renderCastType = (dialect, dbType) => {
|
|
5817
6742
|
const kind = dbType?.kind;
|
|
6743
|
+
const portableType = renderPortableDatatypeCastType(dialect.name, kind);
|
|
6744
|
+
if (portableType !== undefined) {
|
|
6745
|
+
return renderDbTypeName(portableType);
|
|
6746
|
+
}
|
|
5818
6747
|
if (dialect.name !== "sqlite") {
|
|
5819
6748
|
return renderDbTypeName(kind);
|
|
5820
6749
|
}
|
|
@@ -5887,7 +6816,7 @@ var renderSqliteMutationLimit = (expression, state, dialect) => {
|
|
|
5887
6816
|
}
|
|
5888
6817
|
return renderExpression(expression, state, dialect);
|
|
5889
6818
|
};
|
|
5890
|
-
var casingForTable = (table, state) => merge(state.casing, table[
|
|
6819
|
+
var casingForTable = (table, state) => merge(state.casing, table[TypeId7].casing);
|
|
5891
6820
|
var casedColumnName = (columnName, state, tableName) => {
|
|
5892
6821
|
if (tableName !== undefined) {
|
|
5893
6822
|
const mapped = state.sourceNames?.get(tableName)?.columns.get(columnName);
|
|
@@ -5899,7 +6828,7 @@ var casedColumnName = (columnName, state, tableName) => {
|
|
|
5899
6828
|
};
|
|
5900
6829
|
var casedTableReferenceName = (tableName, state) => state.sourceNames?.get(tableName)?.tableName ?? applyCategory(state.casing, "tables", tableName);
|
|
5901
6830
|
var quoteColumn = (columnName, state, dialect, tableName) => dialect.quoteIdentifier(casedColumnName(columnName, state, tableName));
|
|
5902
|
-
var stateWithTableCasing = (state, source) => typeof source === "object" && source !== null && (
|
|
6831
|
+
var stateWithTableCasing = (state, source) => typeof source === "object" && source !== null && (TypeId7 in source) ? { ...state, casing: casingForTable(source, state) } : state;
|
|
5903
6832
|
var referenceCasing = (reference, state) => merge(state.casing, reference.casing);
|
|
5904
6833
|
var renderReferenceTable = (reference, state, dialect) => {
|
|
5905
6834
|
const casing = referenceCasing(reference, state);
|
|
@@ -5912,9 +6841,9 @@ var registerSourceReference = (source, tableName, state) => {
|
|
|
5912
6841
|
if (typeof source !== "object" || source === null) {
|
|
5913
6842
|
return;
|
|
5914
6843
|
}
|
|
5915
|
-
if (
|
|
6844
|
+
if (TypeId7 in source) {
|
|
5916
6845
|
const table = source;
|
|
5917
|
-
const tableState = table[
|
|
6846
|
+
const tableState = table[TypeId7];
|
|
5918
6847
|
const casing = casingForTable(table, state);
|
|
5919
6848
|
const renderedTableName = tableState.kind === "alias" ? tableName : applyCategory(casing, "tables", tableState.baseName);
|
|
5920
6849
|
const columns = new Map(Object.keys(tableState.fields).map((columnName) => [
|
|
@@ -5982,11 +6911,11 @@ var renderCreateTableSql = (targetSource, state, dialect, ifNotExists) => {
|
|
|
5982
6911
|
const normalizedIfNotExists = normalizeStatementFlag(ifNotExists);
|
|
5983
6912
|
const table = targetSource.source;
|
|
5984
6913
|
const tableCasing = casingForTable(table, state);
|
|
5985
|
-
const fields2 = table[
|
|
6914
|
+
const fields2 = table[TypeId7].fields;
|
|
5986
6915
|
const definitions = Object.entries(fields2).map(([columnName, column]) => renderColumnDefinition(dialect, state, columnName, column, targetSource.tableName, tableCasing));
|
|
5987
6916
|
const options2 = table[OptionsSymbol];
|
|
5988
6917
|
const tableOptions = Array.isArray(options2) ? options2 : [options2];
|
|
5989
|
-
validateOptions(table[
|
|
6918
|
+
validateOptions(table[TypeId7].name, fields2, tableOptions);
|
|
5990
6919
|
for (const option2 of tableOptions) {
|
|
5991
6920
|
if (typeof option2 !== "object" || option2 === null || !("kind" in option2)) {
|
|
5992
6921
|
continue;
|
|
@@ -6039,9 +6968,9 @@ var renderDropIndexSql = (targetSource, ddl, state, dialect) => {
|
|
|
6039
6968
|
const tableCasing = casingForTable(table, state);
|
|
6040
6969
|
return dialect.name === "postgres" || dialect.name === "sqlite" ? `drop index${ifExists ? " if exists" : ""} ${dialect.quoteIdentifier(applyCategory(tableCasing, "indexes", name))}` : `drop index ${dialect.quoteIdentifier(applyCategory(tableCasing, "indexes", name))} on ${renderSourceReference(targetSource.source, targetSource.tableName, targetSource.baseTableName, state, dialect)}`;
|
|
6041
6970
|
};
|
|
6042
|
-
var
|
|
6971
|
+
var isExpression4 = (value) => value !== null && typeof value === "object" && (TypeId in value);
|
|
6043
6972
|
var isJsonDbType2 = (dbType) => dbType.kind === "jsonb" || dbType.kind === "json" || ("variant" in dbType) && dbType.variant === "json";
|
|
6044
|
-
var
|
|
6973
|
+
var isJsonExpression2 = (value) => isExpression4(value) && isJsonDbType2(value[TypeId].dbType);
|
|
6045
6974
|
var expectValueExpression = (_functionName, value) => value;
|
|
6046
6975
|
var expectBinaryExpressions = (_functionName, left, right) => [left, right];
|
|
6047
6976
|
var renderBinaryExpression = (functionName, operator, left, right, state, dialect) => {
|
|
@@ -6058,7 +6987,7 @@ var unsupportedJsonFeature = (dialect, feature) => {
|
|
|
6058
6987
|
throw error;
|
|
6059
6988
|
};
|
|
6060
6989
|
var extractJsonBase = (node) => node.value ?? node.base ?? node.input ?? node.left ?? node.target;
|
|
6061
|
-
var isJsonPathValue2 = (value) => value !== null && typeof value === "object" && (
|
|
6990
|
+
var isJsonPathValue2 = (value) => value !== null && typeof value === "object" && (TypeId3 in value);
|
|
6062
6991
|
var isOptionalJsonPathNumber = (value) => value === undefined || typeof value === "number" && Number.isFinite(value);
|
|
6063
6992
|
var isJsonPathSegment = (segment) => {
|
|
6064
6993
|
if (typeof segment === "string") {
|
|
@@ -6074,8 +7003,8 @@ var isJsonPathSegment = (segment) => {
|
|
|
6074
7003
|
case "key":
|
|
6075
7004
|
return typeof segment.key === "string";
|
|
6076
7005
|
case "index": {
|
|
6077
|
-
const
|
|
6078
|
-
return typeof
|
|
7006
|
+
const index4 = segment.index;
|
|
7007
|
+
return typeof index4 === "number" && Number.isFinite(index4);
|
|
6079
7008
|
}
|
|
6080
7009
|
case "wildcard":
|
|
6081
7010
|
case "descend":
|
|
@@ -6096,12 +7025,12 @@ var validateJsonPathSegments = (segments) => {
|
|
|
6096
7025
|
return segments;
|
|
6097
7026
|
};
|
|
6098
7027
|
var extractJsonPathSegments = (node) => {
|
|
6099
|
-
const
|
|
6100
|
-
if (isJsonPathValue2(
|
|
6101
|
-
return validateJsonPathSegments(
|
|
7028
|
+
const path2 = node.path ?? node.segments ?? node.keys;
|
|
7029
|
+
if (isJsonPathValue2(path2)) {
|
|
7030
|
+
return validateJsonPathSegments(path2.segments);
|
|
6102
7031
|
}
|
|
6103
|
-
if (Array.isArray(
|
|
6104
|
-
return validateJsonPathSegments(
|
|
7032
|
+
if (Array.isArray(path2)) {
|
|
7033
|
+
return validateJsonPathSegments(path2);
|
|
6105
7034
|
}
|
|
6106
7035
|
if (node.segments !== undefined) {
|
|
6107
7036
|
return validateJsonPathSegments(node.segments);
|
|
@@ -6115,7 +7044,7 @@ var extractJsonPathSegments = (node) => {
|
|
|
6115
7044
|
return [key(segment)];
|
|
6116
7045
|
}
|
|
6117
7046
|
if (typeof segment === "number") {
|
|
6118
|
-
return [
|
|
7047
|
+
return [index(segment)];
|
|
6119
7048
|
}
|
|
6120
7049
|
if (segment !== null && typeof segment === "object" && SegmentTypeId in segment) {
|
|
6121
7050
|
return [segment];
|
|
@@ -6152,7 +7081,7 @@ var renderJsonPathSegment = (segment) => {
|
|
|
6152
7081
|
throw new Error("Unsupported JSON path segment");
|
|
6153
7082
|
}
|
|
6154
7083
|
};
|
|
6155
|
-
var renderSqliteJsonIndex = (
|
|
7084
|
+
var renderSqliteJsonIndex = (index4) => index4 >= 0 ? String(index4) : `#${index4}`;
|
|
6156
7085
|
var renderSqliteJsonPathSegment = (segment) => {
|
|
6157
7086
|
if (typeof segment === "number") {
|
|
6158
7087
|
return `[${renderSqliteJsonIndex(segment)}]`;
|
|
@@ -6172,11 +7101,11 @@ var renderSqliteJsonPathSegment = (segment) => {
|
|
|
6172
7101
|
return renderJsonPathSegment(segment);
|
|
6173
7102
|
};
|
|
6174
7103
|
var renderJsonPathStringLiteral = (segments, renderSegment = renderJsonPathSegment) => {
|
|
6175
|
-
let
|
|
7104
|
+
let path2 = "$";
|
|
6176
7105
|
for (const segment of segments) {
|
|
6177
|
-
|
|
7106
|
+
path2 += renderSegment(segment);
|
|
6178
7107
|
}
|
|
6179
|
-
return
|
|
7108
|
+
return path2;
|
|
6180
7109
|
};
|
|
6181
7110
|
var renderSqliteJsonPath = (segments, state, dialect) => dialect.renderLiteral(renderJsonPathStringLiteral(segments, renderSqliteJsonPathSegment), state);
|
|
6182
7111
|
var isJsonArrayIndexSegment = (segment) => typeof segment === "number" || typeof segment === "object" && segment !== null && segment.kind === "index";
|
|
@@ -6208,7 +7137,7 @@ var renderPostgresJsonAccessStep = (segment, textMode, state, dialect) => {
|
|
|
6208
7137
|
}
|
|
6209
7138
|
};
|
|
6210
7139
|
var renderPostgresJsonValue = (value, state, dialect) => {
|
|
6211
|
-
if (!
|
|
7140
|
+
if (!isExpression4(value)) {
|
|
6212
7141
|
throw new Error("Expected a JSON expression");
|
|
6213
7142
|
}
|
|
6214
7143
|
const rendered = renderExpression(value, state, dialect);
|
|
@@ -6259,7 +7188,7 @@ var renderJsonOpaquePath = (value, state, dialect) => {
|
|
|
6259
7188
|
}
|
|
6260
7189
|
return dialect.renderLiteral(value, state);
|
|
6261
7190
|
}
|
|
6262
|
-
if (
|
|
7191
|
+
if (isExpression4(value)) {
|
|
6263
7192
|
const ast = value[TypeId2];
|
|
6264
7193
|
if (ast.kind === "literal" && typeof ast.value === "string" && ast.value.trim().length === 0) {
|
|
6265
7194
|
throw new Error("SQL/JSON path input must be a non-empty string");
|
|
@@ -6313,8 +7242,8 @@ var renderJsonExpression = (expression, ast, state, dialect) => {
|
|
|
6313
7242
|
const base = extractJsonBase(ast);
|
|
6314
7243
|
const segments = extractJsonPathSegments(ast);
|
|
6315
7244
|
const exact = segments.every((segment) => segment.kind === "key" || segment.kind === "index");
|
|
6316
|
-
const postgresExpressionKind = dialect.name === "postgres" &&
|
|
6317
|
-
const postgresBaseKind = dialect.name === "postgres" &&
|
|
7245
|
+
const postgresExpressionKind = dialect.name === "postgres" && isJsonExpression2(expression) ? renderPostgresJsonKind(expression) : undefined;
|
|
7246
|
+
const postgresBaseKind = dialect.name === "postgres" && isJsonExpression2(base) ? renderPostgresJsonKind(base) : undefined;
|
|
6318
7247
|
switch (kind) {
|
|
6319
7248
|
case "jsonGet":
|
|
6320
7249
|
case "jsonPath":
|
|
@@ -6324,7 +7253,7 @@ var renderJsonExpression = (expression, ast, state, dialect) => {
|
|
|
6324
7253
|
case "jsonPathText":
|
|
6325
7254
|
case "jsonAccessText":
|
|
6326
7255
|
case "jsonTraverseText": {
|
|
6327
|
-
if (!
|
|
7256
|
+
if (!isExpression4(base) || segments.length === 0) {
|
|
6328
7257
|
return;
|
|
6329
7258
|
}
|
|
6330
7259
|
const baseSql = renderExpression(base, state, dialect);
|
|
@@ -6347,24 +7276,24 @@ var renderJsonExpression = (expression, ast, state, dialect) => {
|
|
|
6347
7276
|
case "jsonKeyExists":
|
|
6348
7277
|
case "jsonHasAnyKeys":
|
|
6349
7278
|
case "jsonHasAllKeys": {
|
|
6350
|
-
if (!
|
|
7279
|
+
if (!isExpression4(base)) {
|
|
6351
7280
|
return;
|
|
6352
7281
|
}
|
|
6353
7282
|
const baseSql = dialect.name === "postgres" ? renderPostgresJsonValue(base, state, dialect) : renderExpression(base, state, dialect);
|
|
6354
|
-
const
|
|
6355
|
-
if (
|
|
7283
|
+
const keys = extractJsonKeys(ast, segments);
|
|
7284
|
+
if (keys.length === 0) {
|
|
6356
7285
|
return;
|
|
6357
7286
|
}
|
|
6358
|
-
if (
|
|
7287
|
+
if (keys.some((key2) => typeof key2 !== "string" || key2.length === 0)) {
|
|
6359
7288
|
throw new Error("json key predicates require string keys");
|
|
6360
7289
|
}
|
|
6361
|
-
const keyNames =
|
|
7290
|
+
const keyNames = keys;
|
|
6362
7291
|
if (dialect.name === "postgres") {
|
|
6363
7292
|
if (kind === "jsonHasAnyKeys") {
|
|
6364
|
-
return `(${baseSql} ?| array[${keyNames.map((
|
|
7293
|
+
return `(${baseSql} ?| array[${keyNames.map((key2) => renderPostgresTextLiteral(key2, state, dialect)).join(", ")}])`;
|
|
6365
7294
|
}
|
|
6366
7295
|
if (kind === "jsonHasAllKeys") {
|
|
6367
|
-
return `(${baseSql} ?& array[${keyNames.map((
|
|
7296
|
+
return `(${baseSql} ?& array[${keyNames.map((key2) => renderPostgresTextLiteral(key2, state, dialect)).join(", ")}])`;
|
|
6368
7297
|
}
|
|
6369
7298
|
return `(${baseSql} ? ${renderPostgresTextLiteral(keyNames[0], state, dialect)})`;
|
|
6370
7299
|
}
|
|
@@ -6377,7 +7306,7 @@ var renderJsonExpression = (expression, ast, state, dialect) => {
|
|
|
6377
7306
|
}
|
|
6378
7307
|
case "jsonConcat":
|
|
6379
7308
|
case "jsonMerge": {
|
|
6380
|
-
if (!
|
|
7309
|
+
if (!isExpression4(ast.left) || !isExpression4(ast.right)) {
|
|
6381
7310
|
return;
|
|
6382
7311
|
}
|
|
6383
7312
|
if (dialect.name === "postgres") {
|
|
@@ -6414,7 +7343,7 @@ var renderJsonExpression = (expression, ast, state, dialect) => {
|
|
|
6414
7343
|
return;
|
|
6415
7344
|
}
|
|
6416
7345
|
case "jsonToJson":
|
|
6417
|
-
if (!
|
|
7346
|
+
if (!isExpression4(base)) {
|
|
6418
7347
|
return;
|
|
6419
7348
|
}
|
|
6420
7349
|
if (dialect.name === "postgres") {
|
|
@@ -6425,7 +7354,7 @@ var renderJsonExpression = (expression, ast, state, dialect) => {
|
|
|
6425
7354
|
}
|
|
6426
7355
|
return;
|
|
6427
7356
|
case "jsonToJsonb":
|
|
6428
|
-
if (!
|
|
7357
|
+
if (!isExpression4(base)) {
|
|
6429
7358
|
return;
|
|
6430
7359
|
}
|
|
6431
7360
|
if (dialect.name === "postgres") {
|
|
@@ -6436,7 +7365,7 @@ var renderJsonExpression = (expression, ast, state, dialect) => {
|
|
|
6436
7365
|
}
|
|
6437
7366
|
return;
|
|
6438
7367
|
case "jsonTypeOf":
|
|
6439
|
-
if (!
|
|
7368
|
+
if (!isExpression4(base)) {
|
|
6440
7369
|
return;
|
|
6441
7370
|
}
|
|
6442
7371
|
if (dialect.name === "postgres") {
|
|
@@ -6448,7 +7377,7 @@ var renderJsonExpression = (expression, ast, state, dialect) => {
|
|
|
6448
7377
|
}
|
|
6449
7378
|
return;
|
|
6450
7379
|
case "jsonLength":
|
|
6451
|
-
if (!
|
|
7380
|
+
if (!isExpression4(base)) {
|
|
6452
7381
|
return;
|
|
6453
7382
|
}
|
|
6454
7383
|
if (dialect.name === "postgres") {
|
|
@@ -6467,7 +7396,7 @@ var renderJsonExpression = (expression, ast, state, dialect) => {
|
|
|
6467
7396
|
}
|
|
6468
7397
|
return;
|
|
6469
7398
|
case "jsonKeys":
|
|
6470
|
-
if (!
|
|
7399
|
+
if (!isExpression4(base)) {
|
|
6471
7400
|
return;
|
|
6472
7401
|
}
|
|
6473
7402
|
if (dialect.name === "postgres") {
|
|
@@ -6482,7 +7411,7 @@ var renderJsonExpression = (expression, ast, state, dialect) => {
|
|
|
6482
7411
|
}
|
|
6483
7412
|
return;
|
|
6484
7413
|
case "jsonStripNulls":
|
|
6485
|
-
if (!
|
|
7414
|
+
if (!isExpression4(base)) {
|
|
6486
7415
|
return;
|
|
6487
7416
|
}
|
|
6488
7417
|
if (dialect.name === "postgres") {
|
|
@@ -6493,7 +7422,7 @@ var renderJsonExpression = (expression, ast, state, dialect) => {
|
|
|
6493
7422
|
case "jsonDelete":
|
|
6494
7423
|
case "jsonDeletePath":
|
|
6495
7424
|
case "jsonRemove": {
|
|
6496
|
-
if (!
|
|
7425
|
+
if (!isExpression4(base) || segments.length === 0) {
|
|
6497
7426
|
return;
|
|
6498
7427
|
}
|
|
6499
7428
|
if (dialect.name === "postgres") {
|
|
@@ -6511,11 +7440,11 @@ var renderJsonExpression = (expression, ast, state, dialect) => {
|
|
|
6511
7440
|
}
|
|
6512
7441
|
case "jsonSet":
|
|
6513
7442
|
case "jsonInsert": {
|
|
6514
|
-
if (!
|
|
7443
|
+
if (!isExpression4(base) || segments.length === 0) {
|
|
6515
7444
|
return;
|
|
6516
7445
|
}
|
|
6517
7446
|
const nextValue = extractJsonValue(ast);
|
|
6518
|
-
if (!
|
|
7447
|
+
if (!isExpression4(nextValue)) {
|
|
6519
7448
|
return;
|
|
6520
7449
|
}
|
|
6521
7450
|
const createMissing = ast.createMissing === true;
|
|
@@ -6535,39 +7464,39 @@ var renderJsonExpression = (expression, ast, state, dialect) => {
|
|
|
6535
7464
|
return;
|
|
6536
7465
|
}
|
|
6537
7466
|
case "jsonPathExists": {
|
|
6538
|
-
if (!
|
|
7467
|
+
if (!isExpression4(base)) {
|
|
6539
7468
|
return;
|
|
6540
7469
|
}
|
|
6541
|
-
const
|
|
6542
|
-
if (
|
|
7470
|
+
const path2 = ast.path ?? ast.query ?? ast.right;
|
|
7471
|
+
if (path2 === undefined) {
|
|
6543
7472
|
return;
|
|
6544
7473
|
}
|
|
6545
7474
|
if (dialect.name === "postgres") {
|
|
6546
|
-
return `(${renderPostgresJsonValue(base, state, dialect)} @? ${renderJsonOpaquePath(
|
|
7475
|
+
return `(${renderPostgresJsonValue(base, state, dialect)} @? ${renderJsonOpaquePath(path2, state, dialect)})`;
|
|
6547
7476
|
}
|
|
6548
7477
|
if (dialect.name === "sqlite") {
|
|
6549
|
-
return `(json_type(${renderExpression(base, state, dialect)}, ${renderJsonOpaquePath(
|
|
7478
|
+
return `(json_type(${renderExpression(base, state, dialect)}, ${renderJsonOpaquePath(path2, state, dialect)}) is not null)`;
|
|
6550
7479
|
}
|
|
6551
7480
|
return;
|
|
6552
7481
|
}
|
|
6553
7482
|
case "jsonPathMatch": {
|
|
6554
|
-
if (!
|
|
7483
|
+
if (!isExpression4(base)) {
|
|
6555
7484
|
return;
|
|
6556
7485
|
}
|
|
6557
|
-
const
|
|
6558
|
-
if (
|
|
7486
|
+
const path2 = ast.path ?? ast.query ?? ast.right;
|
|
7487
|
+
if (path2 === undefined) {
|
|
6559
7488
|
return;
|
|
6560
7489
|
}
|
|
6561
7490
|
if (dialect.name === "postgres") {
|
|
6562
|
-
return `(${renderPostgresJsonValue(base, state, dialect)} @@ ${renderJsonOpaquePath(
|
|
7491
|
+
return `(${renderPostgresJsonValue(base, state, dialect)} @@ ${renderJsonOpaquePath(path2, state, dialect)})`;
|
|
6563
7492
|
}
|
|
6564
7493
|
unsupportedJsonFeature(dialect, "jsonPathMatch");
|
|
6565
7494
|
}
|
|
6566
7495
|
}
|
|
6567
7496
|
return;
|
|
6568
7497
|
};
|
|
6569
|
-
var selectionProjections = (selection) => flattenSelection(selection).map(({ path:
|
|
6570
|
-
path:
|
|
7498
|
+
var selectionProjections = (selection) => flattenSelection(selection).map(({ path: path2, alias: alias2 }) => ({
|
|
7499
|
+
path: path2,
|
|
6571
7500
|
alias: alias2
|
|
6572
7501
|
}));
|
|
6573
7502
|
var renderMutationAssignment = (entry, state, dialect, targetTableName) => {
|
|
@@ -6698,18 +7627,18 @@ var renderQueryAst = (ast, state, dialect, options2 = {}) => {
|
|
|
6698
7627
|
const columns = insertSource.columns.map((column) => quoteColumn(column, state, dialect, targetSource.tableName)).join(", ");
|
|
6699
7628
|
if (dialect.name === "postgres") {
|
|
6700
7629
|
const table = targetSource.source;
|
|
6701
|
-
const fields2 = table[
|
|
7630
|
+
const fields2 = table[TypeId7].fields;
|
|
6702
7631
|
const rendered = insertSource.values.map((entry) => `cast(${dialect.renderLiteral(encodeArrayValues(entry.values, fields2[entry.columnName], state, dialect), state)} as ${renderCastType(dialect, fields2[entry.columnName].metadata.dbType)}[])`).join(", ");
|
|
6703
7632
|
sql += ` (${columns}) select * from unnest(${rendered})`;
|
|
6704
7633
|
} else {
|
|
6705
7634
|
const table = targetSource.source;
|
|
6706
|
-
const fields2 = table[
|
|
7635
|
+
const fields2 = table[TypeId7].fields;
|
|
6707
7636
|
const encodedValues = insertSource.values.map((entry) => ({
|
|
6708
7637
|
columnName: entry.columnName,
|
|
6709
7638
|
values: encodeArrayValues(entry.values, fields2[entry.columnName], state, dialect)
|
|
6710
7639
|
}));
|
|
6711
7640
|
const rowCount = encodedValues[0]?.values.length ?? 0;
|
|
6712
|
-
const rows = Array.from({ length: rowCount }, (_,
|
|
7641
|
+
const rows = Array.from({ length: rowCount }, (_, index4) => `(${encodedValues.map((entry) => dialect.renderLiteral(entry.values[index4], state)).join(", ")})`).join(", ");
|
|
6713
7642
|
sql += ` (${columns}) values ${rows}`;
|
|
6714
7643
|
}
|
|
6715
7644
|
} else {
|
|
@@ -6851,25 +7780,25 @@ var renderQueryAst = (ast, state, dialect, options2 = {}) => {
|
|
|
6851
7780
|
const mergeAst = ast;
|
|
6852
7781
|
const targetSource = mergeAst.target;
|
|
6853
7782
|
const usingSource = mergeAst.using;
|
|
6854
|
-
const
|
|
6855
|
-
sql = `merge into ${renderSourceReference(targetSource.source, targetSource.tableName, targetSource.baseTableName, state, dialect)} using ${renderSourceReference(usingSource.source, usingSource.tableName, usingSource.baseTableName, state, dialect)} on ${renderExpression(
|
|
6856
|
-
if (
|
|
7783
|
+
const merge2 = mergeAst.merge;
|
|
7784
|
+
sql = `merge into ${renderSourceReference(targetSource.source, targetSource.tableName, targetSource.baseTableName, state, dialect)} using ${renderSourceReference(usingSource.source, usingSource.tableName, usingSource.baseTableName, state, dialect)} on ${renderExpression(merge2.on, state, dialect)}`;
|
|
7785
|
+
if (merge2.whenMatched) {
|
|
6857
7786
|
sql += " when matched";
|
|
6858
|
-
if (
|
|
6859
|
-
sql += ` and ${renderExpression(
|
|
7787
|
+
if (merge2.whenMatched.predicate) {
|
|
7788
|
+
sql += ` and ${renderExpression(merge2.whenMatched.predicate, state, dialect)}`;
|
|
6860
7789
|
}
|
|
6861
|
-
if (
|
|
7790
|
+
if (merge2.whenMatched.kind === "delete") {
|
|
6862
7791
|
sql += " then delete";
|
|
6863
7792
|
} else {
|
|
6864
|
-
sql += ` then update set ${
|
|
7793
|
+
sql += ` then update set ${merge2.whenMatched.values.map((entry) => `${dialect.quoteIdentifier(entry.columnName)} = ${renderExpression(entry.value, state, dialect)}`).join(", ")}`;
|
|
6865
7794
|
}
|
|
6866
7795
|
}
|
|
6867
|
-
if (
|
|
7796
|
+
if (merge2.whenNotMatched) {
|
|
6868
7797
|
sql += " when not matched";
|
|
6869
|
-
if (
|
|
6870
|
-
sql += ` and ${renderExpression(
|
|
7798
|
+
if (merge2.whenNotMatched.predicate) {
|
|
7799
|
+
sql += ` and ${renderExpression(merge2.whenNotMatched.predicate, state, dialect)}`;
|
|
6871
7800
|
}
|
|
6872
|
-
sql += ` then insert (${
|
|
7801
|
+
sql += ` then insert (${merge2.whenNotMatched.values.map((entry) => dialect.quoteIdentifier(entry.columnName)).join(", ")}) values (${merge2.whenNotMatched.values.map((entry) => renderExpression(entry.value, state, dialect)).join(", ")})`;
|
|
6873
7802
|
}
|
|
6874
7803
|
break;
|
|
6875
7804
|
}
|
|
@@ -6930,7 +7859,7 @@ var renderSourceReference = (source, tableName, baseTableName, state, dialect) =
|
|
|
6930
7859
|
};
|
|
6931
7860
|
const renderUnnestRows = (arrays, columnNames) => {
|
|
6932
7861
|
const rowCount = arrays[columnNames[0]].length;
|
|
6933
|
-
const rows = Array.from({ length: rowCount }, (_,
|
|
7862
|
+
const rows = Array.from({ length: rowCount }, (_, index4) => Object.fromEntries(columnNames.map((columnName) => [columnName, arrays[columnName][index4]])));
|
|
6934
7863
|
return renderSelectRows(rows, columnNames);
|
|
6935
7864
|
};
|
|
6936
7865
|
if (typeof source === "object" && source !== null && "kind" in source && source.kind === "cte") {
|
|
@@ -6988,10 +7917,10 @@ var renderSourceReference = (source, tableName, baseTableName, state, dialect) =
|
|
|
6988
7917
|
const columnNames = Object.keys(tableFunction.columns);
|
|
6989
7918
|
return `${functionName}(${tableFunction.args.map((arg) => renderExpression(arg, state, dialect)).join(", ")}) as ${dialect.quoteIdentifier(tableFunction.name)}(${columnNames.map((columnName) => dialect.quoteIdentifier(columnName)).join(", ")})`;
|
|
6990
7919
|
}
|
|
6991
|
-
const schemaName = typeof source === "object" && source !== null &&
|
|
6992
|
-
if (typeof source === "object" && source !== null &&
|
|
7920
|
+
const schemaName = typeof source === "object" && source !== null && TypeId7 in source ? source[TypeId7].schemaName : undefined;
|
|
7921
|
+
if (typeof source === "object" && source !== null && TypeId7 in source) {
|
|
6993
7922
|
const table = source;
|
|
6994
|
-
const tableState = table[
|
|
7923
|
+
const tableState = table[TypeId7];
|
|
6995
7924
|
const casing = casingForTable(table, state);
|
|
6996
7925
|
const renderedTableName = tableState.kind === "alias" ? tableName : applyCategory(casing, "tables", baseTableName);
|
|
6997
7926
|
const renderedBaseName = applyCategory(casing, "tables", baseTableName);
|
|
@@ -7088,8 +8017,8 @@ var renderExpression = (expression, state, dialect) => {
|
|
|
7088
8017
|
case "contains": {
|
|
7089
8018
|
const [leftExpression, rightExpression] = expectBinaryExpressions("contains", ast.left, ast.right);
|
|
7090
8019
|
if (dialect.name === "postgres") {
|
|
7091
|
-
const left =
|
|
7092
|
-
const right =
|
|
8020
|
+
const left = isJsonExpression2(leftExpression) ? renderPostgresJsonValue(leftExpression, state, dialect) : renderExpression(leftExpression, state, dialect);
|
|
8021
|
+
const right = isJsonExpression2(rightExpression) ? renderPostgresJsonValue(rightExpression, state, dialect) : renderExpression(rightExpression, state, dialect);
|
|
7093
8022
|
return `(${left} @> ${right})`;
|
|
7094
8023
|
}
|
|
7095
8024
|
throw new Error("Unsupported container operator for SQL rendering");
|
|
@@ -7097,8 +8026,8 @@ var renderExpression = (expression, state, dialect) => {
|
|
|
7097
8026
|
case "containedBy": {
|
|
7098
8027
|
const [leftExpression, rightExpression] = expectBinaryExpressions("containedBy", ast.left, ast.right);
|
|
7099
8028
|
if (dialect.name === "postgres") {
|
|
7100
|
-
const left =
|
|
7101
|
-
const right =
|
|
8029
|
+
const left = isJsonExpression2(leftExpression) ? renderPostgresJsonValue(leftExpression, state, dialect) : renderExpression(leftExpression, state, dialect);
|
|
8030
|
+
const right = isJsonExpression2(rightExpression) ? renderPostgresJsonValue(rightExpression, state, dialect) : renderExpression(rightExpression, state, dialect);
|
|
7102
8031
|
return `(${left} <@ ${right})`;
|
|
7103
8032
|
}
|
|
7104
8033
|
throw new Error("Unsupported container operator for SQL rendering");
|
|
@@ -7106,8 +8035,8 @@ var renderExpression = (expression, state, dialect) => {
|
|
|
7106
8035
|
case "overlaps": {
|
|
7107
8036
|
const [leftExpression, rightExpression] = expectBinaryExpressions("overlaps", ast.left, ast.right);
|
|
7108
8037
|
if (dialect.name === "postgres") {
|
|
7109
|
-
const left =
|
|
7110
|
-
const right =
|
|
8038
|
+
const left = isJsonExpression2(leftExpression) ? renderPostgresJsonValue(leftExpression, state, dialect) : renderExpression(leftExpression, state, dialect);
|
|
8039
|
+
const right = isJsonExpression2(rightExpression) ? renderPostgresJsonValue(rightExpression, state, dialect) : renderExpression(rightExpression, state, dialect);
|
|
7111
8040
|
return `(${left} && ${right})`;
|
|
7112
8041
|
}
|
|
7113
8042
|
throw new Error("Unsupported container operator for SQL rendering");
|
|
@@ -7196,14 +8125,15 @@ var renderExpression = (expression, state, dialect) => {
|
|
|
7196
8125
|
// src/internal/dialect-renderers/postgres.ts
|
|
7197
8126
|
import * as Schema11 from "effect/Schema";
|
|
7198
8127
|
var renderDbType2 = (dialect, dbType) => {
|
|
7199
|
-
|
|
7200
|
-
return "bytea";
|
|
7201
|
-
}
|
|
7202
|
-
return renderDbTypeName(dbType.kind);
|
|
8128
|
+
return renderDbTypeName(renderPortableDatatypeDdlType(dialect.name, dbType.kind) ?? dbType.kind);
|
|
7203
8129
|
};
|
|
7204
8130
|
var isArrayDbType2 = (dbType) => ("element" in dbType);
|
|
7205
8131
|
var renderCastType2 = (dialect, dbType) => {
|
|
7206
8132
|
const kind = dbType?.kind;
|
|
8133
|
+
const portableType = renderPortableDatatypeCastType(dialect.name, kind);
|
|
8134
|
+
if (portableType !== undefined) {
|
|
8135
|
+
return renderDbTypeName(portableType);
|
|
8136
|
+
}
|
|
7207
8137
|
if (dialect.name !== "mysql") {
|
|
7208
8138
|
return renderDbTypeName(kind);
|
|
7209
8139
|
}
|
|
@@ -7225,13 +8155,13 @@ var renderCastType2 = (dialect, dbType) => {
|
|
|
7225
8155
|
return renderDbTypeName(kind);
|
|
7226
8156
|
}
|
|
7227
8157
|
};
|
|
7228
|
-
var casingForTable2 = (table, state) => merge(state.casing, table[
|
|
8158
|
+
var casingForTable2 = (table, state) => merge(state.casing, table[TypeId7].casing);
|
|
7229
8159
|
var casedTableName = (table, state) => {
|
|
7230
|
-
const tableState = table[
|
|
8160
|
+
const tableState = table[TypeId7];
|
|
7231
8161
|
return applyCategory(casingForTable2(table, state), "tables", tableState.baseName);
|
|
7232
8162
|
};
|
|
7233
8163
|
var casedSchemaName = (table, state) => {
|
|
7234
|
-
const schemaName = table[
|
|
8164
|
+
const schemaName = table[TypeId7].schemaName;
|
|
7235
8165
|
return schemaName === undefined ? undefined : applyCategory(casingForTable2(table, state), "schemas", schemaName);
|
|
7236
8166
|
};
|
|
7237
8167
|
var casedColumnName2 = (columnName, state, tableName) => {
|
|
@@ -7245,7 +8175,7 @@ var casedColumnName2 = (columnName, state, tableName) => {
|
|
|
7245
8175
|
};
|
|
7246
8176
|
var casedTableReferenceName2 = (tableName, state) => state.sourceNames?.get(tableName)?.tableName ?? applyCategory(state.casing, "tables", tableName);
|
|
7247
8177
|
var quoteColumn2 = (columnName, state, dialect, tableName) => dialect.quoteIdentifier(casedColumnName2(columnName, state, tableName));
|
|
7248
|
-
var stateWithTableCasing2 = (state, source) => typeof source === "object" && source !== null && (
|
|
8178
|
+
var stateWithTableCasing2 = (state, source) => typeof source === "object" && source !== null && (TypeId7 in source) ? { ...state, casing: casingForTable2(source, state) } : state;
|
|
7249
8179
|
var referenceCasing2 = (reference, state) => merge(state.casing, reference.casing);
|
|
7250
8180
|
var renderReferenceTable2 = (reference, state, dialect) => {
|
|
7251
8181
|
const casing = referenceCasing2(reference, state);
|
|
@@ -7258,9 +8188,9 @@ var registerSourceReference2 = (source, tableName, state) => {
|
|
|
7258
8188
|
if (typeof source !== "object" || source === null) {
|
|
7259
8189
|
return;
|
|
7260
8190
|
}
|
|
7261
|
-
if (
|
|
8191
|
+
if (TypeId7 in source) {
|
|
7262
8192
|
const table = source;
|
|
7263
|
-
const tableState = table[
|
|
8193
|
+
const tableState = table[TypeId7];
|
|
7264
8194
|
const casing = casingForTable2(table, state);
|
|
7265
8195
|
const renderedTableName = tableState.kind === "alias" ? tableName : applyCategory(casing, "tables", tableState.baseName);
|
|
7266
8196
|
const columns = new Map(Object.keys(tableState.fields).map((columnName) => [
|
|
@@ -7374,11 +8304,11 @@ var renderCreateTableSql2 = (targetSource, state, dialect, ifNotExists) => {
|
|
|
7374
8304
|
}
|
|
7375
8305
|
const table = targetSource.source;
|
|
7376
8306
|
const tableCasing = casingForTable2(table, state);
|
|
7377
|
-
const fields2 = table[
|
|
8307
|
+
const fields2 = table[TypeId7].fields;
|
|
7378
8308
|
const definitions = Object.entries(fields2).map(([columnName, column]) => renderColumnDefinition2(dialect, state, columnName, column, targetSource.tableName, tableCasing));
|
|
7379
8309
|
const options2 = table[OptionsSymbol];
|
|
7380
8310
|
const tableOptions = Array.isArray(options2) ? options2 : [options2];
|
|
7381
|
-
validateOptions(table[
|
|
8311
|
+
validateOptions(table[TypeId7].name, fields2, tableOptions);
|
|
7382
8312
|
for (const option2 of tableOptions) {
|
|
7383
8313
|
if (typeof option2 !== "object" || option2 === null || !("kind" in option2)) {
|
|
7384
8314
|
continue;
|
|
@@ -7437,8 +8367,8 @@ var renderDropIndexSql2 = (targetSource, ddl, state, dialect) => {
|
|
|
7437
8367
|
throw new Error(`Unsupported ${dialect.name} drop index options`);
|
|
7438
8368
|
}
|
|
7439
8369
|
if (dialect.name === "postgres") {
|
|
7440
|
-
const table2 = typeof targetSource.source === "object" && targetSource.source !== null &&
|
|
7441
|
-
const schemaName = table2?.[
|
|
8370
|
+
const table2 = typeof targetSource.source === "object" && targetSource.source !== null && TypeId7 in targetSource.source ? targetSource.source : undefined;
|
|
8371
|
+
const schemaName = table2?.[TypeId7].schemaName;
|
|
7442
8372
|
const tableCasing2 = table2 === undefined ? state.casing : casingForTable2(table2, state);
|
|
7443
8373
|
const renderedSchemaName = table2 === undefined ? schemaName : casedSchemaName(table2, state);
|
|
7444
8374
|
const renderedIndexName = applyCategory(tableCasing2, "indexes", name);
|
|
@@ -7449,7 +8379,7 @@ var renderDropIndexSql2 = (targetSource, ddl, state, dialect) => {
|
|
|
7449
8379
|
const tableCasing = casingForTable2(table, state);
|
|
7450
8380
|
return `drop index ${dialect.quoteIdentifier(applyCategory(tableCasing, "indexes", name))} on ${renderSourceReference2(targetSource.source, targetSource.tableName, targetSource.baseTableName, state, dialect)}`;
|
|
7451
8381
|
};
|
|
7452
|
-
var
|
|
8382
|
+
var isExpression5 = (value) => value !== null && typeof value === "object" && (TypeId in value);
|
|
7453
8383
|
var isJsonDbType3 = (dbType) => {
|
|
7454
8384
|
if (dbType.kind === "jsonb" || dbType.kind === "json") {
|
|
7455
8385
|
return true;
|
|
@@ -7460,7 +8390,7 @@ var isJsonDbType3 = (dbType) => {
|
|
|
7460
8390
|
const variant = dbType.variant;
|
|
7461
8391
|
return variant === "json" || variant === "jsonb";
|
|
7462
8392
|
};
|
|
7463
|
-
var
|
|
8393
|
+
var isJsonExpression3 = (value) => isExpression5(value) && isJsonDbType3(value[TypeId].dbType);
|
|
7464
8394
|
var expectValueExpression2 = (_functionName, value) => value;
|
|
7465
8395
|
var expectBinaryExpressions2 = (_functionName, left, right) => [left, right];
|
|
7466
8396
|
var renderBinaryExpression2 = (functionName, operator, left, right, state, dialect) => {
|
|
@@ -7507,7 +8437,7 @@ var unsupportedJsonFeature2 = (dialect, feature) => {
|
|
|
7507
8437
|
throw error;
|
|
7508
8438
|
};
|
|
7509
8439
|
var extractJsonBase2 = (node) => node.value ?? node.base ?? node.input ?? node.left ?? node.target;
|
|
7510
|
-
var isJsonPathValue3 = (value) => value !== null && typeof value === "object" && (
|
|
8440
|
+
var isJsonPathValue3 = (value) => value !== null && typeof value === "object" && (TypeId3 in value);
|
|
7511
8441
|
var isOptionalJsonPathNumber2 = (value) => value === undefined || typeof value === "number" && Number.isFinite(value);
|
|
7512
8442
|
var isJsonPathSegment2 = (segment) => {
|
|
7513
8443
|
if (typeof segment === "string") {
|
|
@@ -7523,8 +8453,8 @@ var isJsonPathSegment2 = (segment) => {
|
|
|
7523
8453
|
case "key":
|
|
7524
8454
|
return typeof segment.key === "string";
|
|
7525
8455
|
case "index": {
|
|
7526
|
-
const
|
|
7527
|
-
return typeof
|
|
8456
|
+
const index4 = segment.index;
|
|
8457
|
+
return typeof index4 === "number" && Number.isFinite(index4);
|
|
7528
8458
|
}
|
|
7529
8459
|
case "wildcard":
|
|
7530
8460
|
case "descend":
|
|
@@ -7545,12 +8475,12 @@ var validateJsonPathSegments2 = (segments) => {
|
|
|
7545
8475
|
return segments;
|
|
7546
8476
|
};
|
|
7547
8477
|
var extractJsonPathSegments2 = (node) => {
|
|
7548
|
-
const
|
|
7549
|
-
if (isJsonPathValue3(
|
|
7550
|
-
return validateJsonPathSegments2(
|
|
8478
|
+
const path2 = node.path ?? node.segments ?? node.keys;
|
|
8479
|
+
if (isJsonPathValue3(path2)) {
|
|
8480
|
+
return validateJsonPathSegments2(path2.segments);
|
|
7551
8481
|
}
|
|
7552
|
-
if (Array.isArray(
|
|
7553
|
-
return validateJsonPathSegments2(
|
|
8482
|
+
if (Array.isArray(path2)) {
|
|
8483
|
+
return validateJsonPathSegments2(path2);
|
|
7554
8484
|
}
|
|
7555
8485
|
if (node.segments !== undefined) {
|
|
7556
8486
|
return validateJsonPathSegments2(node.segments);
|
|
@@ -7564,7 +8494,7 @@ var extractJsonPathSegments2 = (node) => {
|
|
|
7564
8494
|
return [key(segment)];
|
|
7565
8495
|
}
|
|
7566
8496
|
if (typeof segment === "number") {
|
|
7567
|
-
return [
|
|
8497
|
+
return [index(segment)];
|
|
7568
8498
|
}
|
|
7569
8499
|
if (segment !== null && typeof segment === "object" && SegmentTypeId in segment) {
|
|
7570
8500
|
return [segment];
|
|
@@ -7602,11 +8532,11 @@ var renderJsonPathSegment2 = (segment) => {
|
|
|
7602
8532
|
}
|
|
7603
8533
|
};
|
|
7604
8534
|
var renderJsonPathStringLiteral2 = (segments) => {
|
|
7605
|
-
let
|
|
8535
|
+
let path2 = "$";
|
|
7606
8536
|
for (const segment of segments) {
|
|
7607
|
-
|
|
8537
|
+
path2 += renderJsonPathSegment2(segment);
|
|
7608
8538
|
}
|
|
7609
|
-
return
|
|
8539
|
+
return path2;
|
|
7610
8540
|
};
|
|
7611
8541
|
var renderMySqlJsonPath = (segments, state, dialect) => dialect.renderLiteral(renderJsonPathStringLiteral2(segments), state);
|
|
7612
8542
|
var renderPostgresJsonPathArray2 = (segments, state, dialect) => `array[${segments.map((segment) => {
|
|
@@ -7637,7 +8567,7 @@ var renderPostgresJsonAccessStep2 = (segment, textMode, state, dialect) => {
|
|
|
7637
8567
|
}
|
|
7638
8568
|
};
|
|
7639
8569
|
var renderPostgresJsonValue2 = (value, state, dialect) => {
|
|
7640
|
-
if (!
|
|
8570
|
+
if (!isExpression5(value)) {
|
|
7641
8571
|
throw new Error("Expected a JSON expression");
|
|
7642
8572
|
}
|
|
7643
8573
|
const rendered = renderExpression2(value, state, dialect);
|
|
@@ -7681,7 +8611,7 @@ var renderJsonOpaquePath2 = (value, state, dialect) => {
|
|
|
7681
8611
|
}
|
|
7682
8612
|
return dialect.renderLiteral(value, state);
|
|
7683
8613
|
}
|
|
7684
|
-
if (
|
|
8614
|
+
if (isExpression5(value)) {
|
|
7685
8615
|
const ast = value[TypeId2];
|
|
7686
8616
|
if (ast.kind === "literal" && typeof ast.value === "string" && ast.value.trim().length === 0) {
|
|
7687
8617
|
throw new Error("SQL/JSON path input must be a non-empty string");
|
|
@@ -7731,8 +8661,8 @@ var renderJsonExpression2 = (expression, ast, state, dialect) => {
|
|
|
7731
8661
|
const base = extractJsonBase2(ast);
|
|
7732
8662
|
const segments = extractJsonPathSegments2(ast);
|
|
7733
8663
|
const exact = segments.every((segment) => segment.kind === "key" || segment.kind === "index");
|
|
7734
|
-
const postgresExpressionKind = dialect.name === "postgres" &&
|
|
7735
|
-
const postgresBaseKind = dialect.name === "postgres" &&
|
|
8664
|
+
const postgresExpressionKind = dialect.name === "postgres" && isJsonExpression3(expression) ? renderPostgresJsonKind2(expression) : undefined;
|
|
8665
|
+
const postgresBaseKind = dialect.name === "postgres" && isJsonExpression3(base) ? renderPostgresJsonKind2(base) : undefined;
|
|
7736
8666
|
switch (kind) {
|
|
7737
8667
|
case "jsonGet":
|
|
7738
8668
|
case "jsonPath":
|
|
@@ -7742,7 +8672,7 @@ var renderJsonExpression2 = (expression, ast, state, dialect) => {
|
|
|
7742
8672
|
case "jsonPathText":
|
|
7743
8673
|
case "jsonAccessText":
|
|
7744
8674
|
case "jsonTraverseText": {
|
|
7745
|
-
if (!
|
|
8675
|
+
if (!isExpression5(base) || segments.length === 0) {
|
|
7746
8676
|
return;
|
|
7747
8677
|
}
|
|
7748
8678
|
const baseSql = renderExpression2(base, state, dialect);
|
|
@@ -7765,24 +8695,24 @@ var renderJsonExpression2 = (expression, ast, state, dialect) => {
|
|
|
7765
8695
|
case "jsonKeyExists":
|
|
7766
8696
|
case "jsonHasAnyKeys":
|
|
7767
8697
|
case "jsonHasAllKeys": {
|
|
7768
|
-
if (!
|
|
8698
|
+
if (!isExpression5(base)) {
|
|
7769
8699
|
return;
|
|
7770
8700
|
}
|
|
7771
8701
|
const baseSql = dialect.name === "postgres" ? renderPostgresJsonValue2(base, state, dialect) : renderExpression2(base, state, dialect);
|
|
7772
|
-
const
|
|
7773
|
-
if (
|
|
8702
|
+
const keys = extractJsonKeys2(ast, segments);
|
|
8703
|
+
if (keys.length === 0) {
|
|
7774
8704
|
return;
|
|
7775
8705
|
}
|
|
7776
|
-
if (
|
|
8706
|
+
if (keys.some((key2) => typeof key2 !== "string" || key2.length === 0)) {
|
|
7777
8707
|
throw new Error("json key predicates require string keys");
|
|
7778
8708
|
}
|
|
7779
|
-
const keyNames =
|
|
8709
|
+
const keyNames = keys;
|
|
7780
8710
|
if (dialect.name === "postgres") {
|
|
7781
8711
|
if (kind === "jsonHasAnyKeys") {
|
|
7782
|
-
return `(${baseSql} ?| array[${keyNames.map((
|
|
8712
|
+
return `(${baseSql} ?| array[${keyNames.map((key2) => renderPostgresTextLiteral2(key2, state, dialect)).join(", ")}])`;
|
|
7783
8713
|
}
|
|
7784
8714
|
if (kind === "jsonHasAllKeys") {
|
|
7785
|
-
return `(${baseSql} ?& array[${keyNames.map((
|
|
8715
|
+
return `(${baseSql} ?& array[${keyNames.map((key2) => renderPostgresTextLiteral2(key2, state, dialect)).join(", ")}])`;
|
|
7786
8716
|
}
|
|
7787
8717
|
return `(${baseSql} ? ${renderPostgresTextLiteral2(keyNames[0], state, dialect)})`;
|
|
7788
8718
|
}
|
|
@@ -7795,7 +8725,7 @@ var renderJsonExpression2 = (expression, ast, state, dialect) => {
|
|
|
7795
8725
|
}
|
|
7796
8726
|
case "jsonConcat":
|
|
7797
8727
|
case "jsonMerge": {
|
|
7798
|
-
if (!
|
|
8728
|
+
if (!isExpression5(ast.left) || !isExpression5(ast.right)) {
|
|
7799
8729
|
return;
|
|
7800
8730
|
}
|
|
7801
8731
|
if (dialect.name === "postgres") {
|
|
@@ -7832,7 +8762,7 @@ var renderJsonExpression2 = (expression, ast, state, dialect) => {
|
|
|
7832
8762
|
return;
|
|
7833
8763
|
}
|
|
7834
8764
|
case "jsonToJson":
|
|
7835
|
-
if (!
|
|
8765
|
+
if (!isExpression5(base)) {
|
|
7836
8766
|
return;
|
|
7837
8767
|
}
|
|
7838
8768
|
if (dialect.name === "postgres") {
|
|
@@ -7843,7 +8773,7 @@ var renderJsonExpression2 = (expression, ast, state, dialect) => {
|
|
|
7843
8773
|
}
|
|
7844
8774
|
return;
|
|
7845
8775
|
case "jsonToJsonb":
|
|
7846
|
-
if (!
|
|
8776
|
+
if (!isExpression5(base)) {
|
|
7847
8777
|
return;
|
|
7848
8778
|
}
|
|
7849
8779
|
if (dialect.name === "postgres") {
|
|
@@ -7854,7 +8784,7 @@ var renderJsonExpression2 = (expression, ast, state, dialect) => {
|
|
|
7854
8784
|
}
|
|
7855
8785
|
return;
|
|
7856
8786
|
case "jsonTypeOf":
|
|
7857
|
-
if (!
|
|
8787
|
+
if (!isExpression5(base)) {
|
|
7858
8788
|
return;
|
|
7859
8789
|
}
|
|
7860
8790
|
if (dialect.name === "postgres") {
|
|
@@ -7866,7 +8796,7 @@ var renderJsonExpression2 = (expression, ast, state, dialect) => {
|
|
|
7866
8796
|
}
|
|
7867
8797
|
return;
|
|
7868
8798
|
case "jsonLength":
|
|
7869
|
-
if (!
|
|
8799
|
+
if (!isExpression5(base)) {
|
|
7870
8800
|
return;
|
|
7871
8801
|
}
|
|
7872
8802
|
if (dialect.name === "postgres") {
|
|
@@ -7881,7 +8811,7 @@ var renderJsonExpression2 = (expression, ast, state, dialect) => {
|
|
|
7881
8811
|
}
|
|
7882
8812
|
return;
|
|
7883
8813
|
case "jsonKeys":
|
|
7884
|
-
if (!
|
|
8814
|
+
if (!isExpression5(base)) {
|
|
7885
8815
|
return;
|
|
7886
8816
|
}
|
|
7887
8817
|
if (dialect.name === "postgres") {
|
|
@@ -7895,7 +8825,7 @@ var renderJsonExpression2 = (expression, ast, state, dialect) => {
|
|
|
7895
8825
|
}
|
|
7896
8826
|
return;
|
|
7897
8827
|
case "jsonStripNulls":
|
|
7898
|
-
if (!
|
|
8828
|
+
if (!isExpression5(base)) {
|
|
7899
8829
|
return;
|
|
7900
8830
|
}
|
|
7901
8831
|
if (dialect.name === "postgres") {
|
|
@@ -7906,7 +8836,7 @@ var renderJsonExpression2 = (expression, ast, state, dialect) => {
|
|
|
7906
8836
|
case "jsonDelete":
|
|
7907
8837
|
case "jsonDeletePath":
|
|
7908
8838
|
case "jsonRemove": {
|
|
7909
|
-
if (!
|
|
8839
|
+
if (!isExpression5(base) || segments.length === 0) {
|
|
7910
8840
|
return;
|
|
7911
8841
|
}
|
|
7912
8842
|
if (dialect.name === "postgres") {
|
|
@@ -7924,11 +8854,11 @@ var renderJsonExpression2 = (expression, ast, state, dialect) => {
|
|
|
7924
8854
|
}
|
|
7925
8855
|
case "jsonSet":
|
|
7926
8856
|
case "jsonInsert": {
|
|
7927
|
-
if (!
|
|
8857
|
+
if (!isExpression5(base) || segments.length === 0) {
|
|
7928
8858
|
return;
|
|
7929
8859
|
}
|
|
7930
8860
|
const nextValue = extractJsonValue2(ast);
|
|
7931
|
-
if (!
|
|
8861
|
+
if (!isExpression5(nextValue)) {
|
|
7932
8862
|
return;
|
|
7933
8863
|
}
|
|
7934
8864
|
const createMissing = ast.createMissing === true;
|
|
@@ -7945,39 +8875,39 @@ var renderJsonExpression2 = (expression, ast, state, dialect) => {
|
|
|
7945
8875
|
return;
|
|
7946
8876
|
}
|
|
7947
8877
|
case "jsonPathExists": {
|
|
7948
|
-
if (!
|
|
8878
|
+
if (!isExpression5(base)) {
|
|
7949
8879
|
return;
|
|
7950
8880
|
}
|
|
7951
|
-
const
|
|
7952
|
-
if (
|
|
8881
|
+
const path2 = ast.path ?? ast.query ?? ast.right;
|
|
8882
|
+
if (path2 === undefined) {
|
|
7953
8883
|
return;
|
|
7954
8884
|
}
|
|
7955
8885
|
if (dialect.name === "postgres") {
|
|
7956
|
-
return `(${renderPostgresJsonValue2(base, state, dialect)} @? ${renderJsonOpaquePath2(
|
|
8886
|
+
return `(${renderPostgresJsonValue2(base, state, dialect)} @? ${renderJsonOpaquePath2(path2, state, dialect)})`;
|
|
7957
8887
|
}
|
|
7958
8888
|
if (dialect.name === "mysql") {
|
|
7959
|
-
return `json_contains_path(${renderExpression2(base, state, dialect)}, ${dialect.renderLiteral("one", state)}, ${renderJsonOpaquePath2(
|
|
8889
|
+
return `json_contains_path(${renderExpression2(base, state, dialect)}, ${dialect.renderLiteral("one", state)}, ${renderJsonOpaquePath2(path2, state, dialect)})`;
|
|
7960
8890
|
}
|
|
7961
8891
|
return;
|
|
7962
8892
|
}
|
|
7963
8893
|
case "jsonPathMatch": {
|
|
7964
|
-
if (!
|
|
8894
|
+
if (!isExpression5(base)) {
|
|
7965
8895
|
return;
|
|
7966
8896
|
}
|
|
7967
|
-
const
|
|
7968
|
-
if (
|
|
8897
|
+
const path2 = ast.path ?? ast.query ?? ast.right;
|
|
8898
|
+
if (path2 === undefined) {
|
|
7969
8899
|
return;
|
|
7970
8900
|
}
|
|
7971
8901
|
if (dialect.name === "postgres") {
|
|
7972
|
-
return `(${renderPostgresJsonValue2(base, state, dialect)} @@ ${renderJsonOpaquePath2(
|
|
8902
|
+
return `(${renderPostgresJsonValue2(base, state, dialect)} @@ ${renderJsonOpaquePath2(path2, state, dialect)})`;
|
|
7973
8903
|
}
|
|
7974
8904
|
unsupportedJsonFeature2(dialect, "jsonPathMatch");
|
|
7975
8905
|
}
|
|
7976
8906
|
}
|
|
7977
8907
|
return;
|
|
7978
8908
|
};
|
|
7979
|
-
var selectionProjections2 = (selection) => flattenSelection(selection).map(({ path:
|
|
7980
|
-
path:
|
|
8909
|
+
var selectionProjections2 = (selection) => flattenSelection(selection).map(({ path: path2, alias: alias2 }) => ({
|
|
8910
|
+
path: path2,
|
|
7981
8911
|
alias: alias2
|
|
7982
8912
|
}));
|
|
7983
8913
|
var renderMutationAssignment2 = (entry, state, dialect, targetTableName) => {
|
|
@@ -8058,9 +8988,9 @@ var validateDistinctOnOrdering = (distinctOn2, orderBy2) => {
|
|
|
8058
8988
|
}
|
|
8059
8989
|
const remainingDistinctKeys = new Set(distinctOn2.map(groupingKeyOfExpression));
|
|
8060
8990
|
for (const order of orderBy2) {
|
|
8061
|
-
const
|
|
8062
|
-
if (remainingDistinctKeys.has(
|
|
8063
|
-
remainingDistinctKeys.delete(
|
|
8991
|
+
const key2 = groupingKeyOfExpression(order.value);
|
|
8992
|
+
if (remainingDistinctKeys.has(key2)) {
|
|
8993
|
+
remainingDistinctKeys.delete(key2);
|
|
8064
8994
|
continue;
|
|
8065
8995
|
}
|
|
8066
8996
|
if (remainingDistinctKeys.size > 0) {
|
|
@@ -8155,12 +9085,12 @@ var renderQueryAst2 = (ast, state, dialect, options2 = {}) => {
|
|
|
8155
9085
|
const columns = insertSource.columns.map((column) => quoteColumn2(column, state, dialect, targetSource.tableName)).join(", ");
|
|
8156
9086
|
if (dialect.name === "postgres") {
|
|
8157
9087
|
const table = targetSource.source;
|
|
8158
|
-
const fields2 = table[
|
|
9088
|
+
const fields2 = table[TypeId7].fields;
|
|
8159
9089
|
const rendered = insertSource.values.map((entry) => `cast(${dialect.renderLiteral(encodeArrayValues2(entry.values, fields2[entry.columnName], state, dialect), state)} as ${renderCastType2(dialect, fields2[entry.columnName].metadata.dbType)}[])`).join(", ");
|
|
8160
9090
|
sql += ` (${columns}) select * from unnest(${rendered})`;
|
|
8161
9091
|
} else {
|
|
8162
9092
|
const rowCount = insertSource.values[0]?.values.length ?? 0;
|
|
8163
|
-
const rows = Array.from({ length: rowCount }, (_,
|
|
9093
|
+
const rows = Array.from({ length: rowCount }, (_, index4) => `(${insertSource.values.map((entry) => dialect.renderLiteral(entry.values[index4], state, targetSource.source[TypeId7].fields[entry.columnName][TypeId])).join(", ")})`).join(", ");
|
|
8164
9094
|
sql += ` (${columns}) values ${rows}`;
|
|
8165
9095
|
}
|
|
8166
9096
|
} else {
|
|
@@ -8314,27 +9244,27 @@ var renderQueryAst2 = (ast, state, dialect, options2 = {}) => {
|
|
|
8314
9244
|
const mergeAst = ast;
|
|
8315
9245
|
const targetSource = mergeAst.target;
|
|
8316
9246
|
const usingSource = mergeAst.using;
|
|
8317
|
-
const
|
|
8318
|
-
sql = `merge into ${renderSourceReference2(targetSource.source, targetSource.tableName, targetSource.baseTableName, state, dialect)} using ${renderSourceReference2(usingSource.source, usingSource.tableName, usingSource.baseTableName, state, dialect)} on ${renderExpression2(
|
|
8319
|
-
if (
|
|
8320
|
-
const matchedKind =
|
|
9247
|
+
const merge2 = mergeAst.merge;
|
|
9248
|
+
sql = `merge into ${renderSourceReference2(targetSource.source, targetSource.tableName, targetSource.baseTableName, state, dialect)} using ${renderSourceReference2(usingSource.source, usingSource.tableName, usingSource.baseTableName, state, dialect)} on ${renderExpression2(merge2.on, state, dialect)}`;
|
|
9249
|
+
if (merge2.whenMatched) {
|
|
9250
|
+
const matchedKind = merge2.whenMatched.kind === "delete" ? "delete" : "update";
|
|
8321
9251
|
sql += " when matched";
|
|
8322
|
-
if (
|
|
8323
|
-
sql += ` and ${renderExpression2(
|
|
9252
|
+
if (merge2.whenMatched.predicate) {
|
|
9253
|
+
sql += ` and ${renderExpression2(merge2.whenMatched.predicate, state, dialect)}`;
|
|
8324
9254
|
}
|
|
8325
9255
|
if (matchedKind === "delete") {
|
|
8326
9256
|
sql += " then delete";
|
|
8327
9257
|
} else {
|
|
8328
|
-
const matchedUpdate =
|
|
9258
|
+
const matchedUpdate = merge2.whenMatched;
|
|
8329
9259
|
sql += ` then update set ${matchedUpdate.values.map((entry) => `${quoteColumn2(entry.columnName, state, dialect, targetSource.tableName)} = ${renderExpression2(entry.value, state, dialect)}`).join(", ")}`;
|
|
8330
9260
|
}
|
|
8331
9261
|
}
|
|
8332
|
-
if (
|
|
9262
|
+
if (merge2.whenNotMatched) {
|
|
8333
9263
|
sql += " when not matched";
|
|
8334
|
-
if (
|
|
8335
|
-
sql += ` and ${renderExpression2(
|
|
9264
|
+
if (merge2.whenNotMatched.predicate) {
|
|
9265
|
+
sql += ` and ${renderExpression2(merge2.whenNotMatched.predicate, state, dialect)}`;
|
|
8336
9266
|
}
|
|
8337
|
-
sql += ` then insert (${
|
|
9267
|
+
sql += ` then insert (${merge2.whenNotMatched.values.map((entry) => quoteColumn2(entry.columnName, state, dialect, targetSource.tableName)).join(", ")}) values (${merge2.whenNotMatched.values.map((entry) => renderExpression2(entry.value, state, dialect)).join(", ")})`;
|
|
8338
9268
|
}
|
|
8339
9269
|
break;
|
|
8340
9270
|
}
|
|
@@ -8398,7 +9328,7 @@ var renderSourceReference2 = (source, tableName, baseTableName, state, dialect)
|
|
|
8398
9328
|
};
|
|
8399
9329
|
const renderUnnestRows = (arrays, columnNames) => {
|
|
8400
9330
|
const rowCount = arrays[columnNames[0]].length;
|
|
8401
|
-
const rows = Array.from({ length: rowCount }, (_,
|
|
9331
|
+
const rows = Array.from({ length: rowCount }, (_, index4) => Object.fromEntries(columnNames.map((columnName) => [columnName, arrays[columnName][index4]])));
|
|
8402
9332
|
return renderSelectRows(rows, columnNames);
|
|
8403
9333
|
};
|
|
8404
9334
|
if (typeof source === "object" && source !== null && "kind" in source && source.kind === "cte") {
|
|
@@ -8448,11 +9378,11 @@ var renderSourceReference2 = (source, tableName, baseTableName, state, dialect)
|
|
|
8448
9378
|
const columnNames = Object.keys(tableFunction.columns);
|
|
8449
9379
|
return `${functionName}(${tableFunction.args.map((arg) => renderExpression2(arg, state, dialect)).join(", ")}) as ${dialect.quoteIdentifier(tableFunction.name)}(${columnNames.map((columnName) => dialect.quoteIdentifier(columnName)).join(", ")})`;
|
|
8450
9380
|
}
|
|
8451
|
-
const schemaName = typeof source === "object" && source !== null &&
|
|
8452
|
-
if (typeof source === "object" && source !== null &&
|
|
9381
|
+
const schemaName = typeof source === "object" && source !== null && TypeId7 in source ? casedSchemaName(source, state) : undefined;
|
|
9382
|
+
if (typeof source === "object" && source !== null && TypeId7 in source) {
|
|
8453
9383
|
const table = source;
|
|
8454
9384
|
const renderedBaseName = casedTableName(table, state);
|
|
8455
|
-
const renderedTableName = table[
|
|
9385
|
+
const renderedTableName = table[TypeId7].kind === "alias" ? tableName : renderedBaseName;
|
|
8456
9386
|
return dialect.renderTableReference(renderedTableName, renderedBaseName, schemaName);
|
|
8457
9387
|
}
|
|
8458
9388
|
return dialect.renderTableReference(applyCategory(state.casing, "tables", tableName), applyCategory(state.casing, "tables", baseTableName), schemaName);
|
|
@@ -8559,11 +9489,11 @@ var renderExpression2 = (expression, state, dialect) => {
|
|
|
8559
9489
|
const [leftExpression, rightExpression] = expectBinaryExpressions2("contains", ast.left, ast.right);
|
|
8560
9490
|
if (dialect.name === "postgres") {
|
|
8561
9491
|
assertCompatiblePostgresRangeOperands(leftExpression, rightExpression);
|
|
8562
|
-
const left =
|
|
8563
|
-
const right =
|
|
9492
|
+
const left = isJsonExpression3(leftExpression) ? renderPostgresJsonValue2(leftExpression, state, dialect) : renderExpression2(leftExpression, state, dialect);
|
|
9493
|
+
const right = isJsonExpression3(rightExpression) ? renderPostgresJsonValue2(rightExpression, state, dialect) : renderExpression2(rightExpression, state, dialect);
|
|
8564
9494
|
return `(${left} @> ${right})`;
|
|
8565
9495
|
}
|
|
8566
|
-
if (dialect.name === "mysql" &&
|
|
9496
|
+
if (dialect.name === "mysql" && isJsonExpression3(leftExpression) && isJsonExpression3(rightExpression)) {
|
|
8567
9497
|
return `json_contains(${renderExpression2(leftExpression, state, dialect)}, ${renderExpression2(rightExpression, state, dialect)})`;
|
|
8568
9498
|
}
|
|
8569
9499
|
throw new Error("Unsupported container operator for SQL rendering");
|
|
@@ -8572,11 +9502,11 @@ var renderExpression2 = (expression, state, dialect) => {
|
|
|
8572
9502
|
const [leftExpression, rightExpression] = expectBinaryExpressions2("containedBy", ast.left, ast.right);
|
|
8573
9503
|
if (dialect.name === "postgres") {
|
|
8574
9504
|
assertCompatiblePostgresRangeOperands(leftExpression, rightExpression);
|
|
8575
|
-
const left =
|
|
8576
|
-
const right =
|
|
9505
|
+
const left = isJsonExpression3(leftExpression) ? renderPostgresJsonValue2(leftExpression, state, dialect) : renderExpression2(leftExpression, state, dialect);
|
|
9506
|
+
const right = isJsonExpression3(rightExpression) ? renderPostgresJsonValue2(rightExpression, state, dialect) : renderExpression2(rightExpression, state, dialect);
|
|
8577
9507
|
return `(${left} <@ ${right})`;
|
|
8578
9508
|
}
|
|
8579
|
-
if (dialect.name === "mysql" &&
|
|
9509
|
+
if (dialect.name === "mysql" && isJsonExpression3(leftExpression) && isJsonExpression3(rightExpression)) {
|
|
8580
9510
|
return `json_contains(${renderExpression2(rightExpression, state, dialect)}, ${renderExpression2(leftExpression, state, dialect)})`;
|
|
8581
9511
|
}
|
|
8582
9512
|
throw new Error("Unsupported container operator for SQL rendering");
|
|
@@ -8585,11 +9515,11 @@ var renderExpression2 = (expression, state, dialect) => {
|
|
|
8585
9515
|
const [leftExpression, rightExpression] = expectBinaryExpressions2("overlaps", ast.left, ast.right);
|
|
8586
9516
|
if (dialect.name === "postgres") {
|
|
8587
9517
|
assertCompatiblePostgresRangeOperands(leftExpression, rightExpression);
|
|
8588
|
-
const left =
|
|
8589
|
-
const right =
|
|
9518
|
+
const left = isJsonExpression3(leftExpression) ? renderPostgresJsonValue2(leftExpression, state, dialect) : renderExpression2(leftExpression, state, dialect);
|
|
9519
|
+
const right = isJsonExpression3(rightExpression) ? renderPostgresJsonValue2(rightExpression, state, dialect) : renderExpression2(rightExpression, state, dialect);
|
|
8590
9520
|
return `(${left} && ${right})`;
|
|
8591
9521
|
}
|
|
8592
|
-
if (dialect.name === "mysql" &&
|
|
9522
|
+
if (dialect.name === "mysql" && isJsonExpression3(leftExpression) && isJsonExpression3(rightExpression)) {
|
|
8593
9523
|
return `json_overlaps(${renderExpression2(leftExpression, state, dialect)}, ${renderExpression2(rightExpression, state, dialect)})`;
|
|
8594
9524
|
}
|
|
8595
9525
|
throw new Error("Unsupported container operator for SQL rendering");
|
|
@@ -8767,7 +9697,6 @@ var renderSqlitePlan = (plan, options2 = {}) => {
|
|
|
8767
9697
|
|
|
8768
9698
|
// src/sqlite/executor.ts
|
|
8769
9699
|
var withTransaction2 = withTransaction;
|
|
8770
|
-
var withSavepoint2 = withSavepoint;
|
|
8771
9700
|
function driver2(dialectOrExecute, maybeExecute) {
|
|
8772
9701
|
const executeOrHandlers = typeof dialectOrExecute === "string" ? maybeExecute : dialectOrExecute;
|
|
8773
9702
|
return typeof executeOrHandlers === "function" ? driver("sqlite", executeOrHandlers) : driver("sqlite", executeOrHandlers);
|
|
@@ -8789,8 +9718,8 @@ var fromDriver2 = (renderer, sqlDriver, driverMode = "raw", valueMappings) => ({
|
|
|
8789
9718
|
},
|
|
8790
9719
|
stream(plan) {
|
|
8791
9720
|
const rendered = renderer.render(plan);
|
|
8792
|
-
return Stream2.mapError(Stream2.
|
|
8793
|
-
try: () =>
|
|
9721
|
+
return Stream2.mapError(Stream2.mapArrayEffect(sqlDriver.stream(rendered), (rows) => Effect2.try({
|
|
9722
|
+
try: () => decodeRows(rendered, plan, rows, { driverMode, valueMappings }),
|
|
8794
9723
|
catch: (error) => error
|
|
8795
9724
|
})), (error) => {
|
|
8796
9725
|
if (typeof error === "object" && error !== null && "_tag" in error && error._tag === "RowDecodeError") {
|
|
@@ -8817,6 +9746,20 @@ var exports_query_extension = {};
|
|
|
8817
9746
|
__export(exports_query_extension, {
|
|
8818
9747
|
onConflict: () => onConflict
|
|
8819
9748
|
});
|
|
9749
|
+
// src/sqlite/type.ts
|
|
9750
|
+
var custom4 = (kind) => ({
|
|
9751
|
+
dialect: "sqlite",
|
|
9752
|
+
kind
|
|
9753
|
+
});
|
|
9754
|
+
var driverValueMapping3 = (dbType, mapping) => ({
|
|
9755
|
+
...dbType,
|
|
9756
|
+
driverValueMapping: mapping
|
|
9757
|
+
});
|
|
9758
|
+
var type2 = {
|
|
9759
|
+
...pickDatatypeConstructors(sqliteDatatypes, sqliteSpecificDatatypeKeys),
|
|
9760
|
+
custom: custom4,
|
|
9761
|
+
driverValueMapping: driverValueMapping3
|
|
9762
|
+
};
|
|
8820
9763
|
// src/sqlite/renderer.ts
|
|
8821
9764
|
var exports_renderer2 = {};
|
|
8822
9765
|
__export(exports_renderer2, {
|
|
@@ -8824,26 +9767,28 @@ __export(exports_renderer2, {
|
|
|
8824
9767
|
make: () => make5,
|
|
8825
9768
|
TypeId: () => TypeId10
|
|
8826
9769
|
});
|
|
8827
|
-
import { pipeArguments as
|
|
9770
|
+
import { pipeArguments as pipeArguments8 } from "effect/Pipeable";
|
|
8828
9771
|
var RendererProto = {
|
|
8829
9772
|
pipe() {
|
|
8830
|
-
return
|
|
9773
|
+
return pipeArguments8(this, arguments);
|
|
8831
9774
|
}
|
|
8832
9775
|
};
|
|
8833
|
-
var
|
|
8834
|
-
const renderer = makeTrusted("sqlite", (plan) => renderSqlitePlan(plan,
|
|
9776
|
+
var makeWithState = (state = {}) => {
|
|
9777
|
+
const renderer = makeTrusted("sqlite", (plan) => renderSqlitePlan(plan, state));
|
|
8835
9778
|
return Object.assign(Object.create(RendererProto), renderer, {
|
|
8836
|
-
[
|
|
8837
|
-
casing:
|
|
9779
|
+
[TypeId6]: {
|
|
9780
|
+
casing: state.casing
|
|
8838
9781
|
},
|
|
8839
|
-
withCasing: (override) =>
|
|
8840
|
-
...
|
|
8841
|
-
casing: merge(
|
|
9782
|
+
withCasing: (override) => makeWithState({
|
|
9783
|
+
...state,
|
|
9784
|
+
casing: merge(state.casing, override)
|
|
8842
9785
|
})
|
|
8843
9786
|
});
|
|
8844
9787
|
};
|
|
9788
|
+
var make5 = (options2 = {}) => makeWithState({ valueMappings: options2.valueMappings });
|
|
8845
9789
|
var sqlite = make5();
|
|
8846
9790
|
export {
|
|
9791
|
+
type2 as Type,
|
|
8847
9792
|
exports_renderer2 as Renderer,
|
|
8848
9793
|
exports_query_extension as Query,
|
|
8849
9794
|
exports_json as Json,
|