effect-qb 0.13.0 → 0.14.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 +6 -1431
- package/dist/mysql.js +1678 -355
- package/dist/postgres/metadata.js +2724 -0
- package/dist/postgres.js +7197 -5433
- package/package.json +8 -10
- package/src/internal/column-state.ts +84 -10
- package/src/internal/column.ts +556 -34
- package/src/internal/datatypes/define.ts +0 -30
- package/src/internal/executor.ts +45 -11
- package/src/internal/expression-ast.ts +4 -0
- package/src/internal/expression.ts +1 -1
- package/src/internal/implication-runtime.ts +171 -0
- package/src/internal/mysql-query.ts +7173 -0
- package/src/internal/mysql-renderer.ts +2 -2
- package/src/internal/plan.ts +14 -4
- package/src/internal/{query-factory.ts → postgres-query.ts} +619 -167
- package/src/internal/postgres-renderer.ts +2 -2
- package/src/internal/postgres-schema-model.ts +144 -0
- package/src/internal/predicate-analysis.ts +10 -0
- package/src/internal/predicate-context.ts +112 -36
- package/src/internal/predicate-formula.ts +31 -19
- package/src/internal/predicate-normalize.ts +177 -106
- package/src/internal/predicate-runtime.ts +676 -0
- package/src/internal/query.ts +455 -39
- package/src/internal/renderer.ts +2 -2
- package/src/internal/runtime-schema.ts +74 -20
- package/src/internal/schema-ddl.ts +55 -0
- package/src/internal/schema-derivation.ts +93 -21
- package/src/internal/schema-expression.ts +44 -0
- package/src/internal/sql-expression-renderer.ts +95 -31
- package/src/internal/table-options.ts +87 -7
- package/src/internal/table.ts +104 -41
- package/src/mysql/column.ts +1 -0
- package/src/mysql/datatypes/index.ts +17 -2
- package/src/mysql/function/core.ts +1 -0
- package/src/mysql/function/index.ts +1 -0
- package/src/mysql/private/query.ts +1 -13
- package/src/mysql/query.ts +5 -0
- package/src/postgres/cast.ts +31 -0
- package/src/postgres/column.ts +26 -0
- package/src/postgres/datatypes/index.ts +40 -5
- package/src/postgres/function/core.ts +12 -0
- package/src/postgres/function/index.ts +2 -1
- package/src/postgres/function/json.ts +499 -2
- package/src/postgres/metadata.ts +31 -0
- package/src/postgres/private/query.ts +1 -13
- package/src/postgres/query.ts +5 -2
- package/src/postgres/schema-expression.ts +16 -0
- package/src/postgres/schema-management.ts +204 -0
- package/src/postgres/schema.ts +35 -0
- package/src/postgres/table.ts +307 -41
- package/src/postgres/type.ts +4 -0
- package/src/postgres.ts +14 -0
- package/CHANGELOG.md +0 -134
package/dist/mysql.js
CHANGED
|
@@ -22,17 +22,18 @@ __export(exports_column, {
|
|
|
22
22
|
number: () => number2,
|
|
23
23
|
nullable: () => nullable2,
|
|
24
24
|
json: () => json2,
|
|
25
|
-
int: () =>
|
|
25
|
+
int: () => int3,
|
|
26
26
|
generated: () => generated2,
|
|
27
27
|
default: () => default_2,
|
|
28
28
|
datetime: () => datetime,
|
|
29
29
|
date: () => date2,
|
|
30
30
|
custom: () => custom2,
|
|
31
|
+
brand: () => brand5,
|
|
31
32
|
boolean: () => boolean2
|
|
32
33
|
});
|
|
33
34
|
|
|
34
35
|
// src/internal/column.ts
|
|
35
|
-
import * as
|
|
36
|
+
import * as Schema3 from "effect/Schema";
|
|
36
37
|
|
|
37
38
|
// src/internal/runtime-value.ts
|
|
38
39
|
import * as Schema from "effect/Schema";
|
|
@@ -53,6 +54,7 @@ var JsonPrimitiveSchema = Schema.Union(Schema.String, Schema.Number, Schema.Bool
|
|
|
53
54
|
|
|
54
55
|
// src/internal/column-state.ts
|
|
55
56
|
import { pipeArguments } from "effect/Pipeable";
|
|
57
|
+
import * as Schema2 from "effect/Schema";
|
|
56
58
|
|
|
57
59
|
// src/internal/expression.ts
|
|
58
60
|
var exports_expression = {};
|
|
@@ -100,6 +102,9 @@ var makeColumnDefinition = (schema, metadata) => {
|
|
|
100
102
|
references: metadata.references,
|
|
101
103
|
defaultValue: metadata.defaultValue,
|
|
102
104
|
generatedValue: metadata.generatedValue,
|
|
105
|
+
ddlType: metadata.ddlType,
|
|
106
|
+
identity: metadata.identity,
|
|
107
|
+
enum: metadata.enum,
|
|
103
108
|
source: undefined,
|
|
104
109
|
dependencies: {}
|
|
105
110
|
};
|
|
@@ -132,7 +137,10 @@ var remapColumnDefinition = (column, options = {}) => {
|
|
|
132
137
|
unique: metadata.unique,
|
|
133
138
|
references: metadata.references,
|
|
134
139
|
defaultValue: metadata.defaultValue,
|
|
135
|
-
generatedValue: metadata.generatedValue
|
|
140
|
+
generatedValue: metadata.generatedValue,
|
|
141
|
+
ddlType: metadata.ddlType,
|
|
142
|
+
identity: metadata.identity,
|
|
143
|
+
enum: metadata.enum
|
|
136
144
|
};
|
|
137
145
|
if (TypeId2 in column) {
|
|
138
146
|
next[TypeId2] = column[TypeId2];
|
|
@@ -143,13 +151,15 @@ var remapColumnDefinition = (column, options = {}) => {
|
|
|
143
151
|
return next;
|
|
144
152
|
};
|
|
145
153
|
var bindColumn = (tableName, columnName, column, baseTableName, schemaName) => {
|
|
154
|
+
const brandName = `${tableName}.${columnName}`;
|
|
155
|
+
const schema = column.metadata.brand === true ? Schema2.brand(brandName)(column.schema) : column.schema;
|
|
146
156
|
const bound = Object.create(ColumnProto);
|
|
147
|
-
bound.schema =
|
|
157
|
+
bound.schema = schema;
|
|
148
158
|
bound.metadata = column.metadata;
|
|
149
159
|
bound[TypeId] = {
|
|
150
160
|
runtime: undefined,
|
|
151
161
|
dbType: column.metadata.dbType,
|
|
152
|
-
runtimeSchema:
|
|
162
|
+
runtimeSchema: schema,
|
|
153
163
|
nullability: column.metadata.nullable ? "maybe" : "never",
|
|
154
164
|
dialect: column.metadata.dbType.dialect,
|
|
155
165
|
aggregation: "scalar",
|
|
@@ -182,6 +192,7 @@ var bindColumn = (tableName, columnName, column, baseTableName, schemaName) => {
|
|
|
182
192
|
var mapColumn = (column, metadata) => remapColumnDefinition(column, {
|
|
183
193
|
metadata
|
|
184
194
|
});
|
|
195
|
+
var isColumnDefinitionValue = (value) => typeof value === "object" && value !== null && (ColumnTypeId in value);
|
|
185
196
|
var primitive = (schema, dbType) => makeColumnDefinition(schema, {
|
|
186
197
|
dbType,
|
|
187
198
|
nullable: false,
|
|
@@ -195,6 +206,13 @@ var typeFactory = (dialect) => (kind) => ({
|
|
|
195
206
|
dialect,
|
|
196
207
|
kind
|
|
197
208
|
});
|
|
209
|
+
var postgresType = typeFactory("postgres");
|
|
210
|
+
var renderNumericDdlType = (kind, options) => {
|
|
211
|
+
if (options === undefined || options.precision === undefined) {
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
return options.scale === undefined ? `${kind}(${options.precision})` : `${kind}(${options.precision},${options.scale})`;
|
|
215
|
+
};
|
|
198
216
|
var makeColumnModule = (dialect, kinds) => {
|
|
199
217
|
const dialectType = typeFactory(dialect);
|
|
200
218
|
return {
|
|
@@ -205,13 +223,25 @@ var makeColumnModule = (dialect, kinds) => {
|
|
|
205
223
|
generated: false,
|
|
206
224
|
primaryKey: false,
|
|
207
225
|
unique: false,
|
|
208
|
-
references: undefined
|
|
226
|
+
references: undefined,
|
|
227
|
+
ddlType: undefined,
|
|
228
|
+
identity: undefined
|
|
209
229
|
}),
|
|
210
|
-
uuid: () => primitive(
|
|
211
|
-
text: () => primitive(
|
|
212
|
-
int: () => primitive(
|
|
213
|
-
number: () =>
|
|
214
|
-
|
|
230
|
+
uuid: () => primitive(Schema3.UUID, dialectType(kinds.uuid)),
|
|
231
|
+
text: () => primitive(Schema3.String, dialectType(kinds.text)),
|
|
232
|
+
int: () => primitive(Schema3.Int, dialectType(kinds.int)),
|
|
233
|
+
number: (options) => makeColumnDefinition(DecimalStringSchema, {
|
|
234
|
+
dbType: dialectType(kinds.number),
|
|
235
|
+
nullable: false,
|
|
236
|
+
hasDefault: false,
|
|
237
|
+
generated: false,
|
|
238
|
+
primaryKey: false,
|
|
239
|
+
unique: false,
|
|
240
|
+
references: undefined,
|
|
241
|
+
ddlType: renderNumericDdlType(kinds.number, options),
|
|
242
|
+
identity: undefined
|
|
243
|
+
}),
|
|
244
|
+
boolean: () => primitive(Schema3.Boolean, dialectType(kinds.boolean)),
|
|
215
245
|
date: () => primitive(LocalDateStringSchema, dialectType(kinds.date)),
|
|
216
246
|
timestamp: () => primitive(LocalDateTimeStringSchema, dialectType(kinds.timestamp)),
|
|
217
247
|
json: (schema) => makeColumnDefinition(schema, {
|
|
@@ -224,11 +254,13 @@ var makeColumnModule = (dialect, kinds) => {
|
|
|
224
254
|
generated: false,
|
|
225
255
|
primaryKey: false,
|
|
226
256
|
unique: false,
|
|
227
|
-
references: undefined
|
|
257
|
+
references: undefined,
|
|
258
|
+
ddlType: undefined,
|
|
259
|
+
identity: undefined
|
|
228
260
|
})
|
|
229
261
|
};
|
|
230
262
|
};
|
|
231
|
-
var
|
|
263
|
+
var postgresBase = makeColumnModule("postgres", {
|
|
232
264
|
uuid: "uuid",
|
|
233
265
|
text: "text",
|
|
234
266
|
int: "int4",
|
|
@@ -238,6 +270,61 @@ var postgres = makeColumnModule("postgres", {
|
|
|
238
270
|
timestamp: "timestamp",
|
|
239
271
|
json: "json"
|
|
240
272
|
});
|
|
273
|
+
var postgres = {
|
|
274
|
+
...postgresBase,
|
|
275
|
+
int2: () => primitive(Schema3.Int, postgresType("int2")),
|
|
276
|
+
int8: () => primitive(BigIntStringSchema, postgresType("int8")),
|
|
277
|
+
float4: () => primitive(Schema3.Number, postgresType("float4")),
|
|
278
|
+
float8: () => primitive(Schema3.Number, postgresType("float8")),
|
|
279
|
+
char: (length = 1) => makeColumnDefinition(Schema3.String, {
|
|
280
|
+
dbType: postgresType("char"),
|
|
281
|
+
nullable: false,
|
|
282
|
+
hasDefault: false,
|
|
283
|
+
generated: false,
|
|
284
|
+
primaryKey: false,
|
|
285
|
+
unique: false,
|
|
286
|
+
references: undefined,
|
|
287
|
+
ddlType: `char(${length})`,
|
|
288
|
+
identity: undefined
|
|
289
|
+
}),
|
|
290
|
+
varchar: (length) => makeColumnDefinition(Schema3.String, {
|
|
291
|
+
dbType: postgresType("varchar"),
|
|
292
|
+
nullable: false,
|
|
293
|
+
hasDefault: false,
|
|
294
|
+
generated: false,
|
|
295
|
+
primaryKey: false,
|
|
296
|
+
unique: false,
|
|
297
|
+
references: undefined,
|
|
298
|
+
ddlType: length === undefined ? "varchar" : `varchar(${length})`,
|
|
299
|
+
identity: undefined
|
|
300
|
+
}),
|
|
301
|
+
time: () => primitive(LocalTimeStringSchema, postgresType("time")),
|
|
302
|
+
timetz: () => primitive(OffsetTimeStringSchema, postgresType("timetz")),
|
|
303
|
+
timestamptz: () => primitive(InstantStringSchema, postgresType("timestamptz")),
|
|
304
|
+
interval: () => primitive(Schema3.String, postgresType("interval")),
|
|
305
|
+
bytea: () => primitive(Schema3.Uint8ArrayFromSelf, postgresType("bytea")),
|
|
306
|
+
name: () => primitive(Schema3.String, postgresType("name")),
|
|
307
|
+
oid: () => primitive(Schema3.Int, postgresType("oid")),
|
|
308
|
+
regclass: () => primitive(Schema3.String, postgresType("regclass")),
|
|
309
|
+
bit: () => primitive(Schema3.String, postgresType("bit")),
|
|
310
|
+
varbit: () => primitive(Schema3.String, postgresType("varbit")),
|
|
311
|
+
xml: () => primitive(Schema3.String, postgresType("xml")),
|
|
312
|
+
pg_lsn: () => primitive(Schema3.String, postgresType("pg_lsn")),
|
|
313
|
+
jsonb: (schema) => makeColumnDefinition(schema, {
|
|
314
|
+
dbType: {
|
|
315
|
+
...postgresType("jsonb"),
|
|
316
|
+
variant: "jsonb"
|
|
317
|
+
},
|
|
318
|
+
nullable: false,
|
|
319
|
+
hasDefault: false,
|
|
320
|
+
generated: false,
|
|
321
|
+
primaryKey: false,
|
|
322
|
+
unique: false,
|
|
323
|
+
references: undefined,
|
|
324
|
+
ddlType: undefined,
|
|
325
|
+
identity: undefined
|
|
326
|
+
})
|
|
327
|
+
};
|
|
241
328
|
var mysql = makeColumnModule("mysql", {
|
|
242
329
|
uuid: "uuid",
|
|
243
330
|
text: "text",
|
|
@@ -251,15 +338,53 @@ var mysql = makeColumnModule("mysql", {
|
|
|
251
338
|
var uuid = postgres.uuid;
|
|
252
339
|
var text = postgres.text;
|
|
253
340
|
var int = postgres.int;
|
|
341
|
+
var int2 = postgres.int2;
|
|
342
|
+
var int8 = postgres.int8;
|
|
254
343
|
var number = postgres.number;
|
|
344
|
+
var float4 = postgres.float4;
|
|
345
|
+
var float8 = postgres.float8;
|
|
255
346
|
var boolean = postgres.boolean;
|
|
256
347
|
var date = postgres.date;
|
|
257
348
|
var timestamp = postgres.timestamp;
|
|
349
|
+
var time = postgres.time;
|
|
350
|
+
var timetz = postgres.timetz;
|
|
351
|
+
var timestamptz = postgres.timestamptz;
|
|
352
|
+
var char = postgres.char;
|
|
353
|
+
var varchar = postgres.varchar;
|
|
354
|
+
var interval = postgres.interval;
|
|
355
|
+
var bytea = postgres.bytea;
|
|
356
|
+
var name = postgres.name;
|
|
357
|
+
var oid = postgres.oid;
|
|
358
|
+
var regclass = postgres.regclass;
|
|
359
|
+
var bit = postgres.bit;
|
|
360
|
+
var varbit = postgres.varbit;
|
|
361
|
+
var xml = postgres.xml;
|
|
362
|
+
var pg_lsn = postgres.pg_lsn;
|
|
258
363
|
var json = postgres.json;
|
|
364
|
+
var jsonb = postgres.jsonb;
|
|
259
365
|
var custom = postgres.custom;
|
|
260
366
|
var schema = (nextSchema) => (column) => remapColumnDefinition(column, {
|
|
261
367
|
schema: nextSchema
|
|
262
368
|
});
|
|
369
|
+
var brand4 = (column) => {
|
|
370
|
+
if (BoundColumnTypeId in column) {
|
|
371
|
+
const boundColumn = column;
|
|
372
|
+
const brandName = `${boundColumn[BoundColumnTypeId].tableName}.${boundColumn[BoundColumnTypeId].columnName}`;
|
|
373
|
+
return remapColumnDefinition(boundColumn, {
|
|
374
|
+
schema: Schema3.brand(brandName)(boundColumn.schema),
|
|
375
|
+
metadata: {
|
|
376
|
+
...boundColumn.metadata,
|
|
377
|
+
brand: true
|
|
378
|
+
}
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
return remapColumnDefinition(column, {
|
|
382
|
+
metadata: {
|
|
383
|
+
...column.metadata,
|
|
384
|
+
brand: true
|
|
385
|
+
}
|
|
386
|
+
});
|
|
387
|
+
};
|
|
263
388
|
var nullable = (column) => mapColumn(column, {
|
|
264
389
|
...column.metadata,
|
|
265
390
|
nullable: true
|
|
@@ -270,32 +395,100 @@ var primaryKey = (column) => mapColumn(column, {
|
|
|
270
395
|
primaryKey: true,
|
|
271
396
|
unique: true
|
|
272
397
|
});
|
|
273
|
-
var unique = (column) => mapColumn(column, {
|
|
398
|
+
var unique = Object.assign((column) => mapColumn(column, {
|
|
274
399
|
...column.metadata,
|
|
275
400
|
unique: true
|
|
401
|
+
}), {
|
|
402
|
+
options: (options) => (column) => mapColumn(column, {
|
|
403
|
+
...column.metadata,
|
|
404
|
+
unique: true,
|
|
405
|
+
uniqueConstraint: options
|
|
406
|
+
})
|
|
276
407
|
});
|
|
277
408
|
var default_ = (value) => (column) => mapColumn(column, {
|
|
278
409
|
...column.metadata,
|
|
279
410
|
hasDefault: true,
|
|
280
411
|
defaultValue: value,
|
|
281
|
-
generatedValue: undefined
|
|
412
|
+
generatedValue: undefined,
|
|
413
|
+
identity: undefined
|
|
282
414
|
});
|
|
283
415
|
var generated = (value) => (column) => mapColumn(column, {
|
|
284
416
|
...column.metadata,
|
|
285
417
|
generated: true,
|
|
286
418
|
hasDefault: false,
|
|
287
419
|
defaultValue: undefined,
|
|
288
|
-
generatedValue: value
|
|
420
|
+
generatedValue: value,
|
|
421
|
+
identity: undefined
|
|
289
422
|
});
|
|
290
|
-
var
|
|
423
|
+
var ddlType = (sqlType) => (column) => mapColumn(column, {
|
|
291
424
|
...column.metadata,
|
|
292
|
-
|
|
425
|
+
ddlType: sqlType
|
|
293
426
|
});
|
|
427
|
+
var array = (options) => (column) => remapColumnDefinition(column, {
|
|
428
|
+
schema: Schema3.Array(options?.nullableElements ? Schema3.NullOr(column.schema) : column.schema),
|
|
429
|
+
metadata: {
|
|
430
|
+
...column.metadata,
|
|
431
|
+
dbType: {
|
|
432
|
+
dialect: column.metadata.dbType.dialect,
|
|
433
|
+
kind: `${column.metadata.dbType.kind}[]`,
|
|
434
|
+
element: column.metadata.dbType
|
|
435
|
+
},
|
|
436
|
+
ddlType: `${column.metadata.ddlType ?? column.metadata.dbType.kind}[]`
|
|
437
|
+
}
|
|
438
|
+
});
|
|
439
|
+
function index(arg) {
|
|
440
|
+
if (isColumnDefinitionValue(arg)) {
|
|
441
|
+
return mapColumn(arg, {
|
|
442
|
+
...arg.metadata,
|
|
443
|
+
index: arg.metadata.index ?? {}
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
const options = arg ?? {};
|
|
447
|
+
return (column) => mapColumn(column, {
|
|
448
|
+
...column.metadata,
|
|
449
|
+
index: options
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
var identityByDefault = (column) => mapColumn(column, {
|
|
453
|
+
...column.metadata,
|
|
454
|
+
hasDefault: true,
|
|
455
|
+
generated: false,
|
|
456
|
+
defaultValue: undefined,
|
|
457
|
+
generatedValue: undefined,
|
|
458
|
+
identity: {
|
|
459
|
+
generation: "byDefault"
|
|
460
|
+
}
|
|
461
|
+
});
|
|
462
|
+
var identityAlways = (column) => mapColumn(column, {
|
|
463
|
+
...column.metadata,
|
|
464
|
+
hasDefault: false,
|
|
465
|
+
generated: true,
|
|
466
|
+
defaultValue: undefined,
|
|
467
|
+
generatedValue: undefined,
|
|
468
|
+
identity: {
|
|
469
|
+
generation: "always"
|
|
470
|
+
}
|
|
471
|
+
});
|
|
472
|
+
function foreignKey(arg) {
|
|
473
|
+
if (typeof arg === "function") {
|
|
474
|
+
const target = arg;
|
|
475
|
+
return (column) => mapColumn(column, {
|
|
476
|
+
...column.metadata,
|
|
477
|
+
references: { target }
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
const options = arg;
|
|
481
|
+
return (column) => mapColumn(column, {
|
|
482
|
+
...column.metadata,
|
|
483
|
+
references: options
|
|
484
|
+
});
|
|
485
|
+
}
|
|
486
|
+
var references = (target) => foreignKey(target);
|
|
294
487
|
|
|
295
488
|
// src/mysql/column.ts
|
|
296
489
|
var uuid2 = mysql.uuid;
|
|
297
490
|
var text2 = mysql.text;
|
|
298
|
-
var
|
|
491
|
+
var int3 = mysql.int;
|
|
299
492
|
var number2 = mysql.number;
|
|
300
493
|
var boolean2 = mysql.boolean;
|
|
301
494
|
var date2 = mysql.date;
|
|
@@ -304,6 +497,7 @@ var timestamp2 = mysql.timestamp;
|
|
|
304
497
|
var json2 = mysql.json;
|
|
305
498
|
var custom2 = mysql.custom;
|
|
306
499
|
var nullable2 = nullable;
|
|
500
|
+
var brand5 = brand4;
|
|
307
501
|
var primaryKey2 = primaryKey;
|
|
308
502
|
var unique2 = unique;
|
|
309
503
|
var default_2 = default_;
|
|
@@ -316,29 +510,6 @@ __export(exports_datatypes, {
|
|
|
316
510
|
mysqlDatatypes: () => mysqlDatatypes
|
|
317
511
|
});
|
|
318
512
|
|
|
319
|
-
// src/internal/datatypes/define.ts
|
|
320
|
-
var makeDatatypeModule = (dialect, kinds, aliases) => {
|
|
321
|
-
const module = {
|
|
322
|
-
custom: (kind) => ({
|
|
323
|
-
dialect,
|
|
324
|
-
kind
|
|
325
|
-
})
|
|
326
|
-
};
|
|
327
|
-
for (const kind of Object.keys(kinds)) {
|
|
328
|
-
module[kind] = () => ({
|
|
329
|
-
dialect,
|
|
330
|
-
kind
|
|
331
|
-
});
|
|
332
|
-
}
|
|
333
|
-
for (const [alias, kind] of Object.entries(aliases ?? {})) {
|
|
334
|
-
module[alias] = () => ({
|
|
335
|
-
dialect,
|
|
336
|
-
kind
|
|
337
|
-
});
|
|
338
|
-
}
|
|
339
|
-
return module;
|
|
340
|
-
};
|
|
341
|
-
|
|
342
513
|
// src/mysql/datatypes/spec.ts
|
|
343
514
|
var mysqlDatatypeKinds = {
|
|
344
515
|
char: { family: "text", runtime: "string" },
|
|
@@ -388,7 +559,19 @@ var mysqlDatatypeKinds = {
|
|
|
388
559
|
};
|
|
389
560
|
|
|
390
561
|
// src/mysql/datatypes/index.ts
|
|
391
|
-
var
|
|
562
|
+
var mysqlDatatypeModule = {
|
|
563
|
+
custom: (kind) => ({
|
|
564
|
+
dialect: "mysql",
|
|
565
|
+
kind
|
|
566
|
+
})
|
|
567
|
+
};
|
|
568
|
+
for (const kind of Object.keys(mysqlDatatypeKinds)) {
|
|
569
|
+
mysqlDatatypeModule[kind] = () => ({
|
|
570
|
+
dialect: "mysql",
|
|
571
|
+
kind
|
|
572
|
+
});
|
|
573
|
+
}
|
|
574
|
+
var mysqlDatatypes = mysqlDatatypeModule;
|
|
392
575
|
// src/mysql/errors/index.ts
|
|
393
576
|
var exports_errors = {};
|
|
394
577
|
__export(exports_errors, {
|
|
@@ -52189,18 +52372,20 @@ __export(exports_function, {
|
|
|
52189
52372
|
core: () => exports_core,
|
|
52190
52373
|
concat: () => concat,
|
|
52191
52374
|
coalesce: () => coalesce,
|
|
52375
|
+
call: () => call,
|
|
52192
52376
|
aggregate: () => exports_aggregate
|
|
52193
52377
|
});
|
|
52194
52378
|
|
|
52195
52379
|
// src/mysql/function/core.ts
|
|
52196
52380
|
var exports_core = {};
|
|
52197
52381
|
__export(exports_core, {
|
|
52198
|
-
coalesce: () => coalesce
|
|
52382
|
+
coalesce: () => coalesce,
|
|
52383
|
+
call: () => call
|
|
52199
52384
|
});
|
|
52200
52385
|
|
|
52201
|
-
// src/internal/query
|
|
52386
|
+
// src/internal/mysql-query.ts
|
|
52202
52387
|
import { pipeArguments as pipeArguments5 } from "effect/Pipeable";
|
|
52203
|
-
import * as
|
|
52388
|
+
import * as Schema5 from "effect/Schema";
|
|
52204
52389
|
|
|
52205
52390
|
// src/internal/plan.ts
|
|
52206
52391
|
var exports_plan = {};
|
|
@@ -52232,7 +52417,11 @@ var collectInlineOptions = (fields2) => {
|
|
|
52232
52417
|
if (column.metadata.unique && !column.metadata.primaryKey) {
|
|
52233
52418
|
options.push({
|
|
52234
52419
|
kind: "unique",
|
|
52235
|
-
columns: [columnName]
|
|
52420
|
+
columns: [columnName],
|
|
52421
|
+
name: column.metadata.uniqueConstraint?.name,
|
|
52422
|
+
nullsNotDistinct: column.metadata.uniqueConstraint?.nullsNotDistinct,
|
|
52423
|
+
deferrable: column.metadata.uniqueConstraint?.deferrable,
|
|
52424
|
+
initiallyDeferred: column.metadata.uniqueConstraint?.initiallyDeferred
|
|
52236
52425
|
});
|
|
52237
52426
|
}
|
|
52238
52427
|
if (column.metadata.references) {
|
|
@@ -52248,7 +52437,27 @@ var collectInlineOptions = (fields2) => {
|
|
|
52248
52437
|
schemaName: bound.schemaName,
|
|
52249
52438
|
columns: [bound.columnName]
|
|
52250
52439
|
};
|
|
52251
|
-
}
|
|
52440
|
+
},
|
|
52441
|
+
name: column.metadata.references.name,
|
|
52442
|
+
onUpdate: column.metadata.references.onUpdate,
|
|
52443
|
+
onDelete: column.metadata.references.onDelete,
|
|
52444
|
+
deferrable: column.metadata.references.deferrable,
|
|
52445
|
+
initiallyDeferred: column.metadata.references.initiallyDeferred
|
|
52446
|
+
});
|
|
52447
|
+
}
|
|
52448
|
+
if (column.metadata.index) {
|
|
52449
|
+
options.push({
|
|
52450
|
+
kind: "index",
|
|
52451
|
+
keys: [{
|
|
52452
|
+
kind: "column",
|
|
52453
|
+
column: columnName,
|
|
52454
|
+
order: column.metadata.index.order,
|
|
52455
|
+
nulls: column.metadata.index.nulls
|
|
52456
|
+
}],
|
|
52457
|
+
name: column.metadata.index.name,
|
|
52458
|
+
method: column.metadata.index.method,
|
|
52459
|
+
include: column.metadata.index.include,
|
|
52460
|
+
predicate: column.metadata.index.predicate
|
|
52252
52461
|
});
|
|
52253
52462
|
}
|
|
52254
52463
|
}
|
|
@@ -52280,17 +52489,18 @@ var validateOptions = (tableName, fields2, options) => {
|
|
|
52280
52489
|
case "primaryKey":
|
|
52281
52490
|
case "unique":
|
|
52282
52491
|
case "foreignKey": {
|
|
52283
|
-
|
|
52492
|
+
const columns = option.kind === "index" ? option.columns ?? [] : option.columns;
|
|
52493
|
+
if (columns.length === 0 && option.kind !== "index") {
|
|
52284
52494
|
throw new Error(`Option '${option.kind}' on table '${tableName}' requires at least one column`);
|
|
52285
52495
|
}
|
|
52286
|
-
for (const column of
|
|
52496
|
+
for (const column of columns) {
|
|
52287
52497
|
if (!knownColumns.has(column)) {
|
|
52288
52498
|
throw new Error(`Unknown column '${column}' on table '${tableName}'`);
|
|
52289
52499
|
}
|
|
52290
52500
|
}
|
|
52291
52501
|
if (option.kind === "foreignKey") {
|
|
52292
52502
|
const reference = option.references();
|
|
52293
|
-
if (reference.columns.length !==
|
|
52503
|
+
if (reference.columns.length !== columns.length) {
|
|
52294
52504
|
throw new Error(`Foreign key on table '${tableName}' must reference the same number of columns`);
|
|
52295
52505
|
}
|
|
52296
52506
|
if (reference.knownColumns) {
|
|
@@ -52302,6 +52512,21 @@ var validateOptions = (tableName, fields2, options) => {
|
|
|
52302
52512
|
}
|
|
52303
52513
|
}
|
|
52304
52514
|
}
|
|
52515
|
+
if (option.kind === "index") {
|
|
52516
|
+
for (const column of option.include ?? []) {
|
|
52517
|
+
if (!knownColumns.has(column)) {
|
|
52518
|
+
throw new Error(`Unknown included column '${column}' on table '${tableName}'`);
|
|
52519
|
+
}
|
|
52520
|
+
}
|
|
52521
|
+
for (const key of option.keys ?? []) {
|
|
52522
|
+
if (key.kind === "column" && !knownColumns.has(key.column)) {
|
|
52523
|
+
throw new Error(`Unknown index key column '${key.column}' on table '${tableName}'`);
|
|
52524
|
+
}
|
|
52525
|
+
}
|
|
52526
|
+
if (option.columns === undefined && (option.keys === undefined || option.keys.length === 0)) {
|
|
52527
|
+
throw new Error(`Index on table '${tableName}' requires at least one column or key`);
|
|
52528
|
+
}
|
|
52529
|
+
}
|
|
52305
52530
|
break;
|
|
52306
52531
|
}
|
|
52307
52532
|
case "check": {
|
|
@@ -52318,37 +52543,38 @@ var validateOptions = (tableName, fields2, options) => {
|
|
|
52318
52543
|
|
|
52319
52544
|
// src/internal/schema-derivation.ts
|
|
52320
52545
|
import * as VariantSchema from "@effect/experimental/VariantSchema";
|
|
52321
|
-
import * as
|
|
52546
|
+
import * as Schema4 from "effect/Schema";
|
|
52322
52547
|
var TableSchema = VariantSchema.make({
|
|
52323
52548
|
variants: ["select", "insert", "update"],
|
|
52324
52549
|
defaultVariant: "select"
|
|
52325
52550
|
});
|
|
52326
|
-
var
|
|
52327
|
-
var
|
|
52551
|
+
var maybeBrandSchema = (column, tableName, columnName) => column.metadata.brand === true ? Schema4.brand(`${tableName}.${columnName}`)(column.schema) : column.schema;
|
|
52552
|
+
var selectSchema = (column, tableName, columnName) => column.metadata.nullable ? Schema4.NullOr(maybeBrandSchema(column, tableName, columnName)) : maybeBrandSchema(column, tableName, columnName);
|
|
52553
|
+
var insertSchema = (column, tableName, columnName) => {
|
|
52328
52554
|
if (column.metadata.generated) {
|
|
52329
52555
|
return;
|
|
52330
52556
|
}
|
|
52331
|
-
const base = column.metadata.nullable ?
|
|
52332
|
-
return column.metadata.nullable || column.metadata.hasDefault ?
|
|
52557
|
+
const base = column.metadata.nullable ? Schema4.NullOr(maybeBrandSchema(column, tableName, columnName)) : maybeBrandSchema(column, tableName, columnName);
|
|
52558
|
+
return column.metadata.nullable || column.metadata.hasDefault ? Schema4.optional(base) : base;
|
|
52333
52559
|
};
|
|
52334
|
-
var updateSchema = (column, isPrimaryKey) => {
|
|
52560
|
+
var updateSchema = (column, tableName, columnName, isPrimaryKey) => {
|
|
52335
52561
|
if (column.metadata.generated || isPrimaryKey) {
|
|
52336
52562
|
return;
|
|
52337
52563
|
}
|
|
52338
|
-
const base = column.metadata.nullable ?
|
|
52339
|
-
return
|
|
52564
|
+
const base = column.metadata.nullable ? Schema4.NullOr(maybeBrandSchema(column, tableName, columnName)) : maybeBrandSchema(column, tableName, columnName);
|
|
52565
|
+
return Schema4.optional(base);
|
|
52340
52566
|
};
|
|
52341
|
-
var deriveSchemas = (fields2, primaryKeyColumns) => {
|
|
52567
|
+
var deriveSchemas = (tableName, fields2, primaryKeyColumns) => {
|
|
52342
52568
|
const primaryKeySet = new Set(primaryKeyColumns);
|
|
52343
52569
|
const variants = {};
|
|
52344
52570
|
for (const [key, column] of Object.entries(fields2)) {
|
|
52345
52571
|
const config = {
|
|
52346
|
-
select: selectSchema(column),
|
|
52572
|
+
select: selectSchema(column, tableName, key),
|
|
52347
52573
|
insert: undefined,
|
|
52348
52574
|
update: undefined
|
|
52349
52575
|
};
|
|
52350
|
-
const insert = insertSchema(column);
|
|
52351
|
-
const update = updateSchema(column, primaryKeySet.has(key));
|
|
52576
|
+
const insert = insertSchema(column, tableName, key);
|
|
52577
|
+
const update = updateSchema(column, tableName, key, primaryKeySet.has(key));
|
|
52352
52578
|
if (insert !== undefined) {
|
|
52353
52579
|
config.insert = insert;
|
|
52354
52580
|
} else {
|
|
@@ -52380,13 +52606,13 @@ var TableProto = {
|
|
|
52380
52606
|
return pipeArguments2(this, arguments);
|
|
52381
52607
|
}
|
|
52382
52608
|
};
|
|
52383
|
-
var buildArtifacts = (
|
|
52609
|
+
var buildArtifacts = (name2, fields2, declaredOptions, schemaName) => {
|
|
52384
52610
|
const normalizedOptions = [...collectInlineOptions(fields2), ...declaredOptions];
|
|
52385
|
-
validateFieldDialects(
|
|
52386
|
-
validateOptions(
|
|
52611
|
+
validateFieldDialects(name2, fields2);
|
|
52612
|
+
validateOptions(name2, fields2, declaredOptions);
|
|
52387
52613
|
const primaryKey3 = resolvePrimaryKeyColumns(fields2, declaredOptions);
|
|
52388
|
-
const columns = Object.fromEntries(Object.entries(fields2).map(([key, column]) => [key, bindColumn(
|
|
52389
|
-
const schemas = deriveSchemas(fields2, primaryKey3);
|
|
52614
|
+
const columns = Object.fromEntries(Object.entries(fields2).map(([key, column]) => [key, bindColumn(name2, key, column, name2, schemaName)]));
|
|
52615
|
+
const schemas = deriveSchemas(name2, fields2, primaryKey3);
|
|
52390
52616
|
return {
|
|
52391
52617
|
columns,
|
|
52392
52618
|
schemas,
|
|
@@ -52394,16 +52620,16 @@ var buildArtifacts = (name, fields2, declaredOptions, schemaName) => {
|
|
|
52394
52620
|
primaryKey: primaryKey3
|
|
52395
52621
|
};
|
|
52396
52622
|
};
|
|
52397
|
-
var makeTable = (
|
|
52623
|
+
var makeTable = (name2, fields2, declaredOptions, baseName = name2, kind = "schema", schemaName, schemaMode = "default") => {
|
|
52398
52624
|
const resolvedSchemaName = schemaMode === "explicit" ? schemaName : "public";
|
|
52399
|
-
const artifacts = buildArtifacts(
|
|
52625
|
+
const artifacts = buildArtifacts(name2, fields2, declaredOptions, resolvedSchemaName);
|
|
52400
52626
|
const dialect = resolveFieldDialect(fields2);
|
|
52401
52627
|
const table = Object.create(TableProto);
|
|
52402
|
-
table.name =
|
|
52628
|
+
table.name = name2;
|
|
52403
52629
|
table.columns = artifacts.columns;
|
|
52404
52630
|
table.schemas = artifacts.schemas;
|
|
52405
52631
|
table[TypeId4] = {
|
|
52406
|
-
name,
|
|
52632
|
+
name: name2,
|
|
52407
52633
|
baseName,
|
|
52408
52634
|
schemaName: resolvedSchemaName,
|
|
52409
52635
|
fields: fields2,
|
|
@@ -52414,8 +52640,8 @@ var makeTable = (name, fields2, declaredOptions, baseName = name, kind = "schema
|
|
|
52414
52640
|
selection: artifacts.columns,
|
|
52415
52641
|
required: undefined,
|
|
52416
52642
|
available: {
|
|
52417
|
-
[
|
|
52418
|
-
name,
|
|
52643
|
+
[name2]: {
|
|
52644
|
+
name: name2,
|
|
52419
52645
|
mode: "required",
|
|
52420
52646
|
baseName
|
|
52421
52647
|
}
|
|
@@ -52433,6 +52659,12 @@ var makeTable = (name, fields2, declaredOptions, baseName = name, kind = "schema
|
|
|
52433
52659
|
return table;
|
|
52434
52660
|
};
|
|
52435
52661
|
var extractDeclaredOptions = (declaredOptions) => declaredOptions?.map((option) => option.option) ?? [];
|
|
52662
|
+
var applyDeclaredOptions = (table, declaredOptions) => {
|
|
52663
|
+
if (declaredOptions === undefined || declaredOptions.length === 0) {
|
|
52664
|
+
return table;
|
|
52665
|
+
}
|
|
52666
|
+
return declaredOptions.reduce((current, option) => option(current), table);
|
|
52667
|
+
};
|
|
52436
52668
|
var validateClassOptions = (declaredOptions) => {
|
|
52437
52669
|
for (const option of declaredOptions) {
|
|
52438
52670
|
if (option.kind === "primaryKey") {
|
|
@@ -52463,9 +52695,15 @@ var ensureClassArtifacts = (self) => {
|
|
|
52463
52695
|
return cached;
|
|
52464
52696
|
}
|
|
52465
52697
|
const state = self[TypeId4];
|
|
52466
|
-
const
|
|
52467
|
-
validateClassOptions(
|
|
52468
|
-
const
|
|
52698
|
+
const classOptions = self[options];
|
|
52699
|
+
validateClassOptions(extractDeclaredOptions(classOptions));
|
|
52700
|
+
const table = applyDeclaredOptions(makeTable(state.name, state.fields, [], state.name, "schema", state.schemaName, state.schemaName === undefined || state.schemaName === "public" ? "default" : "explicit"), classOptions);
|
|
52701
|
+
const artifacts = {
|
|
52702
|
+
columns: table.columns,
|
|
52703
|
+
schemas: table.schemas,
|
|
52704
|
+
normalizedOptions: table[OptionsSymbol],
|
|
52705
|
+
primaryKey: table[TypeId4].primaryKey
|
|
52706
|
+
};
|
|
52469
52707
|
Object.defineProperty(self, CacheSymbol, {
|
|
52470
52708
|
configurable: true,
|
|
52471
52709
|
value: artifacts
|
|
@@ -52484,13 +52722,14 @@ var makeOption = (option) => {
|
|
|
52484
52722
|
builder.option = option;
|
|
52485
52723
|
return builder;
|
|
52486
52724
|
};
|
|
52487
|
-
|
|
52725
|
+
var option = (spec) => makeOption(spec);
|
|
52726
|
+
function make2(name2, fields2, schemaName) {
|
|
52488
52727
|
const resolvedSchemaName = arguments.length >= 3 ? schemaName : "public";
|
|
52489
|
-
return makeTable(
|
|
52728
|
+
return makeTable(name2, fields2, [], name2, "schema", resolvedSchemaName, arguments.length >= 3 ? "explicit" : "default");
|
|
52490
52729
|
}
|
|
52491
52730
|
var schema3 = (schemaName) => ({
|
|
52492
52731
|
schemaName,
|
|
52493
|
-
table: (
|
|
52732
|
+
table: (name2, fields2, ...options2) => applyDeclaredOptions(makeTable(name2, fields2, [], name2, "schema", schemaName, "explicit"), options2)
|
|
52494
52733
|
});
|
|
52495
52734
|
var alias = (table, aliasName) => {
|
|
52496
52735
|
const state = table[TypeId4];
|
|
@@ -52498,7 +52737,7 @@ var alias = (table, aliasName) => {
|
|
|
52498
52737
|
const aliased = Object.create(TableProto);
|
|
52499
52738
|
aliased.name = aliasName;
|
|
52500
52739
|
aliased.columns = columns;
|
|
52501
|
-
aliased.schemas =
|
|
52740
|
+
aliased.schemas = deriveSchemas(aliasName, state.fields, state.primaryKey);
|
|
52502
52741
|
aliased[TypeId4] = {
|
|
52503
52742
|
name: aliasName,
|
|
52504
52743
|
baseName: state.baseName,
|
|
@@ -52529,12 +52768,12 @@ var alias = (table, aliasName) => {
|
|
|
52529
52768
|
}
|
|
52530
52769
|
return aliased;
|
|
52531
52770
|
};
|
|
52532
|
-
function Class(
|
|
52771
|
+
function Class(name2, schemaName) {
|
|
52533
52772
|
const resolvedSchemaName = arguments.length >= 2 ? schemaName : "public";
|
|
52534
52773
|
return (fields2) => {
|
|
52535
52774
|
|
|
52536
52775
|
class TableClassBase {
|
|
52537
|
-
static tableName =
|
|
52776
|
+
static tableName = name2;
|
|
52538
52777
|
static get columns() {
|
|
52539
52778
|
return ensureClassArtifacts(this).columns;
|
|
52540
52779
|
}
|
|
@@ -52545,8 +52784,8 @@ function Class(name, schemaName) {
|
|
|
52545
52784
|
const declaredOptions = extractDeclaredOptions(this[options]);
|
|
52546
52785
|
validateClassOptions(declaredOptions);
|
|
52547
52786
|
return {
|
|
52548
|
-
name,
|
|
52549
|
-
baseName:
|
|
52787
|
+
name: name2,
|
|
52788
|
+
baseName: name2,
|
|
52550
52789
|
schemaName: resolvedSchemaName,
|
|
52551
52790
|
fields: fields2,
|
|
52552
52791
|
primaryKey: resolvePrimaryKeyColumns(fields2, collectInlineOptions(fields2)),
|
|
@@ -52559,10 +52798,10 @@ function Class(name, schemaName) {
|
|
|
52559
52798
|
selection: artifacts.columns,
|
|
52560
52799
|
required: undefined,
|
|
52561
52800
|
available: {
|
|
52562
|
-
[
|
|
52563
|
-
name,
|
|
52801
|
+
[name2]: {
|
|
52802
|
+
name: name2,
|
|
52564
52803
|
mode: "required",
|
|
52565
|
-
baseName:
|
|
52804
|
+
baseName: name2
|
|
52566
52805
|
}
|
|
52567
52806
|
},
|
|
52568
52807
|
dialect: resolveFieldDialect(fields2)
|
|
@@ -52595,11 +52834,11 @@ var unique3 = (columns) => makeOption({
|
|
|
52595
52834
|
kind: "unique",
|
|
52596
52835
|
columns: normalizeColumnList(columns)
|
|
52597
52836
|
});
|
|
52598
|
-
var
|
|
52837
|
+
var index2 = (columns) => makeOption({
|
|
52599
52838
|
kind: "index",
|
|
52600
52839
|
columns: normalizeColumnList(columns)
|
|
52601
52840
|
});
|
|
52602
|
-
var
|
|
52841
|
+
var foreignKey2 = (columns, target, referencedColumns) => makeOption({
|
|
52603
52842
|
kind: "foreignKey",
|
|
52604
52843
|
columns: normalizeColumnList(columns),
|
|
52605
52844
|
references: () => ({
|
|
@@ -52609,9 +52848,9 @@ var foreignKey = (columns, target, referencedColumns) => makeOption({
|
|
|
52609
52848
|
knownColumns: Object.keys(target()[TypeId4].fields)
|
|
52610
52849
|
})
|
|
52611
52850
|
});
|
|
52612
|
-
var check = (
|
|
52851
|
+
var check = (name2, predicate) => makeOption({
|
|
52613
52852
|
kind: "check",
|
|
52614
|
-
name,
|
|
52853
|
+
name: name2,
|
|
52615
52854
|
predicate
|
|
52616
52855
|
});
|
|
52617
52856
|
|
|
@@ -52621,6 +52860,535 @@ import { pipeArguments as pipeArguments3 } from "effect/Pipeable";
|
|
|
52621
52860
|
// src/internal/query-ast.ts
|
|
52622
52861
|
var TypeId5 = Symbol.for("effect-qb/QueryAst");
|
|
52623
52862
|
|
|
52863
|
+
// src/internal/predicate-runtime.ts
|
|
52864
|
+
var trueFormula = () => ({ kind: "true" });
|
|
52865
|
+
var falseFormula = () => ({ kind: "false" });
|
|
52866
|
+
var atomFormula = (atom) => ({ kind: "atom", atom });
|
|
52867
|
+
var allFormula = (items) => normalizeFormula({ kind: "all", items });
|
|
52868
|
+
var anyFormula = (items) => normalizeFormula({ kind: "any", items });
|
|
52869
|
+
var notFormula = (item) => normalizeFormula({ kind: "not", item });
|
|
52870
|
+
var andFormula = (left, right) => allFormula([left, right]);
|
|
52871
|
+
var unknownTag = (tag) => atomFormula({ kind: "unknown", tag });
|
|
52872
|
+
var emptyContext = () => ({
|
|
52873
|
+
nonNullKeys: new Set,
|
|
52874
|
+
nullKeys: new Set,
|
|
52875
|
+
eqLiterals: new Map,
|
|
52876
|
+
neqLiterals: new Map,
|
|
52877
|
+
sourceNames: new Set,
|
|
52878
|
+
contradiction: false,
|
|
52879
|
+
unknown: false
|
|
52880
|
+
});
|
|
52881
|
+
var cloneContext = (context) => ({
|
|
52882
|
+
nonNullKeys: new Set(context.nonNullKeys),
|
|
52883
|
+
nullKeys: new Set(context.nullKeys),
|
|
52884
|
+
eqLiterals: new Map(context.eqLiterals),
|
|
52885
|
+
neqLiterals: new Map(Array.from(context.neqLiterals.entries(), ([key, values]) => [key, new Set(values)])),
|
|
52886
|
+
sourceNames: new Set(context.sourceNames),
|
|
52887
|
+
contradiction: context.contradiction,
|
|
52888
|
+
unknown: context.unknown
|
|
52889
|
+
});
|
|
52890
|
+
var freezeContext = (context) => context;
|
|
52891
|
+
var sourceNameOfKey = (key) => key.split(".", 1)[0] ?? key;
|
|
52892
|
+
var addSourceName = (context, key) => {
|
|
52893
|
+
context.sourceNames.add(sourceNameOfKey(key));
|
|
52894
|
+
};
|
|
52895
|
+
var addNonNull = (context, key) => {
|
|
52896
|
+
addSourceName(context, key);
|
|
52897
|
+
if (context.nullKeys.has(key)) {
|
|
52898
|
+
context.contradiction = true;
|
|
52899
|
+
}
|
|
52900
|
+
context.nonNullKeys.add(key);
|
|
52901
|
+
};
|
|
52902
|
+
var addNull = (context, key) => {
|
|
52903
|
+
addSourceName(context, key);
|
|
52904
|
+
if (context.nonNullKeys.has(key)) {
|
|
52905
|
+
context.contradiction = true;
|
|
52906
|
+
}
|
|
52907
|
+
context.nullKeys.add(key);
|
|
52908
|
+
};
|
|
52909
|
+
var addEqLiteral = (context, key, value) => {
|
|
52910
|
+
addNonNull(context, key);
|
|
52911
|
+
const existing = context.eqLiterals.get(key);
|
|
52912
|
+
if (existing !== undefined && existing !== value) {
|
|
52913
|
+
context.contradiction = true;
|
|
52914
|
+
}
|
|
52915
|
+
const neqValues = context.neqLiterals.get(key);
|
|
52916
|
+
if (neqValues?.has(value)) {
|
|
52917
|
+
context.contradiction = true;
|
|
52918
|
+
}
|
|
52919
|
+
context.eqLiterals.set(key, value);
|
|
52920
|
+
};
|
|
52921
|
+
var addNeqLiteral = (context, key, value) => {
|
|
52922
|
+
addNonNull(context, key);
|
|
52923
|
+
if (context.eqLiterals.get(key) === value) {
|
|
52924
|
+
context.contradiction = true;
|
|
52925
|
+
}
|
|
52926
|
+
const values = context.neqLiterals.get(key) ?? new Set;
|
|
52927
|
+
values.add(value);
|
|
52928
|
+
context.neqLiterals.set(key, values);
|
|
52929
|
+
};
|
|
52930
|
+
var applyEqColumn = (context, left, right) => {
|
|
52931
|
+
const leftValue = context.eqLiterals.get(left);
|
|
52932
|
+
const rightValue = context.eqLiterals.get(right);
|
|
52933
|
+
if (leftValue === undefined && rightValue === undefined) {
|
|
52934
|
+
addNonNull(context, left);
|
|
52935
|
+
addNonNull(context, right);
|
|
52936
|
+
return;
|
|
52937
|
+
}
|
|
52938
|
+
if (leftValue === undefined && rightValue !== undefined) {
|
|
52939
|
+
addNonNull(context, left);
|
|
52940
|
+
addEqLiteral(context, left, rightValue);
|
|
52941
|
+
return;
|
|
52942
|
+
}
|
|
52943
|
+
if (leftValue !== undefined && rightValue === undefined) {
|
|
52944
|
+
addNonNull(context, right);
|
|
52945
|
+
addEqLiteral(context, right, leftValue);
|
|
52946
|
+
return;
|
|
52947
|
+
}
|
|
52948
|
+
if (leftValue === rightValue) {
|
|
52949
|
+
addEqLiteral(context, left, leftValue);
|
|
52950
|
+
addEqLiteral(context, right, rightValue);
|
|
52951
|
+
return;
|
|
52952
|
+
}
|
|
52953
|
+
context.contradiction = true;
|
|
52954
|
+
};
|
|
52955
|
+
var applyAtom = (context, atom) => {
|
|
52956
|
+
switch (atom.kind) {
|
|
52957
|
+
case "is-null":
|
|
52958
|
+
addNull(context, atom.key);
|
|
52959
|
+
return;
|
|
52960
|
+
case "is-not-null":
|
|
52961
|
+
addNonNull(context, atom.key);
|
|
52962
|
+
return;
|
|
52963
|
+
case "eq-literal":
|
|
52964
|
+
addEqLiteral(context, atom.key, atom.value);
|
|
52965
|
+
return;
|
|
52966
|
+
case "neq-literal":
|
|
52967
|
+
addNeqLiteral(context, atom.key, atom.value);
|
|
52968
|
+
return;
|
|
52969
|
+
case "eq-column":
|
|
52970
|
+
applyEqColumn(context, atom.left, atom.right);
|
|
52971
|
+
return;
|
|
52972
|
+
case "unknown":
|
|
52973
|
+
context.unknown = true;
|
|
52974
|
+
return;
|
|
52975
|
+
}
|
|
52976
|
+
};
|
|
52977
|
+
var applyNegativeAtom = (context, atom) => {
|
|
52978
|
+
switch (atom.kind) {
|
|
52979
|
+
case "is-null":
|
|
52980
|
+
addNonNull(context, atom.key);
|
|
52981
|
+
return;
|
|
52982
|
+
case "is-not-null":
|
|
52983
|
+
addNull(context, atom.key);
|
|
52984
|
+
return;
|
|
52985
|
+
case "eq-literal":
|
|
52986
|
+
addNeqLiteral(context, atom.key, atom.value);
|
|
52987
|
+
return;
|
|
52988
|
+
case "neq-literal":
|
|
52989
|
+
addEqLiteral(context, atom.key, atom.value);
|
|
52990
|
+
return;
|
|
52991
|
+
case "eq-column":
|
|
52992
|
+
addNonNull(context, atom.left);
|
|
52993
|
+
addNonNull(context, atom.right);
|
|
52994
|
+
return;
|
|
52995
|
+
case "unknown":
|
|
52996
|
+
context.unknown = true;
|
|
52997
|
+
return;
|
|
52998
|
+
}
|
|
52999
|
+
};
|
|
53000
|
+
var intersectEqLiterals = (left, right) => {
|
|
53001
|
+
const result = new Map;
|
|
53002
|
+
for (const [key, value] of left) {
|
|
53003
|
+
if (right.get(key) === value) {
|
|
53004
|
+
result.set(key, value);
|
|
53005
|
+
}
|
|
53006
|
+
}
|
|
53007
|
+
return result;
|
|
53008
|
+
};
|
|
53009
|
+
var intersectNeqLiterals = (left, right) => {
|
|
53010
|
+
const result = new Map;
|
|
53011
|
+
for (const [key, leftValues] of left) {
|
|
53012
|
+
const rightValues = right.get(key);
|
|
53013
|
+
if (rightValues === undefined) {
|
|
53014
|
+
continue;
|
|
53015
|
+
}
|
|
53016
|
+
const next = new Set(Array.from(leftValues).filter((value) => rightValues.has(value)));
|
|
53017
|
+
if (next.size > 0) {
|
|
53018
|
+
result.set(key, next);
|
|
53019
|
+
}
|
|
53020
|
+
}
|
|
53021
|
+
return result;
|
|
53022
|
+
};
|
|
53023
|
+
var intersectContexts = (left, right) => {
|
|
53024
|
+
if (left.contradiction) {
|
|
53025
|
+
return cloneContext(right);
|
|
53026
|
+
}
|
|
53027
|
+
if (right.contradiction) {
|
|
53028
|
+
return cloneContext(left);
|
|
53029
|
+
}
|
|
53030
|
+
return {
|
|
53031
|
+
nonNullKeys: new Set(Array.from(left.nonNullKeys).filter((key) => right.nonNullKeys.has(key))),
|
|
53032
|
+
nullKeys: new Set(Array.from(left.nullKeys).filter((key) => right.nullKeys.has(key))),
|
|
53033
|
+
eqLiterals: intersectEqLiterals(left.eqLiterals, right.eqLiterals),
|
|
53034
|
+
neqLiterals: intersectNeqLiterals(left.neqLiterals, right.neqLiterals),
|
|
53035
|
+
sourceNames: new Set(Array.from(left.sourceNames).filter((name2) => right.sourceNames.has(name2))),
|
|
53036
|
+
contradiction: false,
|
|
53037
|
+
unknown: left.unknown || right.unknown
|
|
53038
|
+
};
|
|
53039
|
+
};
|
|
53040
|
+
var analyzeBranchSet = (context, items, polarity) => {
|
|
53041
|
+
let current;
|
|
53042
|
+
for (const item of items) {
|
|
53043
|
+
const branch = analyzeStack(cloneContext(context), [{ formula: item, polarity }]);
|
|
53044
|
+
if (branch.contradiction) {
|
|
53045
|
+
continue;
|
|
53046
|
+
}
|
|
53047
|
+
current = current === undefined ? branch : intersectContexts(current, branch);
|
|
53048
|
+
}
|
|
53049
|
+
if (current === undefined) {
|
|
53050
|
+
const next = cloneContext(context);
|
|
53051
|
+
next.contradiction = true;
|
|
53052
|
+
return next;
|
|
53053
|
+
}
|
|
53054
|
+
return current;
|
|
53055
|
+
};
|
|
53056
|
+
var analyzeStack = (context, stack) => {
|
|
53057
|
+
const queue = [...stack];
|
|
53058
|
+
while (queue.length > 0 && !context.contradiction) {
|
|
53059
|
+
const frame = queue.shift();
|
|
53060
|
+
switch (frame.formula.kind) {
|
|
53061
|
+
case "true":
|
|
53062
|
+
if (frame.polarity === "negative") {
|
|
53063
|
+
context.contradiction = true;
|
|
53064
|
+
}
|
|
53065
|
+
break;
|
|
53066
|
+
case "false":
|
|
53067
|
+
if (frame.polarity === "positive") {
|
|
53068
|
+
context.contradiction = true;
|
|
53069
|
+
}
|
|
53070
|
+
break;
|
|
53071
|
+
case "atom":
|
|
53072
|
+
if (frame.polarity === "positive") {
|
|
53073
|
+
applyAtom(context, frame.formula.atom);
|
|
53074
|
+
} else {
|
|
53075
|
+
applyNegativeAtom(context, frame.formula.atom);
|
|
53076
|
+
}
|
|
53077
|
+
break;
|
|
53078
|
+
case "not":
|
|
53079
|
+
queue.unshift({
|
|
53080
|
+
formula: frame.formula.item,
|
|
53081
|
+
polarity: frame.polarity === "positive" ? "negative" : "positive"
|
|
53082
|
+
});
|
|
53083
|
+
break;
|
|
53084
|
+
case "all":
|
|
53085
|
+
if (frame.polarity === "positive") {
|
|
53086
|
+
queue.unshift(...frame.formula.items.map((formula) => ({ formula, polarity: "positive" })));
|
|
53087
|
+
} else {
|
|
53088
|
+
context = analyzeBranchSet(context, frame.formula.items, "negative");
|
|
53089
|
+
}
|
|
53090
|
+
break;
|
|
53091
|
+
case "any":
|
|
53092
|
+
if (frame.polarity === "positive") {
|
|
53093
|
+
context = analyzeBranchSet(context, frame.formula.items, "positive");
|
|
53094
|
+
} else {
|
|
53095
|
+
queue.unshift(...frame.formula.items.map((formula) => ({ formula, polarity: "negative" })));
|
|
53096
|
+
}
|
|
53097
|
+
break;
|
|
53098
|
+
}
|
|
53099
|
+
}
|
|
53100
|
+
return context;
|
|
53101
|
+
};
|
|
53102
|
+
var analyzeFormula = (formula) => freezeContext(analyzeStack(emptyContext(), [{ formula, polarity: "positive" }]));
|
|
53103
|
+
var astOf = (value) => value[TypeId2];
|
|
53104
|
+
var columnKeyOfExpression = (value) => {
|
|
53105
|
+
const ast = astOf(value);
|
|
53106
|
+
return ast.kind === "column" ? `${ast.tableName}.${ast.columnName}` : undefined;
|
|
53107
|
+
};
|
|
53108
|
+
var valueKeyOfLiteral = (value) => {
|
|
53109
|
+
if (typeof value === "string") {
|
|
53110
|
+
return `string:${value}`;
|
|
53111
|
+
}
|
|
53112
|
+
if (typeof value === "number") {
|
|
53113
|
+
return `number:${value}`;
|
|
53114
|
+
}
|
|
53115
|
+
if (typeof value === "boolean") {
|
|
53116
|
+
return `boolean:${value}`;
|
|
53117
|
+
}
|
|
53118
|
+
if (value === null) {
|
|
53119
|
+
return "null";
|
|
53120
|
+
}
|
|
53121
|
+
if (value instanceof Date) {
|
|
53122
|
+
return `date:${value.toISOString()}`;
|
|
53123
|
+
}
|
|
53124
|
+
return "unknown";
|
|
53125
|
+
};
|
|
53126
|
+
var nonNullFactsOfExpression = (value) => {
|
|
53127
|
+
const key = columnKeyOfExpression(value);
|
|
53128
|
+
return key === undefined ? undefined : atomFormula({ kind: "is-not-null", key });
|
|
53129
|
+
};
|
|
53130
|
+
var combineFacts = (left, right) => {
|
|
53131
|
+
if (left === undefined) {
|
|
53132
|
+
return right ?? trueFormula();
|
|
53133
|
+
}
|
|
53134
|
+
if (right === undefined) {
|
|
53135
|
+
return left;
|
|
53136
|
+
}
|
|
53137
|
+
return andFormula(left, right);
|
|
53138
|
+
};
|
|
53139
|
+
var formulaOfEq = (left, right) => {
|
|
53140
|
+
const leftKey = columnKeyOfExpression(left);
|
|
53141
|
+
const rightKey = columnKeyOfExpression(right);
|
|
53142
|
+
const leftAst = astOf(left);
|
|
53143
|
+
const rightAst = astOf(right);
|
|
53144
|
+
const leftLiteral = leftAst.kind === "literal" ? leftAst.value : undefined;
|
|
53145
|
+
const rightLiteral = rightAst.kind === "literal" ? rightAst.value : undefined;
|
|
53146
|
+
if (leftKey === undefined && rightKey === undefined) {
|
|
53147
|
+
if (leftAst.kind !== "literal" || rightAst.kind !== "literal") {
|
|
53148
|
+
return unknownTag("eq:unsupported");
|
|
53149
|
+
}
|
|
53150
|
+
if (leftLiteral === null || rightLiteral === null) {
|
|
53151
|
+
return falseFormula();
|
|
53152
|
+
}
|
|
53153
|
+
return Object.is(leftLiteral, rightLiteral) ? trueFormula() : falseFormula();
|
|
53154
|
+
}
|
|
53155
|
+
if (leftKey === undefined) {
|
|
53156
|
+
if (leftAst.kind !== "literal") {
|
|
53157
|
+
return unknownTag("eq:unsupported");
|
|
53158
|
+
}
|
|
53159
|
+
if (leftLiteral === null) {
|
|
53160
|
+
return falseFormula();
|
|
53161
|
+
}
|
|
53162
|
+
return atomFormula({
|
|
53163
|
+
kind: "eq-literal",
|
|
53164
|
+
key: rightKey,
|
|
53165
|
+
value: valueKeyOfLiteral(leftLiteral)
|
|
53166
|
+
});
|
|
53167
|
+
}
|
|
53168
|
+
if (rightKey === undefined) {
|
|
53169
|
+
if (rightAst.kind !== "literal") {
|
|
53170
|
+
return unknownTag("eq:unsupported");
|
|
53171
|
+
}
|
|
53172
|
+
if (rightLiteral === null) {
|
|
53173
|
+
return falseFormula();
|
|
53174
|
+
}
|
|
53175
|
+
return atomFormula({
|
|
53176
|
+
kind: "eq-literal",
|
|
53177
|
+
key: leftKey,
|
|
53178
|
+
value: valueKeyOfLiteral(rightLiteral)
|
|
53179
|
+
});
|
|
53180
|
+
}
|
|
53181
|
+
return atomFormula({
|
|
53182
|
+
kind: "eq-column",
|
|
53183
|
+
left: leftKey,
|
|
53184
|
+
right: rightKey
|
|
53185
|
+
});
|
|
53186
|
+
};
|
|
53187
|
+
var formulaOfNeq = (left, right) => {
|
|
53188
|
+
const leftKey = columnKeyOfExpression(left);
|
|
53189
|
+
const rightKey = columnKeyOfExpression(right);
|
|
53190
|
+
const leftAst = astOf(left);
|
|
53191
|
+
const rightAst = astOf(right);
|
|
53192
|
+
const leftLiteral = leftAst.kind === "literal" ? leftAst.value : undefined;
|
|
53193
|
+
const rightLiteral = rightAst.kind === "literal" ? rightAst.value : undefined;
|
|
53194
|
+
if (leftKey === undefined && rightKey === undefined) {
|
|
53195
|
+
if (leftAst.kind !== "literal" || rightAst.kind !== "literal") {
|
|
53196
|
+
return unknownTag("neq:unsupported");
|
|
53197
|
+
}
|
|
53198
|
+
if (leftLiteral === null || rightLiteral === null) {
|
|
53199
|
+
return falseFormula();
|
|
53200
|
+
}
|
|
53201
|
+
return Object.is(leftLiteral, rightLiteral) ? falseFormula() : trueFormula();
|
|
53202
|
+
}
|
|
53203
|
+
if (leftKey === undefined) {
|
|
53204
|
+
if (leftAst.kind !== "literal") {
|
|
53205
|
+
return unknownTag("neq:unsupported");
|
|
53206
|
+
}
|
|
53207
|
+
if (leftLiteral === null) {
|
|
53208
|
+
return falseFormula();
|
|
53209
|
+
}
|
|
53210
|
+
return atomFormula({
|
|
53211
|
+
kind: "neq-literal",
|
|
53212
|
+
key: rightKey,
|
|
53213
|
+
value: valueKeyOfLiteral(leftLiteral)
|
|
53214
|
+
});
|
|
53215
|
+
}
|
|
53216
|
+
if (rightKey === undefined) {
|
|
53217
|
+
if (rightAst.kind !== "literal") {
|
|
53218
|
+
return unknownTag("neq:unsupported");
|
|
53219
|
+
}
|
|
53220
|
+
if (rightLiteral === null) {
|
|
53221
|
+
return falseFormula();
|
|
53222
|
+
}
|
|
53223
|
+
return atomFormula({
|
|
53224
|
+
kind: "neq-literal",
|
|
53225
|
+
key: leftKey,
|
|
53226
|
+
value: valueKeyOfLiteral(rightLiteral)
|
|
53227
|
+
});
|
|
53228
|
+
}
|
|
53229
|
+
return combineFacts(nonNullFactsOfExpression(left), nonNullFactsOfExpression(right));
|
|
53230
|
+
};
|
|
53231
|
+
var formulaOfIsNotDistinctFrom = (left, right) => {
|
|
53232
|
+
const leftKey = columnKeyOfExpression(left);
|
|
53233
|
+
const rightKey = columnKeyOfExpression(right);
|
|
53234
|
+
const leftAst = astOf(left);
|
|
53235
|
+
const rightAst = astOf(right);
|
|
53236
|
+
const leftLiteral = leftAst.kind === "literal" ? leftAst.value : undefined;
|
|
53237
|
+
const rightLiteral = rightAst.kind === "literal" ? rightAst.value : undefined;
|
|
53238
|
+
if (leftAst.kind === "literal" && rightAst.kind === "literal") {
|
|
53239
|
+
return Object.is(leftLiteral, rightLiteral) ? trueFormula() : falseFormula();
|
|
53240
|
+
}
|
|
53241
|
+
if (leftAst.kind === "literal" && leftLiteral === null && rightKey !== undefined) {
|
|
53242
|
+
return atomFormula({ kind: "is-null", key: rightKey });
|
|
53243
|
+
}
|
|
53244
|
+
if (rightAst.kind === "literal" && rightLiteral === null && leftKey !== undefined) {
|
|
53245
|
+
return atomFormula({ kind: "is-null", key: leftKey });
|
|
53246
|
+
}
|
|
53247
|
+
if (leftAst.kind === "literal" && rightKey !== undefined) {
|
|
53248
|
+
return atomFormula({
|
|
53249
|
+
kind: "eq-literal",
|
|
53250
|
+
key: rightKey,
|
|
53251
|
+
value: valueKeyOfLiteral(leftLiteral)
|
|
53252
|
+
});
|
|
53253
|
+
}
|
|
53254
|
+
if (rightAst.kind === "literal" && leftKey !== undefined) {
|
|
53255
|
+
return atomFormula({
|
|
53256
|
+
kind: "eq-literal",
|
|
53257
|
+
key: leftKey,
|
|
53258
|
+
value: valueKeyOfLiteral(rightLiteral)
|
|
53259
|
+
});
|
|
53260
|
+
}
|
|
53261
|
+
return unknownTag("isNotDistinctFrom:unsupported");
|
|
53262
|
+
};
|
|
53263
|
+
var normalizeFormula = (formula) => {
|
|
53264
|
+
switch (formula.kind) {
|
|
53265
|
+
case "all": {
|
|
53266
|
+
const items = [];
|
|
53267
|
+
for (const item of formula.items) {
|
|
53268
|
+
const normalized = normalizeFormula(item);
|
|
53269
|
+
if (normalized.kind === "true") {
|
|
53270
|
+
continue;
|
|
53271
|
+
}
|
|
53272
|
+
if (normalized.kind === "false") {
|
|
53273
|
+
return falseFormula();
|
|
53274
|
+
}
|
|
53275
|
+
if (normalized.kind === "all") {
|
|
53276
|
+
items.push(...normalized.items);
|
|
53277
|
+
} else {
|
|
53278
|
+
items.push(normalized);
|
|
53279
|
+
}
|
|
53280
|
+
}
|
|
53281
|
+
if (items.length === 0) {
|
|
53282
|
+
return trueFormula();
|
|
53283
|
+
}
|
|
53284
|
+
if (items.length === 1) {
|
|
53285
|
+
return items[0];
|
|
53286
|
+
}
|
|
53287
|
+
return { kind: "all", items };
|
|
53288
|
+
}
|
|
53289
|
+
case "any": {
|
|
53290
|
+
const items = [];
|
|
53291
|
+
for (const item of formula.items) {
|
|
53292
|
+
const normalized = normalizeFormula(item);
|
|
53293
|
+
if (normalized.kind === "false") {
|
|
53294
|
+
continue;
|
|
53295
|
+
}
|
|
53296
|
+
if (normalized.kind === "true") {
|
|
53297
|
+
return trueFormula();
|
|
53298
|
+
}
|
|
53299
|
+
if (normalized.kind === "any") {
|
|
53300
|
+
items.push(...normalized.items);
|
|
53301
|
+
} else {
|
|
53302
|
+
items.push(normalized);
|
|
53303
|
+
}
|
|
53304
|
+
}
|
|
53305
|
+
if (items.length === 0) {
|
|
53306
|
+
return falseFormula();
|
|
53307
|
+
}
|
|
53308
|
+
if (items.length === 1) {
|
|
53309
|
+
return items[0];
|
|
53310
|
+
}
|
|
53311
|
+
return { kind: "any", items };
|
|
53312
|
+
}
|
|
53313
|
+
case "not": {
|
|
53314
|
+
const item = normalizeFormula(formula.item);
|
|
53315
|
+
if (item.kind === "true") {
|
|
53316
|
+
return falseFormula();
|
|
53317
|
+
}
|
|
53318
|
+
if (item.kind === "false") {
|
|
53319
|
+
return trueFormula();
|
|
53320
|
+
}
|
|
53321
|
+
return { kind: "not", item };
|
|
53322
|
+
}
|
|
53323
|
+
default:
|
|
53324
|
+
return formula;
|
|
53325
|
+
}
|
|
53326
|
+
};
|
|
53327
|
+
var formulaOfExpression = (value) => {
|
|
53328
|
+
const ast = astOf(value);
|
|
53329
|
+
switch (ast.kind) {
|
|
53330
|
+
case "literal":
|
|
53331
|
+
if (ast.value === true) {
|
|
53332
|
+
return trueFormula();
|
|
53333
|
+
}
|
|
53334
|
+
if (ast.value === false) {
|
|
53335
|
+
return falseFormula();
|
|
53336
|
+
}
|
|
53337
|
+
return unknownTag("literal:non-boolean");
|
|
53338
|
+
case "isNull": {
|
|
53339
|
+
const key = columnKeyOfExpression(ast.value);
|
|
53340
|
+
return key === undefined ? unknownTag("isNull:unsupported") : atomFormula({ kind: "is-null", key });
|
|
53341
|
+
}
|
|
53342
|
+
case "isNotNull": {
|
|
53343
|
+
const key = columnKeyOfExpression(ast.value);
|
|
53344
|
+
return key === undefined ? unknownTag("isNotNull:unsupported") : atomFormula({ kind: "is-not-null", key });
|
|
53345
|
+
}
|
|
53346
|
+
case "not":
|
|
53347
|
+
return notFormula(formulaOfExpression(ast.value));
|
|
53348
|
+
case "eq":
|
|
53349
|
+
return formulaOfEq(ast.left, ast.right);
|
|
53350
|
+
case "neq":
|
|
53351
|
+
return formulaOfNeq(ast.left, ast.right);
|
|
53352
|
+
case "isNotDistinctFrom":
|
|
53353
|
+
return formulaOfIsNotDistinctFrom(ast.left, ast.right);
|
|
53354
|
+
case "isDistinctFrom":
|
|
53355
|
+
return notFormula(formulaOfIsNotDistinctFrom(ast.left, ast.right));
|
|
53356
|
+
case "and":
|
|
53357
|
+
return allFormula(ast.values.map((value2) => formulaOfExpression(value2)));
|
|
53358
|
+
case "or":
|
|
53359
|
+
return anyFormula(ast.values.map((value2) => formulaOfExpression(value2)));
|
|
53360
|
+
case "in": {
|
|
53361
|
+
const [left, ...rest] = ast.values;
|
|
53362
|
+
return left === undefined ? falseFormula() : anyFormula(rest.map((value2) => formulaOfEq(left, value2)));
|
|
53363
|
+
}
|
|
53364
|
+
case "notIn": {
|
|
53365
|
+
const [left, ...rest] = ast.values;
|
|
53366
|
+
return left === undefined ? trueFormula() : allFormula(rest.map((value2) => formulaOfNeq(left, value2)));
|
|
53367
|
+
}
|
|
53368
|
+
case "between":
|
|
53369
|
+
return combineFacts(ast.values.reduce((current, entry) => combineFacts(current, nonNullFactsOfExpression(entry)), undefined), unknownTag("variadic:between"));
|
|
53370
|
+
case "lt":
|
|
53371
|
+
case "lte":
|
|
53372
|
+
case "gt":
|
|
53373
|
+
case "gte":
|
|
53374
|
+
case "like":
|
|
53375
|
+
case "ilike":
|
|
53376
|
+
case "contains":
|
|
53377
|
+
case "containedBy":
|
|
53378
|
+
case "overlaps":
|
|
53379
|
+
return combineFacts(nonNullFactsOfExpression(ast.left), nonNullFactsOfExpression(ast.right));
|
|
53380
|
+
default:
|
|
53381
|
+
return unknownTag(`expr:${ast.kind}`);
|
|
53382
|
+
}
|
|
53383
|
+
};
|
|
53384
|
+
var assumeFormulaTrue = (assumptions, formula) => assumptions.kind === "true" ? formula : andFormula(assumptions, formula);
|
|
53385
|
+
var assumeFormulaFalse = (assumptions, formula) => assumptions.kind === "true" ? notFormula(formula) : andFormula(assumptions, notFormula(formula));
|
|
53386
|
+
var contradictsFormula = (assumptions, formula) => analyzeFormula(andFormula(assumptions, formula)).contradiction;
|
|
53387
|
+
var impliesFormula = (assumptions, formula) => analyzeFormula(andFormula(assumptions, notFormula(formula))).contradiction;
|
|
53388
|
+
var guaranteedNonNullKeys = (assumptions) => analyzeFormula(assumptions).nonNullKeys;
|
|
53389
|
+
var guaranteedNullKeys = (assumptions) => analyzeFormula(assumptions).nullKeys;
|
|
53390
|
+
var guaranteedSourceNames = (assumptions) => analyzeFormula(assumptions).sourceNames;
|
|
53391
|
+
|
|
52624
53392
|
// src/internal/query.ts
|
|
52625
53393
|
var ExpressionProto = {
|
|
52626
53394
|
pipe() {
|
|
@@ -52668,7 +53436,7 @@ var makePlan = (state, ast, _assumptions, _capabilities, _statement, _target, _i
|
|
|
52668
53436
|
required: undefined,
|
|
52669
53437
|
availableNames: undefined,
|
|
52670
53438
|
grouped: undefined,
|
|
52671
|
-
assumptions:
|
|
53439
|
+
assumptions: _assumptions ?? trueFormula(),
|
|
52672
53440
|
capabilities: undefined,
|
|
52673
53441
|
statement: _statement ?? "select",
|
|
52674
53442
|
target: _target ?? undefined,
|
|
@@ -52708,6 +53476,119 @@ var extractSingleSelectedExpressionRuntime = (selection) => {
|
|
|
52708
53476
|
};
|
|
52709
53477
|
var currentRequiredList = (required) => Array.isArray(required) ? [...required] : required === undefined ? [] : [required];
|
|
52710
53478
|
|
|
53479
|
+
// src/internal/implication-runtime.ts
|
|
53480
|
+
var presentFormulaOfSource = (source) => source._presentFormula ?? trueFormula();
|
|
53481
|
+
var collectPresenceWitnesses = (selection, output) => {
|
|
53482
|
+
if (typeof selection !== "object" || selection === null) {
|
|
53483
|
+
return;
|
|
53484
|
+
}
|
|
53485
|
+
if (TypeId in selection && TypeId2 in selection) {
|
|
53486
|
+
const expression = selection;
|
|
53487
|
+
const ast = expression[TypeId2];
|
|
53488
|
+
if (ast.kind === "column" && expression[TypeId].nullability === "never") {
|
|
53489
|
+
output.add(`${ast.tableName}.${ast.columnName}`);
|
|
53490
|
+
}
|
|
53491
|
+
return;
|
|
53492
|
+
}
|
|
53493
|
+
for (const value of Object.values(selection)) {
|
|
53494
|
+
collectPresenceWitnesses(value, output);
|
|
53495
|
+
}
|
|
53496
|
+
};
|
|
53497
|
+
var presenceWitnessesOfSourceLike = (source) => {
|
|
53498
|
+
const output = new Set;
|
|
53499
|
+
if (typeof source !== "object" || source === null) {
|
|
53500
|
+
return [];
|
|
53501
|
+
}
|
|
53502
|
+
if (TypeId4 in source) {
|
|
53503
|
+
collectPresenceWitnesses(source[TypeId3].selection, output);
|
|
53504
|
+
return [...output];
|
|
53505
|
+
}
|
|
53506
|
+
if ("columns" in source) {
|
|
53507
|
+
collectPresenceWitnesses(source.columns, output);
|
|
53508
|
+
}
|
|
53509
|
+
return [...output];
|
|
53510
|
+
};
|
|
53511
|
+
var directAbsentSourceNames = (available, assumptions) => {
|
|
53512
|
+
const nullKeys = guaranteedNullKeys(assumptions);
|
|
53513
|
+
const absent = new Set;
|
|
53514
|
+
for (const [name2, source] of Object.entries(available)) {
|
|
53515
|
+
if (source._presenceWitnesses?.some((key) => nullKeys.has(key))) {
|
|
53516
|
+
absent.add(name2);
|
|
53517
|
+
continue;
|
|
53518
|
+
}
|
|
53519
|
+
if (contradictsFormula(assumptions, presentFormulaOfSource(source))) {
|
|
53520
|
+
absent.add(name2);
|
|
53521
|
+
}
|
|
53522
|
+
}
|
|
53523
|
+
return absent;
|
|
53524
|
+
};
|
|
53525
|
+
var propagateAbsentSourceNames = (available, seed) => {
|
|
53526
|
+
const absent = new Set(seed);
|
|
53527
|
+
let changed = true;
|
|
53528
|
+
while (changed) {
|
|
53529
|
+
changed = false;
|
|
53530
|
+
for (const [name2, source] of Object.entries(available)) {
|
|
53531
|
+
if (absent.has(name2)) {
|
|
53532
|
+
continue;
|
|
53533
|
+
}
|
|
53534
|
+
const required = guaranteedSourceNames(presentFormulaOfSource(source));
|
|
53535
|
+
if (Array.from(required).some((dependency) => absent.has(dependency))) {
|
|
53536
|
+
absent.add(name2);
|
|
53537
|
+
changed = true;
|
|
53538
|
+
}
|
|
53539
|
+
}
|
|
53540
|
+
}
|
|
53541
|
+
return absent;
|
|
53542
|
+
};
|
|
53543
|
+
var resolveImplicationScope = (available, initialAssumptions) => {
|
|
53544
|
+
let assumptions = initialAssumptions;
|
|
53545
|
+
const required = new Set(Object.entries(available).filter(([, source]) => source.mode === "required").map(([name2]) => name2));
|
|
53546
|
+
const appliedRequired = new Set;
|
|
53547
|
+
let absent = new Set;
|
|
53548
|
+
let changed = true;
|
|
53549
|
+
while (changed) {
|
|
53550
|
+
changed = false;
|
|
53551
|
+
for (const name2 of guaranteedSourceNames(assumptions)) {
|
|
53552
|
+
if (!required.has(name2)) {
|
|
53553
|
+
required.add(name2);
|
|
53554
|
+
changed = true;
|
|
53555
|
+
}
|
|
53556
|
+
}
|
|
53557
|
+
for (const name2 of required) {
|
|
53558
|
+
if (absent.has(name2) || appliedRequired.has(name2)) {
|
|
53559
|
+
continue;
|
|
53560
|
+
}
|
|
53561
|
+
const source = available[name2];
|
|
53562
|
+
if (source === undefined) {
|
|
53563
|
+
continue;
|
|
53564
|
+
}
|
|
53565
|
+
assumptions = assumeFormulaTrue(assumptions, presentFormulaOfSource(source));
|
|
53566
|
+
appliedRequired.add(name2);
|
|
53567
|
+
changed = true;
|
|
53568
|
+
}
|
|
53569
|
+
const nextAbsent = propagateAbsentSourceNames(available, directAbsentSourceNames(available, assumptions));
|
|
53570
|
+
if (nextAbsent.size !== absent.size || Array.from(nextAbsent).some((name2) => !absent.has(name2))) {
|
|
53571
|
+
absent = nextAbsent;
|
|
53572
|
+
changed = true;
|
|
53573
|
+
}
|
|
53574
|
+
}
|
|
53575
|
+
for (const name2 of absent) {
|
|
53576
|
+
required.delete(name2);
|
|
53577
|
+
}
|
|
53578
|
+
const sourceModes = new Map;
|
|
53579
|
+
for (const [name2, source] of Object.entries(available)) {
|
|
53580
|
+
sourceModes.set(name2, required.has(name2) ? "required" : source.mode);
|
|
53581
|
+
}
|
|
53582
|
+
return {
|
|
53583
|
+
assumptions,
|
|
53584
|
+
nonNullKeys: guaranteedNonNullKeys(assumptions),
|
|
53585
|
+
nullKeys: guaranteedNullKeys(assumptions),
|
|
53586
|
+
requiredSourceNames: required,
|
|
53587
|
+
absentSourceNames: absent,
|
|
53588
|
+
sourceModes
|
|
53589
|
+
};
|
|
53590
|
+
};
|
|
53591
|
+
|
|
52711
53592
|
// src/internal/json/path.ts
|
|
52712
53593
|
var SegmentTypeId = Symbol.for("effect-qb/JsonPathSegment");
|
|
52713
53594
|
var TypeId6 = Symbol.for("effect-qb/JsonPath");
|
|
@@ -52719,7 +53600,7 @@ var key = (value) => makeSegment({
|
|
|
52719
53600
|
kind: "key",
|
|
52720
53601
|
key: value
|
|
52721
53602
|
});
|
|
52722
|
-
var
|
|
53603
|
+
var index3 = (value) => makeSegment({
|
|
52723
53604
|
[SegmentTypeId]: {
|
|
52724
53605
|
kind: "index"
|
|
52725
53606
|
},
|
|
@@ -52839,7 +53720,7 @@ var isExpression = (value) => typeof value === "object" && value !== null && (Ty
|
|
|
52839
53720
|
var projectionAliasOf = (expression) => (TypeId7 in expression) ? expression[TypeId7].alias : undefined;
|
|
52840
53721
|
var pathKeyOf = (path2) => JSON.stringify(path2);
|
|
52841
53722
|
var formatProjectionPath = (path2) => path2.join(".");
|
|
52842
|
-
var isPrefixPath = (left, right) => left.length < right.length && left.every((segment,
|
|
53723
|
+
var isPrefixPath = (left, right) => left.length < right.length && left.every((segment, index4) => segment === right[index4]);
|
|
52843
53724
|
var flattenSelection = (selection, path2 = []) => {
|
|
52844
53725
|
const fields2 = [];
|
|
52845
53726
|
for (const [key2, value] of Object.entries(selection)) {
|
|
@@ -52870,9 +53751,9 @@ var validateProjections = (projections) => {
|
|
|
52870
53751
|
}
|
|
52871
53752
|
pathKeys.add(pathKey);
|
|
52872
53753
|
}
|
|
52873
|
-
for (let
|
|
52874
|
-
const current = projections[
|
|
52875
|
-
for (let compareIndex =
|
|
53754
|
+
for (let index4 = 0;index4 < projections.length; index4++) {
|
|
53755
|
+
const current = projections[index4];
|
|
53756
|
+
for (let compareIndex = index4 + 1;compareIndex < projections.length; compareIndex++) {
|
|
52876
53757
|
const other = projections[compareIndex];
|
|
52877
53758
|
if (isPrefixPath(current.path, other.path) || isPrefixPath(other.path, current.path)) {
|
|
52878
53759
|
throw new Error(`Conflicting projection paths: ${formatProjectionPath(current.path)} conflicts with ${formatProjectionPath(other.path)}`);
|
|
@@ -52889,8 +53770,8 @@ var DerivedProto = {
|
|
|
52889
53770
|
};
|
|
52890
53771
|
var setPath = (target, path2, value) => {
|
|
52891
53772
|
let current = target;
|
|
52892
|
-
for (let
|
|
52893
|
-
const segment = path2[
|
|
53773
|
+
for (let index4 = 0;index4 < path2.length - 1; index4++) {
|
|
53774
|
+
const segment = path2[index4];
|
|
52894
53775
|
const existing = current[segment];
|
|
52895
53776
|
if (typeof existing === "object" && existing !== null && !Array.isArray(existing)) {
|
|
52896
53777
|
current = existing;
|
|
@@ -52977,8 +53858,17 @@ var makeLateralSource = (plan, alias2) => {
|
|
|
52977
53858
|
return lateral;
|
|
52978
53859
|
};
|
|
52979
53860
|
|
|
52980
|
-
// src/internal/query
|
|
52981
|
-
|
|
53861
|
+
// src/internal/mysql-query.ts
|
|
53862
|
+
var mysqlQuery = (() => {
|
|
53863
|
+
const profile = {
|
|
53864
|
+
dialect: "mysql",
|
|
53865
|
+
textDb: { dialect: "mysql", kind: "text" },
|
|
53866
|
+
numericDb: { dialect: "mysql", kind: "double" },
|
|
53867
|
+
boolDb: { dialect: "mysql", kind: "boolean" },
|
|
53868
|
+
timestampDb: { dialect: "mysql", kind: "timestamp" },
|
|
53869
|
+
nullDb: { dialect: "mysql", kind: "null" },
|
|
53870
|
+
type: mysqlDatatypes
|
|
53871
|
+
};
|
|
52982
53872
|
const ValuesInputProto = {
|
|
52983
53873
|
pipe() {
|
|
52984
53874
|
return pipeArguments5(this, arguments);
|
|
@@ -52988,7 +53878,7 @@ function makeDialectQuery(profile) {
|
|
|
52988
53878
|
if (value === null || value instanceof Date) {
|
|
52989
53879
|
return;
|
|
52990
53880
|
}
|
|
52991
|
-
return
|
|
53881
|
+
return Schema5.Literal(value);
|
|
52992
53882
|
};
|
|
52993
53883
|
const literal = (value) => makeExpression({
|
|
52994
53884
|
runtime: undefined,
|
|
@@ -53004,6 +53894,20 @@ function makeDialectQuery(profile) {
|
|
|
53004
53894
|
kind: "literal",
|
|
53005
53895
|
value
|
|
53006
53896
|
});
|
|
53897
|
+
const column = (name2, dbType, nullable3 = false) => makeExpression({
|
|
53898
|
+
runtime: undefined,
|
|
53899
|
+
dbType,
|
|
53900
|
+
nullability: nullable3 ? "maybe" : "never",
|
|
53901
|
+
dialect: profile.dialect,
|
|
53902
|
+
aggregation: "scalar",
|
|
53903
|
+
source: undefined,
|
|
53904
|
+
sourceNullability: "resolved",
|
|
53905
|
+
dependencies: {}
|
|
53906
|
+
}, {
|
|
53907
|
+
kind: "column",
|
|
53908
|
+
tableName: "",
|
|
53909
|
+
columnName: name2
|
|
53910
|
+
});
|
|
53007
53911
|
const toDialectExpression = (value) => {
|
|
53008
53912
|
if (value !== null && typeof value === "object" && TypeId in value) {
|
|
53009
53913
|
return value;
|
|
@@ -53012,6 +53916,53 @@ function makeDialectQuery(profile) {
|
|
|
53012
53916
|
};
|
|
53013
53917
|
const toDialectStringExpression = (value) => typeof value === "string" ? literal(value) : value;
|
|
53014
53918
|
const toDialectNumericExpression = (value) => typeof value === "number" ? literal(value) : value;
|
|
53919
|
+
const flattenVariadicBooleanExpressions = (kind, values2) => {
|
|
53920
|
+
const flattened = [];
|
|
53921
|
+
for (const value of values2) {
|
|
53922
|
+
const ast = value[TypeId2];
|
|
53923
|
+
if (ast.kind === kind) {
|
|
53924
|
+
flattened.push(...ast.values);
|
|
53925
|
+
} else {
|
|
53926
|
+
flattened.push(value);
|
|
53927
|
+
}
|
|
53928
|
+
}
|
|
53929
|
+
return flattened;
|
|
53930
|
+
};
|
|
53931
|
+
const makeVariadicBooleanExpression = (kind, values2) => {
|
|
53932
|
+
const expressions = flattenVariadicBooleanExpressions(kind, values2);
|
|
53933
|
+
const expression = makeExpression({
|
|
53934
|
+
runtime: true,
|
|
53935
|
+
dbType: profile.boolDb,
|
|
53936
|
+
nullability: mergeNullabilityManyRuntime(expressions),
|
|
53937
|
+
dialect: expressions.find((value) => value[TypeId].dialect !== undefined)?.[TypeId].dialect ?? profile.dialect,
|
|
53938
|
+
aggregation: mergeAggregationManyRuntime(expressions),
|
|
53939
|
+
source: mergeManySources(expressions),
|
|
53940
|
+
sourceNullability: "propagate",
|
|
53941
|
+
dependencies: mergeManyDependencies(expressions)
|
|
53942
|
+
}, {
|
|
53943
|
+
kind,
|
|
53944
|
+
values: expressions
|
|
53945
|
+
});
|
|
53946
|
+
Object.defineProperty(expression, "pipe", {
|
|
53947
|
+
configurable: true,
|
|
53948
|
+
writable: true,
|
|
53949
|
+
value() {
|
|
53950
|
+
if (arguments.length === 0) {
|
|
53951
|
+
return this;
|
|
53952
|
+
}
|
|
53953
|
+
const operations = Array.from(arguments);
|
|
53954
|
+
if (operations.every((operation) => typeof operation !== "function")) {
|
|
53955
|
+
const appended = operations.map((operation) => toDialectExpression(operation));
|
|
53956
|
+
return makeVariadicBooleanExpression(kind, [...expressions, ...appended]);
|
|
53957
|
+
}
|
|
53958
|
+
if (operations.every((operation) => typeof operation === "function")) {
|
|
53959
|
+
return pipeArguments5(this, arguments);
|
|
53960
|
+
}
|
|
53961
|
+
throw new TypeError(`Cannot mix query expressions and pipe functions inside ${kind}(...).pipe(...)`);
|
|
53962
|
+
}
|
|
53963
|
+
});
|
|
53964
|
+
return expression;
|
|
53965
|
+
};
|
|
53015
53966
|
const extractRequiredFromDialectInputRuntime = (value) => {
|
|
53016
53967
|
const expression = toDialectExpression(value);
|
|
53017
53968
|
return Object.keys(expression[TypeId].dependencies);
|
|
@@ -53098,6 +54049,22 @@ function makeDialectQuery(profile) {
|
|
|
53098
54049
|
const [left, right] = args;
|
|
53099
54050
|
return buildBinaryPredicate(left, right, "ilike");
|
|
53100
54051
|
};
|
|
54052
|
+
const regexMatch = (...args) => {
|
|
54053
|
+
const [left, right] = args;
|
|
54054
|
+
return buildBinaryPredicate(left, right, "regexMatch");
|
|
54055
|
+
};
|
|
54056
|
+
const regexIMatch = (...args) => {
|
|
54057
|
+
const [left, right] = args;
|
|
54058
|
+
return buildBinaryPredicate(left, right, "regexIMatch");
|
|
54059
|
+
};
|
|
54060
|
+
const regexNotMatch = (...args) => {
|
|
54061
|
+
const [left, right] = args;
|
|
54062
|
+
return buildBinaryPredicate(left, right, "regexNotMatch");
|
|
54063
|
+
};
|
|
54064
|
+
const regexNotIMatch = (...args) => {
|
|
54065
|
+
const [left, right] = args;
|
|
54066
|
+
return buildBinaryPredicate(left, right, "regexNotIMatch");
|
|
54067
|
+
};
|
|
53101
54068
|
const isDistinctFrom = (...args) => {
|
|
53102
54069
|
const [left, right] = args;
|
|
53103
54070
|
return buildBinaryPredicate(left, right, "isDistinctFrom", "never", "resolved");
|
|
@@ -53188,7 +54155,7 @@ function makeDialectQuery(profile) {
|
|
|
53188
54155
|
target
|
|
53189
54156
|
});
|
|
53190
54157
|
};
|
|
53191
|
-
const
|
|
54158
|
+
const array2 = (element) => ({
|
|
53192
54159
|
dialect: profile.dialect,
|
|
53193
54160
|
kind: `${element.kind}[]`,
|
|
53194
54161
|
element
|
|
@@ -53223,23 +54190,28 @@ function makeDialectQuery(profile) {
|
|
|
53223
54190
|
kind,
|
|
53224
54191
|
variant: "set"
|
|
53225
54192
|
});
|
|
54193
|
+
const custom3 = (kind) => ({
|
|
54194
|
+
dialect: profile.dialect,
|
|
54195
|
+
kind
|
|
54196
|
+
});
|
|
53226
54197
|
const type = {
|
|
53227
54198
|
...profile.type,
|
|
53228
|
-
array,
|
|
54199
|
+
array: array2,
|
|
53229
54200
|
range,
|
|
53230
54201
|
multirange,
|
|
53231
54202
|
record,
|
|
53232
54203
|
domain,
|
|
53233
54204
|
enum: enum_,
|
|
53234
|
-
set
|
|
54205
|
+
set,
|
|
54206
|
+
custom: custom3
|
|
53235
54207
|
};
|
|
53236
54208
|
const makeJsonDb = (kind) => ({
|
|
53237
54209
|
dialect: profile.dialect,
|
|
53238
54210
|
kind,
|
|
53239
|
-
variant: "json"
|
|
54211
|
+
variant: kind === "jsonb" ? "jsonb" : "json"
|
|
53240
54212
|
});
|
|
53241
54213
|
const jsonDb = makeJsonDb("json");
|
|
53242
|
-
const jsonbDb = makeJsonDb(
|
|
54214
|
+
const jsonbDb = makeJsonDb("json");
|
|
53243
54215
|
const isExpressionValue = (value) => value !== null && typeof value === "object" && (TypeId in value);
|
|
53244
54216
|
const isJsonExpressionValue = (value) => isExpressionValue(value) && (() => {
|
|
53245
54217
|
const dbType = value[TypeId].dbType;
|
|
@@ -53259,6 +54231,8 @@ function makeDialectQuery(profile) {
|
|
|
53259
54231
|
sourceNullability: state.sourceNullability ?? "propagate",
|
|
53260
54232
|
dependencies: mergeManyDependencies(expressions)
|
|
53261
54233
|
}, ast);
|
|
54234
|
+
const jsonDbTypeOf = (base) => base[TypeId].dbType;
|
|
54235
|
+
const resolveJsonMergeDbType = (...values2) => values2.some((value) => value[TypeId].dbType.kind === "jsonb") ? jsonbDb : jsonDb;
|
|
53262
54236
|
const makeJsonLiteralExpression = (value, dbType = jsonDb) => makeExpression({
|
|
53263
54237
|
runtime: value,
|
|
53264
54238
|
dbType,
|
|
@@ -53296,7 +54270,7 @@ function makeDialectQuery(profile) {
|
|
|
53296
54270
|
const kind = isJsonPathValue(target) ? isExactJsonPathValue(segments) ? "jsonPath" : "jsonTraverse" : isExactJsonSegmentValue(target) ? "jsonGet" : "jsonAccess";
|
|
53297
54271
|
return buildJsonNodeExpression([base], {
|
|
53298
54272
|
runtime: undefined,
|
|
53299
|
-
dbType:
|
|
54273
|
+
dbType: jsonDbTypeOf(base),
|
|
53300
54274
|
nullability: undefined
|
|
53301
54275
|
}, {
|
|
53302
54276
|
kind,
|
|
@@ -53321,7 +54295,7 @@ function makeDialectQuery(profile) {
|
|
|
53321
54295
|
const segments = normalizeJsonPathInput(target);
|
|
53322
54296
|
return buildJsonNodeExpression([base], {
|
|
53323
54297
|
runtime: undefined,
|
|
53324
|
-
dbType:
|
|
54298
|
+
dbType: jsonDbTypeOf(base),
|
|
53325
54299
|
nullability: undefined
|
|
53326
54300
|
}, {
|
|
53327
54301
|
kind: isJsonPathValue(target) || segments.length > 1 ? "jsonTraverse" : "jsonAccess",
|
|
@@ -53333,7 +54307,7 @@ function makeDialectQuery(profile) {
|
|
|
53333
54307
|
const segments = normalizeJsonPathInput(target);
|
|
53334
54308
|
return buildJsonNodeExpression([base], {
|
|
53335
54309
|
runtime: undefined,
|
|
53336
|
-
dbType:
|
|
54310
|
+
dbType: jsonDbTypeOf(base),
|
|
53337
54311
|
nullability: undefined
|
|
53338
54312
|
}, {
|
|
53339
54313
|
kind: "jsonTraverse",
|
|
@@ -53401,7 +54375,7 @@ function makeDialectQuery(profile) {
|
|
|
53401
54375
|
const segments = normalizeJsonPathInput(target);
|
|
53402
54376
|
return buildJsonNodeExpression([base], {
|
|
53403
54377
|
runtime: undefined,
|
|
53404
|
-
dbType:
|
|
54378
|
+
dbType: jsonDbTypeOf(base),
|
|
53405
54379
|
nullability: undefined
|
|
53406
54380
|
}, {
|
|
53407
54381
|
kind: isJsonPathValue(target) ? "jsonDeletePath" : "jsonDelete",
|
|
@@ -53413,7 +54387,7 @@ function makeDialectQuery(profile) {
|
|
|
53413
54387
|
const segments = normalizeJsonPathInput(target);
|
|
53414
54388
|
return buildJsonNodeExpression([base], {
|
|
53415
54389
|
runtime: undefined,
|
|
53416
|
-
dbType:
|
|
54390
|
+
dbType: jsonDbTypeOf(base),
|
|
53417
54391
|
nullability: undefined
|
|
53418
54392
|
}, {
|
|
53419
54393
|
kind: "jsonRemove",
|
|
@@ -53426,7 +54400,7 @@ function makeDialectQuery(profile) {
|
|
|
53426
54400
|
const newValue = toJsonValueExpression(next);
|
|
53427
54401
|
return buildJsonNodeExpression([base, newValue], {
|
|
53428
54402
|
runtime: undefined,
|
|
53429
|
-
dbType:
|
|
54403
|
+
dbType: jsonDbTypeOf(base),
|
|
53430
54404
|
nullability: undefined
|
|
53431
54405
|
}, {
|
|
53432
54406
|
kind: "jsonSet",
|
|
@@ -53442,7 +54416,7 @@ function makeDialectQuery(profile) {
|
|
|
53442
54416
|
const insertAfter = options2.insertAfter ?? false;
|
|
53443
54417
|
return buildJsonNodeExpression([base, insert2], {
|
|
53444
54418
|
runtime: undefined,
|
|
53445
|
-
dbType:
|
|
54419
|
+
dbType: jsonDbTypeOf(base),
|
|
53446
54420
|
nullability: undefined
|
|
53447
54421
|
}, {
|
|
53448
54422
|
kind: "jsonInsert",
|
|
@@ -53452,12 +54426,12 @@ function makeDialectQuery(profile) {
|
|
|
53452
54426
|
insertAfter
|
|
53453
54427
|
});
|
|
53454
54428
|
};
|
|
53455
|
-
const
|
|
54429
|
+
const jsonConcatAs = (dbType) => (left, right) => {
|
|
53456
54430
|
const leftExpression = toJsonValueExpression(left);
|
|
53457
54431
|
const rightExpression = toJsonValueExpression(right);
|
|
53458
54432
|
return buildJsonNodeExpression([leftExpression, rightExpression], {
|
|
53459
54433
|
runtime: undefined,
|
|
53460
|
-
dbType
|
|
54434
|
+
dbType,
|
|
53461
54435
|
nullability: "maybe"
|
|
53462
54436
|
}, {
|
|
53463
54437
|
kind: "jsonConcat",
|
|
@@ -53465,12 +54439,12 @@ function makeDialectQuery(profile) {
|
|
|
53465
54439
|
right: rightExpression
|
|
53466
54440
|
});
|
|
53467
54441
|
};
|
|
53468
|
-
const
|
|
54442
|
+
const jsonMergeAs = (dbType) => (left, right) => {
|
|
53469
54443
|
const leftExpression = toJsonValueExpression(left);
|
|
53470
54444
|
const rightExpression = toJsonValueExpression(right);
|
|
53471
54445
|
return buildJsonNodeExpression([leftExpression, rightExpression], {
|
|
53472
54446
|
runtime: undefined,
|
|
53473
|
-
dbType
|
|
54447
|
+
dbType,
|
|
53474
54448
|
nullability: "maybe"
|
|
53475
54449
|
}, {
|
|
53476
54450
|
kind: "jsonMerge",
|
|
@@ -53478,6 +54452,8 @@ function makeDialectQuery(profile) {
|
|
|
53478
54452
|
right: rightExpression
|
|
53479
54453
|
});
|
|
53480
54454
|
};
|
|
54455
|
+
const jsonConcat = jsonConcatAs(resolveJsonMergeDbType());
|
|
54456
|
+
const jsonMerge = jsonMergeAs(resolveJsonMergeDbType());
|
|
53481
54457
|
const jsonKeyExists = (base, key2) => buildJsonNodeExpression([base], {
|
|
53482
54458
|
runtime: true,
|
|
53483
54459
|
dbType: profile.boolDb,
|
|
@@ -53488,14 +54464,14 @@ function makeDialectQuery(profile) {
|
|
|
53488
54464
|
base,
|
|
53489
54465
|
keys: [key2]
|
|
53490
54466
|
});
|
|
53491
|
-
const
|
|
54467
|
+
const jsonBuildObjectAs = (dbType) => (shape) => {
|
|
53492
54468
|
const entries = Object.entries(shape).map(([key2, value]) => ({
|
|
53493
54469
|
key: key2,
|
|
53494
54470
|
value: toJsonValueExpression(value)
|
|
53495
54471
|
}));
|
|
53496
54472
|
return buildJsonNodeExpression(entries.map((entry) => entry.value), {
|
|
53497
54473
|
runtime: {},
|
|
53498
|
-
dbType
|
|
54474
|
+
dbType,
|
|
53499
54475
|
nullability: "never",
|
|
53500
54476
|
sourceNullability: "resolved"
|
|
53501
54477
|
}, {
|
|
@@ -53503,11 +54479,11 @@ function makeDialectQuery(profile) {
|
|
|
53503
54479
|
entries
|
|
53504
54480
|
});
|
|
53505
54481
|
};
|
|
53506
|
-
const
|
|
54482
|
+
const jsonBuildArrayAs = (dbType) => (...values2) => {
|
|
53507
54483
|
const expressions = values2.map((value) => toJsonValueExpression(value));
|
|
53508
54484
|
return buildJsonNodeExpression(expressions, {
|
|
53509
54485
|
runtime: [],
|
|
53510
|
-
dbType
|
|
54486
|
+
dbType,
|
|
53511
54487
|
nullability: "never",
|
|
53512
54488
|
sourceNullability: "resolved"
|
|
53513
54489
|
}, {
|
|
@@ -53515,6 +54491,10 @@ function makeDialectQuery(profile) {
|
|
|
53515
54491
|
values: expressions
|
|
53516
54492
|
});
|
|
53517
54493
|
};
|
|
54494
|
+
const jsonBuildObject = jsonBuildObjectAs(jsonDb);
|
|
54495
|
+
const jsonBuildArray = jsonBuildArrayAs(jsonDb);
|
|
54496
|
+
const jsonbBuildObject = jsonBuildObjectAs(jsonbDb);
|
|
54497
|
+
const jsonbBuildArray = jsonBuildArrayAs(jsonbDb);
|
|
53518
54498
|
const jsonToJson = (value) => toJsonValueExpression(value, "jsonToJson", jsonDb);
|
|
53519
54499
|
const jsonToJsonb = (value) => toJsonValueExpression(value, "jsonToJsonb", jsonbDb);
|
|
53520
54500
|
const jsonTypeOf = (base) => buildJsonNodeExpression([base], {
|
|
@@ -53568,7 +54548,7 @@ function makeDialectQuery(profile) {
|
|
|
53568
54548
|
};
|
|
53569
54549
|
const jsonStripNulls = (base) => buildJsonNodeExpression([base], {
|
|
53570
54550
|
runtime: undefined,
|
|
53571
|
-
dbType:
|
|
54551
|
+
dbType: jsonDbTypeOf(base),
|
|
53572
54552
|
nullability: undefined
|
|
53573
54553
|
}, {
|
|
53574
54554
|
kind: "jsonStripNulls",
|
|
@@ -53601,7 +54581,7 @@ function makeDialectQuery(profile) {
|
|
|
53601
54581
|
};
|
|
53602
54582
|
const json3 = {
|
|
53603
54583
|
key,
|
|
53604
|
-
index:
|
|
54584
|
+
index: index3,
|
|
53605
54585
|
wildcard,
|
|
53606
54586
|
slice,
|
|
53607
54587
|
descend,
|
|
@@ -53635,38 +54615,43 @@ function makeDialectQuery(profile) {
|
|
|
53635
54615
|
pathExists: jsonPathExists,
|
|
53636
54616
|
pathMatch: jsonPathMatch
|
|
53637
54617
|
};
|
|
53638
|
-
const
|
|
53639
|
-
|
|
53640
|
-
|
|
53641
|
-
|
|
53642
|
-
|
|
53643
|
-
|
|
53644
|
-
|
|
53645
|
-
|
|
53646
|
-
|
|
53647
|
-
|
|
53648
|
-
|
|
53649
|
-
|
|
53650
|
-
|
|
53651
|
-
|
|
53652
|
-
|
|
53653
|
-
|
|
53654
|
-
|
|
53655
|
-
|
|
53656
|
-
|
|
53657
|
-
|
|
53658
|
-
|
|
53659
|
-
|
|
53660
|
-
|
|
53661
|
-
|
|
53662
|
-
|
|
53663
|
-
|
|
53664
|
-
|
|
53665
|
-
|
|
53666
|
-
|
|
53667
|
-
|
|
53668
|
-
|
|
54618
|
+
const jsonb2 = {
|
|
54619
|
+
key,
|
|
54620
|
+
index: index3,
|
|
54621
|
+
wildcard,
|
|
54622
|
+
slice,
|
|
54623
|
+
descend,
|
|
54624
|
+
path,
|
|
54625
|
+
get: jsonGet,
|
|
54626
|
+
access: jsonAccess,
|
|
54627
|
+
traverse: jsonTraverse,
|
|
54628
|
+
text: jsonText,
|
|
54629
|
+
accessText: jsonAccessText,
|
|
54630
|
+
traverseText: jsonTraverseText,
|
|
54631
|
+
contains: jsonContains,
|
|
54632
|
+
containedBy: jsonContainedBy,
|
|
54633
|
+
hasKey: jsonHasKey,
|
|
54634
|
+
keyExists: jsonKeyExists,
|
|
54635
|
+
hasAnyKeys: jsonHasAnyKeys,
|
|
54636
|
+
hasAllKeys: jsonHasAllKeys,
|
|
54637
|
+
delete: jsonDelete,
|
|
54638
|
+
remove: jsonRemove,
|
|
54639
|
+
set: jsonSet,
|
|
54640
|
+
insert: jsonInsert,
|
|
54641
|
+
concat: jsonConcatAs(jsonbDb),
|
|
54642
|
+
merge: jsonMergeAs(jsonbDb),
|
|
54643
|
+
buildObject: jsonbBuildObject,
|
|
54644
|
+
buildArray: jsonbBuildArray,
|
|
54645
|
+
toJsonb: jsonToJsonb,
|
|
54646
|
+
typeOf: jsonTypeOf,
|
|
54647
|
+
length: jsonLength,
|
|
54648
|
+
keys: jsonKeys,
|
|
54649
|
+
stripNulls: jsonStripNulls,
|
|
54650
|
+
pathExists: jsonPathExists,
|
|
54651
|
+
pathMatch: jsonPathMatch
|
|
53669
54652
|
};
|
|
54653
|
+
const and = (...values2) => makeVariadicBooleanExpression("and", values2.map((value) => toDialectExpression(value)));
|
|
54654
|
+
const or = (...values2) => makeVariadicBooleanExpression("or", values2.map((value) => toDialectExpression(value)));
|
|
53670
54655
|
const not = (value) => {
|
|
53671
54656
|
const expression = toDialectExpression(value);
|
|
53672
54657
|
return makeExpression({
|
|
@@ -53733,7 +54718,7 @@ function makeDialectQuery(profile) {
|
|
|
53733
54718
|
});
|
|
53734
54719
|
};
|
|
53735
54720
|
const exists = (plan) => {
|
|
53736
|
-
const dependencies = Object.fromEntries(currentRequiredList(plan[TypeId3].required).map((
|
|
54721
|
+
const dependencies = Object.fromEntries(currentRequiredList(plan[TypeId3].required).map((name2) => [name2, true]));
|
|
53737
54722
|
return makeExpression({
|
|
53738
54723
|
runtime: true,
|
|
53739
54724
|
dbType: profile.boolDb,
|
|
@@ -53749,7 +54734,7 @@ function makeDialectQuery(profile) {
|
|
|
53749
54734
|
});
|
|
53750
54735
|
};
|
|
53751
54736
|
const scalar = (plan) => {
|
|
53752
|
-
const dependencies = Object.fromEntries(currentRequiredList(plan[TypeId3].required).map((
|
|
54737
|
+
const dependencies = Object.fromEntries(currentRequiredList(plan[TypeId3].required).map((name2) => [name2, true]));
|
|
53753
54738
|
const expression = extractSingleSelectedExpressionRuntime(plan[TypeId3].selection);
|
|
53754
54739
|
return makeExpression({
|
|
53755
54740
|
runtime: undefined,
|
|
@@ -53767,7 +54752,7 @@ function makeDialectQuery(profile) {
|
|
|
53767
54752
|
};
|
|
53768
54753
|
const inSubquery = (left, plan) => {
|
|
53769
54754
|
const leftExpression = toDialectExpression(left);
|
|
53770
|
-
const dependencies = Object.fromEntries(currentRequiredList(plan[TypeId3].required).map((
|
|
54755
|
+
const dependencies = Object.fromEntries(currentRequiredList(plan[TypeId3].required).map((name2) => [name2, true]));
|
|
53771
54756
|
return makeExpression({
|
|
53772
54757
|
runtime: true,
|
|
53773
54758
|
dbType: profile.boolDb,
|
|
@@ -53785,7 +54770,7 @@ function makeDialectQuery(profile) {
|
|
|
53785
54770
|
};
|
|
53786
54771
|
const quantifiedComparison = (left, plan, operator, quantifier) => {
|
|
53787
54772
|
const leftExpression = toDialectExpression(left);
|
|
53788
|
-
const dependencies = Object.fromEntries(currentRequiredList(plan[TypeId3].required).map((
|
|
54773
|
+
const dependencies = Object.fromEntries(currentRequiredList(plan[TypeId3].required).map((name2) => [name2, true]));
|
|
53789
54774
|
return makeExpression({
|
|
53790
54775
|
runtime: true,
|
|
53791
54776
|
dbType: profile.boolDb,
|
|
@@ -53885,6 +54870,51 @@ function makeDialectQuery(profile) {
|
|
|
53885
54870
|
values: expressions
|
|
53886
54871
|
});
|
|
53887
54872
|
};
|
|
54873
|
+
const call = (name2, ...args) => {
|
|
54874
|
+
const expressions = args.map((value) => toDialectExpression(value));
|
|
54875
|
+
return makeExpression({
|
|
54876
|
+
runtime: undefined,
|
|
54877
|
+
dbType: profile.textDb,
|
|
54878
|
+
nullability: "maybe",
|
|
54879
|
+
dialect: expressions.find((value) => value[TypeId].dialect !== undefined)?.[TypeId].dialect ?? profile.dialect,
|
|
54880
|
+
aggregation: mergeAggregationManyRuntime(expressions),
|
|
54881
|
+
source: mergeManySources(expressions),
|
|
54882
|
+
sourceNullability: "resolved",
|
|
54883
|
+
dependencies: mergeManyDependencies(expressions)
|
|
54884
|
+
}, {
|
|
54885
|
+
kind: "function",
|
|
54886
|
+
name: name2,
|
|
54887
|
+
args: expressions
|
|
54888
|
+
});
|
|
54889
|
+
};
|
|
54890
|
+
const uuidGenerateV4 = () => makeExpression({
|
|
54891
|
+
runtime: undefined,
|
|
54892
|
+
dbType: { dialect: "postgres", kind: "uuid" },
|
|
54893
|
+
nullability: "never",
|
|
54894
|
+
dialect: profile.dialect,
|
|
54895
|
+
aggregation: "scalar",
|
|
54896
|
+
source: undefined,
|
|
54897
|
+
sourceNullability: "resolved",
|
|
54898
|
+
dependencies: {}
|
|
54899
|
+
}, {
|
|
54900
|
+
kind: "function",
|
|
54901
|
+
name: "uuid_generate_v4",
|
|
54902
|
+
args: []
|
|
54903
|
+
});
|
|
54904
|
+
const nextVal = (value) => makeExpression({
|
|
54905
|
+
runtime: undefined,
|
|
54906
|
+
dbType: { dialect: "postgres", kind: "int8" },
|
|
54907
|
+
nullability: "never",
|
|
54908
|
+
dialect: profile.dialect,
|
|
54909
|
+
aggregation: "scalar",
|
|
54910
|
+
source: undefined,
|
|
54911
|
+
sourceNullability: "resolved",
|
|
54912
|
+
dependencies: {}
|
|
54913
|
+
}, {
|
|
54914
|
+
kind: "function",
|
|
54915
|
+
name: "nextval",
|
|
54916
|
+
args: [toDialectExpression(value)]
|
|
54917
|
+
});
|
|
53888
54918
|
const resolveCaseNullabilityRuntime = (values2) => {
|
|
53889
54919
|
let sawNever = false;
|
|
53890
54920
|
let sawMaybe = false;
|
|
@@ -53996,15 +55026,15 @@ function makeDialectQuery(profile) {
|
|
|
53996
55026
|
columnName: ast.columnName
|
|
53997
55027
|
});
|
|
53998
55028
|
};
|
|
53999
|
-
const toMutationValueExpression = (value,
|
|
55029
|
+
const toMutationValueExpression = (value, column2) => {
|
|
54000
55030
|
if (value !== null && typeof value === "object" && TypeId in value) {
|
|
54001
55031
|
return value;
|
|
54002
55032
|
}
|
|
54003
55033
|
return makeExpression({
|
|
54004
55034
|
runtime: value,
|
|
54005
|
-
dbType:
|
|
55035
|
+
dbType: column2[TypeId].dbType,
|
|
54006
55036
|
nullability: value === null ? "always" : "never",
|
|
54007
|
-
dialect:
|
|
55037
|
+
dialect: column2[TypeId].dialect,
|
|
54008
55038
|
aggregation: "scalar",
|
|
54009
55039
|
source: undefined,
|
|
54010
55040
|
sourceNullability: "propagate",
|
|
@@ -54132,7 +55162,7 @@ function makeDialectQuery(profile) {
|
|
|
54132
55162
|
const columns = firstColumns;
|
|
54133
55163
|
const normalizedRows = rows.map((row) => {
|
|
54134
55164
|
const rowKeys = Object.keys(row);
|
|
54135
|
-
if (rowKeys.length !== columns.length || columns.some((
|
|
55165
|
+
if (rowKeys.length !== columns.length || columns.some((column2) => !(column2 in row))) {
|
|
54136
55166
|
throw new Error("All values(...) rows must project the same columns in the same shape");
|
|
54137
55167
|
}
|
|
54138
55168
|
const assignments = buildMutationAssignments(target, row);
|
|
@@ -54144,7 +55174,7 @@ function makeDialectQuery(profile) {
|
|
|
54144
55174
|
return {
|
|
54145
55175
|
columns,
|
|
54146
55176
|
rows: normalizedRows,
|
|
54147
|
-
required: required.filter((
|
|
55177
|
+
required: required.filter((name2, index4, list) => list.indexOf(name2) === index4)
|
|
54148
55178
|
};
|
|
54149
55179
|
};
|
|
54150
55180
|
const normalizeInsertSelectColumns = (selection) => {
|
|
@@ -54255,7 +55285,7 @@ function makeDialectQuery(profile) {
|
|
|
54255
55285
|
const columnNames = Object.keys(normalizedRows[0]);
|
|
54256
55286
|
for (const row of normalizedRows) {
|
|
54257
55287
|
const rowKeys = Object.keys(row);
|
|
54258
|
-
if (rowKeys.length !== columnNames.length || !rowKeys.every((key2,
|
|
55288
|
+
if (rowKeys.length !== columnNames.length || !rowKeys.every((key2, index4) => key2 === columnNames[index4])) {
|
|
54259
55289
|
throw new Error("values(...) rows must project the same columns in the same order");
|
|
54260
55290
|
}
|
|
54261
55291
|
}
|
|
@@ -54372,7 +55402,7 @@ function makeDialectQuery(profile) {
|
|
|
54372
55402
|
const predicateRequired = extractRequiredFromDialectInputRuntime(predicate);
|
|
54373
55403
|
return makePlan({
|
|
54374
55404
|
selection: current.selection,
|
|
54375
|
-
required: [...currentRequiredList(current.required), ...predicateRequired].filter((
|
|
55405
|
+
required: [...currentRequiredList(current.required), ...predicateRequired].filter((name2, index4, values2) => !(name2 in current.available) && values2.indexOf(name2) === index4),
|
|
54376
55406
|
available: current.available,
|
|
54377
55407
|
dialect: current.dialect
|
|
54378
55408
|
}, {
|
|
@@ -54381,7 +55411,7 @@ function makeDialectQuery(profile) {
|
|
|
54381
55411
|
kind: "where",
|
|
54382
55412
|
predicate: predicateExpression
|
|
54383
55413
|
}]
|
|
54384
|
-
},
|
|
55414
|
+
}, assumeFormulaTrue(currentQuery.assumptions, formulaOfExpression(predicateExpression)), currentQuery.capabilities, currentQuery.statement);
|
|
54385
55415
|
};
|
|
54386
55416
|
const from = (source) => (plan) => {
|
|
54387
55417
|
const current = plan[TypeId3];
|
|
@@ -54395,6 +55425,7 @@ function makeDialectQuery(profile) {
|
|
|
54395
55425
|
}
|
|
54396
55426
|
const sourceLike = source;
|
|
54397
55427
|
const { sourceName, sourceBaseName } = sourceDetails(sourceLike);
|
|
55428
|
+
const presenceWitnesses = presenceWitnessesOfSourceLike(sourceLike);
|
|
54398
55429
|
if (currentQuery.statement === "select") {
|
|
54399
55430
|
const nextAst = {
|
|
54400
55431
|
...currentAst,
|
|
@@ -54407,12 +55438,14 @@ function makeDialectQuery(profile) {
|
|
|
54407
55438
|
};
|
|
54408
55439
|
return makePlan({
|
|
54409
55440
|
selection: current.selection,
|
|
54410
|
-
required: currentRequiredList(current.required).filter((
|
|
55441
|
+
required: currentRequiredList(current.required).filter((name2) => name2 !== sourceName),
|
|
54411
55442
|
available: {
|
|
54412
55443
|
[sourceName]: {
|
|
54413
55444
|
name: sourceName,
|
|
54414
55445
|
mode: "required",
|
|
54415
|
-
baseName: sourceBaseName
|
|
55446
|
+
baseName: sourceBaseName,
|
|
55447
|
+
_presentFormula: trueFormula(),
|
|
55448
|
+
_presenceWitnesses: presenceWitnesses
|
|
54416
55449
|
}
|
|
54417
55450
|
},
|
|
54418
55451
|
dialect: current.dialect
|
|
@@ -54424,7 +55457,9 @@ function makeDialectQuery(profile) {
|
|
|
54424
55457
|
[sourceName]: {
|
|
54425
55458
|
name: sourceName,
|
|
54426
55459
|
mode: "required",
|
|
54427
|
-
baseName: sourceBaseName
|
|
55460
|
+
baseName: sourceBaseName,
|
|
55461
|
+
_presentFormula: trueFormula(),
|
|
55462
|
+
_presenceWitnesses: presenceWitnesses
|
|
54428
55463
|
}
|
|
54429
55464
|
};
|
|
54430
55465
|
const nextAst = {
|
|
@@ -54441,7 +55476,7 @@ function makeDialectQuery(profile) {
|
|
|
54441
55476
|
};
|
|
54442
55477
|
return makePlan({
|
|
54443
55478
|
selection: current.selection,
|
|
54444
|
-
required: currentRequiredList(current.required).filter((
|
|
55479
|
+
required: currentRequiredList(current.required).filter((name2) => !(name2 in nextAvailable)),
|
|
54445
55480
|
available: nextAvailable,
|
|
54446
55481
|
dialect: current.dialect
|
|
54447
55482
|
}, nextAst, currentQuery.assumptions, currentQuery.capabilities, currentQuery.statement);
|
|
@@ -54456,7 +55491,7 @@ function makeDialectQuery(profile) {
|
|
|
54456
55491
|
const predicateRequired = extractRequiredFromDialectInputRuntime(predicate);
|
|
54457
55492
|
return makePlan({
|
|
54458
55493
|
selection: current.selection,
|
|
54459
|
-
required: [...currentRequiredList(current.required), ...predicateRequired].filter((
|
|
55494
|
+
required: [...currentRequiredList(current.required), ...predicateRequired].filter((name2, index4, values2) => !(name2 in current.available) && values2.indexOf(name2) === index4),
|
|
54460
55495
|
available: current.available,
|
|
54461
55496
|
dialect: current.dialect
|
|
54462
55497
|
}, {
|
|
@@ -54465,7 +55500,7 @@ function makeDialectQuery(profile) {
|
|
|
54465
55500
|
kind: "having",
|
|
54466
55501
|
predicate: predicateExpression
|
|
54467
55502
|
}]
|
|
54468
|
-
}, currentQuery.assumptions, currentQuery.capabilities, currentQuery.statement);
|
|
55503
|
+
}, assumeFormulaTrue(currentQuery.assumptions, formulaOfExpression(predicateExpression)), currentQuery.capabilities, currentQuery.statement);
|
|
54469
55504
|
};
|
|
54470
55505
|
const innerJoin = (table, on) => join("inner", table, on);
|
|
54471
55506
|
const leftJoin = (table, on) => join("left", table, on);
|
|
@@ -54476,16 +55511,19 @@ function makeDialectQuery(profile) {
|
|
|
54476
55511
|
const currentAst = getAst(plan);
|
|
54477
55512
|
const currentQuery = getQueryState(plan);
|
|
54478
55513
|
const { sourceName, sourceBaseName } = sourceDetails(table);
|
|
55514
|
+
const presenceWitnesses = presenceWitnessesOfSourceLike(table);
|
|
54479
55515
|
const nextAvailable = Object.assign({}, current.available, {
|
|
54480
55516
|
[sourceName]: {
|
|
54481
55517
|
name: sourceName,
|
|
54482
55518
|
mode: "required",
|
|
54483
|
-
baseName: sourceBaseName
|
|
55519
|
+
baseName: sourceBaseName,
|
|
55520
|
+
_presentFormula: trueFormula(),
|
|
55521
|
+
_presenceWitnesses: presenceWitnesses
|
|
54484
55522
|
}
|
|
54485
55523
|
});
|
|
54486
55524
|
return makePlan({
|
|
54487
55525
|
selection: current.selection,
|
|
54488
|
-
required: currentRequiredList(current.required).filter((
|
|
55526
|
+
required: currentRequiredList(current.required).filter((name2) => !(name2 in nextAvailable)),
|
|
54489
55527
|
available: nextAvailable,
|
|
54490
55528
|
dialect: current.dialect
|
|
54491
55529
|
}, {
|
|
@@ -54503,23 +55541,29 @@ function makeDialectQuery(profile) {
|
|
|
54503
55541
|
const currentAst = getAst(plan);
|
|
54504
55542
|
const currentQuery = getQueryState(plan);
|
|
54505
55543
|
const onExpression = toDialectExpression(on);
|
|
55544
|
+
const onFormula = formulaOfExpression(onExpression);
|
|
54506
55545
|
const { sourceName, sourceBaseName } = sourceDetails(table);
|
|
54507
|
-
const
|
|
55546
|
+
const presenceWitnesses = presenceWitnessesOfSourceLike(table);
|
|
55547
|
+
const baseAvailable = kind === "right" || kind === "full" ? Object.fromEntries(Object.entries(current.available).map(([name2, source]) => [name2, {
|
|
54508
55548
|
name: source.name,
|
|
54509
55549
|
mode: "optional",
|
|
54510
|
-
baseName: source.baseName
|
|
55550
|
+
baseName: source.baseName,
|
|
55551
|
+
_presentFormula: source._presentFormula,
|
|
55552
|
+
_presenceWitnesses: source._presenceWitnesses
|
|
54511
55553
|
}])) : current.available;
|
|
54512
55554
|
const nextAvailable = {
|
|
54513
55555
|
...baseAvailable,
|
|
54514
55556
|
[sourceName]: {
|
|
54515
55557
|
name: sourceName,
|
|
54516
55558
|
mode: kind === "left" || kind === "full" ? "optional" : "required",
|
|
54517
|
-
baseName: sourceBaseName
|
|
55559
|
+
baseName: sourceBaseName,
|
|
55560
|
+
_presentFormula: kind === "inner" || kind === "left" ? onFormula : trueFormula(),
|
|
55561
|
+
_presenceWitnesses: presenceWitnesses
|
|
54518
55562
|
}
|
|
54519
55563
|
};
|
|
54520
55564
|
return makePlan({
|
|
54521
55565
|
selection: current.selection,
|
|
54522
|
-
required: [...currentRequiredList(current.required), ...extractRequiredFromDialectInputRuntime(on)].filter((
|
|
55566
|
+
required: [...currentRequiredList(current.required), ...extractRequiredFromDialectInputRuntime(on)].filter((name2, index4, values2) => !(name2 in nextAvailable) && values2.indexOf(name2) === index4),
|
|
54523
55567
|
available: nextAvailable,
|
|
54524
55568
|
dialect: current.dialect
|
|
54525
55569
|
}, {
|
|
@@ -54531,7 +55575,7 @@ function makeDialectQuery(profile) {
|
|
|
54531
55575
|
source: table,
|
|
54532
55576
|
on: onExpression
|
|
54533
55577
|
}]
|
|
54534
|
-
}, currentQuery.assumptions, currentQuery.capabilities, currentQuery.statement);
|
|
55578
|
+
}, kind === "inner" ? assumeFormulaTrue(currentQuery.assumptions, onFormula) : currentQuery.assumptions, currentQuery.capabilities, currentQuery.statement);
|
|
54535
55579
|
};
|
|
54536
55580
|
const orderBy = (value, direction = "asc") => (plan) => {
|
|
54537
55581
|
const current = plan[TypeId3];
|
|
@@ -54541,7 +55585,7 @@ function makeDialectQuery(profile) {
|
|
|
54541
55585
|
const required = extractRequiredFromDialectInputRuntime(value);
|
|
54542
55586
|
return makePlan({
|
|
54543
55587
|
selection: current.selection,
|
|
54544
|
-
required: [...currentRequiredList(current.required), ...required].filter((
|
|
55588
|
+
required: [...currentRequiredList(current.required), ...required].filter((name2, index4, values2) => !(name2 in current.available) && values2.indexOf(name2) === index4),
|
|
54545
55589
|
available: current.available,
|
|
54546
55590
|
dialect: current.dialect
|
|
54547
55591
|
}, {
|
|
@@ -54588,30 +55632,10 @@ function makeDialectQuery(profile) {
|
|
|
54588
55632
|
distinct: true
|
|
54589
55633
|
}, currentQuery.assumptions, currentQuery.capabilities, currentQuery.statement);
|
|
54590
55634
|
};
|
|
54591
|
-
const distinctOn =
|
|
54592
|
-
|
|
54593
|
-
|
|
54594
|
-
|
|
54595
|
-
__effect_qb_error__: "effect-qb: distinctOn(...) is only supported by the postgres dialect",
|
|
54596
|
-
__effect_qb_dialect__: profile.dialect,
|
|
54597
|
-
__effect_qb_hint__: "Use postgres.Query.distinctOn(...) or regular distinct()/grouping logic"
|
|
54598
|
-
};
|
|
54599
|
-
}
|
|
54600
|
-
return (plan) => {
|
|
54601
|
-
const current = plan[TypeId3];
|
|
54602
|
-
const currentAst = getAst(plan);
|
|
54603
|
-
const currentQuery = getQueryState(plan);
|
|
54604
|
-
return makePlan({
|
|
54605
|
-
selection: current.selection,
|
|
54606
|
-
required: current.required,
|
|
54607
|
-
available: current.available,
|
|
54608
|
-
dialect: current.dialect
|
|
54609
|
-
}, {
|
|
54610
|
-
...currentAst,
|
|
54611
|
-
distinct: true,
|
|
54612
|
-
distinctOn: expressions
|
|
54613
|
-
}, currentQuery.assumptions, currentQuery.capabilities, currentQuery.statement);
|
|
54614
|
-
};
|
|
55635
|
+
const distinctOn = {
|
|
55636
|
+
__effect_qb_error__: "effect-qb: distinctOn(...) is only supported by the postgres dialect",
|
|
55637
|
+
__effect_qb_dialect__: profile.dialect,
|
|
55638
|
+
__effect_qb_hint__: "Use postgres.Query.distinctOn(...) or regular distinct()/grouping logic"
|
|
54615
55639
|
};
|
|
54616
55640
|
const limit = (value) => (plan) => {
|
|
54617
55641
|
const current = plan[TypeId3];
|
|
@@ -54621,7 +55645,7 @@ function makeDialectQuery(profile) {
|
|
|
54621
55645
|
const required = extractRequiredFromDialectNumericInputRuntime(value);
|
|
54622
55646
|
return makePlan({
|
|
54623
55647
|
selection: current.selection,
|
|
54624
|
-
required: [...currentRequiredList(current.required), ...required].filter((
|
|
55648
|
+
required: [...currentRequiredList(current.required), ...required].filter((name2, index4, values2) => !(name2 in current.available) && values2.indexOf(name2) === index4),
|
|
54625
55649
|
available: current.available,
|
|
54626
55650
|
dialect: current.dialect
|
|
54627
55651
|
}, {
|
|
@@ -54637,7 +55661,7 @@ function makeDialectQuery(profile) {
|
|
|
54637
55661
|
const required = extractRequiredFromDialectNumericInputRuntime(value);
|
|
54638
55662
|
return makePlan({
|
|
54639
55663
|
selection: current.selection,
|
|
54640
|
-
required: [...currentRequiredList(current.required), ...required].filter((
|
|
55664
|
+
required: [...currentRequiredList(current.required), ...required].filter((name2, index4, values2) => !(name2 in current.available) && values2.indexOf(name2) === index4),
|
|
54641
55665
|
available: current.available,
|
|
54642
55666
|
dialect: current.dialect
|
|
54643
55667
|
}, {
|
|
@@ -54649,10 +55673,10 @@ function makeDialectQuery(profile) {
|
|
|
54649
55673
|
const current = plan[TypeId3];
|
|
54650
55674
|
const currentAst = getAst(plan);
|
|
54651
55675
|
const currentQuery = getQueryState(plan);
|
|
54652
|
-
const required = [...values2.flatMap((value) => Object.keys(value[TypeId].dependencies))].filter((
|
|
55676
|
+
const required = [...values2.flatMap((value) => Object.keys(value[TypeId].dependencies))].filter((name2, index4, list) => !(name2 in current.available) && list.indexOf(name2) === index4);
|
|
54653
55677
|
return makePlan({
|
|
54654
55678
|
selection: current.selection,
|
|
54655
|
-
required: [...currentRequiredList(current.required), ...required].filter((
|
|
55679
|
+
required: [...currentRequiredList(current.required), ...required].filter((name2, index4, list) => !(name2 in current.available) && list.indexOf(name2) === index4),
|
|
54656
55680
|
available: current.available,
|
|
54657
55681
|
dialect: current.dialect
|
|
54658
55682
|
}, {
|
|
@@ -54666,7 +55690,7 @@ function makeDialectQuery(profile) {
|
|
|
54666
55690
|
const currentQuery = getQueryState(plan);
|
|
54667
55691
|
return makePlan({
|
|
54668
55692
|
selection,
|
|
54669
|
-
required: [...currentRequiredList(current.required), ...extractRequiredRuntime(selection)].filter((
|
|
55693
|
+
required: [...currentRequiredList(current.required), ...extractRequiredRuntime(selection)].filter((name2, index4, list) => !(name2 in current.available) && list.indexOf(name2) === index4),
|
|
54670
55694
|
available: current.available,
|
|
54671
55695
|
dialect: current.dialect
|
|
54672
55696
|
}, {
|
|
@@ -54681,7 +55705,7 @@ function makeDialectQuery(profile) {
|
|
|
54681
55705
|
const insertState = values2 === undefined ? "missing" : "ready";
|
|
54682
55706
|
return makePlan({
|
|
54683
55707
|
selection: {},
|
|
54684
|
-
required: required.filter((
|
|
55708
|
+
required: required.filter((name2, index4, list) => name2 !== sourceName && list.indexOf(name2) === index4),
|
|
54685
55709
|
available: {
|
|
54686
55710
|
[sourceName]: {
|
|
54687
55711
|
name: sourceName,
|
|
@@ -54720,7 +55744,7 @@ function makeDialectQuery(profile) {
|
|
|
54720
55744
|
const normalized = buildInsertValuesRows(target, valuesSource.rows);
|
|
54721
55745
|
return makePlan({
|
|
54722
55746
|
selection: current.selection,
|
|
54723
|
-
required: normalized.required.filter((
|
|
55747
|
+
required: normalized.required.filter((name2) => name2 !== sourceName),
|
|
54724
55748
|
available: current.available,
|
|
54725
55749
|
dialect: current.dialect
|
|
54726
55750
|
}, {
|
|
@@ -54756,7 +55780,7 @@ function makeDialectQuery(profile) {
|
|
|
54756
55780
|
const columns = normalizeInsertSelectColumns(selection);
|
|
54757
55781
|
return makePlan({
|
|
54758
55782
|
selection: current.selection,
|
|
54759
|
-
required: currentRequiredList(sourcePlan[TypeId3].required).filter((
|
|
55783
|
+
required: currentRequiredList(sourcePlan[TypeId3].required).filter((name2) => name2 !== sourceName),
|
|
54760
55784
|
available: current.available,
|
|
54761
55785
|
dialect: current.dialect
|
|
54762
55786
|
}, {
|
|
@@ -54781,7 +55805,7 @@ function makeDialectQuery(profile) {
|
|
|
54781
55805
|
...currentRequiredList(current.required),
|
|
54782
55806
|
...updateAssignments.flatMap((entry) => Object.keys(entry.value[TypeId].dependencies)),
|
|
54783
55807
|
...updateWhere ? Object.keys(updateWhere[TypeId].dependencies) : []
|
|
54784
|
-
].filter((
|
|
55808
|
+
].filter((name2, index4, list) => !(name2 in current.available) && list.indexOf(name2) === index4);
|
|
54785
55809
|
return makePlan({
|
|
54786
55810
|
selection: current.selection,
|
|
54787
55811
|
required,
|
|
@@ -54803,7 +55827,7 @@ function makeDialectQuery(profile) {
|
|
|
54803
55827
|
const primaryTarget = targets[0];
|
|
54804
55828
|
const assignments = buildMutationAssignments(target, values2);
|
|
54805
55829
|
const targetNames = new Set(targets.map((entry) => entry.tableName));
|
|
54806
|
-
const required = assignments.flatMap((entry) => Object.keys(entry.value[TypeId].dependencies)).filter((
|
|
55830
|
+
const required = assignments.flatMap((entry) => Object.keys(entry.value[TypeId].dependencies)).filter((name2, index4, list) => !targetNames.has(name2) && list.indexOf(name2) === index4);
|
|
54807
55831
|
return makePlan({
|
|
54808
55832
|
selection: {},
|
|
54809
55833
|
required,
|
|
@@ -54832,7 +55856,7 @@ function makeDialectQuery(profile) {
|
|
|
54832
55856
|
];
|
|
54833
55857
|
return makePlan({
|
|
54834
55858
|
selection: {},
|
|
54835
|
-
required: required.filter((
|
|
55859
|
+
required: required.filter((name2, index4, list) => name2 !== sourceName && list.indexOf(name2) === index4),
|
|
54836
55860
|
available: {
|
|
54837
55861
|
[sourceName]: {
|
|
54838
55862
|
name: sourceName,
|
|
@@ -54934,7 +55958,7 @@ function makeDialectQuery(profile) {
|
|
|
54934
55958
|
...notMatchedAssignments.flatMap((entry) => Object.keys(entry.value[TypeId].dependencies)),
|
|
54935
55959
|
...matchedPredicate ? Object.keys(matchedPredicate[TypeId].dependencies) : [],
|
|
54936
55960
|
...notMatchedPredicate ? Object.keys(notMatchedPredicate[TypeId].dependencies) : []
|
|
54937
|
-
].filter((
|
|
55961
|
+
].filter((name2, index4, values2) => name2 !== targetName && name2 !== usingName && values2.indexOf(name2) === index4);
|
|
54938
55962
|
return makePlan({
|
|
54939
55963
|
selection: {},
|
|
54940
55964
|
required,
|
|
@@ -55043,7 +56067,7 @@ function makeDialectQuery(profile) {
|
|
|
55043
56067
|
groupBy: [],
|
|
55044
56068
|
orderBy: []
|
|
55045
56069
|
}, undefined, "transaction", "rollback");
|
|
55046
|
-
const savepoint = (
|
|
56070
|
+
const savepoint = (name2) => makePlan({
|
|
55047
56071
|
selection: {},
|
|
55048
56072
|
required: [],
|
|
55049
56073
|
available: {},
|
|
@@ -55053,7 +56077,7 @@ function makeDialectQuery(profile) {
|
|
|
55053
56077
|
select: {},
|
|
55054
56078
|
transaction: {
|
|
55055
56079
|
kind: "savepoint",
|
|
55056
|
-
name
|
|
56080
|
+
name: name2
|
|
55057
56081
|
},
|
|
55058
56082
|
where: [],
|
|
55059
56083
|
having: [],
|
|
@@ -55061,7 +56085,7 @@ function makeDialectQuery(profile) {
|
|
|
55061
56085
|
groupBy: [],
|
|
55062
56086
|
orderBy: []
|
|
55063
56087
|
}, undefined, "transaction", "savepoint");
|
|
55064
|
-
const rollbackTo = (
|
|
56088
|
+
const rollbackTo = (name2) => makePlan({
|
|
55065
56089
|
selection: {},
|
|
55066
56090
|
required: [],
|
|
55067
56091
|
available: {},
|
|
@@ -55071,7 +56095,7 @@ function makeDialectQuery(profile) {
|
|
|
55071
56095
|
select: {},
|
|
55072
56096
|
transaction: {
|
|
55073
56097
|
kind: "rollbackTo",
|
|
55074
|
-
name
|
|
56098
|
+
name: name2
|
|
55075
56099
|
},
|
|
55076
56100
|
where: [],
|
|
55077
56101
|
having: [],
|
|
@@ -55079,7 +56103,7 @@ function makeDialectQuery(profile) {
|
|
|
55079
56103
|
groupBy: [],
|
|
55080
56104
|
orderBy: []
|
|
55081
56105
|
}, undefined, "transaction", "rollbackTo");
|
|
55082
|
-
const releaseSavepoint = (
|
|
56106
|
+
const releaseSavepoint = (name2) => makePlan({
|
|
55083
56107
|
selection: {},
|
|
55084
56108
|
required: [],
|
|
55085
56109
|
available: {},
|
|
@@ -55089,7 +56113,7 @@ function makeDialectQuery(profile) {
|
|
|
55089
56113
|
select: {},
|
|
55090
56114
|
transaction: {
|
|
55091
56115
|
kind: "releaseSavepoint",
|
|
55092
|
-
name
|
|
56116
|
+
name: name2
|
|
55093
56117
|
},
|
|
55094
56118
|
where: [],
|
|
55095
56119
|
having: [],
|
|
@@ -55213,9 +56237,11 @@ function makeDialectQuery(profile) {
|
|
|
55213
56237
|
};
|
|
55214
56238
|
const api = {
|
|
55215
56239
|
literal,
|
|
56240
|
+
column,
|
|
55216
56241
|
cast,
|
|
55217
56242
|
type,
|
|
55218
56243
|
json: json3,
|
|
56244
|
+
jsonb: jsonb2,
|
|
55219
56245
|
eq,
|
|
55220
56246
|
neq,
|
|
55221
56247
|
lt,
|
|
@@ -55228,6 +56254,10 @@ function makeDialectQuery(profile) {
|
|
|
55228
56254
|
lower,
|
|
55229
56255
|
like,
|
|
55230
56256
|
ilike,
|
|
56257
|
+
regexMatch,
|
|
56258
|
+
regexIMatch,
|
|
56259
|
+
regexNotMatch,
|
|
56260
|
+
regexNotIMatch,
|
|
55231
56261
|
and,
|
|
55232
56262
|
or,
|
|
55233
56263
|
not,
|
|
@@ -55236,6 +56266,9 @@ function makeDialectQuery(profile) {
|
|
|
55236
56266
|
case: case_,
|
|
55237
56267
|
match,
|
|
55238
56268
|
coalesce,
|
|
56269
|
+
call,
|
|
56270
|
+
uuidGenerateV4,
|
|
56271
|
+
nextVal,
|
|
55239
56272
|
in: in_,
|
|
55240
56273
|
notIn,
|
|
55241
56274
|
between,
|
|
@@ -55307,21 +56340,10 @@ function makeDialectQuery(profile) {
|
|
|
55307
56340
|
groupBy
|
|
55308
56341
|
};
|
|
55309
56342
|
return api;
|
|
55310
|
-
}
|
|
55311
|
-
|
|
55312
|
-
// src/mysql/private/query.ts
|
|
55313
|
-
var mysqlQuery = makeDialectQuery({
|
|
55314
|
-
dialect: "mysql",
|
|
55315
|
-
textDb: { dialect: "mysql", kind: "text" },
|
|
55316
|
-
numericDb: { dialect: "mysql", kind: "double" },
|
|
55317
|
-
boolDb: { dialect: "mysql", kind: "boolean" },
|
|
55318
|
-
timestampDb: { dialect: "mysql", kind: "timestamp" },
|
|
55319
|
-
nullDb: { dialect: "mysql", kind: "null" },
|
|
55320
|
-
type: mysqlDatatypes
|
|
55321
|
-
});
|
|
55322
|
-
|
|
56343
|
+
})();
|
|
55323
56344
|
// src/mysql/function/core.ts
|
|
55324
56345
|
var coalesce = mysqlQuery.coalesce;
|
|
56346
|
+
var call = mysqlQuery.call;
|
|
55325
56347
|
// src/mysql/function/string.ts
|
|
55326
56348
|
var exports_string = {};
|
|
55327
56349
|
__export(exports_string, {
|
|
@@ -55366,7 +56388,7 @@ __export(exports_temporal, {
|
|
|
55366
56388
|
currentTime: () => currentTime,
|
|
55367
56389
|
currentDate: () => currentDate
|
|
55368
56390
|
});
|
|
55369
|
-
var makeTemporal = (
|
|
56391
|
+
var makeTemporal = (name2, dbType, runtimeSchema) => makeExpression({
|
|
55370
56392
|
runtime: undefined,
|
|
55371
56393
|
dbType,
|
|
55372
56394
|
runtimeSchema,
|
|
@@ -55378,7 +56400,7 @@ var makeTemporal = (name, dbType, runtimeSchema) => makeExpression({
|
|
|
55378
56400
|
sourceNullability: "resolved"
|
|
55379
56401
|
}, {
|
|
55380
56402
|
kind: "function",
|
|
55381
|
-
name,
|
|
56403
|
+
name: name2,
|
|
55382
56404
|
args: []
|
|
55383
56405
|
});
|
|
55384
56406
|
var currentDate = () => makeTemporal("current_date", { dialect: "mysql", kind: "date" }, LocalDateStringSchema);
|
|
@@ -55401,10 +56423,200 @@ import * as SqlClient3 from "@effect/sql/SqlClient";
|
|
|
55401
56423
|
|
|
55402
56424
|
// src/internal/executor.ts
|
|
55403
56425
|
import * as Effect from "effect/Effect";
|
|
55404
|
-
import * as
|
|
56426
|
+
import * as Schema7 from "effect/Schema";
|
|
55405
56427
|
import * as SqlClient from "@effect/sql/SqlClient";
|
|
55406
56428
|
|
|
55407
56429
|
// src/postgres/datatypes/spec.ts
|
|
56430
|
+
var postgresDatatypeFamilies = {
|
|
56431
|
+
text: {
|
|
56432
|
+
compareGroup: "text",
|
|
56433
|
+
castTargets: [
|
|
56434
|
+
"text",
|
|
56435
|
+
"numeric",
|
|
56436
|
+
"boolean",
|
|
56437
|
+
"date",
|
|
56438
|
+
"time",
|
|
56439
|
+
"timestamp",
|
|
56440
|
+
"interval",
|
|
56441
|
+
"binary",
|
|
56442
|
+
"uuid",
|
|
56443
|
+
"json",
|
|
56444
|
+
"xml",
|
|
56445
|
+
"bit",
|
|
56446
|
+
"oid",
|
|
56447
|
+
"identifier",
|
|
56448
|
+
"network",
|
|
56449
|
+
"spatial",
|
|
56450
|
+
"textsearch",
|
|
56451
|
+
"range",
|
|
56452
|
+
"multirange",
|
|
56453
|
+
"array",
|
|
56454
|
+
"money",
|
|
56455
|
+
"null"
|
|
56456
|
+
],
|
|
56457
|
+
traits: {
|
|
56458
|
+
textual: true,
|
|
56459
|
+
ordered: true
|
|
56460
|
+
}
|
|
56461
|
+
},
|
|
56462
|
+
numeric: {
|
|
56463
|
+
compareGroup: "numeric",
|
|
56464
|
+
castTargets: ["numeric", "text", "boolean", "date", "time", "timestamp", "interval", "uuid", "bit", "oid", "money"],
|
|
56465
|
+
traits: {
|
|
56466
|
+
ordered: true
|
|
56467
|
+
}
|
|
56468
|
+
},
|
|
56469
|
+
boolean: {
|
|
56470
|
+
compareGroup: "boolean",
|
|
56471
|
+
castTargets: ["boolean", "text", "numeric"],
|
|
56472
|
+
traits: {}
|
|
56473
|
+
},
|
|
56474
|
+
date: {
|
|
56475
|
+
compareGroup: "date",
|
|
56476
|
+
castTargets: ["date", "timestamp", "text"],
|
|
56477
|
+
traits: {
|
|
56478
|
+
ordered: true
|
|
56479
|
+
}
|
|
56480
|
+
},
|
|
56481
|
+
time: {
|
|
56482
|
+
compareGroup: "time",
|
|
56483
|
+
castTargets: ["time", "timestamp", "text"],
|
|
56484
|
+
traits: {
|
|
56485
|
+
ordered: true
|
|
56486
|
+
}
|
|
56487
|
+
},
|
|
56488
|
+
timestamp: {
|
|
56489
|
+
compareGroup: "timestamp",
|
|
56490
|
+
castTargets: ["timestamp", "date", "text"],
|
|
56491
|
+
traits: {
|
|
56492
|
+
ordered: true
|
|
56493
|
+
}
|
|
56494
|
+
},
|
|
56495
|
+
interval: {
|
|
56496
|
+
compareGroup: "interval",
|
|
56497
|
+
castTargets: ["interval", "text"],
|
|
56498
|
+
traits: {
|
|
56499
|
+
ordered: true
|
|
56500
|
+
}
|
|
56501
|
+
},
|
|
56502
|
+
binary: {
|
|
56503
|
+
compareGroup: "binary",
|
|
56504
|
+
castTargets: ["binary", "text"],
|
|
56505
|
+
traits: {}
|
|
56506
|
+
},
|
|
56507
|
+
uuid: {
|
|
56508
|
+
compareGroup: "uuid",
|
|
56509
|
+
castTargets: ["uuid", "text"],
|
|
56510
|
+
traits: {
|
|
56511
|
+
ordered: true
|
|
56512
|
+
}
|
|
56513
|
+
},
|
|
56514
|
+
json: {
|
|
56515
|
+
compareGroup: "json",
|
|
56516
|
+
castTargets: ["json", "text"],
|
|
56517
|
+
traits: {}
|
|
56518
|
+
},
|
|
56519
|
+
xml: {
|
|
56520
|
+
compareGroup: "xml",
|
|
56521
|
+
castTargets: ["xml", "text"],
|
|
56522
|
+
traits: {}
|
|
56523
|
+
},
|
|
56524
|
+
bit: {
|
|
56525
|
+
compareGroup: "bit",
|
|
56526
|
+
castTargets: ["bit", "text", "numeric"],
|
|
56527
|
+
traits: {}
|
|
56528
|
+
},
|
|
56529
|
+
oid: {
|
|
56530
|
+
compareGroup: "oid",
|
|
56531
|
+
castTargets: ["oid", "text", "numeric"],
|
|
56532
|
+
traits: {
|
|
56533
|
+
ordered: true
|
|
56534
|
+
}
|
|
56535
|
+
},
|
|
56536
|
+
identifier: {
|
|
56537
|
+
compareGroup: "identifier",
|
|
56538
|
+
castTargets: ["identifier", "text"],
|
|
56539
|
+
traits: {}
|
|
56540
|
+
},
|
|
56541
|
+
network: {
|
|
56542
|
+
compareGroup: "network",
|
|
56543
|
+
castTargets: ["network", "text"],
|
|
56544
|
+
traits: {}
|
|
56545
|
+
},
|
|
56546
|
+
spatial: {
|
|
56547
|
+
compareGroup: "spatial",
|
|
56548
|
+
castTargets: ["spatial", "text"],
|
|
56549
|
+
traits: {}
|
|
56550
|
+
},
|
|
56551
|
+
textsearch: {
|
|
56552
|
+
compareGroup: "textsearch",
|
|
56553
|
+
castTargets: ["textsearch", "text"],
|
|
56554
|
+
traits: {}
|
|
56555
|
+
},
|
|
56556
|
+
range: {
|
|
56557
|
+
compareGroup: "range",
|
|
56558
|
+
castTargets: ["range", "text"],
|
|
56559
|
+
traits: {}
|
|
56560
|
+
},
|
|
56561
|
+
multirange: {
|
|
56562
|
+
compareGroup: "multirange",
|
|
56563
|
+
castTargets: ["multirange", "text"],
|
|
56564
|
+
traits: {}
|
|
56565
|
+
},
|
|
56566
|
+
enum: {
|
|
56567
|
+
compareGroup: "enum",
|
|
56568
|
+
castTargets: ["enum", "text"],
|
|
56569
|
+
traits: {
|
|
56570
|
+
textual: true,
|
|
56571
|
+
ordered: true
|
|
56572
|
+
}
|
|
56573
|
+
},
|
|
56574
|
+
record: {
|
|
56575
|
+
compareGroup: "record",
|
|
56576
|
+
castTargets: ["record", "text"],
|
|
56577
|
+
traits: {}
|
|
56578
|
+
},
|
|
56579
|
+
array: {
|
|
56580
|
+
compareGroup: "array",
|
|
56581
|
+
castTargets: ["array", "text"],
|
|
56582
|
+
traits: {}
|
|
56583
|
+
},
|
|
56584
|
+
money: {
|
|
56585
|
+
compareGroup: "money",
|
|
56586
|
+
castTargets: ["money", "text", "numeric"],
|
|
56587
|
+
traits: {
|
|
56588
|
+
ordered: true
|
|
56589
|
+
}
|
|
56590
|
+
},
|
|
56591
|
+
null: {
|
|
56592
|
+
compareGroup: "null",
|
|
56593
|
+
castTargets: [
|
|
56594
|
+
"text",
|
|
56595
|
+
"numeric",
|
|
56596
|
+
"boolean",
|
|
56597
|
+
"date",
|
|
56598
|
+
"time",
|
|
56599
|
+
"timestamp",
|
|
56600
|
+
"interval",
|
|
56601
|
+
"binary",
|
|
56602
|
+
"uuid",
|
|
56603
|
+
"json",
|
|
56604
|
+
"xml",
|
|
56605
|
+
"bit",
|
|
56606
|
+
"oid",
|
|
56607
|
+
"identifier",
|
|
56608
|
+
"network",
|
|
56609
|
+
"spatial",
|
|
56610
|
+
"textsearch",
|
|
56611
|
+
"range",
|
|
56612
|
+
"multirange",
|
|
56613
|
+
"array",
|
|
56614
|
+
"money",
|
|
56615
|
+
"null"
|
|
56616
|
+
],
|
|
56617
|
+
traits: {}
|
|
56618
|
+
}
|
|
56619
|
+
};
|
|
55408
56620
|
var postgresDatatypeKinds = {
|
|
55409
56621
|
text: { family: "text", runtime: "string" },
|
|
55410
56622
|
varchar: { family: "text", runtime: "string" },
|
|
@@ -55784,7 +56996,7 @@ var normalizeDbValue = (dbType, value) => {
|
|
|
55784
56996
|
};
|
|
55785
56997
|
|
|
55786
56998
|
// src/internal/runtime-schema.ts
|
|
55787
|
-
import * as
|
|
56999
|
+
import * as Schema6 from "effect/Schema";
|
|
55788
57000
|
import * as SchemaAST from "effect/SchemaAST";
|
|
55789
57001
|
var schemaCache = new WeakMap;
|
|
55790
57002
|
var stripParameterizedKind2 = (kind) => {
|
|
@@ -55802,13 +57014,13 @@ var baseKind2 = (kind) => stripArrayKind2(stripParameterizedKind2(kind));
|
|
|
55802
57014
|
var runtimeSchemaForTag = (tag) => {
|
|
55803
57015
|
switch (tag) {
|
|
55804
57016
|
case "string":
|
|
55805
|
-
return
|
|
57017
|
+
return Schema6.String;
|
|
55806
57018
|
case "number":
|
|
55807
|
-
return
|
|
57019
|
+
return Schema6.Number;
|
|
55808
57020
|
case "bigintString":
|
|
55809
57021
|
return BigIntStringSchema;
|
|
55810
57022
|
case "boolean":
|
|
55811
|
-
return
|
|
57023
|
+
return Schema6.Boolean;
|
|
55812
57024
|
case "json":
|
|
55813
57025
|
return JsonValueSchema;
|
|
55814
57026
|
case "localDate":
|
|
@@ -55826,16 +57038,16 @@ var runtimeSchemaForTag = (tag) => {
|
|
|
55826
57038
|
case "decimalString":
|
|
55827
57039
|
return DecimalStringSchema;
|
|
55828
57040
|
case "bytes":
|
|
55829
|
-
return
|
|
57041
|
+
return Schema6.Uint8ArrayFromSelf;
|
|
55830
57042
|
case "array":
|
|
55831
|
-
return
|
|
57043
|
+
return Schema6.Array(Schema6.Unknown);
|
|
55832
57044
|
case "record":
|
|
55833
|
-
return
|
|
55834
|
-
key:
|
|
55835
|
-
value:
|
|
57045
|
+
return Schema6.Record({
|
|
57046
|
+
key: Schema6.String,
|
|
57047
|
+
value: Schema6.Unknown
|
|
55836
57048
|
});
|
|
55837
57049
|
case "null":
|
|
55838
|
-
return
|
|
57050
|
+
return Schema6.Null;
|
|
55839
57051
|
case "unknown":
|
|
55840
57052
|
return;
|
|
55841
57053
|
}
|
|
@@ -55855,22 +57067,22 @@ var runtimeSchemaForDbType = (dbType) => {
|
|
|
55855
57067
|
return runtimeSchemaForDbType(dbType.base);
|
|
55856
57068
|
}
|
|
55857
57069
|
if ("element" in dbType) {
|
|
55858
|
-
return
|
|
57070
|
+
return Schema6.Array(runtimeSchemaForDbType(dbType.element) ?? Schema6.Unknown);
|
|
55859
57071
|
}
|
|
55860
57072
|
if ("fields" in dbType) {
|
|
55861
|
-
const fields2 = Object.fromEntries(Object.entries(dbType.fields).map(([key2, field]) => [key2, runtimeSchemaForDbType(field) ??
|
|
55862
|
-
return
|
|
57073
|
+
const fields2 = Object.fromEntries(Object.entries(dbType.fields).map(([key2, field]) => [key2, runtimeSchemaForDbType(field) ?? Schema6.Unknown]));
|
|
57074
|
+
return Schema6.Struct(fields2);
|
|
55863
57075
|
}
|
|
55864
57076
|
if ("variant" in dbType && dbType.variant === "json") {
|
|
55865
57077
|
return JsonValueSchema;
|
|
55866
57078
|
}
|
|
55867
57079
|
if ("variant" in dbType && (dbType.variant === "enum" || dbType.variant === "set")) {
|
|
55868
|
-
return
|
|
57080
|
+
return Schema6.String;
|
|
55869
57081
|
}
|
|
55870
57082
|
const runtimeTag = runtimeTagOfBaseDbType2(dbType.dialect, dbType.kind);
|
|
55871
57083
|
return runtimeTag === undefined ? undefined : runtimeSchemaForTag(runtimeTag);
|
|
55872
57084
|
};
|
|
55873
|
-
var makeSchemaFromAst = (ast) =>
|
|
57085
|
+
var makeSchemaFromAst = (ast) => Schema6.make(ast);
|
|
55874
57086
|
var unionAst = (asts) => {
|
|
55875
57087
|
if (asts.length === 0) {
|
|
55876
57088
|
return;
|
|
@@ -55893,8 +57105,8 @@ var propertyAstOf = (ast, key2) => {
|
|
|
55893
57105
|
if (property !== undefined) {
|
|
55894
57106
|
return property.type;
|
|
55895
57107
|
}
|
|
55896
|
-
const
|
|
55897
|
-
return
|
|
57108
|
+
const index4 = ast.indexSignatures.find((entry) => entry.parameter._tag === "StringKeyword");
|
|
57109
|
+
return index4?.type;
|
|
55898
57110
|
}
|
|
55899
57111
|
case "Union": {
|
|
55900
57112
|
const values = ast.types.flatMap((member) => {
|
|
@@ -55907,16 +57119,16 @@ var propertyAstOf = (ast, key2) => {
|
|
|
55907
57119
|
return;
|
|
55908
57120
|
}
|
|
55909
57121
|
};
|
|
55910
|
-
var numberAstOf = (ast,
|
|
57122
|
+
var numberAstOf = (ast, index4) => {
|
|
55911
57123
|
switch (ast._tag) {
|
|
55912
57124
|
case "Transformation":
|
|
55913
|
-
return numberAstOf(SchemaAST.typeAST(ast),
|
|
57125
|
+
return numberAstOf(SchemaAST.typeAST(ast), index4);
|
|
55914
57126
|
case "Refinement":
|
|
55915
|
-
return numberAstOf(ast.from,
|
|
57127
|
+
return numberAstOf(ast.from, index4);
|
|
55916
57128
|
case "Suspend":
|
|
55917
|
-
return numberAstOf(ast.f(),
|
|
57129
|
+
return numberAstOf(ast.f(), index4);
|
|
55918
57130
|
case "TupleType": {
|
|
55919
|
-
const element = ast.elements[
|
|
57131
|
+
const element = ast.elements[index4];
|
|
55920
57132
|
if (element !== undefined) {
|
|
55921
57133
|
return element.type;
|
|
55922
57134
|
}
|
|
@@ -55927,7 +57139,7 @@ var numberAstOf = (ast, index3) => {
|
|
|
55927
57139
|
}
|
|
55928
57140
|
case "Union": {
|
|
55929
57141
|
const values = ast.types.flatMap((member) => {
|
|
55930
|
-
const next = numberAstOf(member,
|
|
57142
|
+
const next = numberAstOf(member, index4);
|
|
55931
57143
|
return next === undefined ? [] : [next];
|
|
55932
57144
|
});
|
|
55933
57145
|
return unionAst(values);
|
|
@@ -55968,7 +57180,7 @@ var unionSchemas = (schemas) => {
|
|
|
55968
57180
|
if (resolved.length === 1) {
|
|
55969
57181
|
return resolved[0];
|
|
55970
57182
|
}
|
|
55971
|
-
return
|
|
57183
|
+
return Schema6.Union(...resolved);
|
|
55972
57184
|
};
|
|
55973
57185
|
var firstSelectedExpression = (plan) => {
|
|
55974
57186
|
const selection = getAst(plan).select;
|
|
@@ -56001,12 +57213,39 @@ var jsonCompatibleSchema = (schema4) => {
|
|
|
56001
57213
|
const ast = SchemaAST.typeAST(schema4.ast);
|
|
56002
57214
|
return isJsonCompatibleAst(ast) ? schema4 : JsonValueSchema;
|
|
56003
57215
|
};
|
|
56004
|
-
var buildStructSchema = (entries) => {
|
|
56005
|
-
const fields2 = Object.fromEntries(entries.map((entry) => [entry.key, expressionRuntimeSchema(entry.value) ?? JsonValueSchema]));
|
|
56006
|
-
return
|
|
57216
|
+
var buildStructSchema = (entries, context) => {
|
|
57217
|
+
const fields2 = Object.fromEntries(entries.map((entry) => [entry.key, expressionRuntimeSchema(entry.value, context) ?? JsonValueSchema]));
|
|
57218
|
+
return Schema6.Struct(fields2);
|
|
57219
|
+
};
|
|
57220
|
+
var buildTupleSchema = (values, context) => Schema6.Tuple(...values.map((value) => expressionRuntimeSchema(value, context) ?? JsonValueSchema));
|
|
57221
|
+
var deriveCaseSchema = (ast, context) => {
|
|
57222
|
+
if (context === undefined) {
|
|
57223
|
+
return unionSchemas([
|
|
57224
|
+
...ast.branches.map((branch) => expressionRuntimeSchema(branch.then)),
|
|
57225
|
+
expressionRuntimeSchema(ast.else)
|
|
57226
|
+
]);
|
|
57227
|
+
}
|
|
57228
|
+
const schemas = [];
|
|
57229
|
+
let elseAssumptions = context.assumptions;
|
|
57230
|
+
for (const branch of ast.branches) {
|
|
57231
|
+
const whenFormula = formulaOfExpression(branch.when);
|
|
57232
|
+
if (contradictsFormula(elseAssumptions, whenFormula)) {
|
|
57233
|
+
continue;
|
|
57234
|
+
}
|
|
57235
|
+
const branchContext = { assumptions: assumeFormulaTrue(elseAssumptions, whenFormula) };
|
|
57236
|
+
const branchSchema = expressionRuntimeSchema(branch.then, branchContext);
|
|
57237
|
+
if (branchSchema !== undefined) {
|
|
57238
|
+
schemas.push(branchSchema);
|
|
57239
|
+
}
|
|
57240
|
+
if (impliesFormula(elseAssumptions, whenFormula)) {
|
|
57241
|
+
return unionSchemas(schemas);
|
|
57242
|
+
}
|
|
57243
|
+
elseAssumptions = assumeFormulaFalse(elseAssumptions, whenFormula);
|
|
57244
|
+
}
|
|
57245
|
+
const elseSchema = expressionRuntimeSchema(ast.else, { assumptions: elseAssumptions });
|
|
57246
|
+
return unionSchemas(elseSchema === undefined ? schemas : [...schemas, elseSchema]);
|
|
56007
57247
|
};
|
|
56008
|
-
var
|
|
56009
|
-
var deriveRuntimeSchema = (expression) => {
|
|
57248
|
+
var deriveRuntimeSchema = (expression, context) => {
|
|
56010
57249
|
const state = expression[TypeId];
|
|
56011
57250
|
if (state.runtimeSchema !== undefined) {
|
|
56012
57251
|
return state.runtimeSchema;
|
|
@@ -56018,10 +57257,10 @@ var deriveRuntimeSchema = (expression) => {
|
|
|
56018
57257
|
return state.runtimeSchema;
|
|
56019
57258
|
case "literal":
|
|
56020
57259
|
if (ast.value === null) {
|
|
56021
|
-
return
|
|
57260
|
+
return Schema6.Null;
|
|
56022
57261
|
}
|
|
56023
57262
|
if (typeof ast.value === "string" || typeof ast.value === "number" || typeof ast.value === "boolean") {
|
|
56024
|
-
return
|
|
57263
|
+
return Schema6.Literal(ast.value);
|
|
56025
57264
|
}
|
|
56026
57265
|
return runtimeSchemaForDbType(state.dbType);
|
|
56027
57266
|
case "cast":
|
|
@@ -56057,7 +57296,7 @@ var deriveRuntimeSchema = (expression) => {
|
|
|
56057
57296
|
case "jsonHasAllKeys":
|
|
56058
57297
|
case "jsonPathExists":
|
|
56059
57298
|
case "jsonPathMatch":
|
|
56060
|
-
return
|
|
57299
|
+
return Schema6.Boolean;
|
|
56061
57300
|
case "upper":
|
|
56062
57301
|
case "lower":
|
|
56063
57302
|
case "concat":
|
|
@@ -56066,31 +57305,28 @@ var deriveRuntimeSchema = (expression) => {
|
|
|
56066
57305
|
case "jsonAccessText":
|
|
56067
57306
|
case "jsonTraverseText":
|
|
56068
57307
|
case "jsonTypeOf":
|
|
56069
|
-
return
|
|
57308
|
+
return Schema6.String;
|
|
56070
57309
|
case "count":
|
|
56071
57310
|
case "jsonLength":
|
|
56072
|
-
return
|
|
57311
|
+
return Schema6.Number;
|
|
56073
57312
|
case "max":
|
|
56074
57313
|
case "min":
|
|
56075
|
-
return expressionRuntimeSchema(ast.value);
|
|
57314
|
+
return expressionRuntimeSchema(ast.value, context);
|
|
56076
57315
|
case "case":
|
|
56077
|
-
return
|
|
56078
|
-
...ast.branches.map((branch) => expressionRuntimeSchema(branch.then)),
|
|
56079
|
-
expressionRuntimeSchema(ast.else)
|
|
56080
|
-
]);
|
|
57316
|
+
return deriveCaseSchema(ast, context);
|
|
56081
57317
|
case "coalesce":
|
|
56082
|
-
return unionSchemas(ast.values.map(expressionRuntimeSchema));
|
|
57318
|
+
return unionSchemas(ast.values.map((value) => expressionRuntimeSchema(value, context)));
|
|
56083
57319
|
case "scalarSubquery": {
|
|
56084
57320
|
const selection = firstSelectedExpression(ast.plan);
|
|
56085
|
-
return selection === undefined ? undefined : expressionRuntimeSchema(selection);
|
|
57321
|
+
return selection === undefined ? undefined : expressionRuntimeSchema(selection, context);
|
|
56086
57322
|
}
|
|
56087
57323
|
case "window":
|
|
56088
|
-
return ast.function === "over" && ast.value !== undefined ? expressionRuntimeSchema(ast.value) :
|
|
57324
|
+
return ast.function === "over" && ast.value !== undefined ? expressionRuntimeSchema(ast.value, context) : Schema6.Number;
|
|
56089
57325
|
case "jsonGet":
|
|
56090
57326
|
case "jsonPath":
|
|
56091
57327
|
case "jsonAccess":
|
|
56092
57328
|
case "jsonTraverse": {
|
|
56093
|
-
const baseSchema = expressionRuntimeSchema(ast.base);
|
|
57329
|
+
const baseSchema = expressionRuntimeSchema(ast.base, context);
|
|
56094
57330
|
const segments = ast.segments;
|
|
56095
57331
|
if (baseSchema === undefined || segments === undefined || !exactJsonSegments(segments)) {
|
|
56096
57332
|
return JsonValueSchema;
|
|
@@ -56103,24 +57339,27 @@ var deriveRuntimeSchema = (expression) => {
|
|
|
56103
57339
|
case "jsonRemove":
|
|
56104
57340
|
case "jsonSet":
|
|
56105
57341
|
case "jsonInsert":
|
|
56106
|
-
return expressionRuntimeSchema(ast.base);
|
|
57342
|
+
return expressionRuntimeSchema(ast.base, context);
|
|
56107
57343
|
case "jsonStripNulls":
|
|
56108
|
-
return expressionRuntimeSchema(ast.value);
|
|
57344
|
+
return expressionRuntimeSchema(ast.value, context);
|
|
56109
57345
|
case "jsonConcat":
|
|
56110
57346
|
case "jsonMerge":
|
|
56111
57347
|
return JsonValueSchema;
|
|
56112
57348
|
case "jsonBuildObject":
|
|
56113
|
-
return buildStructSchema(ast.entries ?? []);
|
|
57349
|
+
return buildStructSchema(ast.entries ?? [], context);
|
|
56114
57350
|
case "jsonBuildArray":
|
|
56115
|
-
return buildTupleSchema(ast.values ?? []);
|
|
57351
|
+
return buildTupleSchema(ast.values ?? [], context);
|
|
56116
57352
|
case "jsonToJson":
|
|
56117
57353
|
case "jsonToJsonb":
|
|
56118
|
-
return jsonCompatibleSchema(expressionRuntimeSchema(ast.value));
|
|
57354
|
+
return jsonCompatibleSchema(expressionRuntimeSchema(ast.value, context));
|
|
56119
57355
|
case "jsonKeys":
|
|
56120
|
-
return
|
|
57356
|
+
return Schema6.Array(Schema6.String);
|
|
56121
57357
|
}
|
|
56122
57358
|
};
|
|
56123
|
-
var expressionRuntimeSchema = (expression) => {
|
|
57359
|
+
var expressionRuntimeSchema = (expression, context) => {
|
|
57360
|
+
if (context !== undefined) {
|
|
57361
|
+
return deriveRuntimeSchema(expression, context) ?? runtimeSchemaForDbType(expression[TypeId].dbType);
|
|
57362
|
+
}
|
|
56124
57363
|
const cached = schemaCache.get(expression);
|
|
56125
57364
|
if (cached !== undefined || schemaCache.has(expression)) {
|
|
56126
57365
|
return cached;
|
|
@@ -56133,8 +57372,8 @@ var expressionRuntimeSchema = (expression) => {
|
|
|
56133
57372
|
// src/internal/executor.ts
|
|
56134
57373
|
var setPath2 = (target, path2, value) => {
|
|
56135
57374
|
let current = target;
|
|
56136
|
-
for (let
|
|
56137
|
-
const key2 = path2[
|
|
57375
|
+
for (let index4 = 0;index4 < path2.length - 1; index4++) {
|
|
57376
|
+
const key2 = path2[index4];
|
|
56138
57377
|
const existing = current[key2];
|
|
56139
57378
|
if (typeof existing === "object" && existing !== null && !Array.isArray(existing)) {
|
|
56140
57379
|
current = existing;
|
|
@@ -56193,21 +57432,34 @@ var makeRowDecodeError = (rendered, projection, expression, raw, stage, cause, n
|
|
|
56193
57432
|
stage,
|
|
56194
57433
|
cause
|
|
56195
57434
|
});
|
|
56196
|
-
var hasOptionalSourceDependency = (expression,
|
|
57435
|
+
var hasOptionalSourceDependency = (expression, scope) => {
|
|
56197
57436
|
const state = expression[TypeId];
|
|
56198
57437
|
if (state.sourceNullability === "resolved") {
|
|
56199
57438
|
return false;
|
|
56200
57439
|
}
|
|
56201
|
-
return Object.keys(state.dependencies).some((sourceName) =>
|
|
57440
|
+
return Object.keys(state.dependencies).some((sourceName) => !scope.absentSourceNames.has(sourceName) && scope.sourceModes.get(sourceName) === "optional");
|
|
56202
57441
|
};
|
|
56203
|
-
var effectiveRuntimeNullability = (expression,
|
|
57442
|
+
var effectiveRuntimeNullability = (expression, scope) => {
|
|
56204
57443
|
const nullability = expression[TypeId].nullability;
|
|
57444
|
+
const ast = expression[TypeId2];
|
|
56205
57445
|
if (nullability === "always") {
|
|
56206
57446
|
return "always";
|
|
56207
57447
|
}
|
|
56208
|
-
|
|
57448
|
+
if (ast.kind === "column") {
|
|
57449
|
+
const key2 = `${ast.tableName}.${ast.columnName}`;
|
|
57450
|
+
if (scope.absentSourceNames.has(ast.tableName) || scope.nullKeys.has(key2)) {
|
|
57451
|
+
return "always";
|
|
57452
|
+
}
|
|
57453
|
+
if (scope.nonNullKeys.has(key2)) {
|
|
57454
|
+
return "never";
|
|
57455
|
+
}
|
|
57456
|
+
}
|
|
57457
|
+
if (expression[TypeId].sourceNullability !== "resolved" && Object.keys(expression[TypeId].dependencies).some((sourceName) => scope.absentSourceNames.has(sourceName))) {
|
|
57458
|
+
return "always";
|
|
57459
|
+
}
|
|
57460
|
+
return hasOptionalSourceDependency(expression, scope) ? "maybe" : nullability;
|
|
56209
57461
|
};
|
|
56210
|
-
var decodeProjectionValue = (rendered, projection, expression, raw,
|
|
57462
|
+
var decodeProjectionValue = (rendered, projection, expression, raw, scope, driverMode) => {
|
|
56211
57463
|
let normalized = raw;
|
|
56212
57464
|
if (driverMode === "raw") {
|
|
56213
57465
|
try {
|
|
@@ -56216,21 +57468,25 @@ var decodeProjectionValue = (rendered, projection, expression, raw, available, d
|
|
|
56216
57468
|
throw makeRowDecodeError(rendered, projection, expression, raw, "normalize", cause);
|
|
56217
57469
|
}
|
|
56218
57470
|
}
|
|
57471
|
+
const nullability = effectiveRuntimeNullability(expression, scope);
|
|
56219
57472
|
if (normalized === null) {
|
|
56220
|
-
if (
|
|
57473
|
+
if (nullability === "never") {
|
|
56221
57474
|
throw makeRowDecodeError(rendered, projection, expression, raw, "schema", new Error("Received null for a non-null projection"), normalized);
|
|
56222
57475
|
}
|
|
56223
57476
|
return null;
|
|
56224
57477
|
}
|
|
56225
|
-
|
|
57478
|
+
if (nullability === "always") {
|
|
57479
|
+
throw makeRowDecodeError(rendered, projection, expression, raw, "schema", new Error("Received non-null for an always-null projection"), normalized);
|
|
57480
|
+
}
|
|
57481
|
+
const schema4 = expressionRuntimeSchema(expression, { assumptions: scope.assumptions });
|
|
56226
57482
|
if (schema4 === undefined) {
|
|
56227
57483
|
return normalized;
|
|
56228
57484
|
}
|
|
56229
|
-
if (
|
|
57485
|
+
if (Schema7.is(schema4)(normalized)) {
|
|
56230
57486
|
return normalized;
|
|
56231
57487
|
}
|
|
56232
57488
|
try {
|
|
56233
|
-
return
|
|
57489
|
+
return Schema7.decodeUnknownSync(schema4)(normalized);
|
|
56234
57490
|
} catch (cause) {
|
|
56235
57491
|
throw makeRowDecodeError(rendered, projection, expression, raw, "schema", cause, normalized);
|
|
56236
57492
|
}
|
|
@@ -56239,7 +57495,7 @@ var decodeRows = (rendered, plan, rows, options2 = {}) => {
|
|
|
56239
57495
|
const projections = flattenSelection(getAst(plan).select);
|
|
56240
57496
|
const byAlias = new Map(projections.map((projection) => [projection.alias, projection.expression]));
|
|
56241
57497
|
const driverMode = options2.driverMode ?? "raw";
|
|
56242
|
-
const
|
|
57498
|
+
const scope = resolveImplicationScope(plan[TypeId3].available, getQueryState(plan).assumptions);
|
|
56243
57499
|
return rows.map((row) => {
|
|
56244
57500
|
const decoded = {};
|
|
56245
57501
|
for (const projection of rendered.projections) {
|
|
@@ -56250,7 +57506,7 @@ var decodeRows = (rendered, plan, rows, options2 = {}) => {
|
|
|
56250
57506
|
if (expression === undefined) {
|
|
56251
57507
|
continue;
|
|
56252
57508
|
}
|
|
56253
|
-
setPath2(decoded, projection.path, decodeProjectionValue(rendered, projection, expression, row[projection.alias],
|
|
57509
|
+
setPath2(decoded, projection.path, decodeProjectionValue(rendered, projection, expression, row[projection.alias], scope, driverMode));
|
|
56254
57510
|
}
|
|
56255
57511
|
return decoded;
|
|
56256
57512
|
});
|
|
@@ -56328,6 +57584,29 @@ var validateAggregationSelection = (selection, grouped) => {
|
|
|
56328
57584
|
}
|
|
56329
57585
|
};
|
|
56330
57586
|
|
|
57587
|
+
// src/internal/schema-expression.ts
|
|
57588
|
+
import { parse, toSql } from "pgsql-ast-parser";
|
|
57589
|
+
import { pipeArguments as pipeArguments6 } from "effect/Pipeable";
|
|
57590
|
+
var TypeId8 = Symbol.for("effect-qb/SchemaExpression");
|
|
57591
|
+
var SchemaExpressionProto = {
|
|
57592
|
+
pipe() {
|
|
57593
|
+
return pipeArguments6(this, arguments);
|
|
57594
|
+
}
|
|
57595
|
+
};
|
|
57596
|
+
var isSchemaExpression = (value) => typeof value === "object" && value !== null && (TypeId8 in value);
|
|
57597
|
+
var fromAst = (ast) => {
|
|
57598
|
+
const expression = Object.create(SchemaExpressionProto);
|
|
57599
|
+
expression[TypeId8] = {
|
|
57600
|
+
dialect: "postgres",
|
|
57601
|
+
ast
|
|
57602
|
+
};
|
|
57603
|
+
return expression;
|
|
57604
|
+
};
|
|
57605
|
+
var parseExpression = (sql) => fromAst(parse(sql, "expr"));
|
|
57606
|
+
var toAst = (expression) => expression[TypeId8].ast;
|
|
57607
|
+
var render = (expression) => toSql.expr(expression[TypeId8].ast);
|
|
57608
|
+
var normalize2 = (expression) => parseExpression(render(expression));
|
|
57609
|
+
|
|
56331
57610
|
// src/internal/sql-expression-renderer.ts
|
|
56332
57611
|
var renderDbType = (dialect, dbType) => {
|
|
56333
57612
|
if (dialect.name === "mysql" && dbType.dialect === "mysql" && dbType.kind === "uuid") {
|
|
@@ -56357,43 +57636,43 @@ var renderCastType = (dialect, dbType) => {
|
|
|
56357
57636
|
return dbType.kind;
|
|
56358
57637
|
}
|
|
56359
57638
|
};
|
|
57639
|
+
var renderDdlExpression = (expression, state, dialect) => isSchemaExpression(expression) ? render(expression) : renderExpression(expression, state, dialect);
|
|
56360
57640
|
var renderColumnDefinition = (dialect, state, columnName, column) => {
|
|
56361
57641
|
const clauses = [
|
|
56362
57642
|
dialect.quoteIdentifier(columnName),
|
|
56363
|
-
renderDbType(dialect, column.metadata.dbType)
|
|
57643
|
+
column.metadata.ddlType ?? renderDbType(dialect, column.metadata.dbType)
|
|
56364
57644
|
];
|
|
56365
|
-
if (column.metadata.
|
|
56366
|
-
clauses.push(`generated
|
|
57645
|
+
if (column.metadata.identity) {
|
|
57646
|
+
clauses.push(`generated ${column.metadata.identity.generation === "byDefault" ? "by default" : "always"} as identity`);
|
|
57647
|
+
} else if (column.metadata.generatedValue) {
|
|
57648
|
+
clauses.push(`generated always as (${renderDdlExpression(column.metadata.generatedValue, state, dialect)}) stored`);
|
|
56367
57649
|
} else if (column.metadata.defaultValue) {
|
|
56368
|
-
clauses.push(`default ${
|
|
57650
|
+
clauses.push(`default ${renderDdlExpression(column.metadata.defaultValue, state, dialect)}`);
|
|
56369
57651
|
}
|
|
56370
57652
|
if (!column.metadata.nullable) {
|
|
56371
57653
|
clauses.push("not null");
|
|
56372
57654
|
}
|
|
56373
57655
|
return clauses.join(" ");
|
|
56374
57656
|
};
|
|
56375
|
-
var renderCheckPredicate = (predicate, state, dialect) => {
|
|
56376
|
-
return renderExpression(predicate, state, dialect);
|
|
56377
|
-
};
|
|
56378
57657
|
var renderCreateTableSql = (targetSource, state, dialect, ifNotExists) => {
|
|
56379
57658
|
const table = targetSource.source;
|
|
56380
57659
|
const fields2 = table[TypeId4].fields;
|
|
56381
57660
|
const definitions = Object.entries(fields2).map(([columnName, column]) => renderColumnDefinition(dialect, state, columnName, column));
|
|
56382
|
-
for (const
|
|
56383
|
-
switch (
|
|
57661
|
+
for (const option2 of table[OptionsSymbol]) {
|
|
57662
|
+
switch (option2.kind) {
|
|
56384
57663
|
case "primaryKey":
|
|
56385
|
-
definitions.push(`primary key (${
|
|
57664
|
+
definitions.push(`${option2.name ? `constraint ${dialect.quoteIdentifier(option2.name)} ` : ""}primary key (${option2.columns.map((column) => dialect.quoteIdentifier(column)).join(", ")})${option2.deferrable ? ` deferrable${option2.initiallyDeferred ? " initially deferred" : ""}` : ""}`);
|
|
56386
57665
|
break;
|
|
56387
57666
|
case "unique":
|
|
56388
|
-
definitions.push(`unique (${
|
|
57667
|
+
definitions.push(`${option2.name ? `constraint ${dialect.quoteIdentifier(option2.name)} ` : ""}unique${option2.nullsNotDistinct ? " nulls not distinct" : ""} (${option2.columns.map((column) => dialect.quoteIdentifier(column)).join(", ")})${option2.deferrable ? ` deferrable${option2.initiallyDeferred ? " initially deferred" : ""}` : ""}`);
|
|
56389
57668
|
break;
|
|
56390
57669
|
case "foreignKey": {
|
|
56391
|
-
const reference =
|
|
56392
|
-
definitions.push(`foreign key (${
|
|
57670
|
+
const reference = option2.references();
|
|
57671
|
+
definitions.push(`${option2.name ? `constraint ${dialect.quoteIdentifier(option2.name)} ` : ""}foreign key (${option2.columns.map((column) => dialect.quoteIdentifier(column)).join(", ")}) references ${dialect.renderTableReference(reference.tableName, reference.tableName, reference.schemaName)} (${reference.columns.map((column) => dialect.quoteIdentifier(column)).join(", ")})${option2.onDelete ? ` on delete ${option2.onDelete.replace(/[A-Z]/g, (value) => ` ${value.toLowerCase()}`).trim()}` : ""}${option2.onUpdate ? ` on update ${option2.onUpdate.replace(/[A-Z]/g, (value) => ` ${value.toLowerCase()}`).trim()}` : ""}${option2.deferrable ? ` deferrable${option2.initiallyDeferred ? " initially deferred" : ""}` : ""}`);
|
|
56393
57672
|
break;
|
|
56394
57673
|
}
|
|
56395
57674
|
case "check":
|
|
56396
|
-
definitions.push(`constraint ${dialect.quoteIdentifier(
|
|
57675
|
+
definitions.push(`constraint ${dialect.quoteIdentifier(option2.name)} check (${renderDdlExpression(option2.predicate, state, dialect)})${option2.noInherit ? " no inherit" : ""}`);
|
|
56397
57676
|
break;
|
|
56398
57677
|
case "index":
|
|
56399
57678
|
break;
|
|
@@ -56437,7 +57716,7 @@ var extractJsonPathSegments = (node) => {
|
|
|
56437
57716
|
return [key(segment)];
|
|
56438
57717
|
}
|
|
56439
57718
|
if (typeof segment === "number") {
|
|
56440
|
-
return [
|
|
57719
|
+
return [index3(segment)];
|
|
56441
57720
|
}
|
|
56442
57721
|
if (segment !== null && typeof segment === "object" && SegmentTypeId in segment) {
|
|
56443
57722
|
return [segment];
|
|
@@ -56496,6 +57775,7 @@ var renderPostgresJsonPathArray = (segments, state, dialect) => `array[${segment
|
|
|
56496
57775
|
throw new Error("Postgres JSON traversal requires exact key/index segments");
|
|
56497
57776
|
}
|
|
56498
57777
|
}).join(", ")}]`;
|
|
57778
|
+
var renderPostgresTextLiteral = (value, state, dialect) => `cast(${dialect.renderLiteral(value, state)} as text)`;
|
|
56499
57779
|
var renderPostgresJsonAccessStep = (segment, textMode, state, dialect) => {
|
|
56500
57780
|
switch (segment.kind) {
|
|
56501
57781
|
case "key":
|
|
@@ -56513,6 +57793,7 @@ var renderPostgresJsonValue = (value, state, dialect) => {
|
|
|
56513
57793
|
const rendered = renderExpression(value, state, dialect);
|
|
56514
57794
|
return value[TypeId].dbType.kind === "jsonb" ? rendered : `cast(${rendered} as jsonb)`;
|
|
56515
57795
|
};
|
|
57796
|
+
var renderPostgresJsonKind = (value) => value[TypeId].dbType.kind === "jsonb" ? "jsonb" : "json";
|
|
56516
57797
|
var renderJsonOpaquePath = (value, state, dialect) => {
|
|
56517
57798
|
if (isJsonPathValue(value)) {
|
|
56518
57799
|
return dialect.renderLiteral(renderJsonPathStringLiteral(value.segments), state);
|
|
@@ -56525,23 +57806,39 @@ var renderJsonOpaquePath = (value, state, dialect) => {
|
|
|
56525
57806
|
}
|
|
56526
57807
|
throw new Error("Unsupported SQL/JSON path input");
|
|
56527
57808
|
};
|
|
56528
|
-
var renderFunctionCall = (
|
|
57809
|
+
var renderFunctionCall = (name2, args, state, dialect) => {
|
|
57810
|
+
if (name2 === "array") {
|
|
57811
|
+
return `ARRAY[${args.map((arg) => renderExpression(arg, state, dialect)).join(", ")}]`;
|
|
57812
|
+
}
|
|
57813
|
+
if (name2 === "extract" && args.length === 2) {
|
|
57814
|
+
const field = args[0];
|
|
57815
|
+
const source = args[1];
|
|
57816
|
+
if (field === undefined) {
|
|
57817
|
+
throw new Error("Unsupported SQL extract expression");
|
|
57818
|
+
}
|
|
57819
|
+
if (source === undefined) {
|
|
57820
|
+
throw new Error("Unsupported SQL extract expression");
|
|
57821
|
+
}
|
|
57822
|
+
const fieldRuntime = isExpression3(field) && field[TypeId].dbType.kind === "text" && typeof field[TypeId].runtime === "string" ? field[TypeId].runtime : undefined;
|
|
57823
|
+
const renderedField = fieldRuntime ?? renderExpression(field, state, dialect);
|
|
57824
|
+
return `extract(${renderedField} from ${renderExpression(source, state, dialect)})`;
|
|
57825
|
+
}
|
|
56529
57826
|
const renderedArgs = args.map((arg) => renderExpression(arg, state, dialect)).join(", ");
|
|
56530
57827
|
if (args.length === 0) {
|
|
56531
|
-
switch (
|
|
57828
|
+
switch (name2) {
|
|
56532
57829
|
case "current_date":
|
|
56533
57830
|
case "current_time":
|
|
56534
57831
|
case "current_timestamp":
|
|
56535
57832
|
case "localtime":
|
|
56536
57833
|
case "localtimestamp":
|
|
56537
|
-
return
|
|
57834
|
+
return name2;
|
|
56538
57835
|
default:
|
|
56539
|
-
return `${
|
|
57836
|
+
return `${name2}()`;
|
|
56540
57837
|
}
|
|
56541
57838
|
}
|
|
56542
|
-
return `${
|
|
57839
|
+
return `${name2}(${renderedArgs})`;
|
|
56543
57840
|
};
|
|
56544
|
-
var renderJsonExpression = (ast, state, dialect) => {
|
|
57841
|
+
var renderJsonExpression = (expression, ast, state, dialect) => {
|
|
56545
57842
|
const kind = typeof ast.kind === "string" ? ast.kind : undefined;
|
|
56546
57843
|
if (!kind) {
|
|
56547
57844
|
return;
|
|
@@ -56549,6 +57846,8 @@ var renderJsonExpression = (ast, state, dialect) => {
|
|
|
56549
57846
|
const base = extractJsonBase(ast);
|
|
56550
57847
|
const segments = extractJsonPathSegments(ast);
|
|
56551
57848
|
const exact = segments.every((segment) => segment.kind === "key" || segment.kind === "index");
|
|
57849
|
+
const postgresExpressionKind = dialect.name === "postgres" && isJsonExpression(expression) ? renderPostgresJsonKind(expression) : undefined;
|
|
57850
|
+
const postgresBaseKind = dialect.name === "postgres" && isJsonExpression(base) ? renderPostgresJsonKind(base) : undefined;
|
|
56552
57851
|
switch (kind) {
|
|
56553
57852
|
case "jsonGet":
|
|
56554
57853
|
case "jsonPath":
|
|
@@ -56569,7 +57868,7 @@ var renderJsonExpression = (ast, state, dialect) => {
|
|
|
56569
57868
|
}
|
|
56570
57869
|
const jsonPathLiteral = dialect.renderLiteral(renderJsonPathStringLiteral(segments), state);
|
|
56571
57870
|
const queried = `jsonb_path_query_first(${renderPostgresJsonValue(base, state, dialect)}, ${jsonPathLiteral})`;
|
|
56572
|
-
return textMode ? `
|
|
57871
|
+
return textMode ? `(${queried} #>> '{}')` : queried;
|
|
56573
57872
|
}
|
|
56574
57873
|
if (dialect.name === "mysql") {
|
|
56575
57874
|
const extracted = `json_extract(${baseSql}, ${renderMySqlJsonPath(segments, state, dialect)})`;
|
|
@@ -56591,12 +57890,12 @@ var renderJsonExpression = (ast, state, dialect) => {
|
|
|
56591
57890
|
}
|
|
56592
57891
|
if (dialect.name === "postgres") {
|
|
56593
57892
|
if (kind === "jsonHasAnyKeys") {
|
|
56594
|
-
return `(${baseSql} ?| ${
|
|
57893
|
+
return `(${baseSql} ?| array[${keys.map((key2) => renderPostgresTextLiteral(String(key2), state, dialect)).join(", ")}])`;
|
|
56595
57894
|
}
|
|
56596
57895
|
if (kind === "jsonHasAllKeys") {
|
|
56597
|
-
return `(${baseSql} ?& ${
|
|
57896
|
+
return `(${baseSql} ?& array[${keys.map((key2) => renderPostgresTextLiteral(String(key2), state, dialect)).join(", ")}])`;
|
|
56598
57897
|
}
|
|
56599
|
-
return `(${baseSql} ? ${
|
|
57898
|
+
return `(${baseSql} ? ${renderPostgresTextLiteral(String(keys[0]), state, dialect)})`;
|
|
56600
57899
|
}
|
|
56601
57900
|
if (dialect.name === "mysql") {
|
|
56602
57901
|
const mode = kind === "jsonHasAllKeys" ? "all" : "one";
|
|
@@ -56625,7 +57924,7 @@ var renderJsonExpression = (ast, state, dialect) => {
|
|
|
56625
57924
|
renderExpression(entry.value, state, dialect)
|
|
56626
57925
|
]);
|
|
56627
57926
|
if (dialect.name === "postgres") {
|
|
56628
|
-
return
|
|
57927
|
+
return `${postgresExpressionKind === "jsonb" ? "jsonb" : "json"}_build_object(${renderedEntries.join(", ")})`;
|
|
56629
57928
|
}
|
|
56630
57929
|
if (dialect.name === "mysql") {
|
|
56631
57930
|
return `json_object(${renderedEntries.join(", ")})`;
|
|
@@ -56636,7 +57935,7 @@ var renderJsonExpression = (ast, state, dialect) => {
|
|
|
56636
57935
|
const values = Array.isArray(ast.values) ? ast.values : [];
|
|
56637
57936
|
const renderedValues = values.map((value) => renderExpression(value, state, dialect)).join(", ");
|
|
56638
57937
|
if (dialect.name === "postgres") {
|
|
56639
|
-
return
|
|
57938
|
+
return `${postgresExpressionKind === "jsonb" ? "jsonb" : "json"}_build_array(${renderedValues})`;
|
|
56640
57939
|
}
|
|
56641
57940
|
if (dialect.name === "mysql") {
|
|
56642
57941
|
return `json_array(${renderedValues})`;
|
|
@@ -56670,7 +57969,8 @@ var renderJsonExpression = (ast, state, dialect) => {
|
|
|
56670
57969
|
return;
|
|
56671
57970
|
}
|
|
56672
57971
|
if (dialect.name === "postgres") {
|
|
56673
|
-
|
|
57972
|
+
const baseSql = renderExpression(base, state, dialect);
|
|
57973
|
+
return `${postgresBaseKind === "jsonb" ? "jsonb" : "json"}_typeof(${baseSql})`;
|
|
56674
57974
|
}
|
|
56675
57975
|
if (dialect.name === "mysql") {
|
|
56676
57976
|
return `json_type(${renderExpression(base, state, dialect)})`;
|
|
@@ -56681,8 +57981,11 @@ var renderJsonExpression = (ast, state, dialect) => {
|
|
|
56681
57981
|
return;
|
|
56682
57982
|
}
|
|
56683
57983
|
if (dialect.name === "postgres") {
|
|
56684
|
-
const
|
|
56685
|
-
|
|
57984
|
+
const baseSql = renderExpression(base, state, dialect);
|
|
57985
|
+
const typeOf = `${postgresBaseKind === "jsonb" ? "jsonb" : "json"}_typeof`;
|
|
57986
|
+
const arrayLength = `${postgresBaseKind === "jsonb" ? "jsonb" : "json"}_array_length`;
|
|
57987
|
+
const objectKeys = `${postgresBaseKind === "jsonb" ? "jsonb" : "json"}_object_keys`;
|
|
57988
|
+
return `(case when ${typeOf}(${baseSql}) = 'array' then ${arrayLength}(${baseSql}) when ${typeOf}(${baseSql}) = 'object' then (select count(*)::int from ${objectKeys}(${baseSql})) else null end)`;
|
|
56686
57989
|
}
|
|
56687
57990
|
if (dialect.name === "mysql") {
|
|
56688
57991
|
return `json_length(${renderExpression(base, state, dialect)})`;
|
|
@@ -56693,8 +57996,10 @@ var renderJsonExpression = (ast, state, dialect) => {
|
|
|
56693
57996
|
return;
|
|
56694
57997
|
}
|
|
56695
57998
|
if (dialect.name === "postgres") {
|
|
56696
|
-
const
|
|
56697
|
-
|
|
57999
|
+
const baseSql = renderExpression(base, state, dialect);
|
|
58000
|
+
const typeOf = `${postgresBaseKind === "jsonb" ? "jsonb" : "json"}_typeof`;
|
|
58001
|
+
const objectKeys = `${postgresBaseKind === "jsonb" ? "jsonb" : "json"}_object_keys`;
|
|
58002
|
+
return `(case when ${typeOf}(${baseSql}) = 'object' then array(select ${objectKeys}(${baseSql})) else null end)`;
|
|
56698
58003
|
}
|
|
56699
58004
|
if (dialect.name === "mysql") {
|
|
56700
58005
|
return `json_keys(${renderExpression(base, state, dialect)})`;
|
|
@@ -56705,7 +58010,7 @@ var renderJsonExpression = (ast, state, dialect) => {
|
|
|
56705
58010
|
return;
|
|
56706
58011
|
}
|
|
56707
58012
|
if (dialect.name === "postgres") {
|
|
56708
|
-
return
|
|
58013
|
+
return `${postgresBaseKind === "jsonb" ? "jsonb" : "json"}_strip_nulls(${renderExpression(base, state, dialect)})`;
|
|
56709
58014
|
}
|
|
56710
58015
|
unsupportedJsonFeature(dialect, "jsonStripNulls");
|
|
56711
58016
|
return;
|
|
@@ -56924,7 +58229,7 @@ var renderQueryAst = (ast, state, dialect) => {
|
|
|
56924
58229
|
sql += ` (${columns}) select * from unnest(${rendered})`;
|
|
56925
58230
|
} else {
|
|
56926
58231
|
const rowCount = unnestSource.values[0]?.values.length ?? 0;
|
|
56927
|
-
const rows = Array.from({ length: rowCount }, (_,
|
|
58232
|
+
const rows = Array.from({ length: rowCount }, (_, index4) => `(${unnestSource.values.map((entry) => dialect.renderLiteral(entry.values[index4], state)).join(", ")})`).join(", ");
|
|
56928
58233
|
sql += ` (${columns}) values ${rows}`;
|
|
56929
58234
|
}
|
|
56930
58235
|
} else {
|
|
@@ -57129,7 +58434,7 @@ var renderSourceReference = (source, tableName, baseTableName, state, dialect) =
|
|
|
57129
58434
|
};
|
|
57130
58435
|
const renderUnnestRows = (arrays, columnNames) => {
|
|
57131
58436
|
const rowCount = arrays[columnNames[0]].length;
|
|
57132
|
-
const rows = Array.from({ length: rowCount }, (_,
|
|
58437
|
+
const rows = Array.from({ length: rowCount }, (_, index4) => Object.fromEntries(columnNames.map((columnName) => [columnName, arrays[columnName][index4]])));
|
|
57133
58438
|
return renderSelectRows(rows, columnNames);
|
|
57134
58439
|
};
|
|
57135
58440
|
if (typeof source === "object" && source !== null && "kind" in source && source.kind === "cte") {
|
|
@@ -57175,7 +58480,7 @@ var renderSourceReference = (source, tableName, baseTableName, state, dialect) =
|
|
|
57175
58480
|
};
|
|
57176
58481
|
var renderExpression = (expression, state, dialect) => {
|
|
57177
58482
|
const rawAst = expression[TypeId2];
|
|
57178
|
-
const jsonSql = renderJsonExpression(rawAst, state, dialect);
|
|
58483
|
+
const jsonSql = renderJsonExpression(expression, rawAst, state, dialect);
|
|
57179
58484
|
if (jsonSql !== undefined) {
|
|
57180
58485
|
return jsonSql;
|
|
57181
58486
|
}
|
|
@@ -57183,7 +58488,7 @@ var renderExpression = (expression, state, dialect) => {
|
|
|
57183
58488
|
const renderComparisonOperator = (operator) => operator === "eq" ? "=" : operator === "neq" ? "<>" : operator === "lt" ? "<" : operator === "lte" ? "<=" : operator === "gt" ? ">" : ">=";
|
|
57184
58489
|
switch (ast.kind) {
|
|
57185
58490
|
case "column":
|
|
57186
|
-
return `${dialect.quoteIdentifier(ast.tableName)}.${dialect.quoteIdentifier(ast.columnName)}`;
|
|
58491
|
+
return ast.tableName.length === 0 ? dialect.quoteIdentifier(ast.columnName) : `${dialect.quoteIdentifier(ast.tableName)}.${dialect.quoteIdentifier(ast.columnName)}`;
|
|
57187
58492
|
case "literal":
|
|
57188
58493
|
return dialect.renderLiteral(ast.value, state);
|
|
57189
58494
|
case "excluded":
|
|
@@ -57208,6 +58513,14 @@ var renderExpression = (expression, state, dialect) => {
|
|
|
57208
58513
|
return `(${renderExpression(ast.left, state, dialect)} like ${renderExpression(ast.right, state, dialect)})`;
|
|
57209
58514
|
case "ilike":
|
|
57210
58515
|
return dialect.name === "postgres" ? `(${renderExpression(ast.left, state, dialect)} ilike ${renderExpression(ast.right, state, dialect)})` : `(lower(${renderExpression(ast.left, state, dialect)}) like lower(${renderExpression(ast.right, state, dialect)}))`;
|
|
58516
|
+
case "regexMatch":
|
|
58517
|
+
return dialect.name === "postgres" ? `(${renderExpression(ast.left, state, dialect)} ~ ${renderExpression(ast.right, state, dialect)})` : `(${renderExpression(ast.left, state, dialect)} regexp ${renderExpression(ast.right, state, dialect)})`;
|
|
58518
|
+
case "regexIMatch":
|
|
58519
|
+
return dialect.name === "postgres" ? `(${renderExpression(ast.left, state, dialect)} ~* ${renderExpression(ast.right, state, dialect)})` : `(${renderExpression(ast.left, state, dialect)} regexp ${renderExpression(ast.right, state, dialect)})`;
|
|
58520
|
+
case "regexNotMatch":
|
|
58521
|
+
return dialect.name === "postgres" ? `(${renderExpression(ast.left, state, dialect)} !~ ${renderExpression(ast.right, state, dialect)})` : `(${renderExpression(ast.left, state, dialect)} not regexp ${renderExpression(ast.right, state, dialect)})`;
|
|
58522
|
+
case "regexNotIMatch":
|
|
58523
|
+
return dialect.name === "postgres" ? `(${renderExpression(ast.left, state, dialect)} !~* ${renderExpression(ast.right, state, dialect)})` : `(${renderExpression(ast.left, state, dialect)} not regexp ${renderExpression(ast.right, state, dialect)})`;
|
|
57211
58524
|
case "isDistinctFrom":
|
|
57212
58525
|
return dialect.name === "mysql" ? `(not (${renderExpression(ast.left, state, dialect)} <=> ${renderExpression(ast.right, state, dialect)}))` : `(${renderExpression(ast.left, state, dialect)} is distinct from ${renderExpression(ast.right, state, dialect)})`;
|
|
57213
58526
|
case "isNotDistinctFrom":
|
|
@@ -57328,9 +58641,9 @@ var renderPostgresPlan = (plan) => {
|
|
|
57328
58641
|
};
|
|
57329
58642
|
|
|
57330
58643
|
// src/internal/renderer.ts
|
|
57331
|
-
var
|
|
57332
|
-
function make5(dialect,
|
|
57333
|
-
const implementation =
|
|
58644
|
+
var TypeId9 = Symbol.for("effect-qb/Renderer");
|
|
58645
|
+
function make5(dialect, render2) {
|
|
58646
|
+
const implementation = render2 ?? (dialect === "postgres" ? renderPostgresPlan : undefined);
|
|
57334
58647
|
if (!implementation) {
|
|
57335
58648
|
throw new Error(`No built-in renderer for dialect: ${dialect}`);
|
|
57336
58649
|
}
|
|
@@ -57345,7 +58658,7 @@ function make5(dialect, render) {
|
|
|
57345
58658
|
params: rendered.params ?? [],
|
|
57346
58659
|
projections,
|
|
57347
58660
|
dialect,
|
|
57348
|
-
[
|
|
58661
|
+
[TypeId9]: {
|
|
57349
58662
|
row: undefined,
|
|
57350
58663
|
dialect
|
|
57351
58664
|
}
|
|
@@ -57448,6 +58761,10 @@ __export(exports_query2, {
|
|
|
57448
58761
|
rightJoin: () => rightJoin,
|
|
57449
58762
|
returning: () => returning,
|
|
57450
58763
|
releaseSavepoint: () => releaseSavepoint,
|
|
58764
|
+
regexNotMatch: () => regexNotMatch,
|
|
58765
|
+
regexNotIMatch: () => regexNotIMatch,
|
|
58766
|
+
regexMatch: () => regexMatch,
|
|
58767
|
+
regexIMatch: () => regexIMatch,
|
|
57451
58768
|
overlaps: () => overlaps,
|
|
57452
58769
|
orderBy: () => orderBy,
|
|
57453
58770
|
or: () => or,
|
|
@@ -57504,6 +58821,7 @@ __export(exports_query2, {
|
|
|
57504
58821
|
compareAny: () => compareAny,
|
|
57505
58822
|
compareAll: () => compareAll,
|
|
57506
58823
|
commit: () => commit,
|
|
58824
|
+
column: () => column,
|
|
57507
58825
|
cast: () => cast,
|
|
57508
58826
|
case: () => case_,
|
|
57509
58827
|
between: () => between,
|
|
@@ -57513,6 +58831,7 @@ __export(exports_query2, {
|
|
|
57513
58831
|
all: () => all
|
|
57514
58832
|
});
|
|
57515
58833
|
var literal = mysqlQuery.literal;
|
|
58834
|
+
var column = mysqlQuery.column;
|
|
57516
58835
|
var cast = mysqlQuery.cast;
|
|
57517
58836
|
var type = mysqlQuery.type;
|
|
57518
58837
|
var eq = mysqlQuery.eq;
|
|
@@ -57525,6 +58844,10 @@ var isNull = mysqlQuery.isNull;
|
|
|
57525
58844
|
var isNotNull = mysqlQuery.isNotNull;
|
|
57526
58845
|
var like = mysqlQuery.like;
|
|
57527
58846
|
var ilike = mysqlQuery.ilike;
|
|
58847
|
+
var regexMatch = mysqlQuery.regexMatch;
|
|
58848
|
+
var regexIMatch = mysqlQuery.regexIMatch;
|
|
58849
|
+
var regexNotMatch = mysqlQuery.regexNotMatch;
|
|
58850
|
+
var regexNotIMatch = mysqlQuery.regexNotIMatch;
|
|
57528
58851
|
var and = mysqlQuery.and;
|
|
57529
58852
|
var or = mysqlQuery.or;
|
|
57530
58853
|
var not = mysqlQuery.not;
|
|
@@ -57601,38 +58924,38 @@ __export(exports_table2, {
|
|
|
57601
58924
|
primaryKey: () => primaryKey4,
|
|
57602
58925
|
options: () => options2,
|
|
57603
58926
|
make: () => make7,
|
|
57604
|
-
index: () =>
|
|
57605
|
-
foreignKey: () =>
|
|
58927
|
+
index: () => index4,
|
|
58928
|
+
foreignKey: () => foreignKey3,
|
|
57606
58929
|
check: () => check2,
|
|
57607
58930
|
alias: () => alias2,
|
|
57608
|
-
TypeId: () =>
|
|
58931
|
+
TypeId: () => TypeId10,
|
|
57609
58932
|
OptionsSymbol: () => OptionsSymbol2,
|
|
57610
58933
|
Class: () => Class2
|
|
57611
58934
|
});
|
|
57612
|
-
var
|
|
58935
|
+
var TypeId10 = TypeId4;
|
|
57613
58936
|
var OptionsSymbol2 = OptionsSymbol;
|
|
57614
58937
|
var options2 = options;
|
|
57615
|
-
var make7 = (
|
|
58938
|
+
var make7 = (name2, fields2, schemaName = undefined) => make2(name2, fields2, schemaName);
|
|
57616
58939
|
var schema4 = (schemaName) => ({
|
|
57617
58940
|
schemaName,
|
|
57618
|
-
table: (
|
|
58941
|
+
table: (name2, fields2, ...declaredOptions) => schema3(schemaName).table(name2, fields2, ...declaredOptions)
|
|
57619
58942
|
});
|
|
57620
58943
|
var alias2 = (table, aliasName) => alias(table, aliasName);
|
|
57621
|
-
var Class2 = (
|
|
57622
|
-
const base = Class(
|
|
58944
|
+
var Class2 = (name2, schemaName = undefined) => {
|
|
58945
|
+
const base = Class(name2, schemaName);
|
|
57623
58946
|
return base;
|
|
57624
58947
|
};
|
|
57625
58948
|
var primaryKey4 = primaryKey3;
|
|
57626
58949
|
var unique4 = unique3;
|
|
57627
|
-
var
|
|
57628
|
-
var
|
|
58950
|
+
var index4 = index2;
|
|
58951
|
+
var foreignKey3 = (columns, target, referencedColumns) => foreignKey2(columns, target, referencedColumns);
|
|
57629
58952
|
var check2 = check;
|
|
57630
58953
|
// src/mysql/renderer.ts
|
|
57631
58954
|
var exports_renderer2 = {};
|
|
57632
58955
|
__export(exports_renderer2, {
|
|
57633
58956
|
mysql: () => mysql2,
|
|
57634
58957
|
make: () => make8,
|
|
57635
|
-
TypeId: () =>
|
|
58958
|
+
TypeId: () => TypeId9
|
|
57636
58959
|
});
|
|
57637
58960
|
var make8 = () => make5("mysql", renderMysqlPlan);
|
|
57638
58961
|
var mysql2 = make8();
|