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
package/package.json CHANGED
@@ -1,7 +1,20 @@
1
1
  {
2
2
  "name": "effect-qb",
3
- "version": "0.14.0",
3
+ "version": "0.16.0",
4
4
  "type": "module",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/relsunkaev/effect-qb.git"
9
+ },
10
+ "bugs": {
11
+ "url": "https://github.com/relsunkaev/effect-qb/issues"
12
+ },
13
+ "homepage": "https://github.com/relsunkaev/effect-qb#readme",
14
+ "engines": {
15
+ "node": ">=22",
16
+ "bun": ">=1.3.5"
17
+ },
5
18
  "files": [
6
19
  "dist",
7
20
  "src",
@@ -36,7 +49,7 @@
36
49
  },
37
50
  "devDependencies": {
38
51
  "@types/bun": "latest",
39
- "@typescript/native-preview": "latest"
52
+ "@typescript/native-preview": "beta"
40
53
  },
41
54
  "dependencies": {
42
55
  "@effect/experimental": "^0.57.0",
@@ -1,4 +1,4 @@
1
- import * as Expression from "./expression.js"
1
+ import * as Expression from "./scalar.js"
2
2
  import { groupingKeyOfExpression } from "./grouping-key.js"
3
3
 
4
4
  /** Recursive selection value accepted by aggregate-shape validation. */
@@ -13,7 +13,7 @@ const isExpression = (value: unknown): value is Expression.Any =>
13
13
 
14
14
  const selectionHasAggregate = (selection: SelectionValue): boolean => {
15
15
  if (isExpression(selection)) {
16
- return selection[Expression.TypeId].aggregation === "aggregate"
16
+ return selection[Expression.TypeId].kind === "aggregate"
17
17
  }
18
18
  return Object.values(selection).some((value) => selectionHasAggregate(value))
19
19
  }
@@ -23,7 +23,7 @@ const isGroupedSelectionValid = (
23
23
  groupedExpressions: ReadonlySet<string>
24
24
  ): boolean => {
25
25
  if (isExpression(selection)) {
26
- const aggregation = selection[Expression.TypeId].aggregation
26
+ const aggregation = selection[Expression.TypeId].kind
27
27
  if (aggregation === "aggregate") {
28
28
  return true
29
29
  }
@@ -0,0 +1,18 @@
1
+ import type * as Expression from "./scalar.js";
2
+ import type * as ExpressionAst from "./expression-ast.js";
3
+ import type { PredicateFormula } from "./predicate/formula.js";
4
+ import type { AssumeFormulaFalse, AssumeFormulaTrue, Contradicts, Implies } from "./predicate/analysis.js";
5
+ import type { FormulaOfExpression } from "./predicate/normalize.js";
6
+ export interface CasePath<Assumptions extends PredicateFormula, Value extends Expression.Any> {
7
+ readonly assumptions: Assumptions;
8
+ readonly value: Value;
9
+ }
10
+ type PredicateFormulaOf<Predicate extends Expression.Any> = FormulaOfExpression<Predicate>;
11
+ export type CaseBranchAssumeTrue<Assumptions extends PredicateFormula, Predicate extends Expression.Any> = AssumeFormulaTrue<Assumptions, PredicateFormulaOf<Predicate>>;
12
+ export type CaseBranchAssumeFalse<Assumptions extends PredicateFormula, Predicate extends Expression.Any> = AssumeFormulaFalse<Assumptions, PredicateFormulaOf<Predicate>>;
13
+ export type CaseBranchDecision<Assumptions extends PredicateFormula, Predicate extends Expression.Any> = Contradicts<Assumptions, Predicate> extends true ? "skip" : Implies<Assumptions, Predicate> extends true ? "take" : "branch";
14
+ export type ReachableCasePaths<Assumptions extends PredicateFormula, Branches extends readonly ExpressionAst.CaseBranchNode[], Else extends Expression.Any> = Branches extends readonly [
15
+ infer Head extends ExpressionAst.CaseBranchNode,
16
+ ...infer Tail extends readonly ExpressionAst.CaseBranchNode[]
17
+ ] ? CaseBranchDecision<Assumptions, Head["when"]> extends "skip" ? ReachableCasePaths<Assumptions, Tail, Else> : CaseBranchDecision<Assumptions, Head["when"]> extends "take" ? CasePath<CaseBranchAssumeTrue<Assumptions, Head["when"]>, Head["then"]> : CasePath<CaseBranchAssumeTrue<Assumptions, Head["when"]>, Head["then"]> | ReachableCasePaths<CaseBranchAssumeFalse<Assumptions, Head["when"]>, Tail, Else> : CasePath<Assumptions, Else>;
18
+ export {};
@@ -1,8 +1,8 @@
1
- import type * as Expression from "./expression.js"
1
+ import type * as Expression from "./scalar.js"
2
2
  import type * as ExpressionAst from "./expression-ast.js"
3
- import type { PredicateFormula } from "./predicate-formula.js"
4
- import type { AssumeFormulaFalse, AssumeFormulaTrue, Contradicts, Implies } from "./predicate-analysis.js"
5
- import type { FormulaOfExpression } from "./predicate-normalize.js"
3
+ import type { PredicateFormula } from "./predicate/formula.js"
4
+ import type { AssumeFormulaFalse, AssumeFormulaTrue, Contradicts, Implies } from "./predicate/analysis.js"
5
+ import type { FormulaOfExpression } from "./predicate/normalize.js"
6
6
 
7
7
  export interface CasePath<
8
8
  Assumptions extends PredicateFormula,
@@ -0,0 +1,7 @@
1
+ import type * as Expression from "../scalar.js";
2
+ import type { CastTargetError, OperandCompatibilityError } from "./errors.js";
3
+ import type { CanCastDbType, CanCompareDbTypes, CanTextuallyCoerceDbType } from "./rules.js";
4
+ export type ComparableDbType<Left extends Expression.DbType.Any, Right extends Expression.DbType.Any, Dialect extends string, Operator extends string = "comparison"> = CanCompareDbTypes<Left, Right, Dialect> extends true ? Right : OperandCompatibilityError<Operator, Left, Right, Dialect, "the same db type family">;
5
+ export type TextCompatibleDbType<Db extends Expression.DbType.Any, Dialect extends string, Operator extends string = "text operator"> = CanTextuallyCoerceDbType<Db, Dialect> extends true ? Db : OperandCompatibilityError<Operator, Db, Db, Dialect, "a text-compatible db type">;
6
+ export type CastableDbType<Source extends Expression.DbType.Any, Target extends Expression.DbType.Any, Dialect extends string> = CanCastDbType<Source, Target, Dialect> extends true ? Target : CastTargetError<Source, Target, Dialect>;
7
+ export type RuntimeOfDbType<Db extends Expression.DbType.Any> = Expression.RuntimeOfDbType<Db>;
@@ -1,6 +1,6 @@
1
- import type * as Expression from "./expression.js"
2
- import type { CastTargetError, OperandCompatibilityError } from "./coercion-errors.js"
3
- import type { CanCastDbType, CanCompareDbTypes, CanTextuallyCoerceDbType } from "./coercion-rules.js"
1
+ import type * as Expression from "../scalar.js"
2
+ import type { CastTargetError, OperandCompatibilityError } from "./errors.js"
3
+ import type { CanCastDbType, CanCompareDbTypes, CanTextuallyCoerceDbType } from "./rules.js"
4
4
 
5
5
  export type ComparableDbType<
6
6
  Left extends Expression.DbType.Any,
@@ -0,0 +1,17 @@
1
+ import type * as Expression from "../scalar.js";
2
+ export type OperandCompatibilityError<Operator extends string, Left extends Expression.DbType.Any, Right extends Expression.DbType.Any, Dialect extends string, Expected extends string> = {
3
+ readonly __effect_qb_error__: "effect-qb: incompatible operand types";
4
+ readonly __effect_qb_operator__: Operator;
5
+ readonly __effect_qb_left_db_type__: Left;
6
+ readonly __effect_qb_right_db_type__: Right;
7
+ readonly __effect_qb_dialect__: Dialect;
8
+ readonly __effect_qb_expected__: Expected;
9
+ readonly __effect_qb_hint__: "Use cast(...) or pick values from the same db type family";
10
+ };
11
+ export type CastTargetError<Source extends Expression.DbType.Any, Target extends Expression.DbType.Any, Dialect extends string> = {
12
+ readonly __effect_qb_error__: "effect-qb: unsupported cast target";
13
+ readonly __effect_qb_source_db_type__: Source;
14
+ readonly __effect_qb_target_db_type__: Target;
15
+ readonly __effect_qb_dialect__: Dialect;
16
+ readonly __effect_qb_hint__: "Use one of the supported Q.type.<kind>() witnesses";
17
+ };
@@ -1,4 +1,4 @@
1
- import type * as Expression from "./expression.js"
1
+ import type * as Expression from "../scalar.js"
2
2
 
3
3
  export type OperandCompatibilityError<
4
4
  Operator extends string,
@@ -0,0 +1,4 @@
1
+ import type * as Expression from "../scalar.js";
2
+ import type { FamilyOfDbType } from "../datatypes/lookup.js";
3
+ export type CoercionKind = "text" | "numeric" | "boolean" | "date" | "time" | "timestamp" | "binary" | "interval" | "uuid" | "json" | "xml" | "bit" | "identifier" | "network" | "spatial" | "textsearch" | "range" | "multirange" | "array" | "record" | "domain" | "enum" | "set" | "money" | "null" | `other:${string}`;
4
+ export type CoercionKindOf<Db extends Expression.DbType.Any> = FamilyOfDbType<Db>;
@@ -1,5 +1,5 @@
1
- import type * as Expression from "./expression.js"
2
- import type { FamilyOfDbType } from "./datatypes/lookup.js"
1
+ import type * as Expression from "../scalar.js"
2
+ import type { FamilyOfDbType } from "../datatypes/lookup.js"
3
3
 
4
4
  export type CoercionKind =
5
5
  | "text"
@@ -1,4 +1,4 @@
1
- import type * as Expression from "./expression.js"
1
+ import type * as Expression from "../scalar.js"
2
2
 
3
3
  /** Extracts the database type carried by an expression. */
4
4
  export type DbTypeOfExpression<Value extends Expression.Any> = Expression.DbTypeOf<Value>
@@ -0,0 +1,6 @@
1
+ import type * as Expression from "../scalar.js";
2
+ import type { CanCastDbType as LookupCanCastDbType, CanCompareDbTypes as LookupCanCompareDbTypes, CanContainDbTypes as LookupCanContainDbTypes, CanTextuallyCoerceDbType as LookupCanTextuallyCoerceDbType } from "../datatypes/lookup.js";
3
+ export type CanCompareDbTypes<Left extends Expression.DbType.Any, Right extends Expression.DbType.Any, Dialect extends string> = LookupCanCompareDbTypes<Left, Right, Dialect>;
4
+ export type CanContainDbTypes<Left extends Expression.DbType.Any, Right extends Expression.DbType.Any, Dialect extends string> = LookupCanContainDbTypes<Left, Right, Dialect>;
5
+ export type CanTextuallyCoerceDbType<Db extends Expression.DbType.Any, Dialect extends string> = LookupCanTextuallyCoerceDbType<Db, Dialect>;
6
+ export type CanCastDbType<Source extends Expression.DbType.Any, Target extends Expression.DbType.Any, Dialect extends string> = LookupCanCastDbType<Source, Target, Dialect>;
@@ -1,5 +1,5 @@
1
- import type * as Expression from "./expression.js"
2
- import type { CanCastDbType as LookupCanCastDbType, CanCompareDbTypes as LookupCanCompareDbTypes, CanContainDbTypes as LookupCanContainDbTypes, CanTextuallyCoerceDbType as LookupCanTextuallyCoerceDbType } from "./datatypes/lookup.js"
1
+ import type * as Expression from "../scalar.js"
2
+ import type { CanCastDbType as LookupCanCastDbType, CanCompareDbTypes as LookupCanCompareDbTypes, CanContainDbTypes as LookupCanContainDbTypes, CanTextuallyCoerceDbType as LookupCanTextuallyCoerceDbType } from "../datatypes/lookup.js"
3
3
 
4
4
  export type CanCompareDbTypes<
5
5
  Left extends Expression.DbType.Any,
@@ -0,0 +1,190 @@
1
+ import type * as Brand from "effect/Brand";
2
+ import { type Pipeable } from "effect/Pipeable";
3
+ import * as Schema from "effect/Schema";
4
+ import * as Expression from "./scalar.js";
5
+ import * as ExpressionAst from "./expression-ast.js";
6
+ import type * as SchemaExpression from "./schema-expression.js";
7
+ /** Symbol used to attach column-definition metadata. */
8
+ export declare const ColumnTypeId: unique symbol;
9
+ /** Symbol used to attach bound-column provenance. */
10
+ export declare const BoundColumnTypeId: unique symbol;
11
+ export type ColumnTypeId = typeof ColumnTypeId;
12
+ export type BoundColumnTypeId = typeof BoundColumnTypeId;
13
+ export type DdlExpression = Expression.Any | SchemaExpression.Any;
14
+ /** Lazy reference to another bound column. */
15
+ export interface ColumnReference<Target = unknown> {
16
+ readonly target: () => Target;
17
+ readonly name?: string;
18
+ readonly onUpdate?: "noAction" | "restrict" | "cascade" | "setNull" | "setDefault";
19
+ readonly onDelete?: "noAction" | "restrict" | "cascade" | "setNull" | "setDefault";
20
+ readonly deferrable?: boolean;
21
+ readonly initiallyDeferred?: boolean;
22
+ }
23
+ /** Inline single-column index metadata. */
24
+ export interface ColumnIndexOptions {
25
+ readonly name?: string;
26
+ readonly method?: string;
27
+ readonly include?: readonly string[];
28
+ readonly predicate?: DdlExpression;
29
+ readonly order?: "asc" | "desc";
30
+ readonly nulls?: "first" | "last";
31
+ readonly operatorClass?: string;
32
+ readonly collation?: string;
33
+ }
34
+ /** Inline single-column unique-constraint metadata. */
35
+ export interface ColumnUniqueOptions {
36
+ readonly name?: string;
37
+ readonly nullsNotDistinct?: boolean;
38
+ readonly deferrable?: boolean;
39
+ readonly initiallyDeferred?: boolean;
40
+ }
41
+ /** Complete static state tracked for a column definition. */
42
+ export interface ColumnState<Select, Insert, Update, Db extends Expression.DbType.Any, Nullable extends boolean, HasDefault extends boolean, Generated extends boolean, PrimaryKey extends boolean, Unique extends boolean, Ref, Dependencies extends Expression.BindingId = never> {
43
+ readonly select: Select;
44
+ readonly insert: Insert;
45
+ readonly update: Update;
46
+ readonly dbType: Db;
47
+ readonly nullable: Nullable;
48
+ readonly hasDefault: HasDefault;
49
+ readonly generated: Generated;
50
+ readonly primaryKey: PrimaryKey;
51
+ readonly unique: Unique;
52
+ readonly references: Ref;
53
+ readonly brand?: true;
54
+ readonly index?: ColumnIndexOptions;
55
+ readonly uniqueConstraint?: ColumnUniqueOptions;
56
+ readonly defaultValue?: DdlExpression;
57
+ readonly generatedValue?: DdlExpression;
58
+ readonly ddlType?: string;
59
+ readonly identity?: {
60
+ readonly generation: "always" | "byDefault";
61
+ };
62
+ readonly enum?: {
63
+ readonly name: string;
64
+ readonly schemaName?: string;
65
+ readonly values: readonly [string, ...string[]];
66
+ };
67
+ readonly dependencies?: Dependencies;
68
+ }
69
+ /** Unbound column definition produced by the `Column` DSL. */
70
+ export interface ColumnDefinition<Select, Insert, Update, Db extends Expression.DbType.Any, Nullable extends boolean, HasDefault extends boolean, Generated extends boolean, PrimaryKey extends boolean, Unique extends boolean, Ref, Dependencies extends Expression.BindingId = never> extends Pipeable, Expression.Scalar<Select, Db, Nullable extends true ? "maybe" : "never", Db["dialect"], "scalar", Dependencies> {
71
+ readonly pipe: Pipeable["pipe"];
72
+ readonly [ColumnTypeId]: ColumnState<Select, Insert, Update, Db, Nullable, HasDefault, Generated, PrimaryKey, Unique, Ref, Dependencies>;
73
+ readonly schema: Schema.Schema<NonNullable<Select>, any, any>;
74
+ readonly metadata: {
75
+ readonly dbType: Db;
76
+ readonly nullable: Nullable;
77
+ readonly hasDefault: HasDefault;
78
+ readonly generated: Generated;
79
+ readonly primaryKey: PrimaryKey;
80
+ readonly unique: Unique;
81
+ readonly references: Ref;
82
+ readonly brand?: true;
83
+ readonly index?: ColumnIndexOptions;
84
+ readonly uniqueConstraint?: ColumnUniqueOptions;
85
+ readonly defaultValue?: DdlExpression;
86
+ readonly generatedValue?: DdlExpression;
87
+ readonly ddlType?: string;
88
+ readonly identity?: {
89
+ readonly generation: "always" | "byDefault";
90
+ };
91
+ readonly enum?: {
92
+ readonly name: string;
93
+ readonly schemaName?: string;
94
+ readonly values: readonly [string, ...string[]];
95
+ };
96
+ };
97
+ }
98
+ /** Column definition bound to a concrete table and column name. */
99
+ export interface BoundColumn<Select, Insert, Update, Db extends Expression.DbType.Any, Nullable extends boolean, HasDefault extends boolean, Generated extends boolean, PrimaryKey extends boolean, Unique extends boolean, Ref, TableName extends string, ColumnName extends string, BaseTableName extends string = TableName> extends ColumnDefinition<Select, Insert, Update, Db, Nullable, HasDefault, Generated, PrimaryKey, Unique, Ref, TableName> {
100
+ readonly [BoundColumnTypeId]: {
101
+ readonly tableName: TableName;
102
+ readonly columnName: ColumnName;
103
+ readonly baseTableName: BaseTableName;
104
+ readonly schemaName?: string;
105
+ };
106
+ readonly [Expression.TypeId]: Expression.State<Select, Db, Nullable extends true ? "maybe" : "never", Db["dialect"], "scalar", TableName>;
107
+ readonly [ExpressionAst.TypeId]: ExpressionAst.ColumnNode<TableName, ColumnName>;
108
+ }
109
+ /** Convenience alias for any column definition. */
110
+ export type AnyColumnDefinition = ColumnDefinition<any, any, any, Expression.DbType.Any, boolean, boolean, boolean, boolean, boolean, any, any>;
111
+ /** Convenience alias for any bound column. */
112
+ export type AnyBoundColumn = BoundColumn<any, any, any, Expression.DbType.Any, boolean, boolean, boolean, boolean, boolean, any, string, string, string>;
113
+ /** Constructs a runtime column-definition object from schema and metadata. */
114
+ export declare const makeColumnDefinition: <Select, Insert, Update, Db extends Expression.DbType.Any, Nullable extends boolean, HasDefault extends boolean, Generated extends boolean, PrimaryKey extends boolean, Unique extends boolean, Ref, Dependencies extends string = never>(schema: Schema.Schema<NonNullable<Select>, any, any>, metadata: {
115
+ readonly dbType: Db;
116
+ readonly nullable: Nullable;
117
+ readonly hasDefault: HasDefault;
118
+ readonly generated: Generated;
119
+ readonly primaryKey: PrimaryKey;
120
+ readonly unique: Unique;
121
+ readonly references: Ref;
122
+ readonly brand?: true | undefined;
123
+ readonly index?: ColumnIndexOptions | undefined;
124
+ readonly uniqueConstraint?: ColumnUniqueOptions | undefined;
125
+ readonly defaultValue?: DdlExpression | undefined;
126
+ readonly generatedValue?: DdlExpression | undefined;
127
+ readonly ddlType?: string | undefined;
128
+ readonly identity?: {
129
+ readonly generation: "always" | "byDefault";
130
+ } | undefined;
131
+ readonly enum?: {
132
+ readonly name: string;
133
+ readonly schemaName?: string | undefined;
134
+ readonly values: readonly [string, ...string[]];
135
+ } | undefined;
136
+ }) => ColumnDefinition<Select, Insert, Update, Db, Nullable, HasDefault, Generated, PrimaryKey, Unique, Ref, Dependencies>;
137
+ export declare const remapColumnDefinition: <Select, Insert, Update, Db extends Expression.DbType.Any, Nullable extends boolean, HasDefault extends boolean, Generated extends boolean, PrimaryKey extends boolean, Unique extends boolean, Ref, Dependencies extends string = never>(column: ColumnDefinition<Select, Insert, Update, Db, Nullable, HasDefault, Generated, PrimaryKey, Unique, Ref, Dependencies>, options?: {
138
+ readonly schema?: Schema.Schema.Any | undefined;
139
+ readonly metadata?: {
140
+ readonly dbType: Db;
141
+ readonly nullable: Nullable;
142
+ readonly hasDefault: HasDefault;
143
+ readonly generated: Generated;
144
+ readonly primaryKey: PrimaryKey;
145
+ readonly unique: Unique;
146
+ readonly references: Ref;
147
+ readonly brand?: true | undefined;
148
+ readonly index?: ColumnIndexOptions | undefined;
149
+ readonly uniqueConstraint?: ColumnUniqueOptions | undefined;
150
+ readonly defaultValue?: DdlExpression | undefined;
151
+ readonly generatedValue?: DdlExpression | undefined;
152
+ readonly ddlType?: string | undefined;
153
+ readonly identity?: {
154
+ readonly generation: "always" | "byDefault";
155
+ } | undefined;
156
+ readonly enum?: {
157
+ readonly name: string;
158
+ readonly schemaName?: string | undefined;
159
+ readonly values: readonly [string, ...string[]];
160
+ } | undefined;
161
+ } | undefined;
162
+ }) => ColumnDefinition<Select, Insert, Update, Db, Nullable, HasDefault, Generated, PrimaryKey, Unique, Ref, Dependencies>;
163
+ /** Attaches table/column provenance to an existing column definition. */
164
+ export declare const bindColumn: <TableName extends string, ColumnName extends string, BaseTableName extends string, SchemaName extends string | undefined, Column extends AnyColumnDefinition>(tableName: TableName, columnName: ColumnName, column: Column, baseTableName: BaseTableName, schemaName?: SchemaName | undefined) => BoundColumnFrom<Column, TableName, ColumnName, BaseTableName>;
165
+ /** Extracts the internal state record for a column. */
166
+ export type ColumnStateOf<Column extends AnyColumnDefinition> = Column[typeof ColumnTypeId];
167
+ /** Extracts the read/select type of a column. */
168
+ export type SelectType<Column extends AnyColumnDefinition> = ColumnStateOf<Column>["select"];
169
+ /** Extracts the insert type of a column. */
170
+ export type InsertType<Column extends AnyColumnDefinition> = ColumnStateOf<Column>["insert"];
171
+ /** Extracts the update type of a column. */
172
+ export type UpdateType<Column extends AnyColumnDefinition> = ColumnStateOf<Column>["update"];
173
+ /** Extracts whether a column is nullable. */
174
+ export type IsNullable<Column extends AnyColumnDefinition> = ColumnStateOf<Column>["nullable"];
175
+ /** Extracts whether a column has a server-side default. */
176
+ export type HasDefault<Column extends AnyColumnDefinition> = ColumnStateOf<Column>["hasDefault"];
177
+ /** Extracts whether a column is generated by the database. */
178
+ export type IsGenerated<Column extends AnyColumnDefinition> = ColumnStateOf<Column>["generated"];
179
+ /** Extracts whether a column is part of a primary key. */
180
+ export type IsPrimaryKey<Column extends AnyColumnDefinition> = ColumnStateOf<Column>["primaryKey"];
181
+ /** Extracts whether a column is unique. */
182
+ export type IsUnique<Column extends AnyColumnDefinition> = ColumnStateOf<Column>["unique"];
183
+ /** Extracts a column's foreign-key reference metadata. */
184
+ export type ReferencesOf<Column extends AnyColumnDefinition> = ColumnStateOf<Column>["references"];
185
+ /** Extracts the non-null select type of a column. */
186
+ export type BaseSelectType<Column extends AnyColumnDefinition> = NonNullable<SelectType<Column>>;
187
+ type BrandedValue<Value, BrandName extends string> = [Extract<Value, null | undefined>] extends [never] ? Value & Brand.Brand<BrandName> : (Exclude<Value, null | undefined> & Brand.Brand<BrandName>) | Extract<Value, null | undefined>;
188
+ /** Rebinds a generic column definition to a specific table and key. */
189
+ export type BoundColumnFrom<Column extends AnyColumnDefinition, TableName extends string, ColumnName extends string, BaseTableName extends string = TableName> = BoundColumn<Column["metadata"]["brand"] extends true ? BrandedValue<SelectType<Column>, `${TableName}.${ColumnName}`> : SelectType<Column>, Column["metadata"]["brand"] extends true ? BrandedValue<InsertType<Column>, `${TableName}.${ColumnName}`> : InsertType<Column>, Column["metadata"]["brand"] extends true ? BrandedValue<UpdateType<Column>, `${TableName}.${ColumnName}`> : UpdateType<Column>, ColumnStateOf<Column>["dbType"], IsNullable<Column>, HasDefault<Column>, IsGenerated<Column>, IsPrimaryKey<Column>, IsUnique<Column>, ReferencesOf<Column>, TableName, ColumnName, BaseTableName>;
190
+ export {};
@@ -2,7 +2,7 @@ import type * as Brand from "effect/Brand"
2
2
  import { pipeArguments, type Pipeable } from "effect/Pipeable"
3
3
  import * as Schema from "effect/Schema"
4
4
 
5
- import * as Expression from "./expression.js"
5
+ import * as Expression from "./scalar.js"
6
6
  import * as ExpressionAst from "./expression-ast.js"
7
7
  import type * as SchemaExpression from "./schema-expression.js"
8
8
 
@@ -34,6 +34,8 @@ export interface ColumnIndexOptions {
34
34
  readonly predicate?: DdlExpression
35
35
  readonly order?: "asc" | "desc"
36
36
  readonly nulls?: "first" | "last"
37
+ readonly operatorClass?: string
38
+ readonly collation?: string
37
39
  }
38
40
 
39
41
  /** Inline single-column unique-constraint metadata. */
@@ -56,8 +58,7 @@ export interface ColumnState<
56
58
  PrimaryKey extends boolean,
57
59
  Unique extends boolean,
58
60
  Ref,
59
- Source = never,
60
- Dependencies extends Expression.SourceDependencies = {}
61
+ Dependencies extends Expression.BindingId = never
61
62
  > {
62
63
  readonly select: Select
63
64
  readonly insert: Insert
@@ -75,6 +76,7 @@ export interface ColumnState<
75
76
  readonly defaultValue?: DdlExpression
76
77
  readonly generatedValue?: DdlExpression
77
78
  readonly ddlType?: string
79
+ readonly driverValueMapping?: Expression.DriverValueMapping
78
80
  readonly identity?: {
79
81
  readonly generation: "always" | "byDefault"
80
82
  }
@@ -83,8 +85,7 @@ export interface ColumnState<
83
85
  readonly schemaName?: string
84
86
  readonly values: readonly [string, ...string[]]
85
87
  }
86
- readonly source: Source
87
- readonly dependencies: Dependencies
88
+ readonly dependencies?: Dependencies
88
89
  }
89
90
 
90
91
  /** Unbound column definition produced by the `Column` DSL. */
@@ -99,15 +100,13 @@ export interface ColumnDefinition<
99
100
  PrimaryKey extends boolean,
100
101
  Unique extends boolean,
101
102
  Ref,
102
- Source = never,
103
- Dependencies extends Expression.SourceDependencies = {}
104
- > extends Pipeable, Expression.Expression<
103
+ Dependencies extends Expression.BindingId = never
104
+ > extends Pipeable, Expression.Scalar<
105
105
  Select,
106
106
  Db,
107
107
  Nullable extends true ? "maybe" : "never",
108
108
  Db["dialect"],
109
109
  "scalar",
110
- Source,
111
110
  Dependencies
112
111
  > {
113
112
  readonly pipe: Pipeable["pipe"]
@@ -122,7 +121,6 @@ export interface ColumnDefinition<
122
121
  PrimaryKey,
123
122
  Unique,
124
123
  Ref,
125
- Source,
126
124
  Dependencies
127
125
  >
128
126
  readonly schema: Schema.Schema<NonNullable<Select>, any, any>
@@ -140,6 +138,7 @@ export interface ColumnDefinition<
140
138
  readonly defaultValue?: DdlExpression
141
139
  readonly generatedValue?: DdlExpression
142
140
  readonly ddlType?: string
141
+ readonly driverValueMapping?: Expression.DriverValueMapping
143
142
  readonly identity?: {
144
143
  readonly generation: "always" | "byDefault"
145
144
  }
@@ -161,11 +160,11 @@ export interface BoundColumn<
161
160
  HasDefault extends boolean,
162
161
  Generated extends boolean,
163
162
  PrimaryKey extends boolean,
164
- Unique extends boolean,
165
- Ref,
166
- TableName extends string,
167
- ColumnName extends string,
168
- BaseTableName extends string = TableName
163
+ Unique extends boolean,
164
+ Ref,
165
+ TableName extends string,
166
+ ColumnName extends string,
167
+ BaseTableName extends string = TableName
169
168
  > extends ColumnDefinition<
170
169
  Select,
171
170
  Insert,
@@ -177,8 +176,7 @@ export interface BoundColumn<
177
176
  PrimaryKey,
178
177
  Unique,
179
178
  Ref,
180
- Expression.ColumnSource<TableName, ColumnName, BaseTableName>,
181
- Record<TableName, true>
179
+ TableName
182
180
  > {
183
181
  readonly [BoundColumnTypeId]: {
184
182
  readonly tableName: TableName
@@ -192,9 +190,7 @@ export interface BoundColumn<
192
190
  Nullable extends true ? "maybe" : "never",
193
191
  Db["dialect"],
194
192
  "scalar",
195
- Expression.ColumnSource<TableName, ColumnName, BaseTableName>,
196
- Record<TableName, true>,
197
- "propagate"
193
+ TableName
198
194
  >
199
195
  readonly [ExpressionAst.TypeId]: ExpressionAst.ColumnNode<TableName, ColumnName>
200
196
  }
@@ -226,6 +222,7 @@ export type AnyBoundColumn = BoundColumn<
226
222
  boolean,
227
223
  any,
228
224
  string,
225
+ string,
229
226
  string
230
227
  >
231
228
 
@@ -235,6 +232,17 @@ const ColumnProto = {
235
232
  }
236
233
  }
237
234
 
235
+ const attachPipe = <Value extends object>(value: Value): Value => {
236
+ Object.defineProperty(value, "pipe", {
237
+ configurable: true,
238
+ writable: true,
239
+ value: function(this: unknown) {
240
+ return pipeArguments(value, arguments)
241
+ }
242
+ })
243
+ return value
244
+ }
245
+
238
246
  /** Constructs a runtime column-definition object from schema and metadata. */
239
247
  export const makeColumnDefinition = <
240
248
  Select,
@@ -247,8 +255,7 @@ export const makeColumnDefinition = <
247
255
  PrimaryKey extends boolean,
248
256
  Unique extends boolean,
249
257
  Ref,
250
- Source = never,
251
- Dependencies extends Expression.SourceDependencies = {}
258
+ Dependencies extends Expression.BindingId = never
252
259
  >(
253
260
  schema: Schema.Schema<NonNullable<Select>, any, any>,
254
261
  metadata: ColumnDefinition<
@@ -262,7 +269,6 @@ export const makeColumnDefinition = <
262
269
  PrimaryKey,
263
270
  Unique,
264
271
  Ref,
265
- Source,
266
272
  Dependencies
267
273
  >["metadata"]
268
274
  ): ColumnDefinition<
@@ -276,22 +282,20 @@ export const makeColumnDefinition = <
276
282
  PrimaryKey,
277
283
  Unique,
278
284
  Ref,
279
- Source,
280
285
  Dependencies
281
286
  > => {
282
- const column = Object.create(ColumnProto)
287
+ const column = attachPipe(Object.create(ColumnProto))
283
288
  column.schema = schema
284
289
  column.metadata = metadata
285
290
  column[Expression.TypeId] = {
286
291
  runtime: undefined as Select,
287
292
  dbType: metadata.dbType,
288
293
  runtimeSchema: schema,
294
+ driverValueMapping: metadata.driverValueMapping,
289
295
  nullability: (metadata.nullable ? "maybe" : "never") as Nullable extends true ? "maybe" : "never",
290
296
  dialect: metadata.dbType.dialect,
291
- aggregation: "scalar",
292
- source: undefined as Source,
293
- sourceNullability: "propagate" as const,
294
- dependencies: {} as Dependencies
297
+ kind: "scalar",
298
+ dependencies: {}
295
299
  }
296
300
  column[ColumnTypeId] = {
297
301
  select: undefined as Select,
@@ -307,10 +311,9 @@ export const makeColumnDefinition = <
307
311
  defaultValue: metadata.defaultValue,
308
312
  generatedValue: metadata.generatedValue,
309
313
  ddlType: metadata.ddlType,
314
+ driverValueMapping: metadata.driverValueMapping,
310
315
  identity: metadata.identity,
311
- enum: metadata.enum,
312
- source: undefined as Source,
313
- dependencies: {} as Dependencies
316
+ enum: metadata.enum
314
317
  }
315
318
  return column
316
319
  }
@@ -326,8 +329,7 @@ export const remapColumnDefinition = <
326
329
  PrimaryKey extends boolean,
327
330
  Unique extends boolean,
328
331
  Ref,
329
- Source = never,
330
- Dependencies extends Expression.SourceDependencies = {}
332
+ Dependencies extends Expression.BindingId = never
331
333
  >(
332
334
  column: ColumnDefinition<
333
335
  Select,
@@ -340,7 +342,6 @@ export const remapColumnDefinition = <
340
342
  PrimaryKey,
341
343
  Unique,
342
344
  Ref,
343
- Source,
344
345
  Dependencies
345
346
  >,
346
347
  options: {
@@ -356,7 +357,6 @@ export const remapColumnDefinition = <
356
357
  PrimaryKey,
357
358
  Unique,
358
359
  Ref,
359
- Source,
360
360
  Dependencies
361
361
  >["metadata"]
362
362
  } = {}
@@ -371,12 +371,11 @@ export const remapColumnDefinition = <
371
371
  PrimaryKey,
372
372
  Unique,
373
373
  Ref,
374
- Source,
375
374
  Dependencies
376
375
  > => {
377
376
  const schema = options.schema ?? column.schema
378
377
  const metadata = options.metadata ?? column.metadata
379
- const next = Object.create(ColumnProto)
378
+ const next = attachPipe(Object.create(ColumnProto))
380
379
  next.schema = schema
381
380
  next.metadata = metadata
382
381
  next[Expression.TypeId] = {
@@ -384,6 +383,7 @@ export const remapColumnDefinition = <
384
383
  runtime: undefined as Select,
385
384
  dbType: metadata.dbType,
386
385
  runtimeSchema: schema,
386
+ driverValueMapping: metadata.driverValueMapping,
387
387
  nullability: (metadata.nullable ? "maybe" : "never") as Nullable extends true ? "maybe" : "never",
388
388
  dialect: metadata.dbType.dialect
389
389
  }
@@ -402,6 +402,7 @@ export const remapColumnDefinition = <
402
402
  defaultValue: metadata.defaultValue,
403
403
  generatedValue: metadata.generatedValue,
404
404
  ddlType: metadata.ddlType,
405
+ driverValueMapping: metadata.driverValueMapping,
405
406
  identity: metadata.identity,
406
407
  enum: metadata.enum
407
408
  }
@@ -441,25 +442,20 @@ export const bindColumn = <
441
442
  const schema = column.metadata.brand === true
442
443
  ? Schema.brand(brandName)(column.schema)
443
444
  : column.schema
444
- const bound = Object.create(ColumnProto)
445
+ const bound = attachPipe(Object.create(ColumnProto))
445
446
  bound.schema = schema
446
447
  bound.metadata = column.metadata
447
448
  bound[Expression.TypeId] = {
448
449
  runtime: undefined as SelectType<Column>,
449
450
  dbType: column.metadata.dbType,
450
451
  runtimeSchema: schema,
452
+ driverValueMapping: column.metadata.driverValueMapping,
451
453
  nullability: (column.metadata.nullable ? "maybe" : "never") as IsNullable<Column> extends true ? "maybe" : "never",
452
454
  dialect: column.metadata.dbType.dialect,
453
- aggregation: "scalar",
454
- source: {
455
- tableName,
456
- columnName,
457
- baseTableName
458
- },
459
- sourceNullability: "propagate" as const,
455
+ kind: "scalar",
460
456
  dependencies: {
461
457
  [tableName]: true
462
- } as Record<TableName, true>
458
+ }
463
459
  }
464
460
  bound[ExpressionAst.TypeId] = {
465
461
  kind: "column",