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