effect-qb 0.19.0 → 4.0.0-beta.92

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