effect-qb 0.14.0 → 0.15.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 (141) hide show
  1. package/dist/mysql.js +61270 -4259
  2. package/dist/postgres/metadata.js +176 -82
  3. package/dist/postgres.js +5903 -3316
  4. package/package.json +14 -1
  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 +36 -47
  19. package/src/internal/column.ts +21 -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/dsl-mutation-runtime.ts +378 -0
  29. package/src/internal/dsl-plan-runtime.ts +387 -0
  30. package/src/internal/dsl-query-runtime.ts +160 -0
  31. package/src/internal/dsl-transaction-ddl-runtime.ts +263 -0
  32. package/src/internal/executor.ts +132 -31
  33. package/src/internal/expression-ast.ts +15 -5
  34. package/src/internal/grouping-key.d.ts +3 -0
  35. package/src/internal/grouping-key.ts +1 -1
  36. package/src/internal/implication-runtime.d.ts +15 -0
  37. package/src/internal/implication-runtime.ts +4 -4
  38. package/src/internal/json/ast.d.ts +30 -0
  39. package/src/internal/json/ast.ts +1 -1
  40. package/src/internal/json/errors.d.ts +8 -0
  41. package/src/internal/json/path.d.ts +75 -0
  42. package/src/internal/json/path.ts +1 -1
  43. package/src/internal/json/types.d.ts +62 -0
  44. package/src/internal/predicate/analysis.d.ts +20 -0
  45. package/src/internal/{predicate-analysis.ts → predicate/analysis.ts} +3 -3
  46. package/src/internal/predicate/atom.d.ts +28 -0
  47. package/src/internal/{predicate-branches.ts → predicate/branches.ts} +2 -2
  48. package/src/internal/predicate/context.d.ts +67 -0
  49. package/src/internal/{predicate-context.ts → predicate/context.ts} +8 -5
  50. package/src/internal/predicate/formula.d.ts +35 -0
  51. package/src/internal/{predicate-formula.ts → predicate/formula.ts} +1 -1
  52. package/src/internal/predicate/key.d.ts +11 -0
  53. package/src/internal/{predicate-key.ts → predicate/key.ts} +2 -2
  54. package/src/internal/{predicate-nnf.ts → predicate/nnf.ts} +2 -2
  55. package/src/internal/predicate/normalize.d.ts +53 -0
  56. package/src/internal/{predicate-normalize.ts → predicate/normalize.ts} +19 -19
  57. package/src/internal/predicate/runtime.d.ts +31 -0
  58. package/src/internal/{predicate-runtime.ts → predicate/runtime.ts} +9 -6
  59. package/src/internal/projection-alias.d.ts +13 -0
  60. package/src/internal/projections.d.ts +31 -0
  61. package/src/internal/projections.ts +1 -1
  62. package/src/internal/query-ast.d.ts +217 -0
  63. package/src/internal/query-ast.ts +1 -1
  64. package/src/internal/query-requirements.d.ts +20 -0
  65. package/src/internal/query.d.ts +775 -0
  66. package/src/internal/query.ts +389 -313
  67. package/src/internal/renderer.ts +7 -21
  68. package/src/internal/row-set.d.ts +53 -0
  69. package/src/internal/{plan.ts → row-set.ts} +11 -9
  70. package/src/internal/{runtime-normalize.ts → runtime/normalize.ts} +9 -31
  71. package/src/internal/{runtime-schema.ts → runtime/schema.ts} +13 -38
  72. package/src/internal/runtime/value.d.ts +22 -0
  73. package/src/internal/{runtime-value.ts → runtime/value.ts} +2 -2
  74. package/src/internal/scalar.d.ts +107 -0
  75. package/src/internal/scalar.ts +191 -0
  76. package/src/internal/schema-derivation.d.ts +105 -0
  77. package/src/internal/schema-expression.d.ts +18 -0
  78. package/src/internal/schema-expression.ts +38 -7
  79. package/src/internal/table-options.d.ts +94 -0
  80. package/src/internal/table-options.ts +8 -2
  81. package/src/internal/table.d.ts +173 -0
  82. package/src/internal/table.ts +32 -14
  83. package/src/mysql/column.ts +94 -18
  84. package/src/mysql/datatypes/index.ts +47 -7
  85. package/src/mysql/errors/generated.ts +57336 -0
  86. package/src/mysql/errors/index.ts +1 -0
  87. package/src/mysql/errors/normalize.ts +55 -53
  88. package/src/mysql/errors/types.ts +74 -0
  89. package/src/mysql/executor.ts +69 -7
  90. package/src/mysql/function/aggregate.ts +1 -5
  91. package/src/mysql/function/core.ts +1 -4
  92. package/src/mysql/function/index.ts +0 -1
  93. package/src/mysql/function/string.ts +1 -5
  94. package/src/mysql/function/temporal.ts +12 -15
  95. package/src/mysql/function/window.ts +1 -6
  96. package/src/{internal/mysql-dialect.ts → mysql/internal/dialect.ts} +1 -1
  97. package/src/{internal/mysql-query.ts → mysql/internal/dsl.ts} +1024 -2082
  98. package/src/{internal/mysql-renderer.ts → mysql/internal/renderer.ts} +6 -6
  99. package/src/mysql/internal/sql-expression-renderer.ts +1455 -0
  100. package/src/mysql/json.ts +2 -0
  101. package/src/mysql/query.ts +111 -91
  102. package/src/mysql/renderer.ts +1 -1
  103. package/src/mysql/table.ts +1 -1
  104. package/src/mysql.ts +6 -4
  105. package/src/postgres/cast.ts +11 -12
  106. package/src/postgres/column.ts +178 -46
  107. package/src/postgres/datatypes/index.d.ts +515 -0
  108. package/src/postgres/datatypes/index.ts +22 -13
  109. package/src/postgres/datatypes/spec.d.ts +412 -0
  110. package/src/postgres/errors/generated.ts +2636 -0
  111. package/src/postgres/errors/index.ts +1 -0
  112. package/src/postgres/errors/normalize.ts +47 -62
  113. package/src/postgres/errors/types.ts +92 -34
  114. package/src/postgres/executor.ts +37 -5
  115. package/src/postgres/function/aggregate.ts +1 -5
  116. package/src/postgres/function/core.ts +12 -6
  117. package/src/postgres/function/index.ts +0 -1
  118. package/src/postgres/function/string.ts +1 -5
  119. package/src/postgres/function/temporal.ts +12 -15
  120. package/src/postgres/function/window.ts +1 -6
  121. package/src/{internal/postgres-dialect.ts → postgres/internal/dialect.ts} +1 -1
  122. package/src/{internal/postgres-query.ts → postgres/internal/dsl.ts} +1085 -2089
  123. package/src/{internal/postgres-renderer.ts → postgres/internal/renderer.ts} +6 -6
  124. package/src/postgres/internal/schema-ddl.ts +108 -0
  125. package/src/{internal/postgres-schema-model.ts → postgres/internal/schema-model.ts} +12 -6
  126. package/src/{internal → postgres/internal}/sql-expression-renderer.ts +19 -17
  127. package/src/postgres/{function/json.ts → json.ts} +77 -85
  128. package/src/postgres/metadata.ts +2 -2
  129. package/src/postgres/query.ts +113 -89
  130. package/src/postgres/renderer.ts +3 -13
  131. package/src/postgres/schema-expression.ts +2 -1
  132. package/src/postgres/schema-management.ts +1 -1
  133. package/src/postgres/table.ts +12 -4
  134. package/src/postgres/type.ts +29 -2
  135. package/src/postgres.ts +6 -4
  136. package/src/internal/expression.ts +0 -327
  137. package/src/internal/schema-ddl.ts +0 -55
  138. package/src/mysql/function/json.ts +0 -4
  139. package/src/mysql/private/query.ts +0 -1
  140. package/src/postgres/private/query.ts +0 -1
  141. /package/src/internal/{predicate-atom.ts → predicate/atom.ts} +0 -0
@@ -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
@@ -237,7 +237,6 @@ type ColumnWithSchema<
237
237
  IsPrimaryKey<Column>,
238
238
  Column[typeof ColumnTypeId]["unique"],
239
239
  ReferencesOf<Column>,
240
- Column[typeof ColumnTypeId]["source"],
241
240
  Column[typeof ColumnTypeId]["dependencies"]
242
241
  > & PreserveBrand<Column>
243
242
 
@@ -259,9 +258,9 @@ type PreserveBrand<Column extends AnyColumnDefinition> = Column["metadata"]["bra
259
258
  ? BrandMetadata<Column>
260
259
  : {}
261
260
 
262
- type BrandedColumn<
261
+ type BrandedBoundColumn<
263
262
  Column extends AnyBoundColumn
264
- > = ColumnDefinition<
263
+ > = BoundColumn<
265
264
  BrandedValue<SelectType<Column>, BrandNameOf<Column>>,
266
265
  BrandedValue<InsertType<Column>, BrandNameOf<Column>>,
267
266
  BrandedValue<UpdateType<Column>, BrandNameOf<Column>>,
@@ -272,8 +271,9 @@ type BrandedColumn<
272
271
  IsPrimaryKey<Column>,
273
272
  Column[typeof ColumnTypeId]["unique"],
274
273
  ReferencesOf<Column>,
275
- Column[typeof ColumnTypeId]["source"],
276
- Column[typeof ColumnTypeId]["dependencies"]
274
+ Column[typeof BoundColumnTypeId]["tableName"],
275
+ Column[typeof BoundColumnTypeId]["columnName"],
276
+ Column[typeof BoundColumnTypeId]["baseTableName"]
277
277
  > & BrandMetadata<Column>
278
278
 
279
279
  type BrandMarkedColumn<
@@ -289,7 +289,6 @@ type BrandMarkedColumn<
289
289
  IsPrimaryKey<Column>,
290
290
  Column[typeof ColumnTypeId]["unique"],
291
291
  ReferencesOf<Column>,
292
- Column[typeof ColumnTypeId]["source"],
293
292
  Column[typeof ColumnTypeId]["dependencies"]
294
293
  > & BrandMetadata<Column>
295
294
 
@@ -346,7 +345,6 @@ type ArrayColumn<
346
345
  IsPrimaryKey<Column>,
347
346
  Column[typeof ColumnTypeId]["unique"],
348
347
  ReferencesOf<Column>,
349
- Column[typeof ColumnTypeId]["source"],
350
348
  Column[typeof ColumnTypeId]["dependencies"]
351
349
  > & PreserveBrand<Column>
352
350
 
@@ -429,288 +427,6 @@ type ColumnModule<
429
427
  >
430
428
  }
431
429
 
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
430
  /** Replaces a column's runtime schema while preserving its SQL type metadata. */
715
431
  export const schema = <SchemaType extends Schema.Schema.Any>(nextSchema: SchemaType) =>
716
432
  <Column extends AnyColumnDefinition>(
@@ -721,7 +437,7 @@ export const schema = <SchemaType extends Schema.Schema.Any>(nextSchema: SchemaT
721
437
  }) as ColumnWithSchema<Column, SchemaType>
722
438
 
723
439
  type BrandResult<Column extends AnyColumnDefinition> = Column extends AnyBoundColumn
724
- ? BrandedColumn<Column>
440
+ ? BrandedBoundColumn<Column>
725
441
  : BrandMarkedColumn<Column>
726
442
 
727
443
  /** Brands a column with its `table.column` provenance. */
@@ -754,7 +470,7 @@ export const nullable = <Column extends AnyColumnDefinition>(
754
470
  mapColumn(column, {
755
471
  ...column.metadata,
756
472
  nullable: true
757
- })
473
+ }) as NullableColumn<Column>
758
474
 
759
475
  /** Marks a column as a primary key. Primary keys are always unique and non-null. */
760
476
  export const primaryKey = <Column extends AnyColumnDefinition>(
@@ -765,7 +481,7 @@ export const primaryKey = <Column extends AnyColumnDefinition>(
765
481
  nullable: false,
766
482
  primaryKey: true,
767
483
  unique: true
768
- })
484
+ }) as PrimaryKeyColumn<Column>
769
485
 
770
486
  type UniqueModifier = {
771
487
  <Column extends AnyColumnDefinition>(column: Column): UniqueColumn<Column>
@@ -780,7 +496,7 @@ export const unique: UniqueModifier = Object.assign(
780
496
  mapColumn(column, {
781
497
  ...column.metadata,
782
498
  unique: true
783
- }),
499
+ }) as UniqueColumn<Column>,
784
500
  {
785
501
  options: <const Options extends ColumnUniqueOptions>(options: Options) =>
786
502
  <Column extends AnyColumnDefinition>(column: Column): UniqueColumn<Column> =>
@@ -788,7 +504,7 @@ export const unique: UniqueModifier = Object.assign(
788
504
  ...column.metadata,
789
505
  unique: true,
790
506
  uniqueConstraint: options
791
- })
507
+ }) as UniqueColumn<Column>
792
508
  }
793
509
  )
794
510
 
@@ -803,7 +519,7 @@ export const default_ = <Value extends DdlExpression>(value: Value) =>
803
519
  defaultValue: value,
804
520
  generatedValue: undefined,
805
521
  identity: undefined
806
- })
522
+ }) as HasDefaultColumn<Column>
807
523
 
808
524
  /** Marks a column as generated by the database expression and omitted from insert/update. */
809
525
  export const generated = <Value extends DdlExpression>(value: Value) =>
@@ -817,7 +533,7 @@ export const generated = <Value extends DdlExpression>(value: Value) =>
817
533
  defaultValue: undefined,
818
534
  generatedValue: value,
819
535
  identity: undefined
820
- })
536
+ }) as GeneratedColumn<Column>
821
537
 
822
538
  /** Preserves the exact SQL type used for DDL rendering. */
823
539
  export const ddlType = <SqlType extends string>(sqlType: SqlType) =>
@@ -825,7 +541,7 @@ export const ddlType = <SqlType extends string>(sqlType: SqlType) =>
825
541
  mapColumn(column, {
826
542
  ...column.metadata,
827
543
  ddlType: sqlType
828
- })
544
+ }) as DdlTypedColumn<Column>
829
545
 
830
546
  /** Marks a column as a Postgres array type. */
831
547
  export const array = <Options extends ArrayOptions | undefined = undefined>(
@@ -888,7 +604,7 @@ export const identityByDefault = <Column extends AnyColumnDefinition>(
888
604
  identity: {
889
605
  generation: "byDefault"
890
606
  }
891
- })
607
+ }) as ByDefaultIdentityColumn<Column>
892
608
 
893
609
  /** Marks a column as `generated always as identity`. */
894
610
  export const identityAlways = <Column extends AnyColumnDefinition>(
@@ -903,7 +619,7 @@ export const identityAlways = <Column extends AnyColumnDefinition>(
903
619
  identity: {
904
620
  generation: "always"
905
621
  }
906
- })
622
+ }) as AlwaysIdentityColumn<Column>
907
623
 
908
624
  /**
909
625
  * Attaches a lazy foreign-key reference to another bound column.
@@ -929,7 +645,7 @@ export function foreignKey(arg: unknown): unknown {
929
645
  mapColumn(column, {
930
646
  ...column.metadata,
931
647
  references: { target }
932
- })
648
+ }) as ReferencingColumn<Column, AnyBoundColumn>
933
649
  }
934
650
  const options = arg as ForeignKeyOptions<AnyBoundColumn>
935
651
  return <Column extends AnyColumnDefinition>(
@@ -938,7 +654,7 @@ export function foreignKey(arg: unknown): unknown {
938
654
  mapColumn(column, {
939
655
  ...column.metadata,
940
656
  references: options
941
- })
657
+ }) as ReferencingColumn<Column, ReturnType<typeof options.target>>
942
658
  }
943
659
 
944
660
  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 {};