effect-qb 0.14.0 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (146) hide show
  1. package/dist/mysql.js +61555 -4252
  2. package/dist/postgres/metadata.js +728 -104
  3. package/dist/postgres.js +6906 -4023
  4. package/package.json +15 -2
  5. package/src/internal/aggregation-validation.ts +3 -3
  6. package/src/internal/case-analysis.d.ts +18 -0
  7. package/src/internal/case-analysis.ts +4 -4
  8. package/src/internal/coercion/analysis.d.ts +7 -0
  9. package/src/internal/{coercion-analysis.ts → coercion/analysis.ts} +3 -3
  10. package/src/internal/coercion/errors.d.ts +17 -0
  11. package/src/internal/{coercion-errors.ts → coercion/errors.ts} +1 -1
  12. package/src/internal/coercion/kind.d.ts +4 -0
  13. package/src/internal/{coercion-kind.ts → coercion/kind.ts} +2 -2
  14. package/src/internal/{coercion-normalize.ts → coercion/normalize.ts} +1 -1
  15. package/src/internal/coercion/rules.d.ts +6 -0
  16. package/src/internal/{coercion-rules.ts → coercion/rules.ts} +2 -2
  17. package/src/internal/column-state.d.ts +190 -0
  18. package/src/internal/column-state.ts +43 -47
  19. package/src/internal/column.ts +43 -305
  20. package/src/internal/datatypes/define.d.ts +17 -0
  21. package/src/internal/datatypes/define.ts +18 -4
  22. package/src/internal/datatypes/lookup.d.ts +44 -0
  23. package/src/internal/datatypes/lookup.ts +61 -152
  24. package/src/internal/datatypes/shape.d.ts +16 -0
  25. package/src/internal/datatypes/shape.ts +1 -1
  26. package/src/internal/derived-table.d.ts +4 -0
  27. package/src/internal/derived-table.ts +21 -16
  28. package/src/internal/dialect.ts +12 -1
  29. package/src/internal/dsl-mutation-runtime.ts +378 -0
  30. package/src/internal/dsl-plan-runtime.ts +387 -0
  31. package/src/internal/dsl-query-runtime.ts +160 -0
  32. package/src/internal/dsl-transaction-ddl-runtime.ts +263 -0
  33. package/src/internal/executor.ts +146 -34
  34. package/src/internal/expression-ast.ts +15 -5
  35. package/src/internal/grouping-key.d.ts +3 -0
  36. package/src/internal/grouping-key.ts +1 -1
  37. package/src/internal/implication-runtime.d.ts +15 -0
  38. package/src/internal/implication-runtime.ts +4 -4
  39. package/src/internal/json/ast.d.ts +30 -0
  40. package/src/internal/json/ast.ts +1 -1
  41. package/src/internal/json/errors.d.ts +8 -0
  42. package/src/internal/json/path.d.ts +75 -0
  43. package/src/internal/json/path.ts +1 -1
  44. package/src/internal/json/types.d.ts +62 -0
  45. package/src/internal/predicate/analysis.d.ts +20 -0
  46. package/src/internal/predicate/analysis.ts +183 -0
  47. package/src/internal/predicate/atom.d.ts +28 -0
  48. package/src/internal/{predicate-atom.ts → predicate/atom.ts} +7 -0
  49. package/src/internal/{predicate-branches.ts → predicate/branches.ts} +2 -2
  50. package/src/internal/predicate/context.d.ts +67 -0
  51. package/src/internal/{predicate-context.ts → predicate/context.ts} +163 -20
  52. package/src/internal/predicate/formula.d.ts +35 -0
  53. package/src/internal/{predicate-formula.ts → predicate/formula.ts} +1 -1
  54. package/src/internal/predicate/key.d.ts +11 -0
  55. package/src/internal/predicate/key.ts +73 -0
  56. package/src/internal/{predicate-nnf.ts → predicate/nnf.ts} +2 -2
  57. package/src/internal/predicate/normalize.d.ts +53 -0
  58. package/src/internal/{predicate-normalize.ts → predicate/normalize.ts} +130 -49
  59. package/src/internal/predicate/runtime.d.ts +31 -0
  60. package/src/internal/{predicate-runtime.ts → predicate/runtime.ts} +127 -17
  61. package/src/internal/projection-alias.d.ts +13 -0
  62. package/src/internal/projections.d.ts +31 -0
  63. package/src/internal/projections.ts +1 -1
  64. package/src/internal/query-ast.d.ts +217 -0
  65. package/src/internal/query-ast.ts +1 -1
  66. package/src/internal/query-requirements.d.ts +20 -0
  67. package/src/internal/query.d.ts +775 -0
  68. package/src/internal/query.ts +683 -369
  69. package/src/internal/renderer.ts +11 -21
  70. package/src/internal/row-set.d.ts +53 -0
  71. package/src/internal/{plan.ts → row-set.ts} +11 -9
  72. package/src/internal/runtime/driver-value-mapping.ts +186 -0
  73. package/src/internal/{runtime-normalize.ts → runtime/normalize.ts} +9 -31
  74. package/src/internal/{runtime-schema.ts → runtime/schema.ts} +13 -38
  75. package/src/internal/runtime/value.d.ts +22 -0
  76. package/src/internal/{runtime-value.ts → runtime/value.ts} +2 -2
  77. package/src/internal/scalar.d.ts +107 -0
  78. package/src/internal/scalar.ts +202 -0
  79. package/src/internal/schema-derivation.d.ts +105 -0
  80. package/src/internal/schema-expression.d.ts +18 -0
  81. package/src/internal/schema-expression.ts +38 -7
  82. package/src/internal/table-options.d.ts +94 -0
  83. package/src/internal/table-options.ts +8 -2
  84. package/src/internal/table.d.ts +173 -0
  85. package/src/internal/table.ts +32 -14
  86. package/src/mysql/column.ts +95 -18
  87. package/src/mysql/datatypes/index.ts +47 -7
  88. package/src/mysql/errors/generated.ts +57336 -0
  89. package/src/mysql/errors/index.ts +1 -0
  90. package/src/mysql/errors/normalize.ts +55 -53
  91. package/src/mysql/errors/types.ts +74 -0
  92. package/src/mysql/executor.ts +88 -11
  93. package/src/mysql/function/aggregate.ts +1 -5
  94. package/src/mysql/function/core.ts +1 -4
  95. package/src/mysql/function/index.ts +0 -1
  96. package/src/mysql/function/string.ts +1 -5
  97. package/src/mysql/function/temporal.ts +12 -15
  98. package/src/mysql/function/window.ts +1 -6
  99. package/src/{internal/mysql-dialect.ts → mysql/internal/dialect.ts} +12 -6
  100. package/src/{internal/mysql-query.ts → mysql/internal/dsl.ts} +1299 -2143
  101. package/src/mysql/internal/renderer.ts +46 -0
  102. package/src/mysql/internal/sql-expression-renderer.ts +1501 -0
  103. package/src/mysql/json.ts +2 -0
  104. package/src/mysql/query.ts +111 -91
  105. package/src/mysql/renderer.ts +8 -3
  106. package/src/mysql/table.ts +1 -1
  107. package/src/mysql.ts +6 -4
  108. package/src/postgres/cast.ts +30 -16
  109. package/src/postgres/column.ts +179 -46
  110. package/src/postgres/datatypes/index.d.ts +515 -0
  111. package/src/postgres/datatypes/index.ts +22 -13
  112. package/src/postgres/datatypes/spec.d.ts +412 -0
  113. package/src/postgres/errors/generated.ts +2636 -0
  114. package/src/postgres/errors/index.ts +1 -0
  115. package/src/postgres/errors/normalize.ts +47 -62
  116. package/src/postgres/errors/types.ts +92 -34
  117. package/src/postgres/executor.ts +54 -7
  118. package/src/postgres/function/aggregate.ts +1 -5
  119. package/src/postgres/function/core.ts +12 -6
  120. package/src/postgres/function/index.ts +0 -1
  121. package/src/postgres/function/string.ts +1 -5
  122. package/src/postgres/function/temporal.ts +12 -15
  123. package/src/postgres/function/window.ts +1 -6
  124. package/src/{internal/postgres-dialect.ts → postgres/internal/dialect.ts} +12 -6
  125. package/src/{internal/postgres-query.ts → postgres/internal/dsl.ts} +1356 -2133
  126. package/src/{internal/postgres-renderer.ts → postgres/internal/renderer.ts} +17 -8
  127. package/src/postgres/internal/schema-ddl.ts +108 -0
  128. package/src/{internal/postgres-schema-model.ts → postgres/internal/schema-model.ts} +12 -6
  129. package/src/{internal → postgres/internal}/sql-expression-renderer.ts +79 -25
  130. package/src/postgres/{function/json.ts → json.ts} +77 -85
  131. package/src/postgres/metadata.ts +2 -2
  132. package/src/postgres/query.ts +113 -89
  133. package/src/postgres/renderer.ts +8 -13
  134. package/src/postgres/schema-expression.ts +2 -1
  135. package/src/postgres/schema-management.ts +1 -1
  136. package/src/postgres/table.ts +12 -4
  137. package/src/postgres/type.ts +33 -2
  138. package/src/postgres.ts +6 -4
  139. package/src/internal/expression.ts +0 -327
  140. package/src/internal/mysql-renderer.ts +0 -37
  141. package/src/internal/predicate-analysis.ts +0 -81
  142. package/src/internal/predicate-key.ts +0 -28
  143. package/src/internal/schema-ddl.ts +0 -55
  144. package/src/mysql/function/json.ts +0 -4
  145. package/src/mysql/private/query.ts +0 -1
  146. package/src/postgres/private/query.ts +0 -1
@@ -1,7 +1,7 @@
1
1
  import type * as Brand from "effect/Brand"
2
2
  import * as Schema from "effect/Schema"
3
3
 
4
- import * as Expression from "./expression.js"
4
+ import * as Expression from "./scalar.js"
5
5
  import type { CanCastDbType } from "./datatypes/lookup.js"
6
6
  import {
7
7
  BigIntStringSchema,
@@ -18,7 +18,7 @@ import {
18
18
  type DecimalString,
19
19
  type LocalDateTimeString,
20
20
  type BigIntString
21
- } from "./runtime-value.js"
21
+ } from "./runtime/value.js"
22
22
  import {
23
23
  type AnyBoundColumn,
24
24
  type AnyColumnDefinition,
@@ -48,8 +48,8 @@ type ReferentialAction = "noAction" | "restrict" | "cascade" | "setNull" | "setD
48
48
  type CompatibleReference<
49
49
  Self extends AnyColumnDefinition,
50
50
  Target extends AnyBoundColumn
51
- > = [BaseSelectType<Self>] extends [BaseSelectType<Target>]
52
- ? [BaseSelectType<Target>] extends [BaseSelectType<Self>]
51
+ > = [Self[typeof ColumnTypeId]["dbType"]] extends [Target[typeof ColumnTypeId]["dbType"]]
52
+ ? [Target[typeof ColumnTypeId]["dbType"]] extends [Self[typeof ColumnTypeId]["dbType"]]
53
53
  ? Self
54
54
  : never
55
55
  : never
@@ -123,6 +123,20 @@ type DdlTypedColumn<Column extends AnyColumnDefinition> = ColumnDefinition<
123
123
  ReferencesOf<Column>
124
124
  > & PreserveBrand<Column>
125
125
 
126
+ type DriverValueMappedColumn<Column extends AnyColumnDefinition> = ColumnDefinition<
127
+ SelectType<Column>,
128
+ InsertType<Column>,
129
+ UpdateType<Column>,
130
+ Column[typeof ColumnTypeId]["dbType"],
131
+ IsNullable<Column>,
132
+ HasDefault<Column>,
133
+ IsGenerated<Column>,
134
+ IsPrimaryKey<Column>,
135
+ Column[typeof ColumnTypeId]["unique"],
136
+ ReferencesOf<Column>,
137
+ Column[typeof ColumnTypeId]["dependencies"]
138
+ > & PreserveBrand<Column>
139
+
126
140
  type GeneratedColumn<Column extends AnyColumnDefinition> = ColumnDefinition<
127
141
  SelectType<Column>,
128
142
  InsertType<Column>,
@@ -237,7 +251,6 @@ type ColumnWithSchema<
237
251
  IsPrimaryKey<Column>,
238
252
  Column[typeof ColumnTypeId]["unique"],
239
253
  ReferencesOf<Column>,
240
- Column[typeof ColumnTypeId]["source"],
241
254
  Column[typeof ColumnTypeId]["dependencies"]
242
255
  > & PreserveBrand<Column>
243
256
 
@@ -259,9 +272,9 @@ type PreserveBrand<Column extends AnyColumnDefinition> = Column["metadata"]["bra
259
272
  ? BrandMetadata<Column>
260
273
  : {}
261
274
 
262
- type BrandedColumn<
275
+ type BrandedBoundColumn<
263
276
  Column extends AnyBoundColumn
264
- > = ColumnDefinition<
277
+ > = BoundColumn<
265
278
  BrandedValue<SelectType<Column>, BrandNameOf<Column>>,
266
279
  BrandedValue<InsertType<Column>, BrandNameOf<Column>>,
267
280
  BrandedValue<UpdateType<Column>, BrandNameOf<Column>>,
@@ -272,8 +285,9 @@ type BrandedColumn<
272
285
  IsPrimaryKey<Column>,
273
286
  Column[typeof ColumnTypeId]["unique"],
274
287
  ReferencesOf<Column>,
275
- Column[typeof ColumnTypeId]["source"],
276
- Column[typeof ColumnTypeId]["dependencies"]
288
+ Column[typeof BoundColumnTypeId]["tableName"],
289
+ Column[typeof BoundColumnTypeId]["columnName"],
290
+ Column[typeof BoundColumnTypeId]["baseTableName"]
277
291
  > & BrandMetadata<Column>
278
292
 
279
293
  type BrandMarkedColumn<
@@ -289,7 +303,6 @@ type BrandMarkedColumn<
289
303
  IsPrimaryKey<Column>,
290
304
  Column[typeof ColumnTypeId]["unique"],
291
305
  ReferencesOf<Column>,
292
- Column[typeof ColumnTypeId]["source"],
293
306
  Column[typeof ColumnTypeId]["dependencies"]
294
307
  > & BrandMetadata<Column>
295
308
 
@@ -346,7 +359,6 @@ type ArrayColumn<
346
359
  IsPrimaryKey<Column>,
347
360
  Column[typeof ColumnTypeId]["unique"],
348
361
  ReferencesOf<Column>,
349
- Column[typeof ColumnTypeId]["source"],
350
362
  Column[typeof ColumnTypeId]["dependencies"]
351
363
  > & PreserveBrand<Column>
352
364
 
@@ -429,288 +441,6 @@ type ColumnModule<
429
441
  >
430
442
  }
431
443
 
432
- type PostgresColumnModule = ColumnModule<
433
- "postgres",
434
- "uuid",
435
- "text",
436
- "int4",
437
- "numeric",
438
- "bool",
439
- "date",
440
- "timestamp",
441
- "json"
442
- > & {
443
- readonly int2: () => ColumnDefinition<number, number, number, Expression.DbType.Base<"postgres", "int2">, false, false, false, false, false, undefined>
444
- readonly int8: () => ColumnDefinition<BigIntString, BigIntString, BigIntString, Expression.DbType.Base<"postgres", "int8">, false, false, false, false, false, undefined>
445
- readonly float4: () => ColumnDefinition<number, number, number, Expression.DbType.Base<"postgres", "float4">, false, false, false, false, false, undefined>
446
- readonly float8: () => ColumnDefinition<number, number, number, Expression.DbType.Base<"postgres", "float8">, false, false, false, false, false, undefined>
447
- readonly char: (length?: number) => ColumnDefinition<string, string, string, Expression.DbType.Base<"postgres", "char">, false, false, false, false, false, undefined>
448
- readonly varchar: (length?: number) => ColumnDefinition<string, string, string, Expression.DbType.Base<"postgres", "varchar">, false, false, false, false, false, undefined>
449
- readonly time: () => ColumnDefinition<LocalTimeString, LocalTimeString, LocalTimeString, Expression.DbType.Base<"postgres", "time">, false, false, false, false, false, undefined>
450
- readonly timetz: () => ColumnDefinition<OffsetTimeString, OffsetTimeString, OffsetTimeString, Expression.DbType.Base<"postgres", "timetz">, false, false, false, false, false, undefined>
451
- readonly timestamptz: () => ColumnDefinition<InstantString, InstantString, InstantString, Expression.DbType.Base<"postgres", "timestamptz">, false, false, false, false, false, undefined>
452
- readonly interval: () => ColumnDefinition<string, string, string, Expression.DbType.Base<"postgres", "interval">, false, false, false, false, false, undefined>
453
- readonly bytea: () => ColumnDefinition<Uint8Array, Uint8Array, Uint8Array, Expression.DbType.Base<"postgres", "bytea">, false, false, false, false, false, undefined>
454
- readonly name: () => ColumnDefinition<string, string, string, Expression.DbType.Base<"postgres", "name">, false, false, false, false, false, undefined>
455
- readonly oid: () => ColumnDefinition<number, number, number, Expression.DbType.Base<"postgres", "oid">, false, false, false, false, false, undefined>
456
- readonly regclass: () => ColumnDefinition<string, string, string, Expression.DbType.Base<"postgres", "regclass">, false, false, false, false, false, undefined>
457
- readonly bit: () => ColumnDefinition<string, string, string, Expression.DbType.Base<"postgres", "bit">, false, false, false, false, false, undefined>
458
- readonly varbit: () => ColumnDefinition<string, string, string, Expression.DbType.Base<"postgres", "varbit">, false, false, false, false, false, undefined>
459
- readonly xml: () => ColumnDefinition<string, string, string, Expression.DbType.Base<"postgres", "xml">, false, false, false, false, false, undefined>
460
- readonly pg_lsn: () => ColumnDefinition<string, string, string, Expression.DbType.Base<"postgres", "pg_lsn">, false, false, false, false, false, undefined>
461
- readonly jsonb: <SchemaType extends Schema.Schema.Any>(
462
- schema: SchemaType
463
- ) => ColumnDefinition<
464
- Schema.Schema.Type<SchemaType>,
465
- Schema.Schema.Type<SchemaType>,
466
- Schema.Schema.Type<SchemaType>,
467
- Expression.DbType.Json<"postgres", "jsonb">,
468
- false,
469
- false,
470
- false,
471
- false,
472
- false,
473
- undefined
474
- >
475
- }
476
-
477
- const typeFactory = <Dialect extends string>(dialect: Dialect) =>
478
- <Kind extends string>(kind: Kind): Expression.DbType.Base<Dialect, Kind> => ({
479
- dialect,
480
- kind
481
- })
482
-
483
- const postgresType = typeFactory("postgres")
484
-
485
- const renderNumericDdlType = (
486
- kind: string,
487
- options?: NumericOptions
488
- ): string | undefined => {
489
- if (options === undefined || options.precision === undefined) {
490
- return undefined
491
- }
492
- return options.scale === undefined
493
- ? `${kind}(${options.precision})`
494
- : `${kind}(${options.precision},${options.scale})`
495
- }
496
-
497
- const makeColumnModule = <
498
- Dialect extends string,
499
- UuidKind extends string,
500
- TextKind extends string,
501
- IntKind extends string,
502
- NumberKind extends string,
503
- BooleanKind extends string,
504
- DateKind extends string,
505
- TimestampKind extends string,
506
- JsonKind extends string
507
- >(
508
- dialect: Dialect,
509
- kinds: {
510
- readonly uuid: UuidKind
511
- readonly text: TextKind
512
- readonly int: IntKind
513
- readonly number: NumberKind
514
- readonly boolean: BooleanKind
515
- readonly date: DateKind
516
- readonly timestamp: TimestampKind
517
- readonly json: JsonKind
518
- }
519
- ): ColumnModule<Dialect, UuidKind, TextKind, IntKind, NumberKind, BooleanKind, DateKind, TimestampKind, JsonKind> => {
520
- const dialectType = typeFactory(dialect)
521
- return {
522
- custom: <SchemaType extends Schema.Schema.Any, Db extends Expression.DbType.Any>(
523
- schema: SchemaType,
524
- dbType: Db
525
- ) =>
526
- makeColumnDefinition(schema as unknown as Schema.Schema<NonNullable<Schema.Schema.Type<SchemaType>>, any, any>, {
527
- dbType,
528
- nullable: false,
529
- hasDefault: false,
530
- generated: false,
531
- primaryKey: false,
532
- unique: false,
533
- references: undefined,
534
- ddlType: undefined,
535
- identity: undefined
536
- }),
537
- uuid: () => primitive(Schema.UUID, dialectType(kinds.uuid)),
538
- text: () => primitive(Schema.String, dialectType(kinds.text)),
539
- int: () => primitive(Schema.Int, dialectType(kinds.int)),
540
- number: (options?: NumericOptions) =>
541
- makeColumnDefinition(DecimalStringSchema, {
542
- dbType: dialectType(kinds.number),
543
- nullable: false,
544
- hasDefault: false,
545
- generated: false,
546
- primaryKey: false,
547
- unique: false,
548
- references: undefined,
549
- ddlType: renderNumericDdlType(kinds.number, options),
550
- identity: undefined
551
- }),
552
- boolean: () => primitive(Schema.Boolean, dialectType(kinds.boolean)),
553
- date: () => primitive(LocalDateStringSchema, dialectType(kinds.date)),
554
- timestamp: () => primitive(LocalDateTimeStringSchema, dialectType(kinds.timestamp)),
555
- json: <SchemaType extends Schema.Schema.Any>(schema: SchemaType) =>
556
- makeColumnDefinition(schema as unknown as Schema.Schema<NonNullable<Schema.Schema.Type<SchemaType>>, any, any>, {
557
- dbType: {
558
- ...dialectType(kinds.json),
559
- variant: "json"
560
- } as Expression.DbType.Json<Dialect, JsonKind>,
561
- nullable: false,
562
- hasDefault: false,
563
- generated: false,
564
- primaryKey: false,
565
- unique: false,
566
- references: undefined,
567
- ddlType: undefined,
568
- identity: undefined
569
- })
570
- }
571
- }
572
-
573
- const postgresBase = makeColumnModule("postgres", {
574
- uuid: "uuid",
575
- text: "text",
576
- int: "int4",
577
- number: "numeric",
578
- boolean: "bool",
579
- date: "date",
580
- timestamp: "timestamp",
581
- json: "json"
582
- })
583
-
584
- /** Postgres-specialized column constructors. */
585
- export const postgres: PostgresColumnModule = {
586
- ...postgresBase,
587
- int2: () => primitive(Schema.Int, postgresType("int2")),
588
- int8: () => primitive(BigIntStringSchema, postgresType("int8")),
589
- float4: () => primitive(Schema.Number, postgresType("float4")),
590
- float8: () => primitive(Schema.Number, postgresType("float8")),
591
- char: (length = 1) =>
592
- makeColumnDefinition(Schema.String, {
593
- dbType: postgresType("char"),
594
- nullable: false,
595
- hasDefault: false,
596
- generated: false,
597
- primaryKey: false,
598
- unique: false,
599
- references: undefined,
600
- ddlType: `char(${length})`,
601
- identity: undefined
602
- }),
603
- varchar: (length?: number) =>
604
- makeColumnDefinition(Schema.String, {
605
- dbType: postgresType("varchar"),
606
- nullable: false,
607
- hasDefault: false,
608
- generated: false,
609
- primaryKey: false,
610
- unique: false,
611
- references: undefined,
612
- ddlType: length === undefined ? "varchar" : `varchar(${length})`,
613
- identity: undefined
614
- }),
615
- time: () => primitive(LocalTimeStringSchema, postgresType("time")),
616
- timetz: () => primitive(OffsetTimeStringSchema, postgresType("timetz")),
617
- timestamptz: () => primitive(InstantStringSchema, postgresType("timestamptz")),
618
- interval: () => primitive(Schema.String, postgresType("interval")),
619
- bytea: () => primitive(Schema.Uint8ArrayFromSelf, postgresType("bytea")),
620
- name: () => primitive(Schema.String, postgresType("name")),
621
- oid: () => primitive(Schema.Int, postgresType("oid")),
622
- regclass: () => primitive(Schema.String, postgresType("regclass")),
623
- bit: () => primitive(Schema.String, postgresType("bit")),
624
- varbit: () => primitive(Schema.String, postgresType("varbit")),
625
- xml: () => primitive(Schema.String, postgresType("xml")),
626
- pg_lsn: () => primitive(Schema.String, postgresType("pg_lsn")),
627
- jsonb: <SchemaType extends Schema.Schema.Any>(schema: SchemaType) =>
628
- makeColumnDefinition(schema as unknown as Schema.Schema<NonNullable<Schema.Schema.Type<SchemaType>>, any, any>, {
629
- dbType: {
630
- ...postgresType("jsonb"),
631
- variant: "jsonb"
632
- } as Expression.DbType.Json<"postgres", "jsonb">,
633
- nullable: false,
634
- hasDefault: false,
635
- generated: false,
636
- primaryKey: false,
637
- unique: false,
638
- references: undefined,
639
- ddlType: undefined,
640
- identity: undefined
641
- })
642
- }
643
-
644
- /** MySQL-specialized column constructors. */
645
- export const mysql = makeColumnModule("mysql", {
646
- uuid: "uuid",
647
- text: "text",
648
- int: "int",
649
- number: "decimal",
650
- boolean: "boolean",
651
- date: "date",
652
- timestamp: "timestamp",
653
- json: "json"
654
- })
655
-
656
- /** Creates a Postgres `uuid` column. */
657
- export const uuid = postgres.uuid
658
- /** Creates a Postgres `text` column. */
659
- export const text = postgres.text
660
- /** Creates a Postgres `int4` column. */
661
- export const int = postgres.int
662
- /** Creates a Postgres `int2` column. */
663
- export const int2 = postgres.int2
664
- /** Creates a Postgres `int8` column. */
665
- export const int8 = postgres.int8
666
- /** Creates a Postgres `numeric` column decoded as `DecimalString`. */
667
- export const number = postgres.number
668
- /** Creates a Postgres `float4` column. */
669
- export const float4 = postgres.float4
670
- /** Creates a Postgres `float8` column. */
671
- export const float8 = postgres.float8
672
- /** Creates a Postgres `bool` column. */
673
- export const boolean = postgres.boolean
674
- /** Creates a Postgres `date` column decoded as `LocalDateString`. */
675
- export const date = postgres.date
676
- /** Creates a Postgres `timestamp` column decoded as `LocalDateTimeString`. */
677
- export const timestamp = postgres.timestamp
678
- /** Creates a Postgres `time` column decoded as `LocalTimeString`. */
679
- export const time = postgres.time
680
- /** Creates a Postgres `timetz` column decoded as `OffsetTimeString`. */
681
- export const timetz = postgres.timetz
682
- /** Creates a Postgres `timestamptz` column decoded as `InstantString`. */
683
- export const timestamptz = postgres.timestamptz
684
- /** Creates a Postgres `char` column. */
685
- export const char = postgres.char
686
- /** Creates a Postgres `varchar` column. */
687
- export const varchar = postgres.varchar
688
- /** Creates a Postgres `interval` column. */
689
- export const interval = postgres.interval
690
- /** Creates a Postgres `bytea` column. */
691
- export const bytea = postgres.bytea
692
- /** Creates a Postgres `name` column. */
693
- export const name = postgres.name
694
- /** Creates a Postgres `oid` column. */
695
- export const oid = postgres.oid
696
- /** Creates a Postgres `regclass` column. */
697
- export const regclass = postgres.regclass
698
- /** Creates a Postgres `bit` column. */
699
- export const bit = postgres.bit
700
- /** Creates a Postgres `varbit` column. */
701
- export const varbit = postgres.varbit
702
- /** Creates a Postgres `xml` column. */
703
- export const xml = postgres.xml
704
- /** Creates a Postgres `pg_lsn` column. */
705
- export const pg_lsn = postgres.pg_lsn
706
-
707
- /** Creates a Postgres `json` column backed by an arbitrary Effect schema. */
708
- export const json = postgres.json
709
- /** Creates a Postgres `jsonb` column backed by an arbitrary Effect schema. */
710
- export const jsonb = postgres.jsonb
711
- /** Creates a Postgres column backed by an arbitrary SQL type and Effect schema. */
712
- export const custom = postgres.custom
713
-
714
444
  /** Replaces a column's runtime schema while preserving its SQL type metadata. */
715
445
  export const schema = <SchemaType extends Schema.Schema.Any>(nextSchema: SchemaType) =>
716
446
  <Column extends AnyColumnDefinition>(
@@ -721,7 +451,7 @@ export const schema = <SchemaType extends Schema.Schema.Any>(nextSchema: SchemaT
721
451
  }) as ColumnWithSchema<Column, SchemaType>
722
452
 
723
453
  type BrandResult<Column extends AnyColumnDefinition> = Column extends AnyBoundColumn
724
- ? BrandedColumn<Column>
454
+ ? BrandedBoundColumn<Column>
725
455
  : BrandMarkedColumn<Column>
726
456
 
727
457
  /** Brands a column with its `table.column` provenance. */
@@ -754,7 +484,7 @@ export const nullable = <Column extends AnyColumnDefinition>(
754
484
  mapColumn(column, {
755
485
  ...column.metadata,
756
486
  nullable: true
757
- })
487
+ }) as NullableColumn<Column>
758
488
 
759
489
  /** Marks a column as a primary key. Primary keys are always unique and non-null. */
760
490
  export const primaryKey = <Column extends AnyColumnDefinition>(
@@ -765,7 +495,7 @@ export const primaryKey = <Column extends AnyColumnDefinition>(
765
495
  nullable: false,
766
496
  primaryKey: true,
767
497
  unique: true
768
- })
498
+ }) as PrimaryKeyColumn<Column>
769
499
 
770
500
  type UniqueModifier = {
771
501
  <Column extends AnyColumnDefinition>(column: Column): UniqueColumn<Column>
@@ -780,7 +510,7 @@ export const unique: UniqueModifier = Object.assign(
780
510
  mapColumn(column, {
781
511
  ...column.metadata,
782
512
  unique: true
783
- }),
513
+ }) as UniqueColumn<Column>,
784
514
  {
785
515
  options: <const Options extends ColumnUniqueOptions>(options: Options) =>
786
516
  <Column extends AnyColumnDefinition>(column: Column): UniqueColumn<Column> =>
@@ -788,7 +518,7 @@ export const unique: UniqueModifier = Object.assign(
788
518
  ...column.metadata,
789
519
  unique: true,
790
520
  uniqueConstraint: options
791
- })
521
+ }) as UniqueColumn<Column>
792
522
  }
793
523
  )
794
524
 
@@ -803,7 +533,7 @@ export const default_ = <Value extends DdlExpression>(value: Value) =>
803
533
  defaultValue: value,
804
534
  generatedValue: undefined,
805
535
  identity: undefined
806
- })
536
+ }) as HasDefaultColumn<Column>
807
537
 
808
538
  /** Marks a column as generated by the database expression and omitted from insert/update. */
809
539
  export const generated = <Value extends DdlExpression>(value: Value) =>
@@ -817,7 +547,7 @@ export const generated = <Value extends DdlExpression>(value: Value) =>
817
547
  defaultValue: undefined,
818
548
  generatedValue: value,
819
549
  identity: undefined
820
- })
550
+ }) as GeneratedColumn<Column>
821
551
 
822
552
  /** Preserves the exact SQL type used for DDL rendering. */
823
553
  export const ddlType = <SqlType extends string>(sqlType: SqlType) =>
@@ -825,7 +555,15 @@ export const ddlType = <SqlType extends string>(sqlType: SqlType) =>
825
555
  mapColumn(column, {
826
556
  ...column.metadata,
827
557
  ddlType: sqlType
828
- })
558
+ }) as DdlTypedColumn<Column>
559
+
560
+ /** Overrides how a column crosses the SQL driver boundary. */
561
+ export const driverValueMapping = (mapping: Expression.DriverValueMapping) =>
562
+ <Column extends AnyColumnDefinition>(column: Column): DriverValueMappedColumn<Column> =>
563
+ mapColumn(column, {
564
+ ...column.metadata,
565
+ driverValueMapping: mapping
566
+ }) as DriverValueMappedColumn<Column>
829
567
 
830
568
  /** Marks a column as a Postgres array type. */
831
569
  export const array = <Options extends ArrayOptions | undefined = undefined>(
@@ -888,7 +626,7 @@ export const identityByDefault = <Column extends AnyColumnDefinition>(
888
626
  identity: {
889
627
  generation: "byDefault"
890
628
  }
891
- })
629
+ }) as ByDefaultIdentityColumn<Column>
892
630
 
893
631
  /** Marks a column as `generated always as identity`. */
894
632
  export const identityAlways = <Column extends AnyColumnDefinition>(
@@ -903,7 +641,7 @@ export const identityAlways = <Column extends AnyColumnDefinition>(
903
641
  identity: {
904
642
  generation: "always"
905
643
  }
906
- })
644
+ }) as AlwaysIdentityColumn<Column>
907
645
 
908
646
  /**
909
647
  * Attaches a lazy foreign-key reference to another bound column.
@@ -929,7 +667,7 @@ export function foreignKey(arg: unknown): unknown {
929
667
  mapColumn(column, {
930
668
  ...column.metadata,
931
669
  references: { target }
932
- })
670
+ }) as ReferencingColumn<Column, AnyBoundColumn>
933
671
  }
934
672
  const options = arg as ForeignKeyOptions<AnyBoundColumn>
935
673
  return <Column extends AnyColumnDefinition>(
@@ -938,7 +676,7 @@ export function foreignKey(arg: unknown): unknown {
938
676
  mapColumn(column, {
939
677
  ...column.metadata,
940
678
  references: options
941
- })
679
+ }) as ReferencingColumn<Column, ReturnType<typeof options.target>>
942
680
  }
943
681
 
944
682
  export const references = <Target extends AnyBoundColumn>(target: () => Target) =>
@@ -0,0 +1,17 @@
1
+ import type * as Expression from "../scalar.js";
2
+ import type { DatatypeFamilySpec, DatatypeKindSpec } from "./shape.js";
3
+ type DatatypeWitness<Dialect extends string, Kinds extends Record<string, DatatypeKindSpec>, Families extends Record<string, DatatypeFamilySpec>, Kind extends keyof Kinds & string> = Expression.DbType.Base<Dialect, Kind> & {
4
+ readonly family: Kinds[Kind]["family"];
5
+ readonly runtime: Kinds[Kind]["runtime"];
6
+ readonly compareGroup: Families[Kinds[Kind]["family"]]["compareGroup"];
7
+ readonly castTargets: Families[Kinds[Kind]["family"]]["castTargets"];
8
+ readonly traits: Families[Kinds[Kind]["family"]]["traits"];
9
+ };
10
+ export type DatatypeModule<Dialect extends string, Kinds extends Record<string, DatatypeKindSpec>, Families extends Record<string, DatatypeFamilySpec>, Aliases extends Record<string, string> = Record<never, never>> = {
11
+ readonly custom: <Kind extends string>(kind: Kind) => Expression.DbType.Base<Dialect, Kind>;
12
+ } & {
13
+ readonly [Kind in keyof Kinds]: () => DatatypeWitness<Dialect, Kinds, Families, Kind & string>;
14
+ } & {
15
+ readonly [Alias in keyof Aliases]: () => DatatypeWitness<Dialect, Kinds, Families, Aliases[Alias] & keyof Kinds & string>;
16
+ };
17
+ export {};
@@ -1,14 +1,28 @@
1
- import type * as Expression from ".././expression.js"
2
- import type { DatatypeKindSpec } from "./shape.js"
1
+ import type * as Expression from "../scalar.js"
2
+ import type { DatatypeFamilySpec, DatatypeKindSpec } from "./shape.js"
3
+
4
+ type DatatypeWitness<
5
+ Dialect extends string,
6
+ Kinds extends Record<string, DatatypeKindSpec>,
7
+ Families extends Record<string, DatatypeFamilySpec>,
8
+ Kind extends keyof Kinds & string
9
+ > = Expression.DbType.Base<Dialect, Kind> & {
10
+ readonly family: Kinds[Kind]["family"]
11
+ readonly runtime: Kinds[Kind]["runtime"]
12
+ readonly compareGroup: Families[Kinds[Kind]["family"]]["compareGroup"]
13
+ readonly castTargets: Families[Kinds[Kind]["family"]]["castTargets"]
14
+ readonly traits: Families[Kinds[Kind]["family"]]["traits"]
15
+ }
3
16
 
4
17
  export type DatatypeModule<
5
18
  Dialect extends string,
6
19
  Kinds extends Record<string, DatatypeKindSpec>,
20
+ Families extends Record<string, DatatypeFamilySpec>,
7
21
  Aliases extends Record<string, string> = Record<never, never>
8
22
  > = {
9
23
  readonly custom: <Kind extends string>(kind: Kind) => Expression.DbType.Base<Dialect, Kind>
10
24
  } & {
11
- readonly [Kind in keyof Kinds]: () => Expression.DbType.Base<Dialect, Kind & string>
25
+ readonly [Kind in keyof Kinds]: () => DatatypeWitness<Dialect, Kinds, Families, Kind & string>
12
26
  } & {
13
- readonly [Alias in keyof Aliases]: () => Expression.DbType.Base<Dialect, Aliases[Alias] & string>
27
+ readonly [Alias in keyof Aliases]: () => DatatypeWitness<Dialect, Kinds, Families, Aliases[Alias] & keyof Kinds & string>
14
28
  }
@@ -0,0 +1,44 @@
1
+ import type * as Expression from "../scalar.js";
2
+ import type { RuntimeOfTag, RuntimeTag } from "./shape.js";
3
+ type ExactKindFamily = "array" | "range" | "multirange" | "record" | "enum" | "set";
4
+ type BaseFamilyOf<Db extends Expression.DbType.Base<any, any>> = Db extends {
5
+ readonly family?: infer Family extends string;
6
+ } ? Family : Db["kind"] extends "null" ? "null" : `other:${Db["dialect"]}:${Db["kind"]}`;
7
+ type BaseRuntimeTagOf<Db extends Expression.DbType.Base<any, any>> = Db extends {
8
+ readonly runtime?: infer Runtime extends RuntimeTag;
9
+ } ? Runtime : "unknown";
10
+ type BaseCompareGroupOf<Db extends Expression.DbType.Base<any, any>> = Db extends {
11
+ readonly compareGroup?: infer CompareGroup extends string;
12
+ } ? CompareGroup : BaseFamilyOf<Db>;
13
+ type BaseCastTargetsOf<Db extends Expression.DbType.Base<any, any>> = Db extends {
14
+ readonly castTargets?: readonly (infer Target extends string)[];
15
+ } ? Target : never;
16
+ type BaseHasTextualTrait<Db extends Expression.DbType.Base<any, any>> = Db extends {
17
+ readonly traits?: infer Traits;
18
+ } ? Traits extends {
19
+ readonly textual: true;
20
+ } ? true : false : false;
21
+ export type FamilyOfDbType<Db extends Expression.DbType.Any> = Db extends Expression.DbType.Domain<any, infer Base extends Expression.DbType.Any, any> ? FamilyOfDbType<Base> : Db extends Expression.DbType.Array<any, any, any> ? "array" : Db extends Expression.DbType.Range<any, any, any> ? "range" : Db extends Expression.DbType.Multirange<any, any, any> ? "multirange" : Db extends Expression.DbType.Composite<any, any, any> ? "record" : Db extends Expression.DbType.Enum<any, any> ? "enum" : Db extends Expression.DbType.Set<any, any> ? "set" : Db extends Expression.DbType.Json<any, any> ? "json" : Db extends Expression.DbType.Base<any, any> ? BaseFamilyOf<Db> : "other:unknown:unknown";
22
+ export type CompareGroupOfDbType<Db extends Expression.DbType.Any> = Db extends Expression.DbType.Domain<any, infer Base extends Expression.DbType.Any, any> ? CompareGroupOfDbType<Base> : Db extends Expression.DbType.Array<any, any, infer Kind extends string> ? Kind : Db extends Expression.DbType.Range<any, any, infer Kind extends string> ? Kind : Db extends Expression.DbType.Multirange<any, any, infer Kind extends string> ? Kind : Db extends Expression.DbType.Composite<any, any, infer Kind extends string> ? Kind : Db extends Expression.DbType.Enum<any, infer Kind extends string> ? Kind : Db extends Expression.DbType.Set<any, infer Kind extends string> ? Kind : Db extends Expression.DbType.Json<any, any> ? never : Db extends Expression.DbType.Base<any, any> ? BaseCompareGroupOf<Db> : "other:unknown:unknown";
23
+ export type RuntimeOfDbType<Db extends Expression.DbType.Any> = Db extends Expression.DbType.Domain<any, infer Base extends Expression.DbType.Any, any> ? RuntimeOfDbType<Base> : Db extends Expression.DbType.Array<any, infer Element extends Expression.DbType.Any, any> ? ReadonlyArray<RuntimeOfDbType<Element>> : Db extends Expression.DbType.Composite<any, infer Fields extends Record<string, Expression.DbType.Any>, any> ? {
24
+ readonly [K in keyof Fields]: RuntimeOfDbType<Fields[K]>;
25
+ } : Db extends Expression.DbType.Range<any, any, any> | Expression.DbType.Multirange<any, any, any> ? unknown : Db extends Expression.DbType.Json<any, any> ? import("../runtime/value.js").JsonValue : Db extends Expression.DbType.Enum<any, any> | Expression.DbType.Set<any, any> ? string : Db extends Expression.DbType.Base<any, any> ? BaseRuntimeTagOf<Db> extends infer Runtime extends RuntimeTag ? RuntimeOfTag<Runtime> : unknown : unknown;
26
+ export type CanCompareDbTypes<Left extends Expression.DbType.Any, Right extends Expression.DbType.Any, Dialect extends string> = Left extends {
27
+ readonly dialect: Dialect;
28
+ } ? Right extends {
29
+ readonly dialect: Dialect;
30
+ } ? CompareGroupOfDbType<Left> extends never ? false : CompareGroupOfDbType<Right> extends never ? false : CompareGroupOfDbType<Left> extends "null" ? false : CompareGroupOfDbType<Right> extends "null" ? false : [CompareGroupOfDbType<Left>] extends [CompareGroupOfDbType<Right>] ? [CompareGroupOfDbType<Right>] extends [CompareGroupOfDbType<Left>] ? true : false : false : false : false;
31
+ export type CanContainDbTypes<Left extends Expression.DbType.Any, Right extends Expression.DbType.Any, Dialect extends string> = Left extends {
32
+ readonly dialect: Dialect;
33
+ } ? Right extends {
34
+ readonly dialect: Dialect;
35
+ } ? FamilyOfDbType<Left> extends "array" | "range" | "multirange" ? FamilyOfDbType<Right> extends "array" | "range" | "multirange" ? [CompareGroupOfDbType<Left>] extends [CompareGroupOfDbType<Right>] ? [CompareGroupOfDbType<Right>] extends [CompareGroupOfDbType<Left>] ? true : false : false : false : false : false : false;
36
+ export type CanTextuallyCoerceDbType<Db extends Expression.DbType.Any, Dialect extends string> = Db extends {
37
+ readonly dialect: Dialect;
38
+ } ? Db extends Expression.DbType.Domain<any, infer Base extends Expression.DbType.Any, any> ? CanTextuallyCoerceDbType<Base, Dialect> : Db extends Expression.DbType.Enum<any, any> | Expression.DbType.Set<any, any> ? true : Db extends Expression.DbType.Json<any, any> ? false : Db extends Expression.DbType.Base<any, any> ? BaseHasTextualTrait<Db> : false : false;
39
+ export type CanCastDbType<Source extends Expression.DbType.Any, Target extends Expression.DbType.Any, Dialect extends string> = Source extends {
40
+ readonly dialect: Dialect;
41
+ } ? Target extends {
42
+ readonly dialect: Dialect;
43
+ } ? Source extends Expression.DbType.Domain<any, infer Base extends Expression.DbType.Any, any> ? CanCastDbType<Base, Target, Dialect> : Target extends Expression.DbType.Domain<any, infer TargetBase extends Expression.DbType.Any, any> ? CanCastDbType<Source, TargetBase, Dialect> : [CompareGroupOfDbType<Source>] extends [CompareGroupOfDbType<Target>] ? [CompareGroupOfDbType<Target>] extends [CompareGroupOfDbType<Source>] ? true : false : Target extends Expression.DbType.Array<any, any, any> | Expression.DbType.Range<any, any, any> | Expression.DbType.Multirange<any, any, any> | Expression.DbType.Composite<any, any, any> | Expression.DbType.Enum<any, any> | Expression.DbType.Set<any, any> ? true : Source extends Expression.DbType.Base<any, any> ? Target extends Expression.DbType.Base<any, any> ? BaseFamilyOf<Target> extends ExactKindFamily ? false : BaseFamilyOf<Target> extends BaseCastTargetsOf<Source> ? true : false : false : false : false : false;
44
+ export {};