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
|
@@ -25,7 +25,7 @@ __export(exports_metadata, {
|
|
|
25
25
|
});
|
|
26
26
|
|
|
27
27
|
// src/internal/table.ts
|
|
28
|
-
import { pipeArguments as
|
|
28
|
+
import { pipeArguments as pipeArguments4 } from "effect/Pipeable";
|
|
29
29
|
|
|
30
30
|
// src/internal/row-set.ts
|
|
31
31
|
var exports_row_set = {};
|
|
@@ -35,7 +35,7 @@ __export(exports_row_set, {
|
|
|
35
35
|
var TypeId = Symbol.for("effect-qb/Plan");
|
|
36
36
|
|
|
37
37
|
// src/internal/column-state.ts
|
|
38
|
-
import { pipeArguments } from "effect/Pipeable";
|
|
38
|
+
import { pipeArguments as pipeArguments2 } from "effect/Pipeable";
|
|
39
39
|
import * as Schema from "effect/Schema";
|
|
40
40
|
|
|
41
41
|
// src/internal/scalar.ts
|
|
@@ -48,12 +48,181 @@ var TypeId2 = Symbol.for("effect-qb/Expression");
|
|
|
48
48
|
// src/internal/expression-ast.ts
|
|
49
49
|
var TypeId3 = Symbol.for("effect-qb/ExpressionAst");
|
|
50
50
|
|
|
51
|
+
// src/internal/json/path-access.ts
|
|
52
|
+
import { pipeArguments } from "effect/Pipeable";
|
|
53
|
+
|
|
54
|
+
// src/internal/json/path.ts
|
|
55
|
+
var SegmentTypeId = Symbol.for("effect-qb/JsonPathSegment");
|
|
56
|
+
var TypeId4 = Symbol.for("effect-qb/JsonPath");
|
|
57
|
+
var makeSegment = (segment) => segment;
|
|
58
|
+
var key = (value) => makeSegment({
|
|
59
|
+
[SegmentTypeId]: {
|
|
60
|
+
kind: "key"
|
|
61
|
+
},
|
|
62
|
+
kind: "key",
|
|
63
|
+
key: value
|
|
64
|
+
});
|
|
65
|
+
var index = (value) => makeSegment({
|
|
66
|
+
[SegmentTypeId]: {
|
|
67
|
+
kind: "index"
|
|
68
|
+
},
|
|
69
|
+
kind: "index",
|
|
70
|
+
index: value
|
|
71
|
+
});
|
|
72
|
+
var wildcard = () => makeSegment({
|
|
73
|
+
[SegmentTypeId]: {
|
|
74
|
+
kind: "wildcard"
|
|
75
|
+
},
|
|
76
|
+
kind: "wildcard"
|
|
77
|
+
});
|
|
78
|
+
var slice = (start, end) => makeSegment({
|
|
79
|
+
[SegmentTypeId]: {
|
|
80
|
+
kind: "slice"
|
|
81
|
+
},
|
|
82
|
+
kind: "slice",
|
|
83
|
+
start,
|
|
84
|
+
end
|
|
85
|
+
});
|
|
86
|
+
var descend = () => makeSegment({
|
|
87
|
+
[SegmentTypeId]: {
|
|
88
|
+
kind: "descend"
|
|
89
|
+
},
|
|
90
|
+
kind: "descend"
|
|
91
|
+
});
|
|
92
|
+
var path = (...segments) => ({
|
|
93
|
+
[TypeId4]: {
|
|
94
|
+
segments
|
|
95
|
+
},
|
|
96
|
+
segments
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
// src/internal/json/path-access.ts
|
|
100
|
+
var WrappedTypeId = Symbol.for("effect-qb/JsonPathAccess");
|
|
101
|
+
var accessKinds = new Set([
|
|
102
|
+
"jsonGet",
|
|
103
|
+
"jsonPath",
|
|
104
|
+
"jsonAccess",
|
|
105
|
+
"jsonTraverse",
|
|
106
|
+
"jsonGetText",
|
|
107
|
+
"jsonPathText",
|
|
108
|
+
"jsonAccessText",
|
|
109
|
+
"jsonTraverseText"
|
|
110
|
+
]);
|
|
111
|
+
var reservedKeys = new Set([
|
|
112
|
+
"pipe",
|
|
113
|
+
"then",
|
|
114
|
+
"toString",
|
|
115
|
+
"toJSON",
|
|
116
|
+
"valueOf",
|
|
117
|
+
"constructor",
|
|
118
|
+
"__proto__",
|
|
119
|
+
"prototype",
|
|
120
|
+
"inspect",
|
|
121
|
+
"schema",
|
|
122
|
+
"metadata",
|
|
123
|
+
"columns",
|
|
124
|
+
"name"
|
|
125
|
+
]);
|
|
126
|
+
var isObjectLike = (value) => (typeof value === "object" || typeof value === "function") && value !== null;
|
|
127
|
+
var isExpression = (value) => isObjectLike(value) && (TypeId2 in value);
|
|
128
|
+
var isJsonExpression = (value) => {
|
|
129
|
+
if (!isExpression(value)) {
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
const dbType = value[TypeId2].dbType;
|
|
133
|
+
return dbType.kind === "json" || dbType.kind === "jsonb" || dbType.variant === "json" || dbType.variant === "jsonb";
|
|
134
|
+
};
|
|
135
|
+
var isWrapped = (value) => value[WrappedTypeId] === true;
|
|
136
|
+
var normalizeSegment = (segment) => {
|
|
137
|
+
switch (segment.kind) {
|
|
138
|
+
case "key":
|
|
139
|
+
return key(segment.key);
|
|
140
|
+
case "index":
|
|
141
|
+
return index(segment.index);
|
|
142
|
+
case "wildcard":
|
|
143
|
+
return wildcard();
|
|
144
|
+
case "slice":
|
|
145
|
+
return slice(segment.start, segment.end);
|
|
146
|
+
case "descend":
|
|
147
|
+
return descend();
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
var accessPathOf = (value) => {
|
|
151
|
+
const segments = [];
|
|
152
|
+
let base = value;
|
|
153
|
+
while (isExpression(base)) {
|
|
154
|
+
const ast = base[TypeId3];
|
|
155
|
+
if (ast === undefined || typeof ast.kind !== "string" || !accessKinds.has(ast.kind) || !isExpression(ast.base) || !Array.isArray(ast.segments)) {
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
segments.unshift(...ast.segments.map(normalizeSegment));
|
|
159
|
+
base = ast.base;
|
|
160
|
+
}
|
|
161
|
+
return { base, segments };
|
|
162
|
+
};
|
|
163
|
+
var isIntegerProperty = (property) => /^(?:-?(?:0|[1-9][0-9]*))$/.test(property);
|
|
164
|
+
var jsonAccessKind = (segments) => segments.every((segment) => segment.kind === "key" || segment.kind === "index") ? segments.length === 1 ? "jsonGet" : "jsonPath" : "jsonTraverse";
|
|
165
|
+
var makeExpression = (state, ast) => {
|
|
166
|
+
const expression = Object.create(null);
|
|
167
|
+
Object.defineProperty(expression, "pipe", {
|
|
168
|
+
configurable: true,
|
|
169
|
+
writable: true,
|
|
170
|
+
value: function() {
|
|
171
|
+
return pipeArguments(expression, arguments);
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
expression[TypeId2] = state;
|
|
175
|
+
expression[TypeId3] = ast;
|
|
176
|
+
return expression;
|
|
177
|
+
};
|
|
178
|
+
var makePathExpression = (value, segment) => {
|
|
179
|
+
const access = accessPathOf(value);
|
|
180
|
+
const segments = [...access.segments, normalizeSegment(segment)];
|
|
181
|
+
const base = access.base;
|
|
182
|
+
const baseState = base[TypeId2];
|
|
183
|
+
return withJsonPathAccess(makeExpression({
|
|
184
|
+
...baseState,
|
|
185
|
+
runtime: undefined,
|
|
186
|
+
nullability: undefined
|
|
187
|
+
}, {
|
|
188
|
+
kind: jsonAccessKind(segments),
|
|
189
|
+
base,
|
|
190
|
+
segments
|
|
191
|
+
}));
|
|
192
|
+
};
|
|
193
|
+
var pathProxyHandler = {
|
|
194
|
+
get(target, property, receiver) {
|
|
195
|
+
if (typeof property === "symbol") {
|
|
196
|
+
return Reflect.get(target, property, receiver);
|
|
197
|
+
}
|
|
198
|
+
if (Reflect.has(target, property) || reservedKeys.has(property)) {
|
|
199
|
+
return Reflect.get(target, property, receiver);
|
|
200
|
+
}
|
|
201
|
+
const segment = isIntegerProperty(property) ? index(Number(property)) : key(property);
|
|
202
|
+
return makePathExpression(target, segment);
|
|
203
|
+
},
|
|
204
|
+
has(target, property) {
|
|
205
|
+
return Reflect.has(target, property);
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
var withJsonPathAccess = (value) => {
|
|
209
|
+
if (!isObjectLike(value) || !isJsonExpression(value) || isWrapped(value)) {
|
|
210
|
+
return value;
|
|
211
|
+
}
|
|
212
|
+
const proxy = new Proxy(value, pathProxyHandler);
|
|
213
|
+
Object.defineProperty(proxy, WrappedTypeId, {
|
|
214
|
+
configurable: false,
|
|
215
|
+
value: true
|
|
216
|
+
});
|
|
217
|
+
return proxy;
|
|
218
|
+
};
|
|
219
|
+
|
|
51
220
|
// src/internal/column-state.ts
|
|
52
221
|
var ColumnTypeId = Symbol.for("effect-qb/Column");
|
|
53
222
|
var BoundColumnTypeId = Symbol.for("effect-qb/BoundColumn");
|
|
54
223
|
var ColumnProto = {
|
|
55
224
|
pipe() {
|
|
56
|
-
return
|
|
225
|
+
return pipeArguments2(this, arguments);
|
|
57
226
|
}
|
|
58
227
|
};
|
|
59
228
|
var attachPipe = (value) => {
|
|
@@ -61,7 +230,7 @@ var attachPipe = (value) => {
|
|
|
61
230
|
configurable: true,
|
|
62
231
|
writable: true,
|
|
63
232
|
value: function() {
|
|
64
|
-
return
|
|
233
|
+
return pipeArguments2(value, arguments);
|
|
65
234
|
}
|
|
66
235
|
});
|
|
67
236
|
return value;
|
|
@@ -98,7 +267,7 @@ var makeColumnDefinition = (schema, metadata) => {
|
|
|
98
267
|
identity: metadata.identity,
|
|
99
268
|
enum: metadata.enum
|
|
100
269
|
};
|
|
101
|
-
return column;
|
|
270
|
+
return withJsonPathAccess(column);
|
|
102
271
|
};
|
|
103
272
|
var remapColumnDefinition = (column, options = {}) => {
|
|
104
273
|
const schema = options.schema ?? column.schema;
|
|
@@ -140,7 +309,7 @@ var remapColumnDefinition = (column, options = {}) => {
|
|
|
140
309
|
if (BoundColumnTypeId in column) {
|
|
141
310
|
next[BoundColumnTypeId] = column[BoundColumnTypeId];
|
|
142
311
|
}
|
|
143
|
-
return next;
|
|
312
|
+
return withJsonPathAccess(next);
|
|
144
313
|
};
|
|
145
314
|
var bindColumn = (tableName, columnName, column, baseTableName, schemaName, casing) => {
|
|
146
315
|
const brandName = `${tableName}.${columnName}`;
|
|
@@ -173,16 +342,16 @@ var bindColumn = (tableName, columnName, column, baseTableName, schemaName, casi
|
|
|
173
342
|
schemaName,
|
|
174
343
|
casing
|
|
175
344
|
};
|
|
176
|
-
return bound;
|
|
345
|
+
return withJsonPathAccess(bound);
|
|
177
346
|
};
|
|
178
347
|
|
|
179
348
|
// src/internal/schema-expression.ts
|
|
180
349
|
import { parse, toSql } from "pgsql-ast-parser";
|
|
181
|
-
import { pipeArguments as
|
|
182
|
-
var
|
|
350
|
+
import { pipeArguments as pipeArguments3 } from "effect/Pipeable";
|
|
351
|
+
var TypeId5 = Symbol.for("effect-qb/SchemaExpression");
|
|
183
352
|
var SchemaExpressionProto = {
|
|
184
353
|
pipe() {
|
|
185
|
-
return
|
|
354
|
+
return pipeArguments3(this, arguments);
|
|
186
355
|
}
|
|
187
356
|
};
|
|
188
357
|
var attachPipe2 = (value) => {
|
|
@@ -190,35 +359,35 @@ var attachPipe2 = (value) => {
|
|
|
190
359
|
configurable: true,
|
|
191
360
|
writable: true,
|
|
192
361
|
value: function() {
|
|
193
|
-
return
|
|
362
|
+
return pipeArguments3(value, arguments);
|
|
194
363
|
}
|
|
195
364
|
});
|
|
196
365
|
return value;
|
|
197
366
|
};
|
|
198
|
-
var isSchemaExpression = (value) => typeof value === "object" && value !== null && (
|
|
367
|
+
var isSchemaExpression = (value) => typeof value === "object" && value !== null && (TypeId5 in value);
|
|
199
368
|
var fromAst = (ast) => {
|
|
200
369
|
const expression = attachPipe2(Object.create(SchemaExpressionProto));
|
|
201
|
-
expression[
|
|
370
|
+
expression[TypeId5] = {
|
|
202
371
|
ast
|
|
203
372
|
};
|
|
204
373
|
return expression;
|
|
205
374
|
};
|
|
206
375
|
var fromSql = (sql) => {
|
|
207
376
|
const expression = attachPipe2(Object.create(SchemaExpressionProto));
|
|
208
|
-
expression[
|
|
377
|
+
expression[TypeId5] = {
|
|
209
378
|
sql: sql.trim()
|
|
210
379
|
};
|
|
211
380
|
return expression;
|
|
212
381
|
};
|
|
213
382
|
var parseExpression = (sql) => fromAst(parse(sql, "expr"));
|
|
214
383
|
var toAst = (expression) => {
|
|
215
|
-
const ast = expression[
|
|
384
|
+
const ast = expression[TypeId5].ast;
|
|
216
385
|
if (ast !== undefined) {
|
|
217
386
|
return ast;
|
|
218
387
|
}
|
|
219
388
|
return parse(render(expression), "expr");
|
|
220
389
|
};
|
|
221
|
-
var render = (expression) => expression[
|
|
390
|
+
var render = (expression) => expression[TypeId5].sql ?? toSql.expr(toAst(expression));
|
|
222
391
|
var normalize = (expression) => (() => {
|
|
223
392
|
const sql = render(expression);
|
|
224
393
|
try {
|
|
@@ -313,7 +482,7 @@ var collectInlineOptions = (fields) => {
|
|
|
313
482
|
return options;
|
|
314
483
|
};
|
|
315
484
|
var resolvePrimaryKeyColumns = (fields, declaredOptions) => {
|
|
316
|
-
const inline = Object.entries(fields).filter(([, column]) => column.metadata.primaryKey).map(([
|
|
485
|
+
const inline = Object.entries(fields).filter(([, column]) => column.metadata.primaryKey).map(([key2]) => key2);
|
|
317
486
|
const explicit = declaredOptions.flatMap((option) => {
|
|
318
487
|
if (typeof option !== "object" || option === null || !("kind" in option) || option.kind !== "primaryKey") {
|
|
319
488
|
return [];
|
|
@@ -339,8 +508,8 @@ var validateOptions = (tableName, fields, options) => {
|
|
|
339
508
|
case "foreignKey": {
|
|
340
509
|
if (option.kind === "index") {
|
|
341
510
|
const keys = Array.isArray(option.keys) ? option.keys : [];
|
|
342
|
-
for (const
|
|
343
|
-
if (typeof
|
|
511
|
+
for (const key2 of keys) {
|
|
512
|
+
if (typeof key2 !== "object" || key2 === null || !("kind" in key2)) {
|
|
344
513
|
continue;
|
|
345
514
|
}
|
|
346
515
|
}
|
|
@@ -387,10 +556,10 @@ var fieldSchemaForVariant = (variant, column, tableName, columnName, primaryKeyS
|
|
|
387
556
|
var deriveSchema = (variant, tableName, fields, primaryKeyColumns) => {
|
|
388
557
|
const primaryKeySet = new Set(primaryKeyColumns);
|
|
389
558
|
const structFields = {};
|
|
390
|
-
for (const [
|
|
391
|
-
const schema = fieldSchemaForVariant(variant, column, tableName,
|
|
559
|
+
for (const [key2, column] of Object.entries(fields)) {
|
|
560
|
+
const schema = fieldSchemaForVariant(variant, column, tableName, key2, primaryKeySet);
|
|
392
561
|
if (schema !== undefined) {
|
|
393
|
-
structFields[
|
|
562
|
+
structFields[key2] = schema;
|
|
394
563
|
}
|
|
395
564
|
}
|
|
396
565
|
return Schema2.Struct(structFields);
|
|
@@ -400,7 +569,7 @@ var deriveInsertSchema = (tableName, fields, primaryKeyColumns) => deriveSchema(
|
|
|
400
569
|
var deriveUpdateSchema = (tableName, fields, primaryKeyColumns) => deriveSchema("update", tableName, fields, primaryKeyColumns);
|
|
401
570
|
|
|
402
571
|
// src/internal/casing.ts
|
|
403
|
-
var
|
|
572
|
+
var TypeId6 = Symbol.for("effect-qb/Casing");
|
|
404
573
|
var merge = (base, override) => {
|
|
405
574
|
if (base === undefined) {
|
|
406
575
|
return override;
|
|
@@ -441,15 +610,16 @@ var apply = (style, name) => {
|
|
|
441
610
|
var applyCategory = (options, category, name) => apply(options?.[category], name);
|
|
442
611
|
|
|
443
612
|
// src/internal/table.ts
|
|
444
|
-
var
|
|
613
|
+
var TypeId7 = Symbol.for("effect-qb/Table");
|
|
445
614
|
var OptionsSymbol = Symbol.for("effect-qb/Table/normalizedOptions");
|
|
446
615
|
var options = Symbol.for("effect-qb/Table/declaredOptions");
|
|
447
616
|
var CacheSymbol = Symbol.for("effect-qb/Table/cache");
|
|
448
617
|
var SchemaCacheSymbol = Symbol.for("effect-qb/Table/schemaCache");
|
|
449
618
|
var DeclaredOptionsSymbol = Symbol.for("effect-qb/Table/factoryDeclaredOptions");
|
|
619
|
+
var ResolveOptionSymbol = Symbol.for("effect-qb/Table/resolveOption");
|
|
450
620
|
var TableProto = {
|
|
451
621
|
pipe() {
|
|
452
|
-
return
|
|
622
|
+
return pipeArguments4(this, arguments);
|
|
453
623
|
}
|
|
454
624
|
};
|
|
455
625
|
var attachPipe3 = (value) => {
|
|
@@ -457,21 +627,50 @@ var attachPipe3 = (value) => {
|
|
|
457
627
|
configurable: true,
|
|
458
628
|
writable: true,
|
|
459
629
|
value: function() {
|
|
460
|
-
return
|
|
630
|
+
return pipeArguments4(value, arguments);
|
|
461
631
|
}
|
|
462
632
|
});
|
|
463
633
|
return value;
|
|
464
634
|
};
|
|
635
|
+
var conflictArbitersFromOptions = (options2) => options2.flatMap((option) => {
|
|
636
|
+
if (typeof option !== "object" || option === null) {
|
|
637
|
+
return [];
|
|
638
|
+
}
|
|
639
|
+
if (!("columns" in option) || !Array.isArray(option.columns) || option.columns.length === 0) {
|
|
640
|
+
return [];
|
|
641
|
+
}
|
|
642
|
+
switch (option.kind) {
|
|
643
|
+
case "primaryKey":
|
|
644
|
+
case "unique":
|
|
645
|
+
return [{
|
|
646
|
+
columns: option.columns,
|
|
647
|
+
scope: "unconditional",
|
|
648
|
+
name: option.name,
|
|
649
|
+
constraint: true
|
|
650
|
+
}];
|
|
651
|
+
case "index":
|
|
652
|
+
return option.unique === true ? [{
|
|
653
|
+
columns: option.columns,
|
|
654
|
+
scope: option.predicate === undefined ? "unconditional" : "partial",
|
|
655
|
+
name: option.name,
|
|
656
|
+
constraint: false
|
|
657
|
+
}] : [];
|
|
658
|
+
default:
|
|
659
|
+
return [];
|
|
660
|
+
}
|
|
661
|
+
});
|
|
465
662
|
var buildArtifacts = (name, fields, declaredOptions, schemaName, casing) => {
|
|
466
663
|
const normalizedOptions = [...collectInlineOptions(fields), ...declaredOptions];
|
|
467
664
|
validateFieldDialects(name, fields);
|
|
468
665
|
validateOptions(name, fields, declaredOptions);
|
|
469
666
|
const primaryKey = resolvePrimaryKeyColumns(fields, declaredOptions);
|
|
470
|
-
const
|
|
667
|
+
const conflictArbiters = conflictArbitersFromOptions(normalizedOptions);
|
|
668
|
+
const columns = Object.fromEntries(Object.entries(fields).map(([key2, column]) => [key2, bindColumn(name, key2, column, name, schemaName, casing)]));
|
|
471
669
|
return {
|
|
472
670
|
columns,
|
|
473
671
|
normalizedOptions,
|
|
474
|
-
primaryKey
|
|
672
|
+
primaryKey,
|
|
673
|
+
conflictArbiters
|
|
475
674
|
};
|
|
476
675
|
};
|
|
477
676
|
var getSchemaCache = (table) => {
|
|
@@ -487,7 +686,7 @@ var getSchemaCache = (table) => {
|
|
|
487
686
|
return cache;
|
|
488
687
|
};
|
|
489
688
|
var deriveTableSchema = (table, variant) => {
|
|
490
|
-
const state = table[
|
|
689
|
+
const state = table[TypeId7];
|
|
491
690
|
switch (variant) {
|
|
492
691
|
case "select":
|
|
493
692
|
return deriveSelectSchema(state.name, state.fields, state.primaryKey);
|
|
@@ -556,12 +755,13 @@ var makeTable = (name, fields, declaredOptions, baseName = name, kind = "schema"
|
|
|
556
755
|
table.name = name;
|
|
557
756
|
table.columns = artifacts.columns;
|
|
558
757
|
defineSchemasGetter(table);
|
|
559
|
-
table[
|
|
758
|
+
table[TypeId7] = {
|
|
560
759
|
name,
|
|
561
760
|
baseName,
|
|
562
761
|
schemaName: resolvedSchemaName,
|
|
563
762
|
fields,
|
|
564
763
|
primaryKey: artifacts.primaryKey,
|
|
764
|
+
conflictArbiters: artifacts.conflictArbiters,
|
|
565
765
|
kind,
|
|
566
766
|
casing
|
|
567
767
|
};
|
|
@@ -579,8 +779,8 @@ var makeTable = (name, fields, declaredOptions, baseName = name, kind = "schema"
|
|
|
579
779
|
};
|
|
580
780
|
table[OptionsSymbol] = artifacts.normalizedOptions;
|
|
581
781
|
table[DeclaredOptionsSymbol] = declaredOptions;
|
|
582
|
-
for (const [
|
|
583
|
-
Object.defineProperty(table,
|
|
782
|
+
for (const [key2, value] of Object.entries(artifacts.columns)) {
|
|
783
|
+
Object.defineProperty(table, key2, {
|
|
584
784
|
enumerable: true,
|
|
585
785
|
value
|
|
586
786
|
});
|
|
@@ -618,13 +818,14 @@ var ensureClassArtifacts = (self) => {
|
|
|
618
818
|
if (cached) {
|
|
619
819
|
return cached;
|
|
620
820
|
}
|
|
621
|
-
const state = self[
|
|
821
|
+
const state = self[TypeId7];
|
|
622
822
|
const classOptions = self[options];
|
|
623
823
|
const table = applyDeclaredOptions(makeTable(state.name, state.fields, [], state.name, "schema", state.schemaName, state.schemaName === undefined || state.schemaName === "public" ? "default" : "explicit", state.casing), classOptions);
|
|
624
824
|
const artifacts = {
|
|
625
825
|
columns: table.columns,
|
|
626
826
|
normalizedOptions: table[OptionsSymbol],
|
|
627
|
-
primaryKey: table[
|
|
827
|
+
primaryKey: table[TypeId7].primaryKey,
|
|
828
|
+
conflictArbiters: table[TypeId7].conflictArbiters
|
|
628
829
|
};
|
|
629
830
|
Object.defineProperty(self, CacheSymbol, {
|
|
630
831
|
configurable: true,
|
|
@@ -633,38 +834,54 @@ var ensureClassArtifacts = (self) => {
|
|
|
633
834
|
return artifacts;
|
|
634
835
|
};
|
|
635
836
|
var appendOption = (table, option) => {
|
|
636
|
-
const state = table[
|
|
837
|
+
const state = table[TypeId7];
|
|
637
838
|
return makeTable(state.name, state.fields, [...table[DeclaredOptionsSymbol], option], state.baseName, state.kind, state.schemaName, "explicit", state.casing);
|
|
638
839
|
};
|
|
639
840
|
var makeOption = (option) => {
|
|
640
841
|
return attachPipe3(Object.assign((table, ..._validation) => appendOption(table, option), { option }));
|
|
641
842
|
};
|
|
843
|
+
var makeResolvedOption = (option, resolve) => {
|
|
844
|
+
return attachPipe3(Object.assign((table, ..._validation) => appendOption(table, resolve(table)), {
|
|
845
|
+
option,
|
|
846
|
+
[ResolveOptionSymbol]: resolve
|
|
847
|
+
}));
|
|
848
|
+
};
|
|
642
849
|
var option = (spec) => makeOption(spec);
|
|
850
|
+
var optionFromTable = (spec, resolve) => makeResolvedOption(spec, resolve);
|
|
851
|
+
var resolveOption = (option2, table) => {
|
|
852
|
+
const resolve = option2[ResolveOptionSymbol];
|
|
853
|
+
return resolve === undefined ? option2.option : resolve(table);
|
|
854
|
+
};
|
|
855
|
+
var mapOption = (option2, map) => {
|
|
856
|
+
const resolve = option2[ResolveOptionSymbol];
|
|
857
|
+
return resolve === undefined ? makeOption(map(option2.option)) : makeResolvedOption(map(option2.option), (table) => map(resolve(table)));
|
|
858
|
+
};
|
|
643
859
|
function make(name, fields, schemaName) {
|
|
644
860
|
const resolvedSchemaName = arguments.length >= 3 ? schemaName : "public";
|
|
645
861
|
return makeTable(name, fields, [], name, "schema", resolvedSchemaName, arguments.length >= 3 ? "explicit" : "default");
|
|
646
862
|
}
|
|
647
863
|
var withCasing = (table, casing) => {
|
|
648
|
-
const state = table[
|
|
864
|
+
const state = table[TypeId7];
|
|
649
865
|
return makeTable(state.name, state.fields, table[DeclaredOptionsSymbol], state.baseName, state.kind, state.schemaName, "explicit", merge(state.casing, casing));
|
|
650
866
|
};
|
|
651
867
|
var withSchema = (table, schemaName, schemaCasing) => {
|
|
652
|
-
const state = table[
|
|
868
|
+
const state = table[TypeId7];
|
|
653
869
|
return makeTable(state.name, state.fields, table[DeclaredOptionsSymbol], state.baseName, state.kind, schemaName, "explicit", merge(schemaCasing, state.casing));
|
|
654
870
|
};
|
|
655
871
|
var alias = (table, aliasName) => {
|
|
656
|
-
const state = table[
|
|
657
|
-
const columns = Object.fromEntries(Object.entries(state.fields).map(([
|
|
872
|
+
const state = table[TypeId7];
|
|
873
|
+
const columns = Object.fromEntries(Object.entries(state.fields).map(([key2, column]) => [key2, bindColumn(aliasName, key2, column, state.baseName, state.schemaName, state.casing)]));
|
|
658
874
|
const aliased = attachPipe3(Object.create(TableProto));
|
|
659
875
|
aliased.name = aliasName;
|
|
660
876
|
aliased.columns = columns;
|
|
661
877
|
defineSchemasGetter(aliased);
|
|
662
|
-
aliased[
|
|
878
|
+
aliased[TypeId7] = {
|
|
663
879
|
name: aliasName,
|
|
664
880
|
baseName: state.baseName,
|
|
665
881
|
schemaName: state.schemaName,
|
|
666
882
|
fields: state.fields,
|
|
667
883
|
primaryKey: state.primaryKey,
|
|
884
|
+
conflictArbiters: state.conflictArbiters,
|
|
668
885
|
kind: "alias",
|
|
669
886
|
casing: state.casing
|
|
670
887
|
};
|
|
@@ -682,8 +899,8 @@ var alias = (table, aliasName) => {
|
|
|
682
899
|
};
|
|
683
900
|
aliased[OptionsSymbol] = table[OptionsSymbol];
|
|
684
901
|
aliased[DeclaredOptionsSymbol] = table[DeclaredOptionsSymbol];
|
|
685
|
-
for (const [
|
|
686
|
-
Object.defineProperty(aliased,
|
|
902
|
+
for (const [key2, value] of Object.entries(columns)) {
|
|
903
|
+
Object.defineProperty(aliased, key2, {
|
|
687
904
|
enumerable: true,
|
|
688
905
|
value
|
|
689
906
|
});
|
|
@@ -702,14 +919,16 @@ function Class(name, schemaName) {
|
|
|
702
919
|
static get schemas() {
|
|
703
920
|
return schemasFor(this);
|
|
704
921
|
}
|
|
705
|
-
static get [
|
|
922
|
+
static get [TypeId7]() {
|
|
706
923
|
const declaredOptions = extractDeclaredOptions(this[options]);
|
|
924
|
+
const normalizedOptions = [...collectInlineOptions(fields), ...declaredOptions];
|
|
707
925
|
return {
|
|
708
926
|
name,
|
|
709
927
|
baseName: name,
|
|
710
928
|
schemaName: resolvedSchemaName,
|
|
711
929
|
fields,
|
|
712
930
|
primaryKey: resolvePrimaryKeyColumns(fields, collectInlineOptions(fields)),
|
|
931
|
+
conflictArbiters: conflictArbitersFromOptions(normalizedOptions),
|
|
713
932
|
kind: "schema"
|
|
714
933
|
};
|
|
715
934
|
}
|
|
@@ -732,49 +951,83 @@ function Class(name, schemaName) {
|
|
|
732
951
|
return ensureClassArtifacts(this).normalizedOptions;
|
|
733
952
|
}
|
|
734
953
|
static pipe() {
|
|
735
|
-
return
|
|
954
|
+
return pipeArguments4(this, arguments);
|
|
736
955
|
}
|
|
737
956
|
}
|
|
738
|
-
for (const
|
|
739
|
-
Object.defineProperty(TableClassBase,
|
|
957
|
+
for (const key2 of Object.keys(fields)) {
|
|
958
|
+
Object.defineProperty(TableClassBase, key2, {
|
|
740
959
|
enumerable: true,
|
|
741
960
|
configurable: true,
|
|
742
961
|
get() {
|
|
743
|
-
return ensureClassArtifacts(this).columns[
|
|
962
|
+
return ensureClassArtifacts(this).columns[key2];
|
|
744
963
|
}
|
|
745
964
|
});
|
|
746
965
|
}
|
|
747
966
|
return TableClassBase;
|
|
748
967
|
};
|
|
749
968
|
}
|
|
750
|
-
var
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
}
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
columns:
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
969
|
+
var selectionArray = (selection) => Array.isArray(selection) ? selection : [selection];
|
|
970
|
+
var selectedColumnList = (selection) => selectionArray(selection).map((column) => column[BoundColumnTypeId].columnName);
|
|
971
|
+
var referenceFromSelection = (selection) => {
|
|
972
|
+
const columns = selectionArray(selection);
|
|
973
|
+
const first = columns[0];
|
|
974
|
+
const bound = first[BoundColumnTypeId];
|
|
975
|
+
return {
|
|
976
|
+
tableName: bound.baseTableName,
|
|
977
|
+
schemaName: bound.schemaName,
|
|
978
|
+
casing: bound.casing,
|
|
979
|
+
columns: columns.map((column) => column[BoundColumnTypeId].columnName)
|
|
980
|
+
};
|
|
981
|
+
};
|
|
982
|
+
function primaryKey(columns) {
|
|
983
|
+
return makeResolvedOption({
|
|
984
|
+
kind: "primaryKey",
|
|
985
|
+
columns: []
|
|
986
|
+
}, (table) => ({
|
|
987
|
+
kind: "primaryKey",
|
|
988
|
+
columns: selectedColumnList(columns(table))
|
|
989
|
+
}));
|
|
990
|
+
}
|
|
991
|
+
function unique(columns) {
|
|
992
|
+
return makeResolvedOption({
|
|
993
|
+
kind: "unique",
|
|
994
|
+
columns: []
|
|
995
|
+
}, (table) => ({
|
|
996
|
+
kind: "unique",
|
|
997
|
+
columns: selectedColumnList(columns(table))
|
|
998
|
+
}));
|
|
999
|
+
}
|
|
1000
|
+
function index2(columns) {
|
|
1001
|
+
return makeResolvedOption({
|
|
1002
|
+
kind: "index",
|
|
1003
|
+
columns: []
|
|
1004
|
+
}, (table) => ({
|
|
1005
|
+
kind: "index",
|
|
1006
|
+
columns: selectedColumnList(columns(table))
|
|
1007
|
+
}));
|
|
1008
|
+
}
|
|
1009
|
+
function foreignKey(columns, target) {
|
|
1010
|
+
return makeResolvedOption({
|
|
1011
|
+
kind: "foreignKey",
|
|
1012
|
+
columns: [],
|
|
1013
|
+
references: () => referenceFromSelection(target())
|
|
1014
|
+
}, (table) => ({
|
|
1015
|
+
kind: "foreignKey",
|
|
1016
|
+
columns: selectedColumnList(columns(table)),
|
|
1017
|
+
references: () => referenceFromSelection(target())
|
|
1018
|
+
}));
|
|
1019
|
+
}
|
|
1020
|
+
function check(name, predicate) {
|
|
1021
|
+
const spec = {
|
|
1022
|
+
kind: "check",
|
|
1023
|
+
name,
|
|
1024
|
+
predicate
|
|
1025
|
+
};
|
|
1026
|
+
return typeof predicate === "function" ? makeResolvedOption(spec, (table) => ({
|
|
1027
|
+
...spec,
|
|
1028
|
+
predicate: predicate(table)
|
|
1029
|
+
})) : makeOption(spec);
|
|
1030
|
+
}
|
|
778
1031
|
|
|
779
1032
|
// src/internal/sql-expression-renderer.ts
|
|
780
1033
|
var renderQueryAst = (ast, state, dialect) => {
|
|
@@ -800,10 +1053,10 @@ var renderDbTypeName = (value) => value;
|
|
|
800
1053
|
import * as Schema5 from "effect/Schema";
|
|
801
1054
|
|
|
802
1055
|
// src/internal/query.ts
|
|
803
|
-
import { pipeArguments as
|
|
1056
|
+
import { pipeArguments as pipeArguments5 } from "effect/Pipeable";
|
|
804
1057
|
|
|
805
1058
|
// src/internal/query-ast.ts
|
|
806
|
-
var
|
|
1059
|
+
var TypeId8 = Symbol.for("effect-qb/QueryAst");
|
|
807
1060
|
|
|
808
1061
|
// src/internal/predicate/runtime.ts
|
|
809
1062
|
var trueFormula = () => ({ kind: "true" });
|
|
@@ -828,17 +1081,17 @@ var cloneContext = (context) => ({
|
|
|
828
1081
|
nonNullKeys: new Set(context.nonNullKeys),
|
|
829
1082
|
nullKeys: new Set(context.nullKeys),
|
|
830
1083
|
eqLiterals: new Map(context.eqLiterals),
|
|
831
|
-
neqLiterals: new Map(Array.from(context.neqLiterals.entries(), ([
|
|
832
|
-
literalSets: new Map(Array.from(context.literalSets.entries(), ([
|
|
1084
|
+
neqLiterals: new Map(Array.from(context.neqLiterals.entries(), ([key2, values]) => [key2, new Set(values)])),
|
|
1085
|
+
literalSets: new Map(Array.from(context.literalSets.entries(), ([key2, values]) => [key2, new Set(values)])),
|
|
833
1086
|
sourceNames: new Set(context.sourceNames),
|
|
834
1087
|
contradiction: context.contradiction,
|
|
835
1088
|
unknown: context.unknown
|
|
836
1089
|
});
|
|
837
1090
|
var freezeContext = (context) => context;
|
|
838
1091
|
var columnPredicateKey = (tableName, columnName) => JSON.stringify([tableName, columnName]);
|
|
839
|
-
var columnPredicateKeyParts = (
|
|
840
|
-
const jsonSeparator =
|
|
841
|
-
const columnKey = jsonSeparator === -1 ?
|
|
1092
|
+
var columnPredicateKeyParts = (key2) => {
|
|
1093
|
+
const jsonSeparator = key2.indexOf("#json:");
|
|
1094
|
+
const columnKey = jsonSeparator === -1 ? key2 : key2.slice(0, jsonSeparator);
|
|
842
1095
|
try {
|
|
843
1096
|
const parsed = JSON.parse(columnKey);
|
|
844
1097
|
return Array.isArray(parsed) && parsed.length === 2 && typeof parsed[0] === "string" && typeof parsed[1] === "string" ? [parsed[0], parsed[1]] : undefined;
|
|
@@ -846,59 +1099,59 @@ var columnPredicateKeyParts = (key) => {
|
|
|
846
1099
|
return;
|
|
847
1100
|
}
|
|
848
1101
|
};
|
|
849
|
-
var sourceNameOfKey = (
|
|
850
|
-
var addSourceName = (context,
|
|
851
|
-
context.sourceNames.add(sourceNameOfKey(
|
|
1102
|
+
var sourceNameOfKey = (key2) => columnPredicateKeyParts(key2)?.[0] ?? key2.split(".", 1)[0] ?? key2;
|
|
1103
|
+
var addSourceName = (context, key2) => {
|
|
1104
|
+
context.sourceNames.add(sourceNameOfKey(key2));
|
|
852
1105
|
};
|
|
853
|
-
var addNonNull = (context,
|
|
854
|
-
addSourceName(context,
|
|
855
|
-
if (context.nullKeys.has(
|
|
1106
|
+
var addNonNull = (context, key2) => {
|
|
1107
|
+
addSourceName(context, key2);
|
|
1108
|
+
if (context.nullKeys.has(key2)) {
|
|
856
1109
|
context.contradiction = true;
|
|
857
1110
|
}
|
|
858
|
-
context.nonNullKeys.add(
|
|
1111
|
+
context.nonNullKeys.add(key2);
|
|
859
1112
|
};
|
|
860
|
-
var addNull = (context,
|
|
861
|
-
addSourceName(context,
|
|
862
|
-
if (context.nonNullKeys.has(
|
|
1113
|
+
var addNull = (context, key2) => {
|
|
1114
|
+
addSourceName(context, key2);
|
|
1115
|
+
if (context.nonNullKeys.has(key2)) {
|
|
863
1116
|
context.contradiction = true;
|
|
864
1117
|
}
|
|
865
|
-
context.nullKeys.add(
|
|
1118
|
+
context.nullKeys.add(key2);
|
|
866
1119
|
};
|
|
867
|
-
var addEqLiteral = (context,
|
|
868
|
-
addNonNull(context,
|
|
869
|
-
const existing = context.eqLiterals.get(
|
|
1120
|
+
var addEqLiteral = (context, key2, value) => {
|
|
1121
|
+
addNonNull(context, key2);
|
|
1122
|
+
const existing = context.eqLiterals.get(key2);
|
|
870
1123
|
if (existing !== undefined && existing !== value) {
|
|
871
1124
|
context.contradiction = true;
|
|
872
1125
|
}
|
|
873
|
-
const neqValues = context.neqLiterals.get(
|
|
1126
|
+
const neqValues = context.neqLiterals.get(key2);
|
|
874
1127
|
if (neqValues?.has(value)) {
|
|
875
1128
|
context.contradiction = true;
|
|
876
1129
|
}
|
|
877
|
-
const existingSet = context.literalSets.get(
|
|
1130
|
+
const existingSet = context.literalSets.get(key2);
|
|
878
1131
|
if (existingSet !== undefined && !existingSet.has(value)) {
|
|
879
1132
|
context.contradiction = true;
|
|
880
1133
|
}
|
|
881
|
-
context.eqLiterals.set(
|
|
882
|
-
context.literalSets.set(
|
|
1134
|
+
context.eqLiterals.set(key2, value);
|
|
1135
|
+
context.literalSets.set(key2, new Set([value]));
|
|
883
1136
|
};
|
|
884
|
-
var addNeqLiteral = (context,
|
|
885
|
-
addNonNull(context,
|
|
886
|
-
if (context.eqLiterals.get(
|
|
1137
|
+
var addNeqLiteral = (context, key2, value) => {
|
|
1138
|
+
addNonNull(context, key2);
|
|
1139
|
+
if (context.eqLiterals.get(key2) === value) {
|
|
887
1140
|
context.contradiction = true;
|
|
888
1141
|
}
|
|
889
|
-
const values = context.neqLiterals.get(
|
|
1142
|
+
const values = context.neqLiterals.get(key2) ?? new Set;
|
|
890
1143
|
values.add(value);
|
|
891
|
-
context.neqLiterals.set(
|
|
1144
|
+
context.neqLiterals.set(key2, values);
|
|
892
1145
|
};
|
|
893
|
-
var addLiteralSet = (context,
|
|
894
|
-
addNonNull(context,
|
|
895
|
-
const existingEq = context.eqLiterals.get(
|
|
1146
|
+
var addLiteralSet = (context, key2, values) => {
|
|
1147
|
+
addNonNull(context, key2);
|
|
1148
|
+
const existingEq = context.eqLiterals.get(key2);
|
|
896
1149
|
if (existingEq !== undefined && !values.has(existingEq)) {
|
|
897
1150
|
context.contradiction = true;
|
|
898
1151
|
}
|
|
899
|
-
const existing = context.literalSets.get(
|
|
900
|
-
context.literalSets.set(
|
|
901
|
-
if (context.literalSets.get(
|
|
1152
|
+
const existing = context.literalSets.get(key2);
|
|
1153
|
+
context.literalSets.set(key2, existing === undefined ? new Set(values) : new Set(Array.from(existing).filter((value) => values.has(value))));
|
|
1154
|
+
if (context.literalSets.get(key2)?.size === 0) {
|
|
902
1155
|
context.contradiction = true;
|
|
903
1156
|
}
|
|
904
1157
|
};
|
|
@@ -980,35 +1233,35 @@ var applyNegativeAtom = (context, atom) => {
|
|
|
980
1233
|
};
|
|
981
1234
|
var intersectEqLiterals = (left, right) => {
|
|
982
1235
|
const result = new Map;
|
|
983
|
-
for (const [
|
|
984
|
-
if (right.get(
|
|
985
|
-
result.set(
|
|
1236
|
+
for (const [key2, value] of left) {
|
|
1237
|
+
if (right.get(key2) === value) {
|
|
1238
|
+
result.set(key2, value);
|
|
986
1239
|
}
|
|
987
1240
|
}
|
|
988
1241
|
return result;
|
|
989
1242
|
};
|
|
990
1243
|
var intersectNeqLiterals = (left, right) => {
|
|
991
1244
|
const result = new Map;
|
|
992
|
-
for (const [
|
|
993
|
-
const rightValues = right.get(
|
|
1245
|
+
for (const [key2, leftValues] of left) {
|
|
1246
|
+
const rightValues = right.get(key2);
|
|
994
1247
|
if (rightValues === undefined) {
|
|
995
1248
|
continue;
|
|
996
1249
|
}
|
|
997
1250
|
const next = new Set(Array.from(leftValues).filter((value) => rightValues.has(value)));
|
|
998
1251
|
if (next.size > 0) {
|
|
999
|
-
result.set(
|
|
1252
|
+
result.set(key2, next);
|
|
1000
1253
|
}
|
|
1001
1254
|
}
|
|
1002
1255
|
return result;
|
|
1003
1256
|
};
|
|
1004
1257
|
var unionLiteralSets = (left, right) => {
|
|
1005
1258
|
const result = new Map;
|
|
1006
|
-
for (const [
|
|
1007
|
-
const rightValues = right.get(
|
|
1259
|
+
for (const [key2, leftValues] of left) {
|
|
1260
|
+
const rightValues = right.get(key2);
|
|
1008
1261
|
if (rightValues === undefined) {
|
|
1009
1262
|
continue;
|
|
1010
1263
|
}
|
|
1011
|
-
result.set(
|
|
1264
|
+
result.set(key2, new Set([...leftValues, ...rightValues]));
|
|
1012
1265
|
}
|
|
1013
1266
|
return result;
|
|
1014
1267
|
};
|
|
@@ -1020,8 +1273,8 @@ var intersectContexts = (left, right) => {
|
|
|
1020
1273
|
return cloneContext(left);
|
|
1021
1274
|
}
|
|
1022
1275
|
return {
|
|
1023
|
-
nonNullKeys: new Set(Array.from(left.nonNullKeys).filter((
|
|
1024
|
-
nullKeys: new Set(Array.from(left.nullKeys).filter((
|
|
1276
|
+
nonNullKeys: new Set(Array.from(left.nonNullKeys).filter((key2) => right.nonNullKeys.has(key2))),
|
|
1277
|
+
nullKeys: new Set(Array.from(left.nullKeys).filter((key2) => right.nullKeys.has(key2))),
|
|
1025
1278
|
eqLiterals: intersectEqLiterals(left.eqLiterals, right.eqLiterals),
|
|
1026
1279
|
neqLiterals: intersectNeqLiterals(left.neqLiterals, right.neqLiterals),
|
|
1027
1280
|
literalSets: unionLiteralSets(left.literalSets, right.literalSets),
|
|
@@ -1112,18 +1365,18 @@ var jsonPathPredicateKeyOfExpression = (value) => {
|
|
|
1112
1365
|
if (segments.length === 0 || segments.length > 8) {
|
|
1113
1366
|
return;
|
|
1114
1367
|
}
|
|
1115
|
-
const
|
|
1368
|
+
const path2 = [];
|
|
1116
1369
|
for (const segment of segments) {
|
|
1117
1370
|
if (typeof segment !== "object" || segment === null || segment.kind !== "key") {
|
|
1118
1371
|
return;
|
|
1119
1372
|
}
|
|
1120
|
-
|
|
1373
|
+
path2.push(segment.key);
|
|
1121
1374
|
}
|
|
1122
|
-
if (
|
|
1375
|
+
if (path2.length === 0) {
|
|
1123
1376
|
return;
|
|
1124
1377
|
}
|
|
1125
1378
|
const baseKey = columnKeyOfExpression(jsonAst.base);
|
|
1126
|
-
return baseKey === undefined ? undefined : `${baseKey}#json:${
|
|
1379
|
+
return baseKey === undefined ? undefined : `${baseKey}#json:${path2.map(escapeJsonPathPredicateKeySegment).join(".")}`;
|
|
1127
1380
|
}
|
|
1128
1381
|
default:
|
|
1129
1382
|
return;
|
|
@@ -1160,8 +1413,8 @@ var valueKeyOfLiteral = (value) => {
|
|
|
1160
1413
|
return "unknown";
|
|
1161
1414
|
};
|
|
1162
1415
|
var nonNullFactsOfExpression = (value) => {
|
|
1163
|
-
const
|
|
1164
|
-
return
|
|
1416
|
+
const key2 = predicateKeyOfExpression(value);
|
|
1417
|
+
return key2 === undefined ? undefined : atomFormula({ kind: "is-not-null", key: key2 });
|
|
1165
1418
|
};
|
|
1166
1419
|
var combineFacts = (left, right) => {
|
|
1167
1420
|
if (left === undefined) {
|
|
@@ -1372,12 +1625,12 @@ var formulaOfExpression = (value) => {
|
|
|
1372
1625
|
}
|
|
1373
1626
|
return unknownTag("literal:non-boolean");
|
|
1374
1627
|
case "isNull": {
|
|
1375
|
-
const
|
|
1376
|
-
return
|
|
1628
|
+
const key2 = predicateKeyOfExpression(ast.value);
|
|
1629
|
+
return key2 === undefined ? unknownTag("isNull:unsupported") : atomFormula({ kind: "is-null", key: key2 });
|
|
1377
1630
|
}
|
|
1378
1631
|
case "isNotNull": {
|
|
1379
|
-
const
|
|
1380
|
-
return
|
|
1632
|
+
const key2 = predicateKeyOfExpression(ast.value);
|
|
1633
|
+
return key2 === undefined ? unknownTag("isNotNull:unsupported") : atomFormula({ kind: "is-not-null", key: key2 });
|
|
1381
1634
|
}
|
|
1382
1635
|
case "not":
|
|
1383
1636
|
return notFormula(formulaOfExpression(ast.value));
|
|
@@ -1398,12 +1651,12 @@ var formulaOfExpression = (value) => {
|
|
|
1398
1651
|
if (left === undefined) {
|
|
1399
1652
|
return falseFormula();
|
|
1400
1653
|
}
|
|
1401
|
-
const
|
|
1654
|
+
const key2 = predicateKeyOfExpression(left);
|
|
1402
1655
|
const literalValues = rest.map((entry) => {
|
|
1403
1656
|
const entryAst = astOf(entry);
|
|
1404
1657
|
return entryAst.kind === "literal" && entryAst.value !== null ? valueKeyOfLiteral(entryAst.value) : undefined;
|
|
1405
1658
|
});
|
|
1406
|
-
return
|
|
1659
|
+
return key2 !== undefined && literalValues.every((entry) => entry !== undefined) ? atomFormula({ kind: "literal-set", key: key2, values: literalValues }) : anyFormula(rest.map((value2) => formulaOfEq(left, value2)));
|
|
1407
1660
|
}
|
|
1408
1661
|
case "notIn": {
|
|
1409
1662
|
const [left, ...rest] = ast.values;
|
|
@@ -1440,12 +1693,12 @@ var union_query_capabilities = (...values) => [...new Set(values.flatMap((value)
|
|
|
1440
1693
|
// src/internal/query.ts
|
|
1441
1694
|
var ExpressionProto = {
|
|
1442
1695
|
pipe() {
|
|
1443
|
-
return
|
|
1696
|
+
return pipeArguments5(this, arguments);
|
|
1444
1697
|
}
|
|
1445
1698
|
};
|
|
1446
1699
|
var PlanProto = {
|
|
1447
1700
|
pipe() {
|
|
1448
|
-
return
|
|
1701
|
+
return pipeArguments5(this, arguments);
|
|
1449
1702
|
}
|
|
1450
1703
|
};
|
|
1451
1704
|
var QueryTypeId = Symbol.for("effect-qb/Query/internal");
|
|
@@ -1458,13 +1711,13 @@ var mergeAggregationManyRuntime = (values) => values.reduce((current, value) =>
|
|
|
1458
1711
|
var mergeNullabilityRuntime = (left, right = "never") => left === "always" || right === "always" ? "always" : left === "maybe" || right === "maybe" ? "maybe" : "never";
|
|
1459
1712
|
var mergeNullabilityManyRuntime = (values) => values.reduce((current, value) => mergeNullabilityRuntime(current, value[TypeId2].nullability), "never");
|
|
1460
1713
|
var mergeManyDependencies = (values) => values.reduce((current, value) => mergeDependencies(current, value[TypeId2].dependencies), {});
|
|
1461
|
-
var
|
|
1714
|
+
var makeExpression2 = (state, ast) => {
|
|
1462
1715
|
const expression = Object.create(ExpressionProto);
|
|
1463
1716
|
Object.defineProperty(expression, "pipe", {
|
|
1464
1717
|
configurable: true,
|
|
1465
1718
|
writable: true,
|
|
1466
1719
|
value: function() {
|
|
1467
|
-
return
|
|
1720
|
+
return pipeArguments5(expression, arguments);
|
|
1468
1721
|
}
|
|
1469
1722
|
});
|
|
1470
1723
|
expression[TypeId2] = {
|
|
@@ -1486,11 +1739,11 @@ var makePlan = (state, ast, _assumptions, _capabilities, _statement, _target, _i
|
|
|
1486
1739
|
configurable: true,
|
|
1487
1740
|
writable: true,
|
|
1488
1741
|
value: function() {
|
|
1489
|
-
return
|
|
1742
|
+
return pipeArguments5(plan, arguments);
|
|
1490
1743
|
}
|
|
1491
1744
|
});
|
|
1492
1745
|
plan[TypeId] = state;
|
|
1493
|
-
plan[
|
|
1746
|
+
plan[TypeId8] = ast;
|
|
1494
1747
|
plan[QueryTypeId] = {
|
|
1495
1748
|
required: undefined,
|
|
1496
1749
|
availableNames: undefined,
|
|
@@ -1504,7 +1757,7 @@ var makePlan = (state, ast, _assumptions, _capabilities, _statement, _target, _i
|
|
|
1504
1757
|
};
|
|
1505
1758
|
return plan;
|
|
1506
1759
|
};
|
|
1507
|
-
var getAst = (plan) => plan[
|
|
1760
|
+
var getAst = (plan) => plan[TypeId8];
|
|
1508
1761
|
var getQueryState = (plan) => plan[QueryTypeId];
|
|
1509
1762
|
var extractRequiredRuntime = (selection) => {
|
|
1510
1763
|
const required = new Set;
|
|
@@ -1528,50 +1781,863 @@ var extractSingleSelectedExpressionRuntime = (selection) => {
|
|
|
1528
1781
|
};
|
|
1529
1782
|
var currentRequiredList = (required) => Array.isArray(required) ? [...required] : required === undefined ? [] : [required];
|
|
1530
1783
|
|
|
1531
|
-
// src/internal/
|
|
1532
|
-
var
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1784
|
+
// src/internal/datatypes/matrix.ts
|
|
1785
|
+
var portableDatatypeFamilies = {
|
|
1786
|
+
uuid: {
|
|
1787
|
+
compareGroup: "uuid",
|
|
1788
|
+
castTargets: ["uuid", "char", "varchar", "text"],
|
|
1789
|
+
traits: {
|
|
1790
|
+
textual: true
|
|
1791
|
+
}
|
|
1538
1792
|
},
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1793
|
+
text: {
|
|
1794
|
+
compareGroup: "text",
|
|
1795
|
+
castTargets: [
|
|
1796
|
+
"text",
|
|
1797
|
+
"numeric",
|
|
1798
|
+
"integer",
|
|
1799
|
+
"real",
|
|
1800
|
+
"boolean",
|
|
1801
|
+
"date",
|
|
1802
|
+
"time",
|
|
1803
|
+
"datetime",
|
|
1804
|
+
"interval",
|
|
1805
|
+
"uuid",
|
|
1806
|
+
"json",
|
|
1807
|
+
"blob",
|
|
1808
|
+
"binary",
|
|
1809
|
+
"array",
|
|
1810
|
+
"range",
|
|
1811
|
+
"multirange",
|
|
1812
|
+
"record",
|
|
1813
|
+
"enum",
|
|
1814
|
+
"set",
|
|
1815
|
+
"money",
|
|
1816
|
+
"null"
|
|
1817
|
+
],
|
|
1818
|
+
traits: {
|
|
1819
|
+
textual: true,
|
|
1820
|
+
ordered: true
|
|
1821
|
+
}
|
|
1545
1822
|
},
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1823
|
+
numeric: {
|
|
1824
|
+
compareGroup: "numeric",
|
|
1825
|
+
castTargets: ["numeric", "integer", "real", "text", "boolean", "date", "time", "datetime"],
|
|
1826
|
+
traits: {
|
|
1827
|
+
ordered: true
|
|
1828
|
+
}
|
|
1552
1829
|
},
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1830
|
+
integer: {
|
|
1831
|
+
compareGroup: "numeric",
|
|
1832
|
+
castTargets: ["integer", "numeric", "real", "text", "boolean", "date", "time", "datetime"],
|
|
1833
|
+
traits: {
|
|
1834
|
+
ordered: true
|
|
1835
|
+
}
|
|
1558
1836
|
},
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
kind: "descend"
|
|
1837
|
+
real: {
|
|
1838
|
+
compareGroup: "numeric",
|
|
1839
|
+
castTargets: ["real", "numeric", "integer", "text", "boolean"],
|
|
1840
|
+
traits: {
|
|
1841
|
+
ordered: true
|
|
1842
|
+
}
|
|
1566
1843
|
},
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
segments
|
|
1844
|
+
boolean: {
|
|
1845
|
+
compareGroup: "boolean",
|
|
1846
|
+
castTargets: ["boolean", "integer", "numeric", "text"],
|
|
1847
|
+
traits: {}
|
|
1572
1848
|
},
|
|
1573
|
-
|
|
1574
|
-
|
|
1849
|
+
date: {
|
|
1850
|
+
compareGroup: "date",
|
|
1851
|
+
castTargets: ["date", "time", "datetime", "text", "numeric", "integer"],
|
|
1852
|
+
traits: {
|
|
1853
|
+
ordered: true
|
|
1854
|
+
}
|
|
1855
|
+
},
|
|
1856
|
+
time: {
|
|
1857
|
+
compareGroup: "time",
|
|
1858
|
+
castTargets: ["time", "date", "datetime", "text", "numeric", "integer"],
|
|
1859
|
+
traits: {
|
|
1860
|
+
ordered: true
|
|
1861
|
+
}
|
|
1862
|
+
},
|
|
1863
|
+
datetime: {
|
|
1864
|
+
compareGroup: "datetime",
|
|
1865
|
+
castTargets: ["datetime", "date", "time", "text", "numeric", "integer"],
|
|
1866
|
+
traits: {
|
|
1867
|
+
ordered: true
|
|
1868
|
+
}
|
|
1869
|
+
},
|
|
1870
|
+
json: {
|
|
1871
|
+
compareGroup: "json",
|
|
1872
|
+
castTargets: ["json", "text"],
|
|
1873
|
+
traits: {}
|
|
1874
|
+
},
|
|
1875
|
+
blob: {
|
|
1876
|
+
compareGroup: "blob",
|
|
1877
|
+
castTargets: ["blob", "text"],
|
|
1878
|
+
traits: {}
|
|
1879
|
+
},
|
|
1880
|
+
null: {
|
|
1881
|
+
compareGroup: "null",
|
|
1882
|
+
castTargets: ["uuid", "text", "numeric", "integer", "real", "boolean", "date", "time", "datetime", "json", "blob", "null"],
|
|
1883
|
+
traits: {}
|
|
1884
|
+
}
|
|
1885
|
+
};
|
|
1886
|
+
var portableDatatypeKinds = {
|
|
1887
|
+
uuid: { family: "uuid", runtime: "string" },
|
|
1888
|
+
text: { family: "text", runtime: "string" },
|
|
1889
|
+
varchar: { family: "text", runtime: "string" },
|
|
1890
|
+
char: { family: "text", runtime: "string" },
|
|
1891
|
+
int: { family: "integer", runtime: "number" },
|
|
1892
|
+
integer: { family: "integer", runtime: "number" },
|
|
1893
|
+
bigint: { family: "integer", runtime: "bigintString" },
|
|
1894
|
+
numeric: { family: "numeric", runtime: "decimalString" },
|
|
1895
|
+
decimal: { family: "numeric", runtime: "decimalString" },
|
|
1896
|
+
real: { family: "real", runtime: "number" },
|
|
1897
|
+
boolean: { family: "boolean", runtime: "boolean" },
|
|
1898
|
+
date: { family: "date", runtime: "localDate" },
|
|
1899
|
+
time: { family: "time", runtime: "localTime" },
|
|
1900
|
+
datetime: { family: "datetime", runtime: "localDateTime" },
|
|
1901
|
+
timestamp: { family: "datetime", runtime: "localDateTime" },
|
|
1902
|
+
json: { family: "json", runtime: "json" },
|
|
1903
|
+
blob: { family: "blob", runtime: "bytes" }
|
|
1904
|
+
};
|
|
1905
|
+
var portableDatatypeKeys = Object.keys(portableDatatypeKinds);
|
|
1906
|
+
var portableDatatypeDdlTypeByDialect = {
|
|
1907
|
+
standard: {
|
|
1908
|
+
uuid: "uuid",
|
|
1909
|
+
text: "text",
|
|
1910
|
+
varchar: "varchar",
|
|
1911
|
+
char: "char",
|
|
1912
|
+
int: "int",
|
|
1913
|
+
integer: "integer",
|
|
1914
|
+
bigint: "bigint",
|
|
1915
|
+
numeric: "numeric",
|
|
1916
|
+
decimal: "decimal",
|
|
1917
|
+
real: "real",
|
|
1918
|
+
boolean: "boolean",
|
|
1919
|
+
date: "date",
|
|
1920
|
+
time: "time",
|
|
1921
|
+
datetime: "datetime",
|
|
1922
|
+
timestamp: "timestamp",
|
|
1923
|
+
json: "json",
|
|
1924
|
+
blob: "blob"
|
|
1925
|
+
},
|
|
1926
|
+
postgres: {
|
|
1927
|
+
uuid: "uuid",
|
|
1928
|
+
text: "text",
|
|
1929
|
+
varchar: "varchar",
|
|
1930
|
+
char: "char",
|
|
1931
|
+
int: "int",
|
|
1932
|
+
integer: "integer",
|
|
1933
|
+
bigint: "bigint",
|
|
1934
|
+
numeric: "numeric",
|
|
1935
|
+
decimal: "decimal",
|
|
1936
|
+
real: "real",
|
|
1937
|
+
boolean: "boolean",
|
|
1938
|
+
date: "date",
|
|
1939
|
+
time: "time",
|
|
1940
|
+
datetime: "timestamp",
|
|
1941
|
+
timestamp: "timestamp",
|
|
1942
|
+
json: "json",
|
|
1943
|
+
blob: "bytea"
|
|
1944
|
+
},
|
|
1945
|
+
mysql: {
|
|
1946
|
+
uuid: "char(36)",
|
|
1947
|
+
text: "text",
|
|
1948
|
+
varchar: "varchar(255)",
|
|
1949
|
+
char: "char",
|
|
1950
|
+
int: "int",
|
|
1951
|
+
integer: "integer",
|
|
1952
|
+
bigint: "bigint",
|
|
1953
|
+
numeric: "numeric",
|
|
1954
|
+
decimal: "decimal",
|
|
1955
|
+
real: "real",
|
|
1956
|
+
boolean: "boolean",
|
|
1957
|
+
date: "date",
|
|
1958
|
+
time: "time",
|
|
1959
|
+
datetime: "datetime",
|
|
1960
|
+
timestamp: "timestamp",
|
|
1961
|
+
json: "json",
|
|
1962
|
+
blob: "blob"
|
|
1963
|
+
},
|
|
1964
|
+
sqlite: {
|
|
1965
|
+
uuid: "text",
|
|
1966
|
+
text: "text",
|
|
1967
|
+
varchar: "varchar",
|
|
1968
|
+
char: "char",
|
|
1969
|
+
int: "int",
|
|
1970
|
+
integer: "integer",
|
|
1971
|
+
bigint: "bigint",
|
|
1972
|
+
numeric: "numeric",
|
|
1973
|
+
decimal: "decimal",
|
|
1974
|
+
real: "real",
|
|
1975
|
+
boolean: "boolean",
|
|
1976
|
+
date: "date",
|
|
1977
|
+
time: "time",
|
|
1978
|
+
datetime: "datetime",
|
|
1979
|
+
timestamp: "datetime",
|
|
1980
|
+
json: "json",
|
|
1981
|
+
blob: "blob"
|
|
1982
|
+
}
|
|
1983
|
+
};
|
|
1984
|
+
var portableDatatypeCastTypeByDialect = {
|
|
1985
|
+
standard: portableDatatypeDdlTypeByDialect.standard,
|
|
1986
|
+
postgres: portableDatatypeDdlTypeByDialect.postgres,
|
|
1987
|
+
mysql: {
|
|
1988
|
+
...portableDatatypeDdlTypeByDialect.mysql,
|
|
1989
|
+
uuid: "char(36)",
|
|
1990
|
+
text: "char",
|
|
1991
|
+
varchar: "char",
|
|
1992
|
+
char: "char",
|
|
1993
|
+
int: "signed",
|
|
1994
|
+
integer: "signed",
|
|
1995
|
+
bigint: "signed",
|
|
1996
|
+
numeric: "decimal",
|
|
1997
|
+
decimal: "decimal",
|
|
1998
|
+
boolean: "unsigned",
|
|
1999
|
+
datetime: "datetime",
|
|
2000
|
+
timestamp: "datetime",
|
|
2001
|
+
blob: "binary"
|
|
2002
|
+
},
|
|
2003
|
+
sqlite: {
|
|
2004
|
+
...portableDatatypeDdlTypeByDialect.sqlite,
|
|
2005
|
+
uuid: "text",
|
|
2006
|
+
int: "integer",
|
|
2007
|
+
timestamp: "datetime"
|
|
2008
|
+
}
|
|
2009
|
+
};
|
|
2010
|
+
var hasOwn = (value, key2) => Object.prototype.hasOwnProperty.call(value, key2);
|
|
2011
|
+
var renderPortableDatatypeDdlType = (dialect, kind) => {
|
|
2012
|
+
if (!hasOwn(portableDatatypeDdlTypeByDialect, dialect)) {
|
|
2013
|
+
return;
|
|
2014
|
+
}
|
|
2015
|
+
const byKind = portableDatatypeDdlTypeByDialect[dialect];
|
|
2016
|
+
return hasOwn(byKind, kind) ? byKind[kind] : undefined;
|
|
2017
|
+
};
|
|
2018
|
+
var renderPortableDatatypeCastType = (dialect, kind) => {
|
|
2019
|
+
if (!hasOwn(portableDatatypeCastTypeByDialect, dialect)) {
|
|
2020
|
+
return;
|
|
2021
|
+
}
|
|
2022
|
+
const byKind = portableDatatypeCastTypeByDialect[dialect];
|
|
2023
|
+
return hasOwn(byKind, kind) ? byKind[kind] : undefined;
|
|
2024
|
+
};
|
|
2025
|
+
var postgresDatatypeFamilies = {
|
|
2026
|
+
text: {
|
|
2027
|
+
compareGroup: "text",
|
|
2028
|
+
castTargets: [
|
|
2029
|
+
"text",
|
|
2030
|
+
"numeric",
|
|
2031
|
+
"boolean",
|
|
2032
|
+
"date",
|
|
2033
|
+
"time",
|
|
2034
|
+
"timestamp",
|
|
2035
|
+
"interval",
|
|
2036
|
+
"binary",
|
|
2037
|
+
"uuid",
|
|
2038
|
+
"json",
|
|
2039
|
+
"xml",
|
|
2040
|
+
"bit",
|
|
2041
|
+
"oid",
|
|
2042
|
+
"identifier",
|
|
2043
|
+
"network",
|
|
2044
|
+
"spatial",
|
|
2045
|
+
"textsearch",
|
|
2046
|
+
"range",
|
|
2047
|
+
"multirange",
|
|
2048
|
+
"array",
|
|
2049
|
+
"money",
|
|
2050
|
+
"null"
|
|
2051
|
+
],
|
|
2052
|
+
traits: {
|
|
2053
|
+
textual: true,
|
|
2054
|
+
ordered: true
|
|
2055
|
+
}
|
|
2056
|
+
},
|
|
2057
|
+
numeric: {
|
|
2058
|
+
compareGroup: "numeric",
|
|
2059
|
+
castTargets: ["numeric", "text", "boolean", "date", "time", "timestamp", "interval", "uuid", "bit", "oid", "money"],
|
|
2060
|
+
traits: {
|
|
2061
|
+
ordered: true
|
|
2062
|
+
}
|
|
2063
|
+
},
|
|
2064
|
+
boolean: {
|
|
2065
|
+
compareGroup: "boolean",
|
|
2066
|
+
castTargets: ["boolean", "text", "numeric"],
|
|
2067
|
+
traits: {}
|
|
2068
|
+
},
|
|
2069
|
+
date: {
|
|
2070
|
+
compareGroup: "date",
|
|
2071
|
+
castTargets: ["date", "timestamp", "text"],
|
|
2072
|
+
traits: {
|
|
2073
|
+
ordered: true
|
|
2074
|
+
}
|
|
2075
|
+
},
|
|
2076
|
+
time: {
|
|
2077
|
+
compareGroup: "time",
|
|
2078
|
+
castTargets: ["time", "timestamp", "text"],
|
|
2079
|
+
traits: {
|
|
2080
|
+
ordered: true
|
|
2081
|
+
}
|
|
2082
|
+
},
|
|
2083
|
+
timestamp: {
|
|
2084
|
+
compareGroup: "timestamp",
|
|
2085
|
+
castTargets: ["timestamp", "date", "text"],
|
|
2086
|
+
traits: {
|
|
2087
|
+
ordered: true
|
|
2088
|
+
}
|
|
2089
|
+
},
|
|
2090
|
+
interval: {
|
|
2091
|
+
compareGroup: "interval",
|
|
2092
|
+
castTargets: ["interval", "text"],
|
|
2093
|
+
traits: {
|
|
2094
|
+
ordered: true
|
|
2095
|
+
}
|
|
2096
|
+
},
|
|
2097
|
+
binary: {
|
|
2098
|
+
compareGroup: "binary",
|
|
2099
|
+
castTargets: ["binary", "text"],
|
|
2100
|
+
traits: {}
|
|
2101
|
+
},
|
|
2102
|
+
uuid: {
|
|
2103
|
+
compareGroup: "uuid",
|
|
2104
|
+
castTargets: ["uuid", "text"],
|
|
2105
|
+
traits: {
|
|
2106
|
+
ordered: true
|
|
2107
|
+
}
|
|
2108
|
+
},
|
|
2109
|
+
json: {
|
|
2110
|
+
compareGroup: "json",
|
|
2111
|
+
castTargets: ["json", "text"],
|
|
2112
|
+
traits: {}
|
|
2113
|
+
},
|
|
2114
|
+
xml: {
|
|
2115
|
+
compareGroup: "xml",
|
|
2116
|
+
castTargets: ["xml", "text"],
|
|
2117
|
+
traits: {}
|
|
2118
|
+
},
|
|
2119
|
+
bit: {
|
|
2120
|
+
compareGroup: "bit",
|
|
2121
|
+
castTargets: ["bit", "text", "numeric"],
|
|
2122
|
+
traits: {}
|
|
2123
|
+
},
|
|
2124
|
+
oid: {
|
|
2125
|
+
compareGroup: "oid",
|
|
2126
|
+
castTargets: ["oid", "text", "numeric"],
|
|
2127
|
+
traits: {
|
|
2128
|
+
ordered: true
|
|
2129
|
+
}
|
|
2130
|
+
},
|
|
2131
|
+
identifier: {
|
|
2132
|
+
compareGroup: "identifier",
|
|
2133
|
+
castTargets: ["identifier", "text"],
|
|
2134
|
+
traits: {}
|
|
2135
|
+
},
|
|
2136
|
+
network: {
|
|
2137
|
+
compareGroup: "network",
|
|
2138
|
+
castTargets: ["network", "text"],
|
|
2139
|
+
traits: {}
|
|
2140
|
+
},
|
|
2141
|
+
spatial: {
|
|
2142
|
+
compareGroup: "spatial",
|
|
2143
|
+
castTargets: ["spatial", "text"],
|
|
2144
|
+
traits: {}
|
|
2145
|
+
},
|
|
2146
|
+
textsearch: {
|
|
2147
|
+
compareGroup: "textsearch",
|
|
2148
|
+
castTargets: ["textsearch", "text"],
|
|
2149
|
+
traits: {}
|
|
2150
|
+
},
|
|
2151
|
+
range: {
|
|
2152
|
+
compareGroup: "range",
|
|
2153
|
+
castTargets: ["range", "text"],
|
|
2154
|
+
traits: {}
|
|
2155
|
+
},
|
|
2156
|
+
multirange: {
|
|
2157
|
+
compareGroup: "multirange",
|
|
2158
|
+
castTargets: ["multirange", "text"],
|
|
2159
|
+
traits: {}
|
|
2160
|
+
},
|
|
2161
|
+
enum: {
|
|
2162
|
+
compareGroup: "enum",
|
|
2163
|
+
castTargets: ["enum", "text"],
|
|
2164
|
+
traits: {
|
|
2165
|
+
textual: true,
|
|
2166
|
+
ordered: true
|
|
2167
|
+
}
|
|
2168
|
+
},
|
|
2169
|
+
record: {
|
|
2170
|
+
compareGroup: "record",
|
|
2171
|
+
castTargets: ["record", "text"],
|
|
2172
|
+
traits: {}
|
|
2173
|
+
},
|
|
2174
|
+
array: {
|
|
2175
|
+
compareGroup: "array",
|
|
2176
|
+
castTargets: ["array", "text"],
|
|
2177
|
+
traits: {}
|
|
2178
|
+
},
|
|
2179
|
+
money: {
|
|
2180
|
+
compareGroup: "money",
|
|
2181
|
+
castTargets: ["money", "text", "numeric"],
|
|
2182
|
+
traits: {
|
|
2183
|
+
ordered: true
|
|
2184
|
+
}
|
|
2185
|
+
},
|
|
2186
|
+
null: {
|
|
2187
|
+
compareGroup: "null",
|
|
2188
|
+
castTargets: [
|
|
2189
|
+
"text",
|
|
2190
|
+
"numeric",
|
|
2191
|
+
"boolean",
|
|
2192
|
+
"date",
|
|
2193
|
+
"time",
|
|
2194
|
+
"timestamp",
|
|
2195
|
+
"interval",
|
|
2196
|
+
"binary",
|
|
2197
|
+
"uuid",
|
|
2198
|
+
"json",
|
|
2199
|
+
"xml",
|
|
2200
|
+
"bit",
|
|
2201
|
+
"oid",
|
|
2202
|
+
"identifier",
|
|
2203
|
+
"network",
|
|
2204
|
+
"spatial",
|
|
2205
|
+
"textsearch",
|
|
2206
|
+
"range",
|
|
2207
|
+
"multirange",
|
|
2208
|
+
"array",
|
|
2209
|
+
"money",
|
|
2210
|
+
"null"
|
|
2211
|
+
],
|
|
2212
|
+
traits: {}
|
|
2213
|
+
}
|
|
2214
|
+
};
|
|
2215
|
+
var postgresDatatypeKinds = {
|
|
2216
|
+
text: { family: "text", runtime: "string" },
|
|
2217
|
+
varchar: { family: "text", runtime: "string" },
|
|
2218
|
+
char: { family: "text", runtime: "string" },
|
|
2219
|
+
citext: { family: "text", runtime: "string" },
|
|
2220
|
+
name: { family: "text", runtime: "string" },
|
|
2221
|
+
uuid: { family: "uuid", runtime: "string" },
|
|
2222
|
+
int2: { family: "numeric", runtime: "number" },
|
|
2223
|
+
int4: { family: "numeric", runtime: "number" },
|
|
2224
|
+
int8: { family: "numeric", runtime: "bigintString" },
|
|
2225
|
+
numeric: { family: "numeric", runtime: "decimalString" },
|
|
2226
|
+
float4: { family: "numeric", runtime: "number" },
|
|
2227
|
+
float8: { family: "numeric", runtime: "number" },
|
|
2228
|
+
money: { family: "money", runtime: "number" },
|
|
2229
|
+
bool: { family: "boolean", runtime: "boolean" },
|
|
2230
|
+
date: { family: "date", runtime: "localDate" },
|
|
2231
|
+
time: { family: "time", runtime: "localTime" },
|
|
2232
|
+
timetz: { family: "time", runtime: "offsetTime" },
|
|
2233
|
+
timestamp: { family: "timestamp", runtime: "localDateTime" },
|
|
2234
|
+
timestamptz: { family: "timestamp", runtime: "instant" },
|
|
2235
|
+
interval: { family: "interval", runtime: "string" },
|
|
2236
|
+
bytea: { family: "binary", runtime: "bytes" },
|
|
2237
|
+
json: { family: "json", runtime: "json" },
|
|
2238
|
+
jsonb: { family: "json", runtime: "json" },
|
|
2239
|
+
xml: { family: "xml", runtime: "string" },
|
|
2240
|
+
bit: { family: "bit", runtime: "string" },
|
|
2241
|
+
varbit: { family: "bit", runtime: "string" },
|
|
2242
|
+
oid: { family: "oid", runtime: "number" },
|
|
2243
|
+
xid: { family: "oid", runtime: "number" },
|
|
2244
|
+
xid8: { family: "oid", runtime: "bigintString" },
|
|
2245
|
+
cid: { family: "oid", runtime: "number" },
|
|
2246
|
+
tid: { family: "identifier", runtime: "string" },
|
|
2247
|
+
regclass: { family: "identifier", runtime: "string" },
|
|
2248
|
+
regtype: { family: "identifier", runtime: "string" },
|
|
2249
|
+
regproc: { family: "identifier", runtime: "string" },
|
|
2250
|
+
regprocedure: { family: "identifier", runtime: "string" },
|
|
2251
|
+
regoper: { family: "identifier", runtime: "string" },
|
|
2252
|
+
regoperator: { family: "identifier", runtime: "string" },
|
|
2253
|
+
regconfig: { family: "identifier", runtime: "string" },
|
|
2254
|
+
regdictionary: { family: "identifier", runtime: "string" },
|
|
2255
|
+
pg_lsn: { family: "identifier", runtime: "string" },
|
|
2256
|
+
txid_snapshot: { family: "identifier", runtime: "string" },
|
|
2257
|
+
inet: { family: "network", runtime: "string" },
|
|
2258
|
+
cidr: { family: "network", runtime: "string" },
|
|
2259
|
+
macaddr: { family: "network", runtime: "string" },
|
|
2260
|
+
macaddr8: { family: "network", runtime: "string" },
|
|
2261
|
+
point: { family: "spatial", runtime: "unknown" },
|
|
2262
|
+
line: { family: "spatial", runtime: "unknown" },
|
|
2263
|
+
lseg: { family: "spatial", runtime: "unknown" },
|
|
2264
|
+
box: { family: "spatial", runtime: "unknown" },
|
|
2265
|
+
path: { family: "spatial", runtime: "unknown" },
|
|
2266
|
+
polygon: { family: "spatial", runtime: "unknown" },
|
|
2267
|
+
circle: { family: "spatial", runtime: "unknown" },
|
|
2268
|
+
tsvector: { family: "textsearch", runtime: "string" },
|
|
2269
|
+
tsquery: { family: "textsearch", runtime: "string" },
|
|
2270
|
+
int4range: { family: "range", runtime: "unknown" },
|
|
2271
|
+
int8range: { family: "range", runtime: "unknown" },
|
|
2272
|
+
numrange: { family: "range", runtime: "unknown" },
|
|
2273
|
+
tsrange: { family: "range", runtime: "unknown" },
|
|
2274
|
+
tstzrange: { family: "range", runtime: "unknown" },
|
|
2275
|
+
daterange: { family: "range", runtime: "unknown" },
|
|
2276
|
+
int4multirange: { family: "multirange", runtime: "unknown" },
|
|
2277
|
+
int8multirange: { family: "multirange", runtime: "unknown" },
|
|
2278
|
+
nummultirange: { family: "multirange", runtime: "unknown" },
|
|
2279
|
+
tsmultirange: { family: "multirange", runtime: "unknown" },
|
|
2280
|
+
tstzmultirange: { family: "multirange", runtime: "unknown" },
|
|
2281
|
+
datemultirange: { family: "multirange", runtime: "unknown" }
|
|
2282
|
+
};
|
|
2283
|
+
var postgresSpecificDatatypeKeys = [
|
|
2284
|
+
"int2",
|
|
2285
|
+
"int4",
|
|
2286
|
+
"int8",
|
|
2287
|
+
"float4",
|
|
2288
|
+
"float8",
|
|
2289
|
+
"money",
|
|
2290
|
+
"bool",
|
|
2291
|
+
"timetz",
|
|
2292
|
+
"timestamptz",
|
|
2293
|
+
"interval",
|
|
2294
|
+
"bytea",
|
|
2295
|
+
"citext",
|
|
2296
|
+
"name",
|
|
2297
|
+
"jsonb",
|
|
2298
|
+
"xml",
|
|
2299
|
+
"bit",
|
|
2300
|
+
"varbit",
|
|
2301
|
+
"oid",
|
|
2302
|
+
"xid",
|
|
2303
|
+
"xid8",
|
|
2304
|
+
"cid",
|
|
2305
|
+
"tid",
|
|
2306
|
+
"regclass",
|
|
2307
|
+
"regtype",
|
|
2308
|
+
"regproc",
|
|
2309
|
+
"regprocedure",
|
|
2310
|
+
"regoper",
|
|
2311
|
+
"regoperator",
|
|
2312
|
+
"regconfig",
|
|
2313
|
+
"regdictionary",
|
|
2314
|
+
"pg_lsn",
|
|
2315
|
+
"txid_snapshot",
|
|
2316
|
+
"inet",
|
|
2317
|
+
"cidr",
|
|
2318
|
+
"macaddr",
|
|
2319
|
+
"macaddr8",
|
|
2320
|
+
"point",
|
|
2321
|
+
"line",
|
|
2322
|
+
"lseg",
|
|
2323
|
+
"box",
|
|
2324
|
+
"path",
|
|
2325
|
+
"polygon",
|
|
2326
|
+
"circle",
|
|
2327
|
+
"tsvector",
|
|
2328
|
+
"tsquery",
|
|
2329
|
+
"int4range",
|
|
2330
|
+
"int8range",
|
|
2331
|
+
"numrange",
|
|
2332
|
+
"tsrange",
|
|
2333
|
+
"tstzrange",
|
|
2334
|
+
"daterange",
|
|
2335
|
+
"int4multirange",
|
|
2336
|
+
"int8multirange",
|
|
2337
|
+
"nummultirange",
|
|
2338
|
+
"tsmultirange",
|
|
2339
|
+
"tstzmultirange",
|
|
2340
|
+
"datemultirange"
|
|
2341
|
+
];
|
|
2342
|
+
var mysqlDatatypeFamilies = {
|
|
2343
|
+
text: {
|
|
2344
|
+
compareGroup: "text",
|
|
2345
|
+
castTargets: [
|
|
2346
|
+
"text",
|
|
2347
|
+
"numeric",
|
|
2348
|
+
"boolean",
|
|
2349
|
+
"date",
|
|
2350
|
+
"time",
|
|
2351
|
+
"datetime",
|
|
2352
|
+
"timestamp",
|
|
2353
|
+
"year",
|
|
2354
|
+
"binary",
|
|
2355
|
+
"json",
|
|
2356
|
+
"bit",
|
|
2357
|
+
"enum",
|
|
2358
|
+
"set",
|
|
2359
|
+
"null"
|
|
2360
|
+
],
|
|
2361
|
+
traits: {
|
|
2362
|
+
textual: true,
|
|
2363
|
+
ordered: true
|
|
2364
|
+
}
|
|
2365
|
+
},
|
|
2366
|
+
numeric: {
|
|
2367
|
+
compareGroup: "numeric",
|
|
2368
|
+
castTargets: ["numeric", "text", "boolean", "date", "time", "datetime", "timestamp", "year", "bit"],
|
|
2369
|
+
traits: {
|
|
2370
|
+
ordered: true
|
|
2371
|
+
}
|
|
2372
|
+
},
|
|
2373
|
+
boolean: {
|
|
2374
|
+
compareGroup: "boolean",
|
|
2375
|
+
castTargets: ["boolean", "text", "numeric"],
|
|
2376
|
+
traits: {}
|
|
2377
|
+
},
|
|
2378
|
+
bit: {
|
|
2379
|
+
compareGroup: "bit",
|
|
2380
|
+
castTargets: ["bit", "text", "numeric"],
|
|
2381
|
+
traits: {}
|
|
2382
|
+
},
|
|
2383
|
+
date: {
|
|
2384
|
+
compareGroup: "date",
|
|
2385
|
+
castTargets: ["date", "datetime", "timestamp", "text"],
|
|
2386
|
+
traits: {
|
|
2387
|
+
ordered: true
|
|
2388
|
+
}
|
|
2389
|
+
},
|
|
2390
|
+
time: {
|
|
2391
|
+
compareGroup: "time",
|
|
2392
|
+
castTargets: ["time", "datetime", "timestamp", "text"],
|
|
2393
|
+
traits: {
|
|
2394
|
+
ordered: true
|
|
2395
|
+
}
|
|
2396
|
+
},
|
|
2397
|
+
datetime: {
|
|
2398
|
+
compareGroup: "datetime",
|
|
2399
|
+
castTargets: ["datetime", "timestamp", "date", "text"],
|
|
2400
|
+
traits: {
|
|
2401
|
+
ordered: true
|
|
2402
|
+
}
|
|
2403
|
+
},
|
|
2404
|
+
timestamp: {
|
|
2405
|
+
compareGroup: "timestamp",
|
|
2406
|
+
castTargets: ["timestamp", "datetime", "date", "text"],
|
|
2407
|
+
traits: {
|
|
2408
|
+
ordered: true
|
|
2409
|
+
}
|
|
2410
|
+
},
|
|
2411
|
+
year: {
|
|
2412
|
+
compareGroup: "year",
|
|
2413
|
+
castTargets: ["year", "text", "numeric"],
|
|
2414
|
+
traits: {
|
|
2415
|
+
ordered: true
|
|
2416
|
+
}
|
|
2417
|
+
},
|
|
2418
|
+
binary: {
|
|
2419
|
+
compareGroup: "binary",
|
|
2420
|
+
castTargets: ["binary", "text"],
|
|
2421
|
+
traits: {}
|
|
2422
|
+
},
|
|
2423
|
+
json: {
|
|
2424
|
+
compareGroup: "json",
|
|
2425
|
+
castTargets: ["json", "text"],
|
|
2426
|
+
traits: {}
|
|
2427
|
+
},
|
|
2428
|
+
spatial: {
|
|
2429
|
+
compareGroup: "spatial",
|
|
2430
|
+
castTargets: ["spatial", "text"],
|
|
2431
|
+
traits: {}
|
|
2432
|
+
},
|
|
2433
|
+
enum: {
|
|
2434
|
+
compareGroup: "enum",
|
|
2435
|
+
castTargets: ["enum", "text"],
|
|
2436
|
+
traits: {
|
|
2437
|
+
textual: true,
|
|
2438
|
+
ordered: true
|
|
2439
|
+
}
|
|
2440
|
+
},
|
|
2441
|
+
set: {
|
|
2442
|
+
compareGroup: "set",
|
|
2443
|
+
castTargets: ["set", "text"],
|
|
2444
|
+
traits: {
|
|
2445
|
+
textual: true
|
|
2446
|
+
}
|
|
2447
|
+
},
|
|
2448
|
+
null: {
|
|
2449
|
+
compareGroup: "null",
|
|
2450
|
+
castTargets: [
|
|
2451
|
+
"text",
|
|
2452
|
+
"numeric",
|
|
2453
|
+
"boolean",
|
|
2454
|
+
"bit",
|
|
2455
|
+
"date",
|
|
2456
|
+
"time",
|
|
2457
|
+
"datetime",
|
|
2458
|
+
"timestamp",
|
|
2459
|
+
"year",
|
|
2460
|
+
"binary",
|
|
2461
|
+
"json",
|
|
2462
|
+
"spatial",
|
|
2463
|
+
"enum",
|
|
2464
|
+
"set",
|
|
2465
|
+
"null"
|
|
2466
|
+
],
|
|
2467
|
+
traits: {}
|
|
2468
|
+
}
|
|
2469
|
+
};
|
|
2470
|
+
var mysqlDatatypeKinds = {
|
|
2471
|
+
char: { family: "text", runtime: "string" },
|
|
2472
|
+
varchar: { family: "text", runtime: "string" },
|
|
2473
|
+
tinytext: { family: "text", runtime: "string" },
|
|
2474
|
+
text: { family: "text", runtime: "string" },
|
|
2475
|
+
mediumtext: { family: "text", runtime: "string" },
|
|
2476
|
+
longtext: { family: "text", runtime: "string" },
|
|
2477
|
+
tinyint: { family: "numeric", runtime: "number" },
|
|
2478
|
+
smallint: { family: "numeric", runtime: "number" },
|
|
2479
|
+
mediumint: { family: "numeric", runtime: "number" },
|
|
2480
|
+
int: { family: "numeric", runtime: "number" },
|
|
2481
|
+
integer: { family: "numeric", runtime: "number" },
|
|
2482
|
+
bigint: { family: "numeric", runtime: "bigintString" },
|
|
2483
|
+
decimal: { family: "numeric", runtime: "decimalString" },
|
|
2484
|
+
dec: { family: "numeric", runtime: "decimalString" },
|
|
2485
|
+
numeric: { family: "numeric", runtime: "decimalString" },
|
|
2486
|
+
fixed: { family: "numeric", runtime: "decimalString" },
|
|
2487
|
+
float: { family: "numeric", runtime: "number" },
|
|
2488
|
+
double: { family: "numeric", runtime: "number" },
|
|
2489
|
+
real: { family: "numeric", runtime: "number" },
|
|
2490
|
+
bool: { family: "boolean", runtime: "boolean" },
|
|
2491
|
+
boolean: { family: "boolean", runtime: "boolean" },
|
|
2492
|
+
bit: { family: "bit", runtime: "string" },
|
|
2493
|
+
date: { family: "date", runtime: "localDate" },
|
|
2494
|
+
time: { family: "time", runtime: "localTime" },
|
|
2495
|
+
datetime: { family: "datetime", runtime: "localDateTime" },
|
|
2496
|
+
timestamp: { family: "timestamp", runtime: "localDateTime" },
|
|
2497
|
+
year: { family: "year", runtime: "year" },
|
|
2498
|
+
binary: { family: "binary", runtime: "bytes" },
|
|
2499
|
+
varbinary: { family: "binary", runtime: "bytes" },
|
|
2500
|
+
tinyblob: { family: "binary", runtime: "bytes" },
|
|
2501
|
+
blob: { family: "binary", runtime: "bytes" },
|
|
2502
|
+
mediumblob: { family: "binary", runtime: "bytes" },
|
|
2503
|
+
longblob: { family: "binary", runtime: "bytes" },
|
|
2504
|
+
json: { family: "json", runtime: "json" },
|
|
2505
|
+
geometry: { family: "spatial", runtime: "unknown" },
|
|
2506
|
+
point: { family: "spatial", runtime: "unknown" },
|
|
2507
|
+
linestring: { family: "spatial", runtime: "unknown" },
|
|
2508
|
+
polygon: { family: "spatial", runtime: "unknown" },
|
|
2509
|
+
multipoint: { family: "spatial", runtime: "unknown" },
|
|
2510
|
+
multilinestring: { family: "spatial", runtime: "unknown" },
|
|
2511
|
+
multipolygon: { family: "spatial", runtime: "unknown" },
|
|
2512
|
+
geometrycollection: { family: "spatial", runtime: "unknown" },
|
|
2513
|
+
enum: { family: "enum", runtime: "string" },
|
|
2514
|
+
set: { family: "set", runtime: "string" }
|
|
2515
|
+
};
|
|
2516
|
+
var mysqlSpecificDatatypeKeys = [
|
|
2517
|
+
"tinytext",
|
|
2518
|
+
"mediumtext",
|
|
2519
|
+
"longtext",
|
|
2520
|
+
"tinyint",
|
|
2521
|
+
"smallint",
|
|
2522
|
+
"mediumint",
|
|
2523
|
+
"dec",
|
|
2524
|
+
"fixed",
|
|
2525
|
+
"float",
|
|
2526
|
+
"double",
|
|
2527
|
+
"bool",
|
|
2528
|
+
"bit",
|
|
2529
|
+
"year",
|
|
2530
|
+
"binary",
|
|
2531
|
+
"varbinary",
|
|
2532
|
+
"tinyblob",
|
|
2533
|
+
"mediumblob",
|
|
2534
|
+
"longblob",
|
|
2535
|
+
"geometry",
|
|
2536
|
+
"point",
|
|
2537
|
+
"linestring",
|
|
2538
|
+
"polygon",
|
|
2539
|
+
"multipoint",
|
|
2540
|
+
"multilinestring",
|
|
2541
|
+
"multipolygon",
|
|
2542
|
+
"geometrycollection"
|
|
2543
|
+
];
|
|
2544
|
+
var sqliteDatatypeFamilies = {
|
|
2545
|
+
text: {
|
|
2546
|
+
compareGroup: "text",
|
|
2547
|
+
castTargets: ["text", "numeric", "integer", "real", "boolean", "date", "time", "datetime", "json", "blob", "null"],
|
|
2548
|
+
traits: {
|
|
2549
|
+
textual: true,
|
|
2550
|
+
ordered: true
|
|
2551
|
+
}
|
|
2552
|
+
},
|
|
2553
|
+
numeric: {
|
|
2554
|
+
compareGroup: "numeric",
|
|
2555
|
+
castTargets: ["numeric", "integer", "real", "text", "boolean", "date", "time", "datetime"],
|
|
2556
|
+
traits: {
|
|
2557
|
+
ordered: true
|
|
2558
|
+
}
|
|
2559
|
+
},
|
|
2560
|
+
integer: {
|
|
2561
|
+
compareGroup: "numeric",
|
|
2562
|
+
castTargets: ["integer", "numeric", "real", "text", "boolean", "date", "time", "datetime"],
|
|
2563
|
+
traits: {
|
|
2564
|
+
ordered: true
|
|
2565
|
+
}
|
|
2566
|
+
},
|
|
2567
|
+
real: {
|
|
2568
|
+
compareGroup: "numeric",
|
|
2569
|
+
castTargets: ["real", "numeric", "integer", "text", "boolean"],
|
|
2570
|
+
traits: {
|
|
2571
|
+
ordered: true
|
|
2572
|
+
}
|
|
2573
|
+
},
|
|
2574
|
+
boolean: {
|
|
2575
|
+
compareGroup: "boolean",
|
|
2576
|
+
castTargets: ["boolean", "integer", "numeric", "text"],
|
|
2577
|
+
traits: {}
|
|
2578
|
+
},
|
|
2579
|
+
date: {
|
|
2580
|
+
compareGroup: "date",
|
|
2581
|
+
castTargets: ["date", "time", "datetime", "text", "numeric", "integer"],
|
|
2582
|
+
traits: {
|
|
2583
|
+
ordered: true
|
|
2584
|
+
}
|
|
2585
|
+
},
|
|
2586
|
+
time: {
|
|
2587
|
+
compareGroup: "time",
|
|
2588
|
+
castTargets: ["time", "date", "datetime", "text", "numeric", "integer"],
|
|
2589
|
+
traits: {
|
|
2590
|
+
ordered: true
|
|
2591
|
+
}
|
|
2592
|
+
},
|
|
2593
|
+
datetime: {
|
|
2594
|
+
compareGroup: "datetime",
|
|
2595
|
+
castTargets: ["datetime", "date", "time", "text", "numeric", "integer"],
|
|
2596
|
+
traits: {
|
|
2597
|
+
ordered: true
|
|
2598
|
+
}
|
|
2599
|
+
},
|
|
2600
|
+
json: {
|
|
2601
|
+
compareGroup: "json",
|
|
2602
|
+
castTargets: ["json", "text"],
|
|
2603
|
+
traits: {}
|
|
2604
|
+
},
|
|
2605
|
+
blob: {
|
|
2606
|
+
compareGroup: "blob",
|
|
2607
|
+
castTargets: ["blob", "text"],
|
|
2608
|
+
traits: {}
|
|
2609
|
+
},
|
|
2610
|
+
null: {
|
|
2611
|
+
compareGroup: "null",
|
|
2612
|
+
castTargets: ["text", "numeric", "integer", "real", "boolean", "date", "time", "datetime", "json", "blob", "null"],
|
|
2613
|
+
traits: {}
|
|
2614
|
+
}
|
|
2615
|
+
};
|
|
2616
|
+
var sqliteDatatypeKinds = {
|
|
2617
|
+
text: { family: "text", runtime: "string" },
|
|
2618
|
+
varchar: { family: "text", runtime: "string" },
|
|
2619
|
+
char: { family: "text", runtime: "string" },
|
|
2620
|
+
clob: { family: "text", runtime: "string" },
|
|
2621
|
+
int: { family: "integer", runtime: "number" },
|
|
2622
|
+
integer: { family: "integer", runtime: "number" },
|
|
2623
|
+
bigint: { family: "integer", runtime: "bigintString" },
|
|
2624
|
+
numeric: { family: "numeric", runtime: "decimalString" },
|
|
2625
|
+
decimal: { family: "numeric", runtime: "decimalString" },
|
|
2626
|
+
real: { family: "real", runtime: "number" },
|
|
2627
|
+
double: { family: "real", runtime: "number" },
|
|
2628
|
+
boolean: { family: "boolean", runtime: "boolean" },
|
|
2629
|
+
date: { family: "date", runtime: "localDate" },
|
|
2630
|
+
time: { family: "time", runtime: "localTime" },
|
|
2631
|
+
datetime: { family: "datetime", runtime: "localDateTime" },
|
|
2632
|
+
timestamp: { family: "datetime", runtime: "localDateTime" },
|
|
2633
|
+
json: { family: "json", runtime: "json" },
|
|
2634
|
+
blob: { family: "blob", runtime: "bytes" }
|
|
2635
|
+
};
|
|
2636
|
+
var sqliteSpecificDatatypeKeys = [
|
|
2637
|
+
"clob",
|
|
2638
|
+
"double"
|
|
2639
|
+
];
|
|
2640
|
+
var pickDatatypeConstructors = (module, keys) => Object.fromEntries(keys.map((key2) => [key2, module[key2]]));
|
|
1575
2641
|
|
|
1576
2642
|
// src/internal/dsl-plan-runtime.ts
|
|
1577
2643
|
var renderSelectLockMode = (mode) => mode === "update" ? "for update" : "for share";
|
|
@@ -2491,7 +3557,7 @@ import * as Schema4 from "effect/Schema";
|
|
|
2491
3557
|
|
|
2492
3558
|
// src/internal/runtime/value.ts
|
|
2493
3559
|
import * as Schema3 from "effect/Schema";
|
|
2494
|
-
var brandString = (
|
|
3560
|
+
var brandString = (pattern, brand4) => Schema3.String.pipe(Schema3.check(Schema3.isPattern(pattern)), Schema3.brand(brand4));
|
|
2495
3561
|
var localDatePattern = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
2496
3562
|
var isValidLocalDateString = (value) => {
|
|
2497
3563
|
const match = localDatePattern.exec(value);
|
|
@@ -2544,11 +3610,11 @@ var isValidInstantString = (value) => {
|
|
|
2544
3610
|
const match = instantPattern.exec(value);
|
|
2545
3611
|
return match !== null && isValidLocalDateString(match[1]) && isValidLocalTimeString(match[2]) && isValidOffset(match[3]);
|
|
2546
3612
|
};
|
|
2547
|
-
var LocalDateStringSchema = Schema3.String.pipe(Schema3.
|
|
2548
|
-
var LocalTimeStringSchema = Schema3.String.pipe(Schema3.
|
|
2549
|
-
var OffsetTimeStringSchema = Schema3.String.pipe(Schema3.
|
|
2550
|
-
var LocalDateTimeStringSchema = Schema3.String.pipe(Schema3.
|
|
2551
|
-
var InstantStringSchema = Schema3.String.pipe(Schema3.
|
|
3613
|
+
var LocalDateStringSchema = Schema3.String.pipe(Schema3.check(Schema3.isPattern(localDatePattern)), Schema3.check(Schema3.makeFilter((value) => isValidLocalDateString(value))), Schema3.brand("LocalDateString"));
|
|
3614
|
+
var LocalTimeStringSchema = Schema3.String.pipe(Schema3.check(Schema3.isPattern(localTimePattern)), Schema3.check(Schema3.makeFilter((value) => isValidLocalTimeString(value))), Schema3.brand("LocalTimeString"));
|
|
3615
|
+
var OffsetTimeStringSchema = Schema3.String.pipe(Schema3.check(Schema3.isPattern(offsetTimePattern)), Schema3.check(Schema3.makeFilter((value) => isValidOffsetTimeString(value))), Schema3.brand("OffsetTimeString"));
|
|
3616
|
+
var LocalDateTimeStringSchema = Schema3.String.pipe(Schema3.check(Schema3.isPattern(localDateTimePattern)), Schema3.check(Schema3.makeFilter((value) => isValidLocalDateTimeString(value))), Schema3.brand("LocalDateTimeString"));
|
|
3617
|
+
var InstantStringSchema = Schema3.String.pipe(Schema3.check(Schema3.isPattern(instantPattern)), Schema3.check(Schema3.makeFilter((value) => isValidInstantString(value))), Schema3.brand("InstantString"));
|
|
2552
3618
|
var YearStringSchema = brandString(/^\d{4}$/, "YearString");
|
|
2553
3619
|
var canonicalizeBigIntString = (input) => {
|
|
2554
3620
|
const trimmed = input.trim();
|
|
@@ -2588,13 +3654,22 @@ var isCanonicalDecimalString = (value) => {
|
|
|
2588
3654
|
return false;
|
|
2589
3655
|
}
|
|
2590
3656
|
};
|
|
2591
|
-
var BigIntStringSchema = Schema3.String.pipe(Schema3.
|
|
2592
|
-
var DecimalStringSchema = Schema3.String.pipe(Schema3.
|
|
2593
|
-
var JsonValueSchema = Schema3.suspend(() => Schema3.Union(
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
3657
|
+
var BigIntStringSchema = Schema3.String.pipe(Schema3.check(Schema3.makeFilter((value) => isCanonicalBigIntString(value))), Schema3.brand("BigIntString"));
|
|
3658
|
+
var DecimalStringSchema = Schema3.String.pipe(Schema3.check(Schema3.makeFilter((value) => isCanonicalDecimalString(value))), Schema3.brand("DecimalString"));
|
|
3659
|
+
var JsonValueSchema = Schema3.suspend(() => Schema3.Union([
|
|
3660
|
+
Schema3.String,
|
|
3661
|
+
Schema3.Number.check(Schema3.isFinite()),
|
|
3662
|
+
Schema3.Boolean,
|
|
3663
|
+
Schema3.Null,
|
|
3664
|
+
Schema3.Array(JsonValueSchema),
|
|
3665
|
+
Schema3.Record(Schema3.String, JsonValueSchema)
|
|
3666
|
+
]));
|
|
3667
|
+
var JsonPrimitiveSchema = Schema3.Union([
|
|
3668
|
+
Schema3.String,
|
|
3669
|
+
Schema3.Number.check(Schema3.isFinite()),
|
|
3670
|
+
Schema3.Boolean,
|
|
3671
|
+
Schema3.Null
|
|
3672
|
+
]);
|
|
2598
3673
|
|
|
2599
3674
|
// src/internal/runtime/normalize.ts
|
|
2600
3675
|
var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -3079,7 +4154,7 @@ var TypeId9 = Symbol.for("effect-qb/ProjectionAlias");
|
|
|
3079
4154
|
|
|
3080
4155
|
// src/internal/projections.ts
|
|
3081
4156
|
var aliasFromPath = (path2) => path2.join("__");
|
|
3082
|
-
var
|
|
4157
|
+
var isExpression2 = (value) => typeof value === "object" && value !== null && (TypeId2 in value);
|
|
3083
4158
|
var projectionAliasOf = (expression) => (TypeId9 in expression) ? expression[TypeId9].alias : undefined;
|
|
3084
4159
|
var pathKeyOf = (path2) => JSON.stringify(path2);
|
|
3085
4160
|
var formatProjectionPath = (path2) => path2.join(".");
|
|
@@ -3088,7 +4163,7 @@ var flattenSelection = (selection, path2 = []) => {
|
|
|
3088
4163
|
const fields = [];
|
|
3089
4164
|
for (const [key2, value] of Object.entries(selection)) {
|
|
3090
4165
|
const nextPath = [...path2, key2];
|
|
3091
|
-
if (
|
|
4166
|
+
if (isExpression2(value)) {
|
|
3092
4167
|
fields.push({
|
|
3093
4168
|
path: nextPath,
|
|
3094
4169
|
expression: value,
|
|
@@ -3158,8 +4233,8 @@ var literalGroupingKey = (value) => {
|
|
|
3158
4233
|
return `literal:${JSON.stringify(value)}`;
|
|
3159
4234
|
}
|
|
3160
4235
|
};
|
|
3161
|
-
var
|
|
3162
|
-
var expressionGroupingKey = (value) =>
|
|
4236
|
+
var isExpression3 = (value) => value !== null && typeof value === "object" && (TypeId2 in value);
|
|
4237
|
+
var expressionGroupingKey = (value) => isExpression3(value) ? groupingKeyOfExpression(value) : "missing";
|
|
3163
4238
|
var requiredExpressionGroupingKey = (_functionName, value) => groupingKeyOfExpression(value);
|
|
3164
4239
|
var requiredBinaryExpressionGroupingKey = (_functionName, left, right) => `${groupingKeyOfExpression(left)},${groupingKeyOfExpression(right)}`;
|
|
3165
4240
|
var functionCallArgsGroupingKey = (args) => args.map(groupingKeyOfExpression).join(",");
|
|
@@ -3215,7 +4290,7 @@ var jsonPathGroupingKey = (segments) => {
|
|
|
3215
4290
|
}
|
|
3216
4291
|
return segments.map(jsonSegmentGroupingKey).join(",");
|
|
3217
4292
|
};
|
|
3218
|
-
var isJsonPath = (value) => value !== null && typeof value === "object" && (
|
|
4293
|
+
var isJsonPath = (value) => value !== null && typeof value === "object" && (TypeId4 in value);
|
|
3219
4294
|
var jsonOpaquePathGroupingKey = (value) => {
|
|
3220
4295
|
if (isJsonPath(value)) {
|
|
3221
4296
|
return `jsonpath:${jsonPathGroupingKey(value.segments)}`;
|
|
@@ -3223,7 +4298,7 @@ var jsonOpaquePathGroupingKey = (value) => {
|
|
|
3223
4298
|
if (typeof value === "string") {
|
|
3224
4299
|
return `jsonpath:${escapeGroupingText(value)}`;
|
|
3225
4300
|
}
|
|
3226
|
-
if (
|
|
4301
|
+
if (isExpression3(value)) {
|
|
3227
4302
|
return `jsonpath:${groupingKeyOfExpression(value)}`;
|
|
3228
4303
|
}
|
|
3229
4304
|
return "jsonpath:unknown";
|
|
@@ -3354,14 +4429,15 @@ var dedupeGroupedExpressions = (values) => {
|
|
|
3354
4429
|
|
|
3355
4430
|
// src/internal/dialect-renderers/postgres.ts
|
|
3356
4431
|
var renderDbType = (dialect, dbType) => {
|
|
3357
|
-
|
|
3358
|
-
return "bytea";
|
|
3359
|
-
}
|
|
3360
|
-
return renderDbTypeName(dbType.kind);
|
|
4432
|
+
return renderDbTypeName(renderPortableDatatypeDdlType(dialect.name, dbType.kind) ?? dbType.kind);
|
|
3361
4433
|
};
|
|
3362
4434
|
var isArrayDbType = (dbType) => ("element" in dbType);
|
|
3363
4435
|
var renderCastType = (dialect, dbType) => {
|
|
3364
4436
|
const kind = dbType?.kind;
|
|
4437
|
+
const portableType = renderPortableDatatypeCastType(dialect.name, kind);
|
|
4438
|
+
if (portableType !== undefined) {
|
|
4439
|
+
return renderDbTypeName(portableType);
|
|
4440
|
+
}
|
|
3365
4441
|
if (dialect.name !== "mysql") {
|
|
3366
4442
|
return renderDbTypeName(kind);
|
|
3367
4443
|
}
|
|
@@ -3383,13 +4459,13 @@ var renderCastType = (dialect, dbType) => {
|
|
|
3383
4459
|
return renderDbTypeName(kind);
|
|
3384
4460
|
}
|
|
3385
4461
|
};
|
|
3386
|
-
var casingForTable = (table, state) => merge(state.casing, table[
|
|
4462
|
+
var casingForTable = (table, state) => merge(state.casing, table[TypeId7].casing);
|
|
3387
4463
|
var casedTableName = (table, state) => {
|
|
3388
|
-
const tableState = table[
|
|
4464
|
+
const tableState = table[TypeId7];
|
|
3389
4465
|
return applyCategory(casingForTable(table, state), "tables", tableState.baseName);
|
|
3390
4466
|
};
|
|
3391
4467
|
var casedSchemaName = (table, state) => {
|
|
3392
|
-
const schemaName = table[
|
|
4468
|
+
const schemaName = table[TypeId7].schemaName;
|
|
3393
4469
|
return schemaName === undefined ? undefined : applyCategory(casingForTable(table, state), "schemas", schemaName);
|
|
3394
4470
|
};
|
|
3395
4471
|
var casedColumnName = (columnName, state, tableName) => {
|
|
@@ -3403,7 +4479,7 @@ var casedColumnName = (columnName, state, tableName) => {
|
|
|
3403
4479
|
};
|
|
3404
4480
|
var casedTableReferenceName = (tableName, state) => state.sourceNames?.get(tableName)?.tableName ?? applyCategory(state.casing, "tables", tableName);
|
|
3405
4481
|
var quoteColumn = (columnName, state, dialect, tableName) => dialect.quoteIdentifier(casedColumnName(columnName, state, tableName));
|
|
3406
|
-
var stateWithTableCasing = (state, source) => typeof source === "object" && source !== null && (
|
|
4482
|
+
var stateWithTableCasing = (state, source) => typeof source === "object" && source !== null && (TypeId7 in source) ? { ...state, casing: casingForTable(source, state) } : state;
|
|
3407
4483
|
var referenceCasing = (reference, state) => merge(state.casing, reference.casing);
|
|
3408
4484
|
var renderReferenceTable = (reference, state, dialect) => {
|
|
3409
4485
|
const casing = referenceCasing(reference, state);
|
|
@@ -3416,9 +4492,9 @@ var registerSourceReference = (source, tableName, state) => {
|
|
|
3416
4492
|
if (typeof source !== "object" || source === null) {
|
|
3417
4493
|
return;
|
|
3418
4494
|
}
|
|
3419
|
-
if (
|
|
4495
|
+
if (TypeId7 in source) {
|
|
3420
4496
|
const table = source;
|
|
3421
|
-
const tableState = table[
|
|
4497
|
+
const tableState = table[TypeId7];
|
|
3422
4498
|
const casing = casingForTable(table, state);
|
|
3423
4499
|
const renderedTableName = tableState.kind === "alias" ? tableName : applyCategory(casing, "tables", tableState.baseName);
|
|
3424
4500
|
const columns = new Map(Object.keys(tableState.fields).map((columnName) => [
|
|
@@ -3532,11 +4608,11 @@ var renderCreateTableSql = (targetSource, state, dialect, ifNotExists) => {
|
|
|
3532
4608
|
}
|
|
3533
4609
|
const table = targetSource.source;
|
|
3534
4610
|
const tableCasing = casingForTable(table, state);
|
|
3535
|
-
const fields = table[
|
|
4611
|
+
const fields = table[TypeId7].fields;
|
|
3536
4612
|
const definitions = Object.entries(fields).map(([columnName, column]) => renderColumnDefinition(dialect, state, columnName, column, targetSource.tableName, tableCasing));
|
|
3537
4613
|
const options2 = table[OptionsSymbol];
|
|
3538
4614
|
const tableOptions = Array.isArray(options2) ? options2 : [options2];
|
|
3539
|
-
validateOptions(table[
|
|
4615
|
+
validateOptions(table[TypeId7].name, fields, tableOptions);
|
|
3540
4616
|
for (const option2 of tableOptions) {
|
|
3541
4617
|
if (typeof option2 !== "object" || option2 === null || !("kind" in option2)) {
|
|
3542
4618
|
continue;
|
|
@@ -3595,8 +4671,8 @@ var renderDropIndexSql = (targetSource, ddl, state, dialect) => {
|
|
|
3595
4671
|
throw new Error(`Unsupported ${dialect.name} drop index options`);
|
|
3596
4672
|
}
|
|
3597
4673
|
if (dialect.name === "postgres") {
|
|
3598
|
-
const table2 = typeof targetSource.source === "object" && targetSource.source !== null &&
|
|
3599
|
-
const schemaName = table2?.[
|
|
4674
|
+
const table2 = typeof targetSource.source === "object" && targetSource.source !== null && TypeId7 in targetSource.source ? targetSource.source : undefined;
|
|
4675
|
+
const schemaName = table2?.[TypeId7].schemaName;
|
|
3600
4676
|
const tableCasing2 = table2 === undefined ? state.casing : casingForTable(table2, state);
|
|
3601
4677
|
const renderedSchemaName = table2 === undefined ? schemaName : casedSchemaName(table2, state);
|
|
3602
4678
|
const renderedIndexName = applyCategory(tableCasing2, "indexes", name);
|
|
@@ -3607,7 +4683,7 @@ var renderDropIndexSql = (targetSource, ddl, state, dialect) => {
|
|
|
3607
4683
|
const tableCasing = casingForTable(table, state);
|
|
3608
4684
|
return `drop index ${dialect.quoteIdentifier(applyCategory(tableCasing, "indexes", name))} on ${renderSourceReference(targetSource.source, targetSource.tableName, targetSource.baseTableName, state, dialect)}`;
|
|
3609
4685
|
};
|
|
3610
|
-
var
|
|
4686
|
+
var isExpression4 = (value) => value !== null && typeof value === "object" && (TypeId2 in value);
|
|
3611
4687
|
var isJsonDbType2 = (dbType) => {
|
|
3612
4688
|
if (dbType.kind === "jsonb" || dbType.kind === "json") {
|
|
3613
4689
|
return true;
|
|
@@ -3618,7 +4694,7 @@ var isJsonDbType2 = (dbType) => {
|
|
|
3618
4694
|
const variant = dbType.variant;
|
|
3619
4695
|
return variant === "json" || variant === "jsonb";
|
|
3620
4696
|
};
|
|
3621
|
-
var
|
|
4697
|
+
var isJsonExpression2 = (value) => isExpression4(value) && isJsonDbType2(value[TypeId2].dbType);
|
|
3622
4698
|
var expectValueExpression = (_functionName, value) => value;
|
|
3623
4699
|
var expectBinaryExpressions = (_functionName, left, right) => [left, right];
|
|
3624
4700
|
var renderBinaryExpression = (functionName, operator, left, right, state, dialect) => {
|
|
@@ -3665,7 +4741,7 @@ var unsupportedJsonFeature = (dialect, feature) => {
|
|
|
3665
4741
|
throw error;
|
|
3666
4742
|
};
|
|
3667
4743
|
var extractJsonBase = (node) => node.value ?? node.base ?? node.input ?? node.left ?? node.target;
|
|
3668
|
-
var isJsonPathValue = (value) => value !== null && typeof value === "object" && (
|
|
4744
|
+
var isJsonPathValue = (value) => value !== null && typeof value === "object" && (TypeId4 in value);
|
|
3669
4745
|
var isOptionalJsonPathNumber = (value) => value === undefined || typeof value === "number" && Number.isFinite(value);
|
|
3670
4746
|
var isJsonPathSegment = (segment) => {
|
|
3671
4747
|
if (typeof segment === "string") {
|
|
@@ -3722,7 +4798,7 @@ var extractJsonPathSegments = (node) => {
|
|
|
3722
4798
|
return [key(segment)];
|
|
3723
4799
|
}
|
|
3724
4800
|
if (typeof segment === "number") {
|
|
3725
|
-
return [
|
|
4801
|
+
return [index(segment)];
|
|
3726
4802
|
}
|
|
3727
4803
|
if (segment !== null && typeof segment === "object" && SegmentTypeId in segment) {
|
|
3728
4804
|
return [segment];
|
|
@@ -3795,7 +4871,7 @@ var renderPostgresJsonAccessStep = (segment, textMode, state, dialect) => {
|
|
|
3795
4871
|
}
|
|
3796
4872
|
};
|
|
3797
4873
|
var renderPostgresJsonValue = (value, state, dialect) => {
|
|
3798
|
-
if (!
|
|
4874
|
+
if (!isExpression4(value)) {
|
|
3799
4875
|
throw new Error("Expected a JSON expression");
|
|
3800
4876
|
}
|
|
3801
4877
|
const rendered = renderExpression2(value, state, dialect);
|
|
@@ -3839,7 +4915,7 @@ var renderJsonOpaquePath = (value, state, dialect) => {
|
|
|
3839
4915
|
}
|
|
3840
4916
|
return dialect.renderLiteral(value, state);
|
|
3841
4917
|
}
|
|
3842
|
-
if (
|
|
4918
|
+
if (isExpression4(value)) {
|
|
3843
4919
|
const ast = value[TypeId3];
|
|
3844
4920
|
if (ast.kind === "literal" && typeof ast.value === "string" && ast.value.trim().length === 0) {
|
|
3845
4921
|
throw new Error("SQL/JSON path input must be a non-empty string");
|
|
@@ -3889,8 +4965,8 @@ var renderJsonExpression = (expression, ast, state, dialect) => {
|
|
|
3889
4965
|
const base = extractJsonBase(ast);
|
|
3890
4966
|
const segments = extractJsonPathSegments(ast);
|
|
3891
4967
|
const exact = segments.every((segment) => segment.kind === "key" || segment.kind === "index");
|
|
3892
|
-
const postgresExpressionKind = dialect.name === "postgres" &&
|
|
3893
|
-
const postgresBaseKind = dialect.name === "postgres" &&
|
|
4968
|
+
const postgresExpressionKind = dialect.name === "postgres" && isJsonExpression2(expression) ? renderPostgresJsonKind(expression) : undefined;
|
|
4969
|
+
const postgresBaseKind = dialect.name === "postgres" && isJsonExpression2(base) ? renderPostgresJsonKind(base) : undefined;
|
|
3894
4970
|
switch (kind) {
|
|
3895
4971
|
case "jsonGet":
|
|
3896
4972
|
case "jsonPath":
|
|
@@ -3900,7 +4976,7 @@ var renderJsonExpression = (expression, ast, state, dialect) => {
|
|
|
3900
4976
|
case "jsonPathText":
|
|
3901
4977
|
case "jsonAccessText":
|
|
3902
4978
|
case "jsonTraverseText": {
|
|
3903
|
-
if (!
|
|
4979
|
+
if (!isExpression4(base) || segments.length === 0) {
|
|
3904
4980
|
return;
|
|
3905
4981
|
}
|
|
3906
4982
|
const baseSql = renderExpression2(base, state, dialect);
|
|
@@ -3923,7 +4999,7 @@ var renderJsonExpression = (expression, ast, state, dialect) => {
|
|
|
3923
4999
|
case "jsonKeyExists":
|
|
3924
5000
|
case "jsonHasAnyKeys":
|
|
3925
5001
|
case "jsonHasAllKeys": {
|
|
3926
|
-
if (!
|
|
5002
|
+
if (!isExpression4(base)) {
|
|
3927
5003
|
return;
|
|
3928
5004
|
}
|
|
3929
5005
|
const baseSql = dialect.name === "postgres" ? renderPostgresJsonValue(base, state, dialect) : renderExpression2(base, state, dialect);
|
|
@@ -3953,7 +5029,7 @@ var renderJsonExpression = (expression, ast, state, dialect) => {
|
|
|
3953
5029
|
}
|
|
3954
5030
|
case "jsonConcat":
|
|
3955
5031
|
case "jsonMerge": {
|
|
3956
|
-
if (!
|
|
5032
|
+
if (!isExpression4(ast.left) || !isExpression4(ast.right)) {
|
|
3957
5033
|
return;
|
|
3958
5034
|
}
|
|
3959
5035
|
if (dialect.name === "postgres") {
|
|
@@ -3990,7 +5066,7 @@ var renderJsonExpression = (expression, ast, state, dialect) => {
|
|
|
3990
5066
|
return;
|
|
3991
5067
|
}
|
|
3992
5068
|
case "jsonToJson":
|
|
3993
|
-
if (!
|
|
5069
|
+
if (!isExpression4(base)) {
|
|
3994
5070
|
return;
|
|
3995
5071
|
}
|
|
3996
5072
|
if (dialect.name === "postgres") {
|
|
@@ -4001,7 +5077,7 @@ var renderJsonExpression = (expression, ast, state, dialect) => {
|
|
|
4001
5077
|
}
|
|
4002
5078
|
return;
|
|
4003
5079
|
case "jsonToJsonb":
|
|
4004
|
-
if (!
|
|
5080
|
+
if (!isExpression4(base)) {
|
|
4005
5081
|
return;
|
|
4006
5082
|
}
|
|
4007
5083
|
if (dialect.name === "postgres") {
|
|
@@ -4012,7 +5088,7 @@ var renderJsonExpression = (expression, ast, state, dialect) => {
|
|
|
4012
5088
|
}
|
|
4013
5089
|
return;
|
|
4014
5090
|
case "jsonTypeOf":
|
|
4015
|
-
if (!
|
|
5091
|
+
if (!isExpression4(base)) {
|
|
4016
5092
|
return;
|
|
4017
5093
|
}
|
|
4018
5094
|
if (dialect.name === "postgres") {
|
|
@@ -4024,7 +5100,7 @@ var renderJsonExpression = (expression, ast, state, dialect) => {
|
|
|
4024
5100
|
}
|
|
4025
5101
|
return;
|
|
4026
5102
|
case "jsonLength":
|
|
4027
|
-
if (!
|
|
5103
|
+
if (!isExpression4(base)) {
|
|
4028
5104
|
return;
|
|
4029
5105
|
}
|
|
4030
5106
|
if (dialect.name === "postgres") {
|
|
@@ -4039,7 +5115,7 @@ var renderJsonExpression = (expression, ast, state, dialect) => {
|
|
|
4039
5115
|
}
|
|
4040
5116
|
return;
|
|
4041
5117
|
case "jsonKeys":
|
|
4042
|
-
if (!
|
|
5118
|
+
if (!isExpression4(base)) {
|
|
4043
5119
|
return;
|
|
4044
5120
|
}
|
|
4045
5121
|
if (dialect.name === "postgres") {
|
|
@@ -4053,7 +5129,7 @@ var renderJsonExpression = (expression, ast, state, dialect) => {
|
|
|
4053
5129
|
}
|
|
4054
5130
|
return;
|
|
4055
5131
|
case "jsonStripNulls":
|
|
4056
|
-
if (!
|
|
5132
|
+
if (!isExpression4(base)) {
|
|
4057
5133
|
return;
|
|
4058
5134
|
}
|
|
4059
5135
|
if (dialect.name === "postgres") {
|
|
@@ -4064,7 +5140,7 @@ var renderJsonExpression = (expression, ast, state, dialect) => {
|
|
|
4064
5140
|
case "jsonDelete":
|
|
4065
5141
|
case "jsonDeletePath":
|
|
4066
5142
|
case "jsonRemove": {
|
|
4067
|
-
if (!
|
|
5143
|
+
if (!isExpression4(base) || segments.length === 0) {
|
|
4068
5144
|
return;
|
|
4069
5145
|
}
|
|
4070
5146
|
if (dialect.name === "postgres") {
|
|
@@ -4082,11 +5158,11 @@ var renderJsonExpression = (expression, ast, state, dialect) => {
|
|
|
4082
5158
|
}
|
|
4083
5159
|
case "jsonSet":
|
|
4084
5160
|
case "jsonInsert": {
|
|
4085
|
-
if (!
|
|
5161
|
+
if (!isExpression4(base) || segments.length === 0) {
|
|
4086
5162
|
return;
|
|
4087
5163
|
}
|
|
4088
5164
|
const nextValue = extractJsonValue(ast);
|
|
4089
|
-
if (!
|
|
5165
|
+
if (!isExpression4(nextValue)) {
|
|
4090
5166
|
return;
|
|
4091
5167
|
}
|
|
4092
5168
|
const createMissing = ast.createMissing === true;
|
|
@@ -4103,7 +5179,7 @@ var renderJsonExpression = (expression, ast, state, dialect) => {
|
|
|
4103
5179
|
return;
|
|
4104
5180
|
}
|
|
4105
5181
|
case "jsonPathExists": {
|
|
4106
|
-
if (!
|
|
5182
|
+
if (!isExpression4(base)) {
|
|
4107
5183
|
return;
|
|
4108
5184
|
}
|
|
4109
5185
|
const path2 = ast.path ?? ast.query ?? ast.right;
|
|
@@ -4119,7 +5195,7 @@ var renderJsonExpression = (expression, ast, state, dialect) => {
|
|
|
4119
5195
|
return;
|
|
4120
5196
|
}
|
|
4121
5197
|
case "jsonPathMatch": {
|
|
4122
|
-
if (!
|
|
5198
|
+
if (!isExpression4(base)) {
|
|
4123
5199
|
return;
|
|
4124
5200
|
}
|
|
4125
5201
|
const path2 = ast.path ?? ast.query ?? ast.right;
|
|
@@ -4313,12 +5389,12 @@ var renderQueryAst2 = (ast, state, dialect, options2 = {}) => {
|
|
|
4313
5389
|
const columns = insertSource.columns.map((column) => quoteColumn(column, state, dialect, targetSource.tableName)).join(", ");
|
|
4314
5390
|
if (dialect.name === "postgres") {
|
|
4315
5391
|
const table = targetSource.source;
|
|
4316
|
-
const fields = table[
|
|
5392
|
+
const fields = table[TypeId7].fields;
|
|
4317
5393
|
const rendered = insertSource.values.map((entry) => `cast(${dialect.renderLiteral(encodeArrayValues(entry.values, fields[entry.columnName], state, dialect), state)} as ${renderCastType(dialect, fields[entry.columnName].metadata.dbType)}[])`).join(", ");
|
|
4318
5394
|
sql += ` (${columns}) select * from unnest(${rendered})`;
|
|
4319
5395
|
} else {
|
|
4320
5396
|
const rowCount = insertSource.values[0]?.values.length ?? 0;
|
|
4321
|
-
const rows = Array.from({ length: rowCount }, (_, index3) => `(${insertSource.values.map((entry) => dialect.renderLiteral(entry.values[index3], state, targetSource.source[
|
|
5397
|
+
const rows = Array.from({ length: rowCount }, (_, index3) => `(${insertSource.values.map((entry) => dialect.renderLiteral(entry.values[index3], state, targetSource.source[TypeId7].fields[entry.columnName][TypeId2])).join(", ")})`).join(", ");
|
|
4322
5398
|
sql += ` (${columns}) values ${rows}`;
|
|
4323
5399
|
}
|
|
4324
5400
|
} else {
|
|
@@ -4606,11 +5682,11 @@ var renderSourceReference = (source, tableName, baseTableName, state, dialect) =
|
|
|
4606
5682
|
const columnNames = Object.keys(tableFunction.columns);
|
|
4607
5683
|
return `${functionName}(${tableFunction.args.map((arg) => renderExpression2(arg, state, dialect)).join(", ")}) as ${dialect.quoteIdentifier(tableFunction.name)}(${columnNames.map((columnName) => dialect.quoteIdentifier(columnName)).join(", ")})`;
|
|
4608
5684
|
}
|
|
4609
|
-
const schemaName = typeof source === "object" && source !== null &&
|
|
4610
|
-
if (typeof source === "object" && source !== null &&
|
|
5685
|
+
const schemaName = typeof source === "object" && source !== null && TypeId7 in source ? casedSchemaName(source, state) : undefined;
|
|
5686
|
+
if (typeof source === "object" && source !== null && TypeId7 in source) {
|
|
4611
5687
|
const table = source;
|
|
4612
5688
|
const renderedBaseName = casedTableName(table, state);
|
|
4613
|
-
const renderedTableName = table[
|
|
5689
|
+
const renderedTableName = table[TypeId7].kind === "alias" ? tableName : renderedBaseName;
|
|
4614
5690
|
return dialect.renderTableReference(renderedTableName, renderedBaseName, schemaName);
|
|
4615
5691
|
}
|
|
4616
5692
|
return dialect.renderTableReference(applyCategory(state.casing, "tables", tableName), applyCategory(state.casing, "tables", baseTableName), schemaName);
|
|
@@ -4717,11 +5793,11 @@ var renderExpression2 = (expression, state, dialect) => {
|
|
|
4717
5793
|
const [leftExpression, rightExpression] = expectBinaryExpressions("contains", ast.left, ast.right);
|
|
4718
5794
|
if (dialect.name === "postgres") {
|
|
4719
5795
|
assertCompatiblePostgresRangeOperands(leftExpression, rightExpression);
|
|
4720
|
-
const left =
|
|
4721
|
-
const right =
|
|
5796
|
+
const left = isJsonExpression2(leftExpression) ? renderPostgresJsonValue(leftExpression, state, dialect) : renderExpression2(leftExpression, state, dialect);
|
|
5797
|
+
const right = isJsonExpression2(rightExpression) ? renderPostgresJsonValue(rightExpression, state, dialect) : renderExpression2(rightExpression, state, dialect);
|
|
4722
5798
|
return `(${left} @> ${right})`;
|
|
4723
5799
|
}
|
|
4724
|
-
if (dialect.name === "mysql" &&
|
|
5800
|
+
if (dialect.name === "mysql" && isJsonExpression2(leftExpression) && isJsonExpression2(rightExpression)) {
|
|
4725
5801
|
return `json_contains(${renderExpression2(leftExpression, state, dialect)}, ${renderExpression2(rightExpression, state, dialect)})`;
|
|
4726
5802
|
}
|
|
4727
5803
|
throw new Error("Unsupported container operator for SQL rendering");
|
|
@@ -4730,11 +5806,11 @@ var renderExpression2 = (expression, state, dialect) => {
|
|
|
4730
5806
|
const [leftExpression, rightExpression] = expectBinaryExpressions("containedBy", ast.left, ast.right);
|
|
4731
5807
|
if (dialect.name === "postgres") {
|
|
4732
5808
|
assertCompatiblePostgresRangeOperands(leftExpression, rightExpression);
|
|
4733
|
-
const left =
|
|
4734
|
-
const right =
|
|
5809
|
+
const left = isJsonExpression2(leftExpression) ? renderPostgresJsonValue(leftExpression, state, dialect) : renderExpression2(leftExpression, state, dialect);
|
|
5810
|
+
const right = isJsonExpression2(rightExpression) ? renderPostgresJsonValue(rightExpression, state, dialect) : renderExpression2(rightExpression, state, dialect);
|
|
4735
5811
|
return `(${left} <@ ${right})`;
|
|
4736
5812
|
}
|
|
4737
|
-
if (dialect.name === "mysql" &&
|
|
5813
|
+
if (dialect.name === "mysql" && isJsonExpression2(leftExpression) && isJsonExpression2(rightExpression)) {
|
|
4738
5814
|
return `json_contains(${renderExpression2(rightExpression, state, dialect)}, ${renderExpression2(leftExpression, state, dialect)})`;
|
|
4739
5815
|
}
|
|
4740
5816
|
throw new Error("Unsupported container operator for SQL rendering");
|
|
@@ -4743,11 +5819,11 @@ var renderExpression2 = (expression, state, dialect) => {
|
|
|
4743
5819
|
const [leftExpression, rightExpression] = expectBinaryExpressions("overlaps", ast.left, ast.right);
|
|
4744
5820
|
if (dialect.name === "postgres") {
|
|
4745
5821
|
assertCompatiblePostgresRangeOperands(leftExpression, rightExpression);
|
|
4746
|
-
const left =
|
|
4747
|
-
const right =
|
|
5822
|
+
const left = isJsonExpression2(leftExpression) ? renderPostgresJsonValue(leftExpression, state, dialect) : renderExpression2(leftExpression, state, dialect);
|
|
5823
|
+
const right = isJsonExpression2(rightExpression) ? renderPostgresJsonValue(rightExpression, state, dialect) : renderExpression2(rightExpression, state, dialect);
|
|
4748
5824
|
return `(${left} && ${right})`;
|
|
4749
5825
|
}
|
|
4750
|
-
if (dialect.name === "mysql" &&
|
|
5826
|
+
if (dialect.name === "mysql" && isJsonExpression2(leftExpression) && isJsonExpression2(rightExpression)) {
|
|
4751
5827
|
return `json_overlaps(${renderExpression2(leftExpression, state, dialect)}, ${renderExpression2(rightExpression, state, dialect)})`;
|
|
4752
5828
|
}
|
|
4753
5829
|
throw new Error("Unsupported container operator for SQL rendering");
|
|
@@ -4979,7 +6055,7 @@ var normalizeDdlExpressionSql = (expression, state) => {
|
|
|
4979
6055
|
|
|
4980
6056
|
// src/postgres/schema-management.ts
|
|
4981
6057
|
import * as Schema6 from "effect/Schema";
|
|
4982
|
-
import { pipeArguments as
|
|
6058
|
+
import { pipeArguments as pipeArguments6 } from "effect/Pipeable";
|
|
4983
6059
|
var EnumTypeId = Symbol.for("effect-qb/SchemaManagement/Enum");
|
|
4984
6060
|
var SequenceTypeId = Symbol.for("effect-qb/SchemaManagement/Sequence");
|
|
4985
6061
|
var safeUnquotedIdentifier = /^[a-z_][a-z0-9_$]*$/;
|
|
@@ -4988,7 +6064,7 @@ var renderIdentifier = (value) => safeUnquotedIdentifier.test(value) ? value : q
|
|
|
4988
6064
|
var renderQualifiedTypeName = (name, schemaName) => schemaName === undefined || schemaName === "public" ? renderIdentifier(name) : `${renderIdentifier(schemaName)}.${renderIdentifier(name)}`;
|
|
4989
6065
|
var EnumProto = {
|
|
4990
6066
|
pipe() {
|
|
4991
|
-
return
|
|
6067
|
+
return pipeArguments6(this, arguments);
|
|
4992
6068
|
},
|
|
4993
6069
|
qualifiedName() {
|
|
4994
6070
|
return this.schemaName === undefined || this.schemaName === "public" ? this.name : `${this.schemaName}.${this.name}`;
|
|
@@ -5001,12 +6077,7 @@ var EnumProto = {
|
|
|
5001
6077
|
};
|
|
5002
6078
|
},
|
|
5003
6079
|
column() {
|
|
5004
|
-
|
|
5005
|
-
const values = [
|
|
5006
|
-
Schema6.Literal(first),
|
|
5007
|
-
...rest.map((value) => Schema6.Literal(value))
|
|
5008
|
-
];
|
|
5009
|
-
return makeColumnDefinition(values.length === 1 ? values[0] : Schema6.Union(...values), {
|
|
6080
|
+
return makeColumnDefinition(Schema6.Literals(this.values), {
|
|
5010
6081
|
dbType: this.type(),
|
|
5011
6082
|
nullable: false,
|
|
5012
6083
|
hasDefault: false,
|
|
@@ -5026,7 +6097,7 @@ var EnumProto = {
|
|
|
5026
6097
|
};
|
|
5027
6098
|
var SequenceProto = {
|
|
5028
6099
|
pipe() {
|
|
5029
|
-
return
|
|
6100
|
+
return pipeArguments6(this, arguments);
|
|
5030
6101
|
},
|
|
5031
6102
|
qualifiedName() {
|
|
5032
6103
|
return this.schemaName === undefined || this.schemaName === "public" ? this.name : `${this.schemaName}.${this.name}`;
|
|
@@ -5059,7 +6130,7 @@ function sequence(name, schemaName) {
|
|
|
5059
6130
|
var isSequenceDefinition = (value) => typeof value === "object" && value !== null && (SequenceTypeId in value);
|
|
5060
6131
|
|
|
5061
6132
|
// src/postgres/internal/schema-model.ts
|
|
5062
|
-
var isTableDefinition = (value) => value !== null && (typeof value === "object" || typeof value === "function") && (
|
|
6133
|
+
var isTableDefinition = (value) => value !== null && (typeof value === "object" || typeof value === "function") && (TypeId7 in value);
|
|
5063
6134
|
var isEnumDefinition = (value) => typeof value === "object" && value !== null && (EnumTypeId in value);
|
|
5064
6135
|
var applyCasing = (casing, category, name) => applyCategory(casing, category, name);
|
|
5065
6136
|
var mapColumnList = (columns, casing) => !Array.isArray(columns) ? columns : columns.length === 0 ? columns : [
|
|
@@ -5081,7 +6152,7 @@ function mapOptionName(name, casing, category) {
|
|
|
5081
6152
|
function mapCasedValue(value, casing, category) {
|
|
5082
6153
|
return typeof value === "string" ? applyCasing(casing, category, value) : value;
|
|
5083
6154
|
}
|
|
5084
|
-
var isDdlExpressionLike = (value) => typeof value === "object" && value !== null && ((TypeId2 in value) || (
|
|
6155
|
+
var isDdlExpressionLike = (value) => typeof value === "object" && value !== null && ((TypeId2 in value) || (TypeId5 in value));
|
|
5085
6156
|
function mapIndexKey(key2, casing, expressionState) {
|
|
5086
6157
|
if (typeof key2 !== "object" || key2 === null || !("kind" in key2)) {
|
|
5087
6158
|
return key2;
|
|
@@ -5103,7 +6174,7 @@ function mapIndexKey(key2, casing, expressionState) {
|
|
|
5103
6174
|
}
|
|
5104
6175
|
return key2;
|
|
5105
6176
|
}
|
|
5106
|
-
var
|
|
6177
|
+
var mapOption2 = (option2, casing, expressionState) => {
|
|
5107
6178
|
switch (option2.kind) {
|
|
5108
6179
|
case "index":
|
|
5109
6180
|
return {
|
|
@@ -5160,7 +6231,7 @@ var mapOption = (option2, casing, expressionState) => {
|
|
|
5160
6231
|
}
|
|
5161
6232
|
};
|
|
5162
6233
|
var toTableModel = (table) => {
|
|
5163
|
-
const state = table[
|
|
6234
|
+
const state = table[TypeId7];
|
|
5164
6235
|
const casing = state.casing;
|
|
5165
6236
|
const tableName = applyCasing(casing, "tables", state.baseName);
|
|
5166
6237
|
const schemaName = state.schemaName === undefined ? undefined : applyCasing(casing, "schemas", state.schemaName);
|
|
@@ -5194,7 +6265,7 @@ var toTableModel = (table) => {
|
|
|
5194
6265
|
schemaName,
|
|
5195
6266
|
name: tableName,
|
|
5196
6267
|
columns,
|
|
5197
|
-
options: normalizedOptions.map((option2) => typeof option2 === "object" && option2 !== null && ("kind" in option2) ?
|
|
6268
|
+
options: normalizedOptions.map((option2) => typeof option2 === "object" && option2 !== null && ("kind" in option2) ? mapOption2(option2, casing, expressionState) : option2),
|
|
5198
6269
|
table
|
|
5199
6270
|
};
|
|
5200
6271
|
};
|
|
@@ -5205,7 +6276,7 @@ var toEnumModel = (definition) => ({
|
|
|
5205
6276
|
values: [...definition.values]
|
|
5206
6277
|
});
|
|
5207
6278
|
var enumModelsOfTable = (table) => {
|
|
5208
|
-
const state = table[
|
|
6279
|
+
const state = table[TypeId7];
|
|
5209
6280
|
const fields = state.fields;
|
|
5210
6281
|
return Object.values(fields).flatMap((column) => column.metadata.enum === undefined ? [] : [
|
|
5211
6282
|
{
|