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,14 +1,14 @@
1
1
  import { pipeArguments } from "effect/Pipeable"
2
2
  import * as Schema from "effect/Schema"
3
3
 
4
- import { mysqlDatatypes } from "../mysql/datatypes/index.js"
5
-
6
- import * as Expression from "./expression.js"
7
- import * as Plan from "./plan.js"
8
- import * as Table from "./table.js"
9
- import type { CastTargetError, OperandCompatibilityError } from "./coercion-errors.js"
10
- import type { RuntimeOfDbType } from "./coercion-analysis.js"
11
- import type { CanCastDbType, CanCompareDbTypes, CanContainDbTypes, CanTextuallyCoerceDbType } from "./coercion-rules.js"
4
+ import { mysqlDatatypes } from "../datatypes/index.js"
5
+
6
+ import * as Expression from "../../internal/scalar.js"
7
+ import * as Plan from "../../internal/row-set.js"
8
+ import * as Table from "../../internal/table.js"
9
+ import type { CastTargetError, OperandCompatibilityError } from "../../internal/coercion/errors.js"
10
+ import type { RuntimeOfDbType } from "../../internal/coercion/analysis.js"
11
+ import type { CanCastDbType, CanCompareDbTypes, CanContainDbTypes, CanTextuallyCoerceDbType } from "../../internal/coercion/rules.js"
12
12
  import {
13
13
  currentRequiredList,
14
14
  extractRequiredRuntime,
@@ -21,15 +21,12 @@ import {
21
21
  mergeAggregationRuntime,
22
22
  mergeDependencies,
23
23
  mergeManyDependencies,
24
- mergeManySources,
25
24
  mergeNullabilityManyRuntime,
26
- mergeSources,
27
25
  type AddAvailable,
28
26
  type AddAvailableMany,
29
27
  type AvailableAfterJoin,
30
28
  type AddExpressionRequired,
31
29
  type AddJoinRequired,
32
- type AggregationOf,
33
30
  type AssumptionsOfPlan,
34
31
  type AvailableOfPlan,
35
32
  type CapabilitiesOfPlan,
@@ -58,6 +55,7 @@ import {
58
55
  type PlanDialectOf,
59
56
  type PresenceWitnessKeysOfSource,
60
57
  type PredicateInput,
58
+ type KindOf,
61
59
  type QueryPlan,
62
60
  type OutputOfSelection,
63
61
  type ScalarOutputOfPlan,
@@ -80,7 +78,6 @@ import {
80
78
  type MergeCapabilities,
81
79
  type MutationTargetInput,
82
80
  type MutationValuesInput,
83
- type SourceOf,
84
81
  type SourceDialectOf,
85
82
  type SourceLike,
86
83
  type SourceNameOf,
@@ -89,6 +86,7 @@ import {
89
86
  type ValuesInput,
90
87
  type AnyValuesSource,
91
88
  type AnyUnnestSource,
89
+ type AnyTableFunctionSource,
92
90
  type UnnestSource,
93
91
  type TableFunctionSource,
94
92
  type StringExpressionInput,
@@ -98,14 +96,13 @@ import {
98
96
  type MutationTargetTuple,
99
97
  type TupleDependencies,
100
98
  type TupleDialect,
101
- type TupleSource,
102
99
  type ResultRow
103
- } from "./query.js"
104
- import * as ExpressionAst from "./expression-ast.js"
105
- import { presenceWitnessesOfSourceLike } from "./implication-runtime.js"
106
- import type { JsonNode } from "./json/ast.js"
107
- import type { JsonPathUsageError } from "./json/errors.js"
108
- import * as JsonPath from "./json/path.js"
100
+ } from "../../internal/query.js"
101
+ import * as ExpressionAst from "../../internal/expression-ast.js"
102
+ import { presenceWitnessesOfSourceLike } from "../../internal/implication-runtime.js"
103
+ import type { JsonNode } from "../../internal/json/ast.js"
104
+ import type { JsonPathUsageError } from "../../internal/json/errors.js"
105
+ import * as JsonPath from "../../internal/json/path.js"
109
106
  import type {
110
107
  JsonConcatResult,
111
108
  JsonDeleteAtPath,
@@ -119,16 +116,20 @@ import type {
119
116
  JsonTypeName,
120
117
  JsonValueAtPath,
121
118
  NormalizeJsonLiteral
122
- } from "./json/types.js"
123
- import type { AssumeTrue } from "./predicate-analysis.js"
124
- import type { FormulaOfPredicate } from "./predicate-normalize.js"
125
- import type { TrueFormula } from "./predicate-formula.js"
126
- import { assumeFormulaTrue, formulaOfExpression as formulaOfExpressionRuntime, trueFormula } from "./predicate-runtime.js"
127
- import { dedupeGroupedExpressions } from "./grouping-key.js"
128
- import { makeCteSource, makeDerivedSource, makeLateralSource } from "./derived-table.js"
129
- import * as ProjectionAlias from "./projection-alias.js"
130
- import * as QueryAst from "./query-ast.js"
131
- import { normalizeColumnList } from "./table-options.js"
119
+ } from "../../internal/json/types.js"
120
+ import type { AssumeTrue } from "../../internal/predicate/analysis.js"
121
+ import type { FormulaOfPredicate } from "../../internal/predicate/normalize.js"
122
+ import type { TrueFormula } from "../../internal/predicate/formula.js"
123
+ import { assumeFormulaTrue, formulaOfExpression as formulaOfExpressionRuntime, trueFormula } from "../../internal/predicate/runtime.js"
124
+ import { dedupeGroupedExpressions } from "../../internal/grouping-key.js"
125
+ import { makeDslMutationRuntime } from "../../internal/dsl-mutation-runtime.js"
126
+ import { makeDslPlanRuntime } from "../../internal/dsl-plan-runtime.js"
127
+ import { makeDslQueryRuntime } from "../../internal/dsl-query-runtime.js"
128
+ import { makeDslTransactionDdlRuntime } from "../../internal/dsl-transaction-ddl-runtime.js"
129
+ import { makeCteSource, makeDerivedSource, makeLateralSource } from "../../internal/derived-table.js"
130
+ import * as ProjectionAlias from "../../internal/projection-alias.js"
131
+ import * as QueryAst from "../../internal/query-ast.js"
132
+ import { normalizeColumnList } from "../../internal/table-options.js"
132
133
 
133
134
  /**
134
135
  * Dialect-specific DB type profile used to specialize the shared query
@@ -190,7 +191,7 @@ type DialectLiteralExpression<
190
191
  BoolDb extends Expression.DbType.Any,
191
192
  TimestampDb extends Expression.DbType.Any,
192
193
  NullDb extends Expression.DbType.Any
193
- > = Expression.Expression<
194
+ > = Expression.Scalar<
194
195
  DialectLiteralRuntime<Value, TimestampDb>,
195
196
  DialectLiteralDbType<Value, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
196
197
  LiteralNullability<Value>,
@@ -325,15 +326,13 @@ type CastResult<
325
326
  BoolDb extends Expression.DbType.Any,
326
327
  TimestampDb extends Expression.DbType.Any,
327
328
  NullDb extends Expression.DbType.Any
328
- > = Expression.Expression<
329
+ > = Expression.Scalar<
329
330
  RuntimeOfDbType<Target>,
330
331
  Target,
331
332
  Expression.NullabilityOf<DialectAsExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
332
333
  Dialect,
333
- AggregationOf<DialectAsExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
334
- SourceOfDialectInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
335
- DependenciesOfDialectInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
336
- Expression.SourceNullabilityOf<DialectAsExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>
334
+ KindOf<DialectAsExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
335
+ DependenciesOfDialectInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
337
336
  > & {
338
337
  readonly [ExpressionAst.TypeId]: ExpressionAst.CastNode<
339
338
  DialectAsExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
@@ -370,17 +369,39 @@ type ComparableGuard<
370
369
  TimestampDb extends Expression.DbType.Any,
371
370
  NullDb extends Expression.DbType.Any,
372
371
  Operator extends string
373
- > = CanCompareDbTypes<
374
- DialectDbTypeOfInput<Left, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
375
- DialectDbTypeOfInput<Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
376
- Dialect
377
- > extends true ? true : OperandCompatibilityError<
378
- Operator,
379
- DialectDbTypeOfInput<Left, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
380
- DialectDbTypeOfInput<Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
372
+ > = 0 extends (1 & Left)
373
+ ? true
374
+ : 0 extends (1 & Right)
375
+ ? true
376
+ : DialectDbTypeOfInput<
377
+ Left,
381
378
  Dialect,
382
- "the same db type family"
383
- >
379
+ TextDb,
380
+ NumericDb,
381
+ BoolDb,
382
+ TimestampDb,
383
+ NullDb
384
+ > extends infer LeftDb extends Expression.DbType.Any
385
+ ? DialectDbTypeOfInput<
386
+ Right,
387
+ Dialect,
388
+ TextDb,
389
+ NumericDb,
390
+ BoolDb,
391
+ TimestampDb,
392
+ NullDb
393
+ > extends infer RightDb extends Expression.DbType.Any
394
+ ? CanCompareDbTypes<LeftDb, RightDb, Dialect> extends true
395
+ ? true
396
+ : OperandCompatibilityError<
397
+ Operator,
398
+ LeftDb,
399
+ RightDb,
400
+ Dialect,
401
+ "the same db type family"
402
+ >
403
+ : never
404
+ : never
384
405
 
385
406
  type TextGuard<
386
407
  Value extends ExpressionInput,
@@ -465,9 +486,10 @@ type ComparableArgs<
465
486
  TimestampDb extends Expression.DbType.Any,
466
487
  NullDb extends Expression.DbType.Any,
467
488
  Operator extends string
468
- > = ComparableGuard<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, Operator> extends true
469
- ? readonly [left: Left, right: Right]
470
- : readonly [ComparableGuard<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, Operator>]
489
+ > = readonly [
490
+ left: Left,
491
+ right: Right & ComparableInput<NoInfer<Left>, NoInfer<Right>, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, Operator>
492
+ ]
471
493
 
472
494
  type ContainmentGuard<
473
495
  Left extends ExpressionInput,
@@ -515,11 +537,10 @@ type TextArgs<
515
537
  TimestampDb extends Expression.DbType.Any,
516
538
  NullDb extends Expression.DbType.Any,
517
539
  Operator extends string
518
- > = TextGuard<Left, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, Operator> extends true
519
- ? TextGuard<Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, Operator> extends true
520
- ? readonly [left: Left, right: Right]
521
- : readonly [TextGuard<Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, Operator>]
522
- : readonly [TextGuard<Left, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, Operator>]
540
+ > = readonly [
541
+ left: Left & TextInput<NoInfer<Left>, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, Operator>,
542
+ right: Right & TextInput<NoInfer<Right>, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, Operator>
543
+ ]
523
544
 
524
545
  type MembershipArgs<
525
546
  Values extends readonly [ExpressionInput, ExpressionInput, ...ExpressionInput[]],
@@ -590,17 +611,6 @@ type BetweenArgs<
590
611
  "between"
591
612
  >]
592
613
 
593
- /** Provenance carried by a dialect-specialized scalar input. */
594
- type SourceOfDialectInput<
595
- Value extends ExpressionInput,
596
- Dialect extends string,
597
- TextDb extends Expression.DbType.Any,
598
- NumericDb extends Expression.DbType.Any,
599
- BoolDb extends Expression.DbType.Any,
600
- TimestampDb extends Expression.DbType.Any,
601
- NullDb extends Expression.DbType.Any
602
- > = SourceOf<DialectAsExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>
603
-
604
614
  /** Dialect carried by a dialect-specialized scalar input. */
605
615
  type DialectOfDialectInput<
606
616
  Value extends ExpressionInput,
@@ -634,17 +644,6 @@ type RequiredFromDialectInput<
634
644
  NullDb extends Expression.DbType.Any
635
645
  > = RequiredFromDependencies<DependenciesOfDialectInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>
636
646
 
637
- /** Provenance carried by a dialect-specialized string input. */
638
- type SourceOfDialectStringInput<
639
- Value extends ExpressionInput,
640
- Dialect extends string,
641
- TextDb extends Expression.DbType.Any,
642
- NumericDb extends Expression.DbType.Any,
643
- BoolDb extends Expression.DbType.Any,
644
- TimestampDb extends Expression.DbType.Any,
645
- NullDb extends Expression.DbType.Any
646
- > = SourceOf<DialectAsStringExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>
647
-
648
647
  /** Dialect carried by a dialect-specialized string input. */
649
648
  type DialectOfDialectStringInput<
650
649
  Value extends ExpressionInput,
@@ -714,9 +713,9 @@ type RequiredFromDialectNumericInput<
714
713
  /** Folds aggregation kinds across a tuple of expressions. */
715
714
  type MergeAggregationTuple<
716
715
  Values extends readonly Expression.Any[],
717
- Current extends Expression.AggregationKind = "scalar"
716
+ Current extends Expression.ScalarKind = "scalar"
718
717
  > = Values extends readonly [infer Head extends Expression.Any, ...infer Tail extends readonly Expression.Any[]]
719
- ? MergeAggregationTuple<Tail, MergeAggregation<Current, AggregationOf<Head>>>
718
+ ? MergeAggregationTuple<Tail, MergeAggregation<Current, KindOf<Head>>>
720
719
  : Current
721
720
 
722
721
  /** Result nullability for binary `coalesce(...)`. */
@@ -836,20 +835,16 @@ type AstBackedExpression<
836
835
  Db extends Expression.DbType.Any,
837
836
  Nullable extends Expression.Nullability,
838
837
  Dialect extends string,
839
- Aggregation extends Expression.AggregationKind,
840
- Source,
841
- Dependencies extends Expression.SourceDependencies,
842
- Ast extends ExpressionAst.Any,
843
- SourceNullability extends Expression.SourceNullabilityMode = "propagate"
844
- > = Expression.Expression<
838
+ Aggregation extends Expression.ScalarKind,
839
+ Dependencies extends Expression.BindingId,
840
+ Ast extends ExpressionAst.Any
841
+ > = Expression.Scalar<
845
842
  Runtime,
846
843
  Db,
847
844
  Nullable,
848
845
  Dialect,
849
846
  Aggregation,
850
- Source,
851
- Dependencies,
852
- SourceNullability
847
+ Dependencies
853
848
  > & {
854
849
  readonly [ExpressionAst.TypeId]: Ast
855
850
  }
@@ -882,8 +877,7 @@ type VariadicBooleanExpression<
882
877
  BoolDb,
883
878
  MergeNullabilityTuple<Values>,
884
879
  TupleDialect<Values>,
885
- MergeAggregationTuple<Values>,
886
- TupleSource<Values>,
880
+ "scalar",
887
881
  TupleDependencies<Values>,
888
882
  ExpressionAst.VariadicNode<Kind, Values>
889
883
  > & {
@@ -915,32 +909,26 @@ type JsonExpression<
915
909
  Db extends Expression.DbType.Any,
916
910
  Nullability extends Expression.Nullability,
917
911
  Dialect extends string,
918
- Aggregation extends Expression.AggregationKind,
919
- Source,
920
- Dependencies extends Expression.SourceDependencies,
921
- Ast extends ExpressionAst.Any,
922
- SourceNullability extends Expression.SourceNullabilityMode = "propagate"
912
+ Aggregation extends Expression.ScalarKind,
913
+ Dependencies extends Expression.BindingId,
914
+ Ast extends ExpressionAst.Any
923
915
  > = AstBackedExpression<
924
916
  Runtime,
925
917
  Db,
926
918
  Nullability,
927
919
  Dialect,
928
920
  Aggregation,
929
- Source,
930
921
  Dependencies,
931
- Ast,
932
- SourceNullability
922
+ Ast
933
923
  >
934
924
 
935
- type JsonExpressionLike<Runtime = unknown> = Expression.Expression<
925
+ type JsonExpressionLike<Runtime = unknown> = Expression.Scalar<
936
926
  Runtime,
937
927
  Expression.DbType.Json<any, any>,
938
928
  Expression.Nullability,
939
929
  string,
940
- Expression.AggregationKind,
941
- any,
942
- Expression.SourceDependencies,
943
- Expression.SourceNullabilityMode
930
+ Expression.ScalarKind,
931
+ Expression.BindingId
944
932
  >
945
933
 
946
934
  type JsonDbOfExpression<Value extends JsonExpressionLike<any>> = Expression.DbTypeOf<Value>
@@ -1100,8 +1088,8 @@ type CaseResultTupleWithElse<
1100
1088
  > = [...CaseResultTuple<Branches>, Else]
1101
1089
 
1102
1090
  type MergeAggregationUnion<Value extends Expression.Any> =
1103
- Extract<AggregationOf<Value>, "window"> extends never
1104
- ? Extract<AggregationOf<Value>, "aggregate"> extends never ? "scalar" : "aggregate"
1091
+ Extract<KindOf<Value>, "window"> extends never
1092
+ ? Extract<KindOf<Value>, "aggregate"> extends never ? "scalar" : "aggregate"
1105
1093
  : "window"
1106
1094
 
1107
1095
  type CaseNullabilityOfUnion<Value extends Expression.Any> =
@@ -1149,10 +1137,8 @@ type CaseBuilder<
1149
1137
  CaseNullabilityOfUnion<CaseResultTupleWithElse<Branches, DialectAsExpression<Else, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>[number]>,
1150
1138
  TupleDialect<CaseAllTuple<Branches, DialectAsExpression<Else, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>>,
1151
1139
  MergeAggregationTuple<CaseAllTuple<Branches, DialectAsExpression<Else, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>>,
1152
- TupleSource<CaseAllTuple<Branches, DialectAsExpression<Else, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>>,
1153
1140
  TupleDependencies<CaseAllTuple<Branches, DialectAsExpression<Else, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>>,
1154
- ExpressionAst.CaseNode<CaseAstBranches<Branches>, DialectAsExpression<Else, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
1155
- "resolved"
1141
+ ExpressionAst.CaseNode<CaseAstBranches<Branches>, DialectAsExpression<Else, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>
1156
1142
  >
1157
1143
  }
1158
1144
 
@@ -1167,7 +1153,7 @@ type MatchBuilder<
1167
1153
  NullDb extends Expression.DbType.Any
1168
1154
  > = {
1169
1155
  when<Compare extends ExpressionInput, Then extends ExpressionInput>(
1170
- compare: Compare & ComparableInput<Subject, Compare, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "match">,
1156
+ compare: Compare & ComparableInput<NoInfer<Subject>, NoInfer<Compare>, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "match">,
1171
1157
  result: Then
1172
1158
  ): MatchBuilder<
1173
1159
  Subject,
@@ -1190,10 +1176,8 @@ type MatchBuilder<
1190
1176
  CaseNullabilityOfUnion<CaseResultTupleWithElse<Branches, DialectAsExpression<Else, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>[number]>,
1191
1177
  TupleDialect<CaseAllTuple<Branches, DialectAsExpression<Else, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>>,
1192
1178
  MergeAggregationTuple<CaseAllTuple<Branches, DialectAsExpression<Else, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>>,
1193
- TupleSource<CaseAllTuple<Branches, DialectAsExpression<Else, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>>,
1194
1179
  TupleDependencies<CaseAllTuple<Branches, DialectAsExpression<Else, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>>,
1195
- ExpressionAst.CaseNode<CaseAstBranches<Branches>, DialectAsExpression<Else, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
1196
- "resolved"
1180
+ ExpressionAst.CaseNode<CaseAstBranches<Branches>, DialectAsExpression<Else, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>
1197
1181
  >
1198
1182
  }
1199
1183
 
@@ -1232,7 +1216,7 @@ type MatchStarter<
1232
1216
  NullDb extends Expression.DbType.Any
1233
1217
  > = {
1234
1218
  when<Compare extends ExpressionInput, Then extends ExpressionInput>(
1235
- compare: Compare & ComparableInput<Subject, Compare, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "match">,
1219
+ compare: Compare & ComparableInput<NoInfer<Subject>, NoInfer<Compare>, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "match">,
1236
1220
  result: Then
1237
1221
  ): MatchBuilder<
1238
1222
  Subject,
@@ -1249,15 +1233,13 @@ type MatchStarter<
1249
1233
  >
1250
1234
  }
1251
1235
 
1252
- type WindowPartitionInput = Expression.Expression<
1236
+ type WindowPartitionInput = Expression.Scalar<
1253
1237
  any,
1254
1238
  Expression.DbType.Any,
1255
1239
  Expression.Nullability,
1256
1240
  string,
1257
1241
  "scalar",
1258
- any,
1259
- Expression.SourceDependencies,
1260
- Expression.SourceNullabilityMode
1242
+ Expression.BindingId
1261
1243
  >
1262
1244
 
1263
1245
  type WindowOrderInput = WindowPartitionInput
@@ -1316,12 +1298,6 @@ type WindowDialectOf<
1316
1298
  OrderBy extends readonly WindowOrderTermInput[]
1317
1299
  > = DialectOf<Value> | TupleDialect<PartitionBy> | TupleDialect<WindowOrderExpressionTuple<OrderBy>>
1318
1300
 
1319
- type WindowSourceOf<
1320
- Value extends Expression.Any,
1321
- PartitionBy extends readonly WindowPartitionInput[],
1322
- OrderBy extends readonly WindowOrderTermInput[]
1323
- > = SourceOf<Value> | TupleSource<PartitionBy> | TupleSource<WindowOrderExpressionTuple<OrderBy>>
1324
-
1325
1301
  type WindowDependenciesOf<
1326
1302
  Value extends Expression.Any,
1327
1303
  PartitionBy extends readonly WindowPartitionInput[],
@@ -1337,11 +1313,6 @@ type NumberWindowDialectOf<
1337
1313
  OrderBy extends readonly WindowOrderTermInput[]
1338
1314
  > = TupleDialect<PartitionBy> | TupleDialect<WindowOrderExpressionTuple<OrderBy>>
1339
1315
 
1340
- type NumberWindowSourceOf<
1341
- PartitionBy extends readonly WindowPartitionInput[],
1342
- OrderBy extends readonly WindowOrderTermInput[]
1343
- > = TupleSource<PartitionBy> | TupleSource<WindowOrderExpressionTuple<OrderBy>>
1344
-
1345
1316
  type NumberWindowDependenciesOf<
1346
1317
  PartitionBy extends readonly WindowPartitionInput[],
1347
1318
  OrderBy extends readonly WindowOrderTermInput[]
@@ -1360,10 +1331,8 @@ type WindowedExpression<
1360
1331
  Expression.NullabilityOf<Value>,
1361
1332
  WindowDialectOf<Value, PartitionBy, OrderBy>,
1362
1333
  "window",
1363
- WindowSourceOf<Value, PartitionBy, OrderBy>,
1364
1334
  WindowDependenciesOf<Value, PartitionBy, OrderBy>,
1365
- WindowNodeOf<"over", Value, PartitionBy, OrderBy>,
1366
- "resolved"
1335
+ WindowNodeOf<"over", Value, PartitionBy, OrderBy>
1367
1336
  >
1368
1337
 
1369
1338
  type NumberWindowExpression<
@@ -1376,10 +1345,8 @@ type NumberWindowExpression<
1376
1345
  "never",
1377
1346
  NumberWindowDialectOf<PartitionBy, OrderBy>,
1378
1347
  "window",
1379
- NumberWindowSourceOf<PartitionBy, OrderBy>,
1380
1348
  NumberWindowDependenciesOf<PartitionBy, OrderBy>,
1381
- WindowNodeOf<Kind, undefined, PartitionBy, OrderBy>,
1382
- "resolved"
1349
+ WindowNodeOf<Kind, undefined, PartitionBy, OrderBy>
1383
1350
  >
1384
1351
 
1385
1352
  /**
@@ -1389,22 +1356,33 @@ type NumberWindowExpression<
1389
1356
  * that manufacture new expressions are specialized to the supplied dialect DB
1390
1357
  * types instead of relying on the Postgres-default root module.
1391
1358
  */
1392
- export const mysqlQuery = (() => {
1393
1359
  type Dialect = "mysql"
1394
- type TextDb = Expression.DbType.MySqlText
1395
- type NumericDb = Expression.DbType.MySqlDouble
1396
- type BoolDb = Expression.DbType.MySqlBool
1397
- type TimestampDb = Expression.DbType.MySqlTimestamp
1398
- type NullDb = Expression.DbType.Base<"mysql", "null">
1360
+ type TextDb = ReturnType<typeof mysqlDatatypes.text>
1361
+ type NumericDb = ReturnType<typeof mysqlDatatypes.double>
1362
+ type BoolDb = ReturnType<typeof mysqlDatatypes.boolean>
1363
+ type TimestampDb = ReturnType<typeof mysqlDatatypes.timestamp>
1364
+ type NullDb = Expression.DbType.Base<"mysql", "null"> & {
1365
+ readonly family: "null"
1366
+ readonly runtime: "unknown"
1367
+ readonly compareGroup: "null"
1368
+ readonly traits: {}
1369
+ }
1399
1370
  type TypeWitnesses = typeof mysqlDatatypes
1400
1371
 
1401
1372
  const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, TypeWitnesses> = {
1402
1373
  dialect: "mysql",
1403
- textDb: { dialect: "mysql", kind: "text" } as TextDb,
1404
- numericDb: { dialect: "mysql", kind: "double" } as NumericDb,
1405
- boolDb: { dialect: "mysql", kind: "boolean" } as BoolDb,
1406
- timestampDb: { dialect: "mysql", kind: "timestamp" } as TimestampDb,
1407
- nullDb: { dialect: "mysql", kind: "null" } as NullDb,
1374
+ textDb: mysqlDatatypes.text() as TextDb,
1375
+ numericDb: mysqlDatatypes.double() as NumericDb,
1376
+ boolDb: mysqlDatatypes.boolean() as BoolDb,
1377
+ timestampDb: mysqlDatatypes.timestamp() as TimestampDb,
1378
+ nullDb: {
1379
+ dialect: "mysql",
1380
+ kind: "null",
1381
+ family: "null",
1382
+ runtime: "unknown",
1383
+ compareGroup: "null",
1384
+ traits: {}
1385
+ } as NullDb,
1408
1386
  type: mysqlDatatypes
1409
1387
  }
1410
1388
  const ValuesInputProto = {
@@ -1437,9 +1415,8 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
1437
1415
  runtimeSchema: literalSchemaOf(value),
1438
1416
  nullability: (value === null ? "always" : "never") as LiteralNullability<Value>,
1439
1417
  dialect: profile.dialect as Dialect,
1440
- aggregation: "scalar",
1441
- source: undefined as never,
1442
- sourceNullability: "propagate" as const,
1418
+ kind: "scalar",
1419
+
1443
1420
  dependencies: {}
1444
1421
  }, {
1445
1422
  kind: "literal",
@@ -1453,15 +1430,13 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
1453
1430
  name: Name,
1454
1431
  dbType: Db,
1455
1432
  nullable = false
1456
- ): Expression.Expression<
1433
+ ): Expression.Scalar<
1457
1434
  Expression.RuntimeOfDbType<Db> | null,
1458
1435
  Db,
1459
1436
  Expression.Nullability,
1460
1437
  Dialect,
1461
1438
  "scalar",
1462
- never,
1463
- {},
1464
- "resolved"
1439
+ never
1465
1440
  > & {
1466
1441
  readonly [ExpressionAst.TypeId]: ExpressionAst.ColumnNode<"", Name>
1467
1442
  } =>
@@ -1470,23 +1445,20 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
1470
1445
  dbType,
1471
1446
  nullability: (nullable ? "maybe" : "never") as typeof nullable extends true ? "maybe" : "never",
1472
1447
  dialect: profile.dialect as Dialect,
1473
- aggregation: "scalar",
1474
- source: undefined as never,
1475
- sourceNullability: "resolved" as const,
1448
+ kind: "scalar",
1449
+
1476
1450
  dependencies: {}
1477
1451
  }, {
1478
1452
  kind: "column",
1479
1453
  tableName: "",
1480
1454
  columnName: name
1481
- }) as Expression.Expression<
1455
+ }) as Expression.Scalar<
1482
1456
  Expression.RuntimeOfDbType<Db> | null,
1483
1457
  Db,
1484
1458
  Expression.Nullability,
1485
1459
  Dialect,
1486
1460
  "scalar",
1487
- never,
1488
- {},
1489
- "resolved"
1461
+ never
1490
1462
  > & {
1491
1463
  readonly [ExpressionAst.TypeId]: ExpressionAst.ColumnNode<"", Name>
1492
1464
  }
@@ -1554,10 +1526,9 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
1554
1526
  dbType: profile.boolDb as BoolDb,
1555
1527
  nullability: mergeNullabilityManyRuntime(expressions) as MergeNullabilityTuple<Values>,
1556
1528
  dialect: (expressions.find((value) => value[Expression.TypeId].dialect !== undefined)?.[Expression.TypeId].dialect ?? profile.dialect) as TupleDialect<Values>,
1557
- aggregation: mergeAggregationManyRuntime(expressions) as MergeAggregationTuple<Values>,
1558
- source: mergeManySources(expressions) as TupleSource<Values>,
1559
- sourceNullability: "propagate" as const,
1560
- dependencies: mergeManyDependencies(expressions) as TupleDependencies<Values>
1529
+ kind: "scalar",
1530
+
1531
+ dependencies: mergeManyDependencies(expressions)
1561
1532
  }, {
1562
1533
  kind,
1563
1534
  values: expressions
@@ -1624,39 +1595,32 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
1624
1595
  return Object.keys(expression[Expression.TypeId].dependencies)
1625
1596
  }
1626
1597
 
1627
- type BinaryPredicateExpression<
1628
- Left extends ExpressionInput,
1629
- Right extends ExpressionInput,
1630
- Kind extends ExpressionAst.BinaryKind,
1631
- Nullability extends Expression.Nullability = "maybe",
1632
- SourceNullability extends Expression.SourceNullabilityMode = "propagate"
1633
- > = AstBackedExpression<
1634
- boolean,
1635
- BoolDb,
1636
- Nullability,
1637
- DialectOfDialectInput<Left, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> | DialectOfDialectInput<Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
1638
- MergeAggregation<
1639
- AggregationOf<DialectAsExpression<Left, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
1640
- AggregationOf<DialectAsExpression<Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>
1641
- >,
1642
- SourceOfDialectInput<Left, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> | SourceOfDialectInput<Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
1643
- DependencyRecord<
1644
- RequiredFromDialectInput<Left, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> |
1645
- RequiredFromDialectInput<Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
1646
- >,
1647
- ExpressionAst.BinaryNode<
1648
- Kind,
1649
- DialectAsExpression<Left, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
1650
- DialectAsExpression<Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
1651
- >,
1652
- SourceNullability
1598
+ type BinaryPredicateExpression<
1599
+ Left extends ExpressionInput,
1600
+ Right extends ExpressionInput,
1601
+ Kind extends ExpressionAst.BinaryKind,
1602
+ Nullability extends Expression.Nullability = "maybe"
1603
+ > = AstBackedExpression<
1604
+ boolean,
1605
+ BoolDb,
1606
+ Nullability,
1607
+ DialectOfDialectInput<Left, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> | DialectOfDialectInput<Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
1608
+ "scalar",
1609
+ DependencyRecord<
1610
+ RequiredFromDialectInput<Left, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> |
1611
+ RequiredFromDialectInput<Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
1612
+ >,
1613
+ ExpressionAst.BinaryNode<
1614
+ Kind,
1615
+ DialectAsExpression<Left, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
1616
+ DialectAsExpression<Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
1653
1617
  >
1618
+ >
1654
1619
 
1655
1620
  type SubqueryPredicateExpression<
1656
1621
  Dialect extends string,
1657
- Aggregation extends Expression.AggregationKind,
1658
- Source,
1659
- Dependencies extends Expression.SourceDependencies,
1622
+ Aggregation extends Expression.ScalarKind,
1623
+ Dependencies extends Expression.BindingId,
1660
1624
  Ast extends ExpressionAst.Any
1661
1625
  > = AstBackedExpression<
1662
1626
  boolean,
@@ -1664,7 +1628,6 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
1664
1628
  "maybe",
1665
1629
  Dialect,
1666
1630
  Aggregation,
1667
- Source,
1668
1631
  Dependencies,
1669
1632
  Ast
1670
1633
  >
@@ -1672,29 +1635,27 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
1672
1635
  type VariadicPredicateExpression<
1673
1636
  Values extends readonly ExpressionInput[],
1674
1637
  Kind extends ExpressionAst.VariadicKind
1675
- > = AstBackedExpression<
1676
- boolean,
1677
- BoolDb,
1678
- "maybe",
1679
- TupleDialect<DialectExpressionTuple<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
1680
- MergeAggregationTuple<DialectExpressionTuple<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
1681
- TupleSource<DialectExpressionTuple<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
1682
- TupleDependencies<DialectExpressionTuple<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
1683
- ExpressionAst.VariadicNode<Kind, DialectExpressionTuple<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>
1684
- >
1638
+ > = AstBackedExpression<
1639
+ boolean,
1640
+ BoolDb,
1641
+ "maybe",
1642
+ TupleDialect<DialectExpressionTuple<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
1643
+ "scalar",
1644
+ TupleDependencies<DialectExpressionTuple<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
1645
+ ExpressionAst.VariadicNode<Kind, DialectExpressionTuple<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>
1646
+ >
1685
1647
 
1686
1648
  const buildBinaryPredicate = <
1687
1649
  Left extends ExpressionInput,
1688
1650
  Right extends ExpressionInput,
1689
1651
  Kind extends ExpressionAst.BinaryKind,
1690
1652
  Nullability extends Expression.Nullability = "maybe",
1691
- SourceNullability extends Expression.SourceNullabilityMode = "propagate"
1653
+ SourceNullability extends string = "propagate"
1692
1654
  >(
1693
1655
  left: Left,
1694
1656
  right: Right,
1695
1657
  kind: Kind,
1696
1658
  nullability: Nullability = "maybe" as Nullability,
1697
- sourceNullability: SourceNullability = "propagate" as SourceNullability
1698
1659
  ): any => {
1699
1660
  const leftExpression = toDialectExpression(left)
1700
1661
  const rightExpression = toDialectExpression(right)
@@ -1703,16 +1664,11 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
1703
1664
  dbType: profile.boolDb as BoolDb,
1704
1665
  nullability,
1705
1666
  dialect: (leftExpression[Expression.TypeId].dialect ?? rightExpression[Expression.TypeId].dialect) as DialectOfDialectInput<Left, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> | DialectOfDialectInput<Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
1706
- aggregation: mergeAggregationRuntime(
1707
- leftExpression[Expression.TypeId].aggregation,
1708
- rightExpression[Expression.TypeId].aggregation
1709
- ) as MergeAggregation<AggregationOf<DialectAsExpression<Left, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>, AggregationOf<DialectAsExpression<Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>>,
1710
- source: mergeSources(leftExpression[Expression.TypeId].source, rightExpression[Expression.TypeId].source) as SourceOfDialectInput<Left, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> | SourceOfDialectInput<Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
1711
- sourceNullability,
1667
+ kind: "scalar",
1712
1668
  dependencies: mergeDependencies(
1713
1669
  leftExpression[Expression.TypeId].dependencies,
1714
1670
  rightExpression[Expression.TypeId].dependencies
1715
- ) as DependencyRecord<RequiredFromDialectInput<Left, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> | RequiredFromDialectInput<Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>
1671
+ )
1716
1672
  } as any, {
1717
1673
  kind,
1718
1674
  left: leftExpression,
@@ -1730,9 +1686,8 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
1730
1686
  dbType: profile.boolDb as BoolDb,
1731
1687
  nullability: "maybe",
1732
1688
  dialect: (expressions.find((value) => value[Expression.TypeId].dialect !== undefined)?.[Expression.TypeId].dialect ?? profile.dialect) as Dialect,
1733
- aggregation: mergeAggregationManyRuntime(expressions) as Expression.AggregationKind,
1734
- source: mergeManySources(expressions),
1735
- sourceNullability: "propagate" as const,
1689
+ kind: "scalar",
1690
+
1736
1691
  dependencies: mergeManyDependencies(expressions)
1737
1692
  }, {
1738
1693
  kind,
@@ -1746,7 +1701,7 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
1746
1701
  >(
1747
1702
  ...args: ComparableArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "eq">
1748
1703
  ): BinaryPredicateExpression<Left, Right, "eq"> => {
1749
- const [left, right] = args as [Left, Right]
1704
+ const [left, right] = args as unknown as [Left, Right]
1750
1705
  return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "eq")
1751
1706
  }
1752
1707
 
@@ -1756,7 +1711,7 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
1756
1711
  >(
1757
1712
  ...args: ComparableArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "neq">
1758
1713
  ): BinaryPredicateExpression<Left, Right, "neq"> => {
1759
- const [left, right] = args as [Left, Right]
1714
+ const [left, right] = args as unknown as [Left, Right]
1760
1715
  return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "neq")
1761
1716
  }
1762
1717
 
@@ -1766,7 +1721,7 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
1766
1721
  >(
1767
1722
  ...args: ComparableArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "lt">
1768
1723
  ): BinaryPredicateExpression<Left, Right, "lt"> => {
1769
- const [left, right] = args as [Left, Right]
1724
+ const [left, right] = args as unknown as [Left, Right]
1770
1725
  return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "lt")
1771
1726
  }
1772
1727
 
@@ -1776,7 +1731,7 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
1776
1731
  >(
1777
1732
  ...args: ComparableArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "lte">
1778
1733
  ): BinaryPredicateExpression<Left, Right, "lte"> => {
1779
- const [left, right] = args as [Left, Right]
1734
+ const [left, right] = args as unknown as [Left, Right]
1780
1735
  return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "lte")
1781
1736
  }
1782
1737
 
@@ -1786,7 +1741,7 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
1786
1741
  >(
1787
1742
  ...args: ComparableArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "gt">
1788
1743
  ): BinaryPredicateExpression<Left, Right, "gt"> => {
1789
- const [left, right] = args as [Left, Right]
1744
+ const [left, right] = args as unknown as [Left, Right]
1790
1745
  return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "gt")
1791
1746
  }
1792
1747
 
@@ -1796,7 +1751,7 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
1796
1751
  >(
1797
1752
  ...args: ComparableArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "gte">
1798
1753
  ): BinaryPredicateExpression<Left, Right, "gte"> => {
1799
- const [left, right] = args as [Left, Right]
1754
+ const [left, right] = args as unknown as [Left, Right]
1800
1755
  return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "gte")
1801
1756
  }
1802
1757
 
@@ -1806,7 +1761,7 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
1806
1761
  >(
1807
1762
  ...args: TextArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "like">
1808
1763
  ): BinaryPredicateExpression<Left, Right, "like"> => {
1809
- const [left, right] = args as [Left, Right]
1764
+ const [left, right] = args as unknown as [Left, Right]
1810
1765
  return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "like")
1811
1766
  }
1812
1767
 
@@ -1816,7 +1771,7 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
1816
1771
  >(
1817
1772
  ...args: TextArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "ilike">
1818
1773
  ): BinaryPredicateExpression<Left, Right, "ilike"> => {
1819
- const [left, right] = args as [Left, Right]
1774
+ const [left, right] = args as unknown as [Left, Right]
1820
1775
  return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "ilike")
1821
1776
  }
1822
1777
 
@@ -1826,7 +1781,7 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
1826
1781
  >(
1827
1782
  ...args: TextArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "regexMatch">
1828
1783
  ): BinaryPredicateExpression<Left, Right, "regexMatch"> => {
1829
- const [left, right] = args as [Left, Right]
1784
+ const [left, right] = args as unknown as [Left, Right]
1830
1785
  return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "regexMatch")
1831
1786
  }
1832
1787
 
@@ -1836,7 +1791,7 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
1836
1791
  >(
1837
1792
  ...args: TextArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "regexIMatch">
1838
1793
  ): BinaryPredicateExpression<Left, Right, "regexIMatch"> => {
1839
- const [left, right] = args as [Left, Right]
1794
+ const [left, right] = args as unknown as [Left, Right]
1840
1795
  return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "regexIMatch")
1841
1796
  }
1842
1797
 
@@ -1846,7 +1801,7 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
1846
1801
  >(
1847
1802
  ...args: TextArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "regexNotMatch">
1848
1803
  ): BinaryPredicateExpression<Left, Right, "regexNotMatch"> => {
1849
- const [left, right] = args as [Left, Right]
1804
+ const [left, right] = args as unknown as [Left, Right]
1850
1805
  return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "regexNotMatch")
1851
1806
  }
1852
1807
 
@@ -1856,7 +1811,7 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
1856
1811
  >(
1857
1812
  ...args: TextArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "regexNotIMatch">
1858
1813
  ): BinaryPredicateExpression<Left, Right, "regexNotIMatch"> => {
1859
- const [left, right] = args as [Left, Right]
1814
+ const [left, right] = args as unknown as [Left, Right]
1860
1815
  return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "regexNotIMatch")
1861
1816
  }
1862
1817
 
@@ -1865,9 +1820,9 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
1865
1820
  Right extends ExpressionInput
1866
1821
  >(
1867
1822
  ...args: ComparableArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "isDistinctFrom">
1868
- ): BinaryPredicateExpression<Left, Right, "isDistinctFrom", "never", "resolved"> => {
1869
- const [left, right] = args as [Left, Right]
1870
- return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "isDistinctFrom", "never", "resolved")
1823
+ ): BinaryPredicateExpression<Left, Right, "isDistinctFrom", "never"> => {
1824
+ const [left, right] = args as unknown as [Left, Right]
1825
+ return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "isDistinctFrom", "never")
1871
1826
  }
1872
1827
 
1873
1828
  const isNotDistinctFrom = <
@@ -1875,9 +1830,9 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
1875
1830
  Right extends ExpressionInput
1876
1831
  >(
1877
1832
  ...args: ComparableArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "isNotDistinctFrom">
1878
- ): BinaryPredicateExpression<Left, Right, "isNotDistinctFrom", "never", "resolved"> => {
1879
- const [left, right] = args as [Left, Right]
1880
- return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "isNotDistinctFrom", "never", "resolved")
1833
+ ): BinaryPredicateExpression<Left, Right, "isNotDistinctFrom", "never"> => {
1834
+ const [left, right] = args as unknown as [Left, Right]
1835
+ return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "isNotDistinctFrom", "never")
1881
1836
  }
1882
1837
 
1883
1838
  const isNull = <Value extends ExpressionInput>(
@@ -1887,11 +1842,9 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
1887
1842
  BoolDb,
1888
1843
  "never",
1889
1844
  DialectOfDialectInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
1890
- AggregationOf<DialectAsExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
1891
- SourceOfDialectInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
1845
+ "scalar",
1892
1846
  DependenciesOfDialectInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
1893
- ExpressionAst.UnaryNode<"isNull", DialectAsExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
1894
- "resolved"
1847
+ ExpressionAst.UnaryNode<"isNull", DialectAsExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>
1895
1848
  > => {
1896
1849
  const expression = toDialectExpression(value)
1897
1850
  return makeExpression({
@@ -1899,10 +1852,9 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
1899
1852
  dbType: profile.boolDb as BoolDb,
1900
1853
  nullability: "never",
1901
1854
  dialect: expression[Expression.TypeId].dialect,
1902
- aggregation: expression[Expression.TypeId].aggregation as AggregationOf<DialectAsExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
1903
- source: expression[Expression.TypeId].source as SourceOfDialectInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
1904
- sourceNullability: "resolved" as const,
1905
- dependencies: expression[Expression.TypeId].dependencies as DependenciesOfDialectInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
1855
+ kind: "scalar",
1856
+
1857
+ dependencies: expression[Expression.TypeId].dependencies
1906
1858
  }, {
1907
1859
  kind: "isNull",
1908
1860
  value: expression
@@ -1916,11 +1868,9 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
1916
1868
  BoolDb,
1917
1869
  "never",
1918
1870
  DialectOfDialectInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
1919
- AggregationOf<DialectAsExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
1920
- SourceOfDialectInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
1871
+ "scalar",
1921
1872
  DependenciesOfDialectInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
1922
- ExpressionAst.UnaryNode<"isNotNull", DialectAsExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
1923
- "resolved"
1873
+ ExpressionAst.UnaryNode<"isNotNull", DialectAsExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>
1924
1874
  > => {
1925
1875
  const expression = toDialectExpression(value)
1926
1876
  return makeExpression({
@@ -1928,10 +1878,9 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
1928
1878
  dbType: profile.boolDb as BoolDb,
1929
1879
  nullability: "never",
1930
1880
  dialect: expression[Expression.TypeId].dialect,
1931
- aggregation: expression[Expression.TypeId].aggregation as AggregationOf<DialectAsExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
1932
- source: expression[Expression.TypeId].source as SourceOfDialectInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
1933
- sourceNullability: "resolved" as const,
1934
- dependencies: expression[Expression.TypeId].dependencies as DependenciesOfDialectInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
1881
+ kind: "scalar",
1882
+
1883
+ dependencies: expression[Expression.TypeId].dependencies
1935
1884
  }, {
1936
1885
  kind: "isNotNull",
1937
1886
  value: expression
@@ -1945,8 +1894,7 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
1945
1894
  TextDb,
1946
1895
  NullabilityOfDialectStringInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
1947
1896
  DialectOfDialectStringInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
1948
- AggregationOf<DialectAsStringExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
1949
- SourceOfDialectStringInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
1897
+ KindOf<DialectAsStringExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
1950
1898
  DependenciesOfDialectStringInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
1951
1899
  ExpressionAst.UnaryNode<"upper", DialectAsStringExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>
1952
1900
  > => {
@@ -1956,10 +1904,9 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
1956
1904
  dbType: profile.textDb as TextDb,
1957
1905
  nullability: expression[Expression.TypeId].nullability as NullabilityOfDialectStringInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
1958
1906
  dialect: expression[Expression.TypeId].dialect,
1959
- aggregation: expression[Expression.TypeId].aggregation as AggregationOf<DialectAsStringExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
1960
- source: expression[Expression.TypeId].source as SourceOfDialectStringInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
1961
- sourceNullability: "propagate" as const,
1962
- dependencies: expression[Expression.TypeId].dependencies as DependenciesOfDialectStringInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
1907
+ kind: expression[Expression.TypeId].kind as KindOf<DialectAsStringExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
1908
+
1909
+ dependencies: expression[Expression.TypeId].dependencies
1963
1910
  }, {
1964
1911
  kind: "upper",
1965
1912
  value: expression
@@ -1973,8 +1920,7 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
1973
1920
  TextDb,
1974
1921
  NullabilityOfDialectStringInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
1975
1922
  DialectOfDialectStringInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
1976
- AggregationOf<DialectAsStringExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
1977
- SourceOfDialectStringInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
1923
+ KindOf<DialectAsStringExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
1978
1924
  DependenciesOfDialectStringInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
1979
1925
  ExpressionAst.UnaryNode<"lower", DialectAsStringExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>
1980
1926
  > => {
@@ -1984,10 +1930,9 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
1984
1930
  dbType: profile.textDb as TextDb,
1985
1931
  nullability: expression[Expression.TypeId].nullability as NullabilityOfDialectStringInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
1986
1932
  dialect: expression[Expression.TypeId].dialect,
1987
- aggregation: expression[Expression.TypeId].aggregation as AggregationOf<DialectAsStringExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
1988
- source: expression[Expression.TypeId].source as SourceOfDialectStringInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
1989
- sourceNullability: "propagate" as const,
1990
- dependencies: expression[Expression.TypeId].dependencies as DependenciesOfDialectStringInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
1933
+ kind: expression[Expression.TypeId].kind as KindOf<DialectAsStringExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
1934
+
1935
+ dependencies: expression[Expression.TypeId].dependencies
1991
1936
  }, {
1992
1937
  kind: "lower",
1993
1938
  value: expression
@@ -2017,9 +1962,8 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
2017
1962
  runtimeSchema: undefined,
2018
1963
  nullability: expression[Expression.TypeId].nullability,
2019
1964
  dialect: expression[Expression.TypeId].dialect,
2020
- aggregation: expression[Expression.TypeId].aggregation,
2021
- source: expression[Expression.TypeId].source,
2022
- sourceNullability: expression[Expression.TypeId].sourceNullability,
1965
+ kind: expression[Expression.TypeId].kind,
1966
+
2023
1967
  dependencies: expression[Expression.TypeId].dependencies
2024
1968
  }, {
2025
1969
  kind: "cast",
@@ -2143,15 +2087,13 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
2143
2087
  Runtime,
2144
2088
  Db extends Expression.DbType.Any,
2145
2089
  Nullability extends Expression.Nullability,
2146
- Ast extends ExpressionAst.Any,
2147
- SourceNullability extends Expression.SourceNullabilityMode = "propagate"
2090
+ Ast extends ExpressionAst.Any
2148
2091
  >(
2149
2092
  expressions: readonly Expression.Any[],
2150
2093
  state: {
2151
2094
  readonly runtime: Runtime
2152
2095
  readonly dbType: Db
2153
2096
  readonly nullability: Nullability
2154
- readonly sourceNullability?: SourceNullability
2155
2097
  },
2156
2098
  ast: Ast
2157
2099
  ): AstBackedExpression<
@@ -2160,29 +2102,24 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
2160
2102
  Nullability,
2161
2103
  TupleDialect<typeof expressions>,
2162
2104
  MergeAggregationTuple<typeof expressions>,
2163
- TupleSource<typeof expressions>,
2164
2105
  TupleDependencies<typeof expressions>,
2165
- Ast,
2166
- SourceNullability
2106
+ Ast
2167
2107
  > => makeExpression({
2168
2108
  runtime: state.runtime,
2169
2109
  dbType: state.dbType,
2170
2110
  nullability: state.nullability,
2171
2111
  dialect: (expressions.find((expression) => expression[Expression.TypeId].dialect !== undefined)?.[Expression.TypeId].dialect ?? profile.dialect) as TupleDialect<typeof expressions>,
2172
- aggregation: mergeAggregationManyRuntime(expressions) as MergeAggregationTuple<typeof expressions>,
2173
- source: mergeManySources(expressions) as TupleSource<typeof expressions>,
2174
- sourceNullability: (state.sourceNullability ?? "propagate") as SourceNullability,
2175
- dependencies: mergeManyDependencies(expressions) as TupleDependencies<typeof expressions>
2112
+ kind: mergeAggregationManyRuntime(expressions) as MergeAggregationTuple<typeof expressions>,
2113
+
2114
+ dependencies: mergeManyDependencies(expressions)
2176
2115
  }, ast) as AstBackedExpression<
2177
2116
  Runtime,
2178
2117
  Db,
2179
2118
  Nullability,
2180
2119
  TupleDialect<typeof expressions>,
2181
2120
  MergeAggregationTuple<typeof expressions>,
2182
- TupleSource<typeof expressions>,
2183
2121
  TupleDependencies<typeof expressions>,
2184
- Ast,
2185
- SourceNullability
2122
+ Ast
2186
2123
  >
2187
2124
 
2188
2125
  const jsonDbTypeOf = <Base extends JsonExpressionLike<any>>(
@@ -2204,9 +2141,8 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
2204
2141
  dbType,
2205
2142
  nullability: (value === null ? "always" : "never") as JsonNullabilityOf<Value>,
2206
2143
  dialect: profile.dialect as Dialect,
2207
- aggregation: "scalar",
2208
- source: undefined as never,
2209
- sourceNullability: "resolved" as const,
2144
+ kind: "scalar",
2145
+
2210
2146
  dependencies: {}
2211
2147
  }, {
2212
2148
  kind: "literal",
@@ -2223,7 +2159,6 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
2223
2159
  runtime: undefined as unknown as JsonRuntime<Expression.RuntimeOf<typeof value>>,
2224
2160
  dbType,
2225
2161
  nullability: value[Expression.TypeId].nullability as JsonNullabilityOf<JsonRuntime<Expression.RuntimeOf<typeof value>>>,
2226
- sourceNullability: value[Expression.TypeId].sourceNullability
2227
2162
  },
2228
2163
  {
2229
2164
  kind,
@@ -2259,8 +2194,7 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
2259
2194
  JsonDbOfExpression<Base>,
2260
2195
  JsonNullabilityOf<JsonPathOutputOf<Expression.RuntimeOf<Base>, Target, "json.get">>,
2261
2196
  DialectOf<Base>,
2262
- AggregationOf<Base>,
2263
- SourceOf<Base>,
2197
+ KindOf<Base>,
2264
2198
  DependenciesOf<Base>,
2265
2199
  JsonNode
2266
2200
  > => {
@@ -2285,8 +2219,7 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
2285
2219
  JsonDbOfExpression<Base>,
2286
2220
  JsonNullabilityOf<JsonPathOutputOf<Expression.RuntimeOf<Base>, Target, "json.get">>,
2287
2221
  DialectOf<Base>,
2288
- AggregationOf<Base>,
2289
- SourceOf<Base>,
2222
+ KindOf<Base>,
2290
2223
  DependenciesOf<Base>,
2291
2224
  JsonNode
2292
2225
  >
@@ -2304,8 +2237,7 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
2304
2237
  TextDb,
2305
2238
  JsonNullabilityOf<JsonPathOutputOf<Expression.RuntimeOf<Base>, Target, "json.text">>,
2306
2239
  DialectOf<Base>,
2307
- AggregationOf<Base>,
2308
- SourceOf<Base>,
2240
+ KindOf<Base>,
2309
2241
  DependenciesOf<Base>,
2310
2242
  JsonNode
2311
2243
  > => {
@@ -2332,8 +2264,7 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
2332
2264
  TextDb,
2333
2265
  JsonNullabilityOf<JsonPathOutputOf<Expression.RuntimeOf<Base>, Target, "json.text">>,
2334
2266
  DialectOf<Base>,
2335
- AggregationOf<Base>,
2336
- SourceOf<Base>,
2267
+ KindOf<Base>,
2337
2268
  DependenciesOf<Base>,
2338
2269
  JsonNode
2339
2270
  >
@@ -2461,7 +2392,6 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
2461
2392
  runtime: true as boolean,
2462
2393
  dbType: profile.boolDb as BoolDb,
2463
2394
  nullability: "never" as const,
2464
- sourceNullability: "resolved" as const
2465
2395
  },
2466
2396
  {
2467
2397
  kind: "jsonHasKey",
@@ -2482,7 +2412,6 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
2482
2412
  runtime: true as boolean,
2483
2413
  dbType: profile.boolDb as BoolDb,
2484
2414
  nullability: "never" as const,
2485
- sourceNullability: "resolved" as const
2486
2415
  },
2487
2416
  {
2488
2417
  kind: "jsonHasAnyKeys",
@@ -2503,7 +2432,6 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
2503
2432
  runtime: true as boolean,
2504
2433
  dbType: profile.boolDb as BoolDb,
2505
2434
  nullability: "never" as const,
2506
- sourceNullability: "resolved" as const
2507
2435
  },
2508
2436
  {
2509
2437
  kind: "jsonHasAllKeys",
@@ -2523,8 +2451,7 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
2523
2451
  JsonDbOfExpression<Base>,
2524
2452
  JsonNullabilityOf<JsonDeleteOutputOf<Expression.RuntimeOf<Base>, Target, "json.delete">>,
2525
2453
  DialectOf<Base>,
2526
- AggregationOf<Base>,
2527
- SourceOf<Base>,
2454
+ KindOf<Base>,
2528
2455
  DependenciesOf<Base>,
2529
2456
  JsonNode
2530
2457
  > => {
@@ -2546,8 +2473,7 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
2546
2473
  JsonDbOfExpression<Base>,
2547
2474
  JsonNullabilityOf<JsonDeleteOutputOf<Expression.RuntimeOf<Base>, Target, "json.delete">>,
2548
2475
  DialectOf<Base>,
2549
- AggregationOf<Base>,
2550
- SourceOf<Base>,
2476
+ KindOf<Base>,
2551
2477
  DependenciesOf<Base>,
2552
2478
  JsonNode
2553
2479
  >
@@ -2564,8 +2490,7 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
2564
2490
  JsonDbOfExpression<Base>,
2565
2491
  JsonNullabilityOf<JsonDeleteOutputOf<Expression.RuntimeOf<Base>, Target, "json.remove">>,
2566
2492
  DialectOf<Base>,
2567
- AggregationOf<Base>,
2568
- SourceOf<Base>,
2493
+ KindOf<Base>,
2569
2494
  DependenciesOf<Base>,
2570
2495
  JsonNode
2571
2496
  > => {
@@ -2587,8 +2512,7 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
2587
2512
  JsonDbOfExpression<Base>,
2588
2513
  JsonNullabilityOf<JsonDeleteOutputOf<Expression.RuntimeOf<Base>, Target, "json.remove">>,
2589
2514
  DialectOf<Base>,
2590
- AggregationOf<Base>,
2591
- SourceOf<Base>,
2515
+ KindOf<Base>,
2592
2516
  DependenciesOf<Base>,
2593
2517
  JsonNode
2594
2518
  >
@@ -2610,8 +2534,7 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
2610
2534
  JsonDbOfExpression<Base>,
2611
2535
  JsonNullabilityOf<JsonSetOutputOf<Expression.RuntimeOf<Base>, Target, Next, "json.set">>,
2612
2536
  DialectOf<Base>,
2613
- AggregationOf<Base>,
2614
- SourceOf<Base>,
2537
+ KindOf<Base>,
2615
2538
  DependenciesOf<Base>,
2616
2539
  JsonNode
2617
2540
  > => {
@@ -2636,8 +2559,7 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
2636
2559
  JsonDbOfExpression<Base>,
2637
2560
  JsonNullabilityOf<JsonSetOutputOf<Expression.RuntimeOf<Base>, Target, Next, "json.set">>,
2638
2561
  DialectOf<Base>,
2639
- AggregationOf<Base>,
2640
- SourceOf<Base>,
2562
+ KindOf<Base>,
2641
2563
  DependenciesOf<Base>,
2642
2564
  JsonNode
2643
2565
  >
@@ -2660,8 +2582,7 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
2660
2582
  JsonDbOfExpression<Base>,
2661
2583
  JsonNullabilityOf<JsonInsertOutputOf<Expression.RuntimeOf<Base>, Target, Next, InsertAfter, "json.insert">>,
2662
2584
  DialectOf<Base>,
2663
- AggregationOf<Base>,
2664
- SourceOf<Base>,
2585
+ KindOf<Base>,
2665
2586
  DependenciesOf<Base>,
2666
2587
  JsonNode
2667
2588
  > => {
@@ -2687,8 +2608,7 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
2687
2608
  JsonDbOfExpression<Base>,
2688
2609
  JsonNullabilityOf<JsonInsertOutputOf<Expression.RuntimeOf<Base>, Target, Next, InsertAfter, "json.insert">>,
2689
2610
  DialectOf<Base>,
2690
- AggregationOf<Base>,
2691
- SourceOf<Base>,
2611
+ KindOf<Base>,
2692
2612
  DependenciesOf<Base>,
2693
2613
  JsonNode
2694
2614
  >
@@ -2709,9 +2629,8 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
2709
2629
  Db,
2710
2630
  "maybe",
2711
2631
  Dialect,
2712
- Expression.AggregationKind,
2632
+ Expression.ScalarKind,
2713
2633
  never,
2714
- {},
2715
2634
  JsonNode
2716
2635
  > => {
2717
2636
  const leftExpression = toJsonValueExpression(left)
@@ -2733,9 +2652,8 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
2733
2652
  Db,
2734
2653
  "maybe",
2735
2654
  Dialect,
2736
- Expression.AggregationKind,
2655
+ Expression.ScalarKind,
2737
2656
  never,
2738
- {},
2739
2657
  JsonNode
2740
2658
  >
2741
2659
  }
@@ -2783,7 +2701,6 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
2783
2701
  runtime: true as boolean,
2784
2702
  dbType: profile.boolDb as BoolDb,
2785
2703
  nullability: "never" as const,
2786
- sourceNullability: "resolved" as const
2787
2704
  },
2788
2705
  {
2789
2706
  kind: "jsonKeyExists",
@@ -2811,7 +2728,6 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
2811
2728
  runtime: {} as JsonObjectOutput<Shape>,
2812
2729
  dbType,
2813
2730
  nullability: "never" as const,
2814
- sourceNullability: "resolved" as const
2815
2731
  },
2816
2732
  {
2817
2733
  kind: "jsonBuildObject",
@@ -2836,7 +2752,6 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
2836
2752
  runtime: [] as JsonArrayOutput<Values>,
2837
2753
  dbType,
2838
2754
  nullability: "never" as const,
2839
- sourceNullability: "resolved" as const
2840
2755
  },
2841
2756
  {
2842
2757
  kind: "jsonBuildArray",
@@ -2857,9 +2772,8 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
2857
2772
  JsonDb<Dialect>,
2858
2773
  JsonNullabilityOf<JsonOutputOfInput<Value>>,
2859
2774
  string,
2860
- Expression.AggregationKind,
2861
- unknown,
2862
- Expression.SourceDependencies,
2775
+ Expression.ScalarKind,
2776
+ Expression.BindingId,
2863
2777
  JsonNode
2864
2778
  >
2865
2779
 
@@ -2870,9 +2784,8 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
2870
2784
  JsonDb<Dialect, JsonbKindForDialect<Dialect>>,
2871
2785
  JsonNullabilityOf<JsonOutputOfInput<Value>>,
2872
2786
  string,
2873
- Expression.AggregationKind,
2874
- unknown,
2875
- Expression.SourceDependencies,
2787
+ Expression.ScalarKind,
2788
+ Expression.BindingId,
2876
2789
  JsonNode
2877
2790
  >
2878
2791
 
@@ -2932,7 +2845,6 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
2932
2845
  runtime: true as boolean,
2933
2846
  dbType: profile.boolDb as BoolDb,
2934
2847
  nullability: "never" as const,
2935
- sourceNullability: "resolved" as const
2936
2848
  },
2937
2849
  {
2938
2850
  kind: "jsonPathExists",
@@ -2948,7 +2860,6 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
2948
2860
  runtime: true as boolean,
2949
2861
  dbType: profile.boolDb as BoolDb,
2950
2862
  nullability: "never" as const,
2951
- sourceNullability: "resolved" as const
2952
2863
  },
2953
2864
  {
2954
2865
  kind: "jsonPathExists",
@@ -2984,7 +2895,6 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
2984
2895
  runtime: true as boolean,
2985
2896
  dbType: profile.boolDb as BoolDb,
2986
2897
  nullability: "never" as const,
2987
- sourceNullability: "resolved" as const
2988
2898
  },
2989
2899
  {
2990
2900
  kind: "jsonPathMatch",
@@ -3000,7 +2910,6 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
3000
2910
  runtime: true as boolean,
3001
2911
  dbType: profile.boolDb as BoolDb,
3002
2912
  nullability: "never" as const,
3003
- sourceNullability: "resolved" as const
3004
2913
  },
3005
2914
  {
3006
2915
  kind: "jsonPathMatch",
@@ -3128,8 +3037,7 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
3128
3037
  BoolDb,
3129
3038
  Expression.NullabilityOf<DialectAsExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
3130
3039
  DialectOfDialectInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
3131
- AggregationOf<DialectAsExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
3132
- SourceOfDialectInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
3040
+ KindOf<DialectAsExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
3133
3041
  DependenciesOfDialectInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
3134
3042
  ExpressionAst.UnaryNode<"not", DialectAsExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>
3135
3043
  > => {
@@ -3139,10 +3047,9 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
3139
3047
  dbType: profile.boolDb as BoolDb,
3140
3048
  nullability: expression[Expression.TypeId].nullability as Expression.NullabilityOf<DialectAsExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
3141
3049
  dialect: expression[Expression.TypeId].dialect,
3142
- aggregation: expression[Expression.TypeId].aggregation as AggregationOf<DialectAsExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
3143
- source: expression[Expression.TypeId].source as SourceOfDialectInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
3144
- sourceNullability: "propagate" as const,
3145
- dependencies: expression[Expression.TypeId].dependencies as DependenciesOfDialectInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
3050
+ kind: expression[Expression.TypeId].kind as KindOf<DialectAsExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
3051
+
3052
+ dependencies: expression[Expression.TypeId].dependencies
3146
3053
  }, {
3147
3054
  kind: "not",
3148
3055
  value: expression
@@ -3156,8 +3063,8 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
3156
3063
  head: Head,
3157
3064
  ...tail: {
3158
3065
  readonly [K in keyof Tail]: Tail[K] & ComparableInput<
3159
- Head,
3160
- Tail[K],
3066
+ NoInfer<Head>,
3067
+ NoInfer<Tail[K]>,
3161
3068
  Dialect,
3162
3069
  TextDb,
3163
3070
  NumericDb,
@@ -3177,8 +3084,8 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
3177
3084
  head: Head,
3178
3085
  ...tail: {
3179
3086
  readonly [K in keyof Tail]: Tail[K] & ComparableInput<
3180
- Head,
3181
- Tail[K],
3087
+ NoInfer<Head>,
3088
+ NoInfer<Tail[K]>,
3182
3089
  Dialect,
3183
3090
  TextDb,
3184
3091
  NumericDb,
@@ -3240,7 +3147,6 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
3240
3147
  MergeNullabilityTuple<DialectStringExpressionTuple<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
3241
3148
  TupleDialect<DialectStringExpressionTuple<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
3242
3149
  MergeAggregationTuple<DialectStringExpressionTuple<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
3243
- TupleSource<DialectStringExpressionTuple<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
3244
3150
  TupleDependencies<DialectStringExpressionTuple<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
3245
3151
  ExpressionAst.VariadicNode<"concat", DialectStringExpressionTuple<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>
3246
3152
  > => {
@@ -3250,10 +3156,9 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
3250
3156
  dbType: profile.textDb as TextDb,
3251
3157
  nullability: mergeNullabilityManyRuntime(expressions) as MergeNullabilityTuple<DialectStringExpressionTuple<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
3252
3158
  dialect: (expressions.find((value) => value[Expression.TypeId].dialect !== undefined)?.[Expression.TypeId].dialect ?? profile.dialect) as TupleDialect<DialectStringExpressionTuple<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
3253
- aggregation: mergeAggregationManyRuntime(expressions) as MergeAggregationTuple<DialectStringExpressionTuple<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
3254
- source: mergeManySources(expressions) as TupleSource<DialectStringExpressionTuple<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
3255
- sourceNullability: "propagate" as const,
3256
- dependencies: mergeManyDependencies(expressions) as TupleDependencies<DialectStringExpressionTuple<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>
3159
+ kind: mergeAggregationManyRuntime(expressions) as MergeAggregationTuple<DialectStringExpressionTuple<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
3160
+
3161
+ dependencies: mergeManyDependencies(expressions)
3257
3162
  }, {
3258
3163
  kind: "concat",
3259
3164
  values: expressions
@@ -3263,7 +3168,6 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
3263
3168
  MergeNullabilityTuple<DialectStringExpressionTuple<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
3264
3169
  TupleDialect<DialectStringExpressionTuple<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
3265
3170
  MergeAggregationTuple<DialectStringExpressionTuple<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
3266
- TupleSource<DialectStringExpressionTuple<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
3267
3171
  TupleDependencies<DialectStringExpressionTuple<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
3268
3172
  ExpressionAst.VariadicNode<"concat", DialectStringExpressionTuple<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>
3269
3173
  >
@@ -3289,10 +3193,8 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
3289
3193
  "never",
3290
3194
  DialectOfDialectInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
3291
3195
  "aggregate",
3292
- SourceOfDialectInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
3293
3196
  DependenciesOfDialectInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
3294
- ExpressionAst.UnaryNode<"count", DialectAsExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
3295
- "resolved"
3197
+ ExpressionAst.UnaryNode<"count", DialectAsExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>
3296
3198
  > => {
3297
3199
  const expression = toDialectExpression(value)
3298
3200
  return makeExpression({
@@ -3300,10 +3202,9 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
3300
3202
  dbType: profile.numericDb as NumericDb,
3301
3203
  nullability: "never",
3302
3204
  dialect: expression[Expression.TypeId].dialect,
3303
- aggregation: "aggregate",
3304
- source: expression[Expression.TypeId].source as SourceOfDialectInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
3305
- sourceNullability: "resolved" as const,
3306
- dependencies: expression[Expression.TypeId].dependencies as DependenciesOfDialectInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
3205
+ kind: "aggregate",
3206
+
3207
+ dependencies: expression[Expression.TypeId].dependencies
3307
3208
  }, {
3308
3209
  kind: "count",
3309
3210
  value: expression
@@ -3320,10 +3221,8 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
3320
3221
  "never",
3321
3222
  Dialect,
3322
3223
  "scalar",
3323
- never,
3324
3224
  DependencyRecord<OutstandingOfPlan<PlanValue>>,
3325
- ExpressionAst.ExistsNode<PlanValue>,
3326
- "resolved"
3225
+ ExpressionAst.ExistsNode<PlanValue>
3327
3226
  > => {
3328
3227
  const dependencies = Object.fromEntries(
3329
3228
  currentRequiredList(plan[Plan.TypeId].required).map((name) => [name, true] as const)
@@ -3333,9 +3232,8 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
3333
3232
  dbType: profile.boolDb as BoolDb,
3334
3233
  nullability: "never",
3335
3234
  dialect: profile.dialect as Dialect,
3336
- aggregation: "scalar",
3337
- source: undefined as never,
3338
- sourceNullability: "resolved" as const,
3235
+ kind: "scalar",
3236
+
3339
3237
  dependencies
3340
3238
  }, {
3341
3239
  kind: "exists",
@@ -3353,10 +3251,8 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
3353
3251
  "maybe",
3354
3252
  Dialect,
3355
3253
  "scalar",
3356
- never,
3357
3254
  DependencyRecord<OutstandingOfPlan<PlanValue>>,
3358
- ExpressionAst.ScalarSubqueryNode<PlanValue>,
3359
- "resolved"
3255
+ ExpressionAst.ScalarSubqueryNode<PlanValue>
3360
3256
  > => {
3361
3257
  const dependencies = Object.fromEntries(
3362
3258
  currentRequiredList(plan[Plan.TypeId].required).map((name) => [name, true] as const)
@@ -3367,9 +3263,8 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
3367
3263
  dbType: expression[Expression.TypeId].dbType as Expression.DbTypeOf<ScalarOutputOfPlan<PlanValue>>,
3368
3264
  nullability: "maybe",
3369
3265
  dialect: profile.dialect as Dialect,
3370
- aggregation: "scalar",
3371
- source: undefined as never,
3372
- sourceNullability: "resolved" as const,
3266
+ kind: "scalar",
3267
+
3373
3268
  dependencies
3374
3269
  }, {
3375
3270
  kind: "scalarSubquery",
@@ -3407,8 +3302,7 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
3407
3302
  )
3408
3303
  ): SubqueryPredicateExpression<
3409
3304
  Dialect,
3410
- AggregationOf<DialectAsExpression<Left, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
3411
- SourceOfDialectInput<Left, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
3305
+ KindOf<DialectAsExpression<Left, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
3412
3306
  DependencyRecord<RequiredFromDialectInput<Left, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> | OutstandingOfPlan<PlanValue>>,
3413
3307
  ExpressionAst.InSubqueryNode<
3414
3308
  DialectAsExpression<Left, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
@@ -3424,12 +3318,9 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
3424
3318
  dbType: profile.boolDb as BoolDb,
3425
3319
  nullability: "maybe",
3426
3320
  dialect: (leftExpression[Expression.TypeId].dialect ?? profile.dialect) as Dialect,
3427
- aggregation: leftExpression[Expression.TypeId].aggregation as AggregationOf<DialectAsExpression<Left, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
3428
- source: leftExpression[Expression.TypeId].source as SourceOfDialectInput<Left, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
3429
- sourceNullability: "propagate" as const,
3430
- dependencies: mergeDependencies(leftExpression[Expression.TypeId].dependencies, dependencies) as DependencyRecord<
3431
- RequiredFromDialectInput<Left, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> | OutstandingOfPlan<PlanValue>
3432
- >
3321
+ kind: leftExpression[Expression.TypeId].kind as KindOf<DialectAsExpression<Left, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
3322
+
3323
+ dependencies: mergeDependencies(leftExpression[Expression.TypeId].dependencies, dependencies)
3433
3324
  }, {
3434
3325
  kind: "inSubquery",
3435
3326
  left: leftExpression,
@@ -3457,12 +3348,9 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
3457
3348
  dbType: profile.boolDb as BoolDb,
3458
3349
  nullability: "maybe",
3459
3350
  dialect: (leftExpression[Expression.TypeId].dialect ?? profile.dialect) as Dialect,
3460
- aggregation: leftExpression[Expression.TypeId].aggregation as AggregationOf<DialectAsExpression<Left, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
3461
- source: leftExpression[Expression.TypeId].source as SourceOfDialectInput<Left, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
3462
- sourceNullability: "propagate" as const,
3463
- dependencies: mergeDependencies(leftExpression[Expression.TypeId].dependencies, dependencies) as DependencyRecord<
3464
- RequiredFromDialectInput<Left, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> | OutstandingOfPlan<PlanValue>
3465
- >
3351
+ kind: leftExpression[Expression.TypeId].kind as KindOf<DialectAsExpression<Left, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
3352
+
3353
+ dependencies: mergeDependencies(leftExpression[Expression.TypeId].dependencies, dependencies)
3466
3354
  }, renderQuantifiedComparisonAst(leftExpression, plan, operator, quantifier) as ExpressionAst.QuantifiedComparisonNode<
3467
3355
  Quantifier extends "any" ? "comparisonAny" : "comparisonAll",
3468
3356
  Operator,
@@ -3492,15 +3380,13 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
3492
3380
  ): Expression.Any => quantifiedComparison(left, plan, operator, "all") as Expression.Any
3493
3381
 
3494
3382
  const over = <
3495
- Value extends Expression.Expression<
3383
+ Value extends Expression.Scalar<
3496
3384
  any,
3497
3385
  Expression.DbType.Any,
3498
3386
  Expression.Nullability,
3499
3387
  string,
3500
3388
  "aggregate",
3501
- any,
3502
- Expression.SourceDependencies,
3503
- Expression.SourceNullabilityMode
3389
+ Expression.BindingId
3504
3390
  >,
3505
3391
  PartitionBy extends readonly WindowPartitionInput[] = [],
3506
3392
  OrderBy extends readonly WindowOrderTermInput[] = []
@@ -3515,10 +3401,9 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
3515
3401
  dbType: value[Expression.TypeId].dbType as Expression.DbTypeOf<Value>,
3516
3402
  nullability: value[Expression.TypeId].nullability as Expression.NullabilityOf<Value>,
3517
3403
  dialect: (expressions.find((expression) => expression[Expression.TypeId].dialect !== undefined)?.[Expression.TypeId].dialect ?? profile.dialect) as WindowDialectOf<Value, PartitionBy, OrderBy>,
3518
- aggregation: "window",
3519
- source: mergeManySources(expressions) as WindowSourceOf<Value, PartitionBy, OrderBy>,
3520
- sourceNullability: "resolved" as const,
3521
- dependencies: mergeManyDependencies(expressions) as WindowDependenciesOf<Value, PartitionBy, OrderBy>
3404
+ kind: "window",
3405
+
3406
+ dependencies: mergeManyDependencies(expressions)
3522
3407
  }, {
3523
3408
  kind: "window",
3524
3409
  function: "over",
@@ -3543,10 +3428,9 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
3543
3428
  dbType: profile.numericDb as Expression.DbType.Any,
3544
3429
  nullability: "never",
3545
3430
  dialect: (expressions.find((expression) => expression[Expression.TypeId].dialect !== undefined)?.[Expression.TypeId].dialect ?? profile.dialect) as NumberWindowDialectOf<PartitionBy, OrderBy>,
3546
- aggregation: "window",
3547
- source: mergeManySources(expressions) as NumberWindowSourceOf<PartitionBy, OrderBy>,
3548
- sourceNullability: "resolved" as const,
3549
- dependencies: mergeManyDependencies(expressions) as NumberWindowDependenciesOf<PartitionBy, OrderBy>
3431
+ kind: "window",
3432
+
3433
+ dependencies: mergeManyDependencies(expressions)
3550
3434
  }, {
3551
3435
  kind: "window",
3552
3436
  function: kind,
@@ -3587,20 +3471,17 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
3587
3471
  "maybe",
3588
3472
  DialectOf<Value>,
3589
3473
  "aggregate",
3590
- SourceOf<Value>,
3591
3474
  DependenciesOf<Value>,
3592
- ExpressionAst.UnaryNode<"max", Value>,
3593
- "resolved"
3475
+ ExpressionAst.UnaryNode<"max", Value>
3594
3476
  > =>
3595
3477
  makeExpression({
3596
3478
  runtime: undefined as Expression.RuntimeOf<Value>,
3597
3479
  dbType: value[Expression.TypeId].dbType as Expression.DbTypeOf<Value>,
3598
3480
  nullability: "maybe",
3599
3481
  dialect: value[Expression.TypeId].dialect,
3600
- aggregation: "aggregate",
3601
- source: value[Expression.TypeId].source as SourceOf<Value>,
3602
- sourceNullability: "resolved" as const,
3603
- dependencies: value[Expression.TypeId].dependencies as DependenciesOf<Value>
3482
+ kind: "aggregate",
3483
+
3484
+ dependencies: value[Expression.TypeId].dependencies
3604
3485
  }, {
3605
3486
  kind: "max",
3606
3487
  value
@@ -3614,20 +3495,17 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
3614
3495
  "maybe",
3615
3496
  DialectOf<Value>,
3616
3497
  "aggregate",
3617
- SourceOf<Value>,
3618
3498
  DependenciesOf<Value>,
3619
- ExpressionAst.UnaryNode<"min", Value>,
3620
- "resolved"
3499
+ ExpressionAst.UnaryNode<"min", Value>
3621
3500
  > =>
3622
3501
  makeExpression({
3623
3502
  runtime: undefined as Expression.RuntimeOf<Value>,
3624
3503
  dbType: value[Expression.TypeId].dbType as Expression.DbTypeOf<Value>,
3625
3504
  nullability: "maybe",
3626
3505
  dialect: value[Expression.TypeId].dialect,
3627
- aggregation: "aggregate",
3628
- source: value[Expression.TypeId].source as SourceOf<Value>,
3629
- sourceNullability: "resolved" as const,
3630
- dependencies: value[Expression.TypeId].dependencies as DependenciesOf<Value>
3506
+ kind: "aggregate",
3507
+
3508
+ dependencies: value[Expression.TypeId].dependencies
3631
3509
  }, {
3632
3510
  kind: "min",
3633
3511
  value
@@ -3652,10 +3530,8 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
3652
3530
  CoalesceNullabilityTuple<DialectExpressionTuple<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
3653
3531
  TupleDialect<DialectExpressionTuple<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
3654
3532
  MergeAggregationTuple<DialectExpressionTuple<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
3655
- TupleSource<DialectExpressionTuple<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
3656
3533
  TupleDependencies<DialectExpressionTuple<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
3657
- ExpressionAst.VariadicNode<"coalesce", DialectExpressionTuple<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
3658
- "resolved"
3534
+ ExpressionAst.VariadicNode<"coalesce", DialectExpressionTuple<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>
3659
3535
  > => {
3660
3536
  const expressions = values.map((value) => toDialectExpression(value)) as readonly Expression.Any[]
3661
3537
  const representative = expressions.find((value) =>
@@ -3665,10 +3541,9 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
3665
3541
  dbType: representative[Expression.TypeId].dbType as any,
3666
3542
  nullability: resolveCoalesceNullabilityRuntime(expressions) as any,
3667
3543
  dialect: (expressions.find((value) => value[Expression.TypeId].dialect !== undefined)?.[Expression.TypeId].dialect ?? profile.dialect) as any,
3668
- aggregation: mergeAggregationManyRuntime(expressions) as any,
3669
- source: mergeManySources(expressions) as any,
3670
- sourceNullability: "resolved" as const,
3671
- dependencies: mergeManyDependencies(expressions) as any
3544
+ kind: mergeAggregationManyRuntime(expressions) as any,
3545
+
3546
+ dependencies: mergeManyDependencies(expressions)
3672
3547
  }, {
3673
3548
  kind: "coalesce",
3674
3549
  values: expressions
@@ -3678,10 +3553,8 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
3678
3553
  CoalesceNullabilityTuple<DialectExpressionTuple<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
3679
3554
  TupleDialect<DialectExpressionTuple<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
3680
3555
  MergeAggregationTuple<DialectExpressionTuple<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
3681
- TupleSource<DialectExpressionTuple<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
3682
3556
  TupleDependencies<DialectExpressionTuple<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
3683
- ExpressionAst.VariadicNode<"coalesce", DialectExpressionTuple<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
3684
- "resolved"
3557
+ ExpressionAst.VariadicNode<"coalesce", DialectExpressionTuple<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>
3685
3558
  >
3686
3559
  }
3687
3560
 
@@ -3698,9 +3571,8 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
3698
3571
  dbType: profile.textDb,
3699
3572
  nullability: "maybe",
3700
3573
  dialect: (expressions.find((value) => value[Expression.TypeId].dialect !== undefined)?.[Expression.TypeId].dialect ?? profile.dialect) as Dialect,
3701
- aggregation: mergeAggregationManyRuntime(expressions),
3702
- source: mergeManySources(expressions),
3703
- sourceNullability: "resolved" as const,
3574
+ kind: mergeAggregationManyRuntime(expressions),
3575
+
3704
3576
  dependencies: mergeManyDependencies(expressions)
3705
3577
  }, {
3706
3578
  kind: "function",
@@ -3709,25 +3581,22 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
3709
3581
  }) as Expression.Any
3710
3582
  }
3711
3583
 
3712
- const uuidGenerateV4 = (): Expression.Expression<
3584
+ const uuidGenerateV4 = (): Expression.Scalar<
3713
3585
  string,
3714
- Expression.DbType.PgUuid,
3586
+ Expression.DbType.Base<"mysql", "uuid">,
3715
3587
  "never",
3716
3588
  Dialect,
3717
3589
  "scalar",
3718
- never,
3719
- {},
3720
- "resolved"
3590
+ never
3721
3591
  > & {
3722
3592
  readonly [ExpressionAst.TypeId]: ExpressionAst.FunctionCallNode<"uuid_generate_v4", readonly []>
3723
3593
  } => makeExpression({
3724
3594
  runtime: undefined as unknown as string,
3725
- dbType: { dialect: "postgres", kind: "uuid" } as Expression.DbType.PgUuid,
3595
+ dbType: mysqlDatatypes.uuid(),
3726
3596
  nullability: "never",
3727
3597
  dialect: profile.dialect as Dialect,
3728
- aggregation: "scalar",
3729
- source: undefined as never,
3730
- sourceNullability: "resolved" as const,
3598
+ kind: "scalar",
3599
+
3731
3600
  dependencies: {}
3732
3601
  }, {
3733
3602
  kind: "function",
@@ -3737,25 +3606,22 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
3737
3606
 
3738
3607
  const nextVal = <Value extends ExpressionInput>(
3739
3608
  value: Value
3740
- ): Expression.Expression<
3741
- Expression.RuntimeOfDbType<Expression.DbType.PgInt8>,
3742
- Expression.DbType.PgInt8,
3609
+ ): Expression.Scalar<
3610
+ Expression.RuntimeOfDbType<Expression.DbType.Base<"mysql", "bigint">>,
3611
+ Expression.DbType.Base<"mysql", "bigint">,
3743
3612
  "never",
3744
3613
  Dialect,
3745
3614
  "scalar",
3746
- never,
3747
- {},
3748
- "resolved"
3615
+ never
3749
3616
  > & {
3750
3617
  readonly [ExpressionAst.TypeId]: ExpressionAst.FunctionCallNode<"nextval", readonly [Expression.Any]>
3751
3618
  } => makeExpression({
3752
- runtime: undefined as unknown as Expression.RuntimeOfDbType<Expression.DbType.PgInt8>,
3753
- dbType: { dialect: "postgres", kind: "int8" } as Expression.DbType.PgInt8,
3619
+ runtime: undefined as unknown as Expression.RuntimeOfDbType<Expression.DbType.Base<"mysql", "bigint">>,
3620
+ dbType: mysqlDatatypes.bigint(),
3754
3621
  nullability: "never",
3755
3622
  dialect: profile.dialect as Dialect,
3756
- aggregation: "scalar",
3757
- source: undefined as never,
3758
- sourceNullability: "resolved" as const,
3623
+ kind: "scalar",
3624
+
3759
3625
  dependencies: {}
3760
3626
  }, {
3761
3627
  kind: "function",
@@ -3805,9 +3671,8 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
3805
3671
  dbType: representative[Expression.TypeId].dbType,
3806
3672
  nullability: resolveCaseNullabilityRuntime(resultExpressions),
3807
3673
  dialect: (allExpressions.find((value) => value[Expression.TypeId].dialect !== undefined)?.[Expression.TypeId].dialect ?? profile.dialect),
3808
- aggregation: mergeAggregationManyRuntime(allExpressions),
3809
- source: mergeManySources(allExpressions),
3810
- sourceNullability: "resolved" as const,
3674
+ kind: mergeAggregationManyRuntime(allExpressions),
3675
+
3811
3676
  dependencies: mergeManyDependencies(allExpressions)
3812
3677
  }, {
3813
3678
  kind: "case",
@@ -3912,15 +3777,13 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
3912
3777
  }
3913
3778
 
3914
3779
  const excluded = <
3915
- Value extends Expression.Expression<
3780
+ Value extends Expression.Scalar<
3916
3781
  any,
3917
3782
  Expression.DbType.Any,
3918
3783
  Expression.Nullability,
3919
3784
  string,
3920
3785
  "scalar",
3921
- any,
3922
- Expression.SourceDependencies,
3923
- Expression.SourceNullabilityMode
3786
+ Expression.BindingId
3924
3787
  >
3925
3788
  >(
3926
3789
  value: Value
@@ -3931,9 +3794,7 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
3931
3794
  Dialect,
3932
3795
  "scalar",
3933
3796
  never,
3934
- {},
3935
- ExpressionAst.ExcludedNode<AstOf<Value> extends ExpressionAst.ColumnNode<any, infer ColumnName extends string> ? ColumnName : string>,
3936
- "resolved"
3797
+ ExpressionAst.ExcludedNode<AstOf<Value> extends ExpressionAst.ColumnNode<any, infer ColumnName extends string> ? ColumnName : string>
3937
3798
  > => {
3938
3799
  const ast = ((value as unknown) as Expression.Any & { readonly [ExpressionAst.TypeId]: ExpressionAst.Any })[ExpressionAst.TypeId]
3939
3800
  if (ast.kind !== "column") {
@@ -3945,9 +3806,8 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
3945
3806
  runtimeSchema: value[Expression.TypeId].runtimeSchema,
3946
3807
  nullability: value[Expression.TypeId].nullability as Expression.NullabilityOf<Value>,
3947
3808
  dialect: profile.dialect as Dialect,
3948
- aggregation: "scalar",
3949
- source: undefined as never,
3950
- sourceNullability: "resolved" as const,
3809
+ kind: "scalar",
3810
+
3951
3811
  dependencies: {}
3952
3812
  }, {
3953
3813
  kind: "excluded",
@@ -3959,9 +3819,7 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
3959
3819
  Dialect,
3960
3820
  "scalar",
3961
3821
  never,
3962
- {},
3963
- ExpressionAst.ExcludedNode<AstOf<Value> extends ExpressionAst.ColumnNode<any, infer ColumnName extends string> ? ColumnName : string>,
3964
- "resolved"
3822
+ ExpressionAst.ExcludedNode<AstOf<Value> extends ExpressionAst.ColumnNode<any, infer ColumnName extends string> ? ColumnName : string>
3965
3823
  >
3966
3824
  }
3967
3825
 
@@ -3977,9 +3835,8 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
3977
3835
  dbType: column[Expression.TypeId].dbType,
3978
3836
  nullability: value === null ? "always" : "never",
3979
3837
  dialect: column[Expression.TypeId].dialect,
3980
- aggregation: "scalar",
3981
- source: undefined as never,
3982
- sourceNullability: "propagate" as const,
3838
+ kind: "scalar",
3839
+
3983
3840
  dependencies: {}
3984
3841
  }, {
3985
3842
  kind: "literal",
@@ -4052,13 +3909,7 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
4052
3909
  runtimeSchema: state.runtimeSchema,
4053
3910
  nullability: state.nullability,
4054
3911
  dialect: state.dialect,
4055
- aggregation: "scalar",
4056
- source: {
4057
- tableName: alias,
4058
- columnName,
4059
- baseTableName: alias
4060
- },
4061
- sourceNullability: "propagate" as const,
3912
+ kind: "scalar",
4062
3913
  dependencies: {
4063
3914
  [alias]: true
4064
3915
  } as Record<Alias, true>
@@ -4693,8 +4544,6 @@ type AstOf<Value extends Expression.Any> =
4693
4544
  ? Ast
4694
4545
  : never
4695
4546
 
4696
- type AvailableNames<Available extends Record<string, Plan.AnySource>> = Extract<keyof Available, string>
4697
-
4698
4547
  type RequiredFromInput<Value extends ExpressionInput> =
4699
4548
  Value extends Expression.Any
4700
4549
  ? RequiredFromDependencies<DependenciesOf<Value>>
@@ -4846,6 +4695,74 @@ type FromPlanResult<
4846
4695
  : never
4847
4696
  : never
4848
4697
 
4698
+ export type PublicStructuredFromConstraint<
4699
+ PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>,
4700
+ CurrentSource extends AnyValuesSource | AnyUnnestSource | AnyTableFunctionSource,
4701
+ Dialect extends string
4702
+ > =
4703
+ StatementOfPlan<PlanValue> extends "insert"
4704
+ ? CurrentSource extends AnyValuesSource | AnyUnnestSource
4705
+ ? RequirePendingInsertStatement<PlanValue>
4706
+ : FromPlanConstraint<PlanValue, CurrentSource, Dialect>
4707
+ : FromPlanConstraint<PlanValue, CurrentSource, Dialect>
4708
+
4709
+ export type PublicStructuredFromResult<
4710
+ PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>,
4711
+ CurrentSource extends AnyValuesSource | AnyUnnestSource | AnyTableFunctionSource,
4712
+ Dialect extends string
4713
+ > =
4714
+ StatementOfPlan<PlanValue> extends "select"
4715
+ ? QueryPlan<
4716
+ SelectionOfPlan<PlanValue>,
4717
+ Exclude<RequiredOfPlan<PlanValue>, SourceNameOf<CurrentSource>>,
4718
+ AddAvailable<{}, SourceNameOf<CurrentSource>>,
4719
+ PlanDialectOf<PlanValue> | SourceDialectOf<CurrentSource>,
4720
+ GroupedOfPlan<PlanValue>,
4721
+ SourceNameOf<CurrentSource>,
4722
+ Exclude<OutstandingOfPlan<PlanValue>, SourceNameOf<CurrentSource>>,
4723
+ AssumptionsOfPlan<PlanValue>,
4724
+ MergeCapabilities<CapabilitiesOfPlan<PlanValue>, SourceCapabilitiesOf<CurrentSource>>,
4725
+ StatementOfPlan<PlanValue>
4726
+ >
4727
+ : StatementOfPlan<PlanValue> extends "update"
4728
+ ? QueryPlan<
4729
+ SelectionOfPlan<PlanValue>,
4730
+ Exclude<RequiredOfPlan<PlanValue>, SourceNameOf<CurrentSource>>,
4731
+ AddAvailable<AvailableOfPlan<PlanValue>, SourceNameOf<CurrentSource>>,
4732
+ PlanDialectOf<PlanValue> | SourceDialectOf<CurrentSource>,
4733
+ GroupedOfPlan<PlanValue>,
4734
+ ScopedNamesOfPlan<PlanValue> | SourceNameOf<CurrentSource>,
4735
+ Exclude<OutstandingOfPlan<PlanValue>, SourceNameOf<CurrentSource>>,
4736
+ AssumptionsOfPlan<PlanValue>,
4737
+ MergeCapabilities<CapabilitiesOfPlan<PlanValue>, SourceCapabilitiesOf<CurrentSource>>,
4738
+ StatementOfPlan<PlanValue>
4739
+ >
4740
+ : StatementOfPlan<PlanValue> extends "insert"
4741
+ ? CurrentSource extends AnyValuesSource | AnyUnnestSource
4742
+ ? QueryPlan<
4743
+ SelectionOfPlan<PlanValue>,
4744
+ never,
4745
+ AvailableOfPlan<PlanValue>,
4746
+ PlanDialectOf<PlanValue>,
4747
+ GroupedOfPlan<PlanValue>,
4748
+ ScopedNamesOfPlan<PlanValue>,
4749
+ never,
4750
+ AssumptionsOfPlan<PlanValue>,
4751
+ CapabilitiesOfPlan<PlanValue>,
4752
+ StatementOfPlan<PlanValue>,
4753
+ MutationTargetOfPlan<PlanValue>,
4754
+ "ready"
4755
+ >
4756
+ : FromPlanResult<PlanValue, CurrentSource, Dialect>
4757
+ : FromPlanResult<PlanValue, CurrentSource, Dialect>
4758
+
4759
+ export type PublicNonStructuredFromApi = <CurrentSource extends Exclude<FromInput, AnyValuesSource | AnyUnnestSource | AnyTableFunctionSource>>(
4760
+ source: CurrentSource
4761
+ ) =>
4762
+ <PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
4763
+ plan: PlanValue & FromPlanConstraint<PlanValue, CurrentSource, Dialect>
4764
+ ) => FromPlanResult<PlanValue, CurrentSource, Dialect>
4765
+
4849
4766
  type MergeRequiredFromPredicate<
4850
4767
  Predicate extends PredicateInput | undefined,
4851
4768
  Available extends Record<string, Plan.AnySource>
@@ -4923,7 +4840,7 @@ type AsCurriedResult<
4923
4840
  if (typeof value !== "object" || value === null || Expression.TypeId in value) {
4924
4841
  const expression = toDialectExpression(value as ExpressionInput)
4925
4842
  const projected = Object.create(Object.getPrototypeOf(expression)) as {
4926
- [Expression.TypeId]: Expression.State<any, any, any, any, any, any, any, Expression.SourceNullabilityMode>
4843
+ [Expression.TypeId]: Expression.State<any, any, any, any, any, any>
4927
4844
  [ExpressionAst.TypeId]: ExpressionAst.Any
4928
4845
  [ProjectionAlias.TypeId]: ProjectionAlias.State<string>
4929
4846
  schema?: unknown
@@ -4959,14 +4876,14 @@ type AsCurriedResult<
4959
4876
  alias: Alias
4960
4877
  ): <PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
4961
4878
  value: CompletePlan<PlanValue>
4962
- ) => import("./query.js").CteSource<PlanValue, Alias>
4879
+ ) => import("../../internal/query.js").CteSource<PlanValue, Alias>
4963
4880
  function with_<
4964
4881
  PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>,
4965
4882
  Alias extends string
4966
4883
  >(
4967
4884
  value: CompletePlan<PlanValue>,
4968
4885
  alias: Alias
4969
- ): import("./query.js").CteSource<PlanValue, Alias>
4886
+ ): import("../../internal/query.js").CteSource<PlanValue, Alias>
4970
4887
  function with_(valueOrAlias: unknown, alias?: string): unknown {
4971
4888
  if (alias === undefined) {
4972
4889
  return (value: unknown) => with_(value as any, valueOrAlias as string)
@@ -4983,14 +4900,14 @@ type AsCurriedResult<
4983
4900
  alias: Alias
4984
4901
  ): <PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
4985
4902
  value: CompletePlan<PlanValue>
4986
- ) => import("./query.js").CteSource<PlanValue, Alias>
4903
+ ) => import("../../internal/query.js").CteSource<PlanValue, Alias>
4987
4904
  function withRecursive_<
4988
4905
  PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>,
4989
4906
  Alias extends string
4990
4907
  >(
4991
4908
  value: CompletePlan<PlanValue>,
4992
4909
  alias: Alias
4993
- ): import("./query.js").CteSource<PlanValue, Alias>
4910
+ ): import("../../internal/query.js").CteSource<PlanValue, Alias>
4994
4911
  function withRecursive_(valueOrAlias: unknown, alias?: string): unknown {
4995
4912
  if (alias === undefined) {
4996
4913
  return (value: unknown) => withRecursive_(value as any, valueOrAlias as string)
@@ -5008,14 +4925,14 @@ type AsCurriedResult<
5008
4925
  alias: Alias
5009
4926
  ): <PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
5010
4927
  value: PlanValue
5011
- ) => import("./query.js").LateralSource<PlanValue, Alias>
4928
+ ) => import("../../internal/query.js").LateralSource<PlanValue, Alias>
5012
4929
  function lateral<
5013
4930
  PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>,
5014
4931
  Alias extends string
5015
4932
  >(
5016
4933
  value: PlanValue,
5017
4934
  alias: Alias
5018
- ): import("./query.js").LateralSource<PlanValue, Alias>
4935
+ ): import("../../internal/query.js").LateralSource<PlanValue, Alias>
5019
4936
  function lateral(valueOrAlias: unknown, alias?: string): unknown {
5020
4937
  if (alias === undefined) {
5021
4938
  return (value: unknown) => lateral(value as any, valueOrAlias as string)
@@ -5026,105 +4943,29 @@ type AsCurriedResult<
5026
4943
  )
5027
4944
  }
5028
4945
 
5029
- const values = <
4946
+ export type ValuesApi = <
5030
4947
  Rows extends ValuesRowsInput
5031
4948
  >(
5032
4949
  rows: Rows
5033
- ): ValuesInput<
4950
+ ) => ValuesInput<
5034
4951
  Rows,
5035
4952
  ValuesOutputShape<Rows[0], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
5036
4953
  Dialect
5037
- > => {
5038
- if (rows.length === 0) {
5039
- throw new Error("values(...) requires at least one row")
5040
- }
5041
- const normalizedRows: readonly [
5042
- Record<string, Expression.Any>,
5043
- ...Record<string, Expression.Any>[]
5044
- ] = rows.map((row) => normalizeValuesRow(row)) as any
5045
- const columnNames = Object.keys(normalizedRows[0]!)
5046
- for (const row of normalizedRows) {
5047
- const rowKeys = Object.keys(row)
5048
- if (rowKeys.length !== columnNames.length || !rowKeys.every((key, index) => key === columnNames[index])) {
5049
- throw new Error("values(...) rows must project the same columns in the same order")
5050
- }
5051
- }
5052
- return Object.assign(Object.create(ValuesInputProto), {
5053
- kind: "values",
5054
- dialect: profile.dialect,
5055
- rows: normalizedRows,
5056
- selection: normalizedRows[0]! as ValuesOutputShape<
5057
- Rows[0],
5058
- Dialect,
5059
- TextDb,
5060
- NumericDb,
5061
- BoolDb,
5062
- TimestampDb,
5063
- NullDb
5064
- >
5065
- }) as ValuesInput<
5066
- Rows,
5067
- ValuesOutputShape<Rows[0], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
5068
- Dialect
5069
- >
5070
- }
4954
+ >
5071
4955
 
5072
- const unnest = <
4956
+ export type UnnestApi = <
5073
4957
  Columns extends UnnestColumnsInput,
5074
4958
  Alias extends string
5075
4959
  >(
5076
4960
  columns: Columns,
5077
4961
  alias: Alias
5078
- ): UnnestSource<
4962
+ ) => UnnestSource<
5079
4963
  UnnestOutputShape<Columns, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
5080
4964
  Alias,
5081
4965
  Dialect
5082
- > => {
5083
- const normalizedColumns = normalizeUnnestColumns(columns)
5084
- const columnNames = Object.keys(normalizedColumns)
5085
- if (columnNames.length === 0) {
5086
- throw new Error("unnest(...) requires at least one column array")
5087
- }
5088
- const firstColumn = normalizedColumns[columnNames[0] as keyof typeof normalizedColumns]
5089
- const rowCount = firstColumn?.length ?? 0
5090
- if (rowCount === 0) {
5091
- throw new Error("unnest(...) requires at least one row")
5092
- }
5093
- for (const columnName of columnNames) {
5094
- const values = normalizedColumns[columnName]!
5095
- if (values.length !== rowCount) {
5096
- throw new Error("unnest(...) column arrays must have the same length")
5097
- }
5098
- }
5099
- const firstRow = Object.fromEntries(
5100
- columnNames.map((columnName) => [columnName, normalizedColumns[columnName]![0]!])
5101
- ) as Record<string, Expression.Any>
5102
- const columnsSelection = makeColumnReferenceSelection(alias, firstRow) as any as UnnestOutputShape<
5103
- Columns,
5104
- Dialect,
5105
- TextDb,
5106
- NumericDb,
5107
- BoolDb,
5108
- TimestampDb,
5109
- NullDb
5110
- >
5111
- const source = {
5112
- kind: "unnest",
5113
- name: alias,
5114
- baseName: alias,
5115
- dialect: profile.dialect,
5116
- values: columns,
5117
- arrays: normalizedColumns,
5118
- columns: columnsSelection
5119
- }
5120
- return Object.assign(source, columnsSelection) as unknown as UnnestSource<
5121
- UnnestOutputShape<Columns, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
5122
- Alias,
5123
- Dialect
5124
- >
5125
- }
4966
+ >
5126
4967
 
5127
- const generateSeries = <
4968
+ export type GenerateSeriesApi = <
5128
4969
  Start extends NumericExpressionInput,
5129
4970
  Stop extends NumericExpressionInput,
5130
4971
  Step extends NumericExpressionInput | undefined = undefined,
@@ -5133,54 +4974,19 @@ type AsCurriedResult<
5133
4974
  start: Start,
5134
4975
  stop: Stop,
5135
4976
  step?: Step,
5136
- alias: Alias = "series" as Alias
5137
- ): Dialect extends "postgres"
4977
+ alias?: Alias
4978
+ ) => Dialect extends "postgres"
5138
4979
  ? TableFunctionSource<
5139
4980
  GenerateSeriesOutputShape<Start, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
5140
4981
  Alias,
5141
4982
  Dialect,
5142
4983
  "generate_series"
5143
4984
  >
5144
- : GenerateSeriesUnsupportedError<Dialect> => {
5145
- const startExpression = toDialectNumericExpression(start)
5146
- const stopExpression = toDialectNumericExpression(stop)
5147
- const stepExpression = step === undefined ? undefined : toDialectNumericExpression(step)
5148
- const valueSelection = {
5149
- value: startExpression
5150
- } as Record<string, Expression.Any>
5151
- const columns = makeColumnReferenceSelection(alias, valueSelection) as any as GenerateSeriesOutputShape<
5152
- Start,
5153
- Dialect,
5154
- TextDb,
5155
- NumericDb,
5156
- BoolDb,
5157
- TimestampDb,
5158
- NullDb
5159
- >
5160
- const source = {
5161
- kind: "tableFunction",
5162
- name: alias,
5163
- baseName: alias,
5164
- dialect: profile.dialect,
5165
- functionName: "generate_series",
5166
- args: stepExpression === undefined
5167
- ? [startExpression, stopExpression] as readonly Expression.Any[]
5168
- : [startExpression, stopExpression, stepExpression] as readonly Expression.Any[],
5169
- columns
5170
- }
5171
- return Object.assign(source, columns) as unknown as Dialect extends "postgres"
5172
- ? TableFunctionSource<
5173
- GenerateSeriesOutputShape<Start, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
5174
- Alias,
5175
- Dialect,
5176
- "generate_series"
5177
- >
5178
- : GenerateSeriesUnsupportedError<Dialect>
5179
- }
4985
+ : GenerateSeriesUnsupportedError<Dialect>
5180
4986
 
5181
- const select = <Selection extends SelectionShape>(
4987
+ export type SelectApi = <Selection extends SelectionShape>(
5182
4988
  selection: Selection
5183
- ): QueryPlan<
4989
+ ) => QueryPlan<
5184
4990
  Selection,
5185
4991
  ExtractRequired<Selection>,
5186
4992
  {},
@@ -5191,214 +4997,41 @@ type AsCurriedResult<
5191
4997
  TrueFormula,
5192
4998
  "read",
5193
4999
  "select"
5194
- > =>
5195
- makePlan({
5196
- selection,
5197
- required: extractRequiredRuntime(selection) as ExtractRequired<Selection>,
5198
- available: {},
5199
- dialect: profile.dialect as ExtractDialect<Selection> extends never ? Dialect : ExtractDialect<Selection>
5200
- }, {
5201
- kind: "select",
5202
- select: selection,
5203
- where: [],
5204
- having: [],
5205
- joins: [],
5206
- groupBy: [],
5207
- orderBy: []
5208
- }, undefined as unknown as TrueFormula, "read", "select")
5209
-
5210
- const buildSetOperation = <
5211
- Operator extends QueryAst.SetOperatorKind,
5212
- LeftPlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>,
5213
- RightPlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>
5214
- >(
5215
- kind: Operator,
5216
- all: boolean,
5217
- left: SetCompatiblePlan<LeftPlanValue, Dialect>,
5218
- right: SetCompatibleRightPlan<LeftPlanValue, RightPlanValue, Dialect>
5219
- ): QueryPlan<
5220
- SelectionOfPlan<LeftPlanValue>,
5221
- never,
5222
- {},
5223
- PlanDialectOf<LeftPlanValue> | PlanDialectOf<RightPlanValue>,
5224
- GroupedOfPlan<LeftPlanValue>,
5225
- never,
5226
- never,
5227
- TrueFormula,
5228
- CapabilitiesOfPlan<LeftPlanValue> | CapabilitiesOfPlan<RightPlanValue>,
5229
- "set"
5230
- > => {
5231
- const leftState = left[Plan.TypeId]
5232
- const leftAst = getAst(left)
5233
- const basePlan = leftAst.kind === "set"
5234
- ? leftAst.setBase ?? left
5235
- : left
5236
- const leftOperations = leftAst.kind === "set"
5237
- ? [...(leftAst.setOperations ?? [])]
5238
- : []
5239
- return makePlan({
5240
- selection: leftState.selection as SelectionOfPlan<LeftPlanValue>,
5241
- required: undefined as never,
5242
- available: {},
5243
- dialect: (leftState.dialect ?? right[Plan.TypeId].dialect) as PlanDialectOf<LeftPlanValue> | PlanDialectOf<RightPlanValue>
5244
- }, {
5245
- kind: "set",
5246
- select: leftState.selection,
5247
- where: [],
5248
- having: [],
5249
- joins: [],
5250
- groupBy: [],
5251
- orderBy: [],
5252
- setBase: basePlan,
5253
- setOperations: [
5254
- ...leftOperations,
5255
- {
5256
- kind,
5257
- all,
5258
- query: right
5259
- }
5260
- ]
5261
- }, undefined as unknown as TrueFormula, undefined as unknown as CapabilitiesOfPlan<LeftPlanValue> | CapabilitiesOfPlan<RightPlanValue>, "set")
5262
- }
5263
-
5264
- const union = <
5265
- LeftPlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>,
5266
- RightPlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>
5267
- >(
5268
- left: SetCompatiblePlan<LeftPlanValue, Dialect>,
5269
- right: SetCompatibleRightPlan<LeftPlanValue, RightPlanValue, Dialect>
5270
- ): QueryPlan<
5271
- SelectionOfPlan<LeftPlanValue>,
5272
- never,
5273
- {},
5274
- PlanDialectOf<LeftPlanValue> | PlanDialectOf<RightPlanValue>,
5275
- GroupedOfPlan<LeftPlanValue>,
5276
- never,
5277
- never,
5278
- TrueFormula,
5279
- CapabilitiesOfPlan<LeftPlanValue> | CapabilitiesOfPlan<RightPlanValue>,
5280
- "set"
5281
- > => buildSetOperation("union", false, left as never, right as never) as QueryPlan<
5282
- SelectionOfPlan<LeftPlanValue>,
5283
- never,
5284
- {},
5285
- PlanDialectOf<LeftPlanValue> | PlanDialectOf<RightPlanValue>,
5286
- GroupedOfPlan<LeftPlanValue>,
5287
- never,
5288
- never,
5289
- TrueFormula,
5290
- CapabilitiesOfPlan<LeftPlanValue> | CapabilitiesOfPlan<RightPlanValue>,
5291
- "set"
5292
- >
5293
-
5294
- const unionAll = <
5295
- LeftPlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>,
5296
- RightPlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>
5297
- >(
5298
- left: SetCompatiblePlan<LeftPlanValue, Dialect>,
5299
- right: SetCompatibleRightPlan<LeftPlanValue, RightPlanValue, Dialect>
5300
- ): QueryPlan<
5301
- SelectionOfPlan<LeftPlanValue>,
5302
- never,
5303
- {},
5304
- PlanDialectOf<LeftPlanValue> | PlanDialectOf<RightPlanValue>,
5305
- GroupedOfPlan<LeftPlanValue>,
5306
- never,
5307
- never,
5308
- TrueFormula,
5309
- CapabilitiesOfPlan<LeftPlanValue> | CapabilitiesOfPlan<RightPlanValue>,
5310
- "set"
5311
- > => buildSetOperation("union", true, left as never, right as never) as QueryPlan<
5312
- SelectionOfPlan<LeftPlanValue>,
5313
- never,
5314
- {},
5315
- PlanDialectOf<LeftPlanValue> | PlanDialectOf<RightPlanValue>,
5316
- GroupedOfPlan<LeftPlanValue>,
5317
- never,
5318
- never,
5319
- TrueFormula,
5320
- CapabilitiesOfPlan<LeftPlanValue> | CapabilitiesOfPlan<RightPlanValue>,
5321
- "set"
5322
- >
5323
-
5324
- const intersect = <
5325
- LeftPlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>,
5326
- RightPlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>
5327
- >(
5328
- left: SetCompatiblePlan<LeftPlanValue, Dialect>,
5329
- right: SetCompatibleRightPlan<LeftPlanValue, RightPlanValue, Dialect>
5330
- ): QueryPlan<
5331
- SelectionOfPlan<LeftPlanValue>,
5332
- never,
5333
- {},
5334
- PlanDialectOf<LeftPlanValue> | PlanDialectOf<RightPlanValue>,
5335
- GroupedOfPlan<LeftPlanValue>,
5336
- never,
5337
- never,
5338
- TrueFormula,
5339
- CapabilitiesOfPlan<LeftPlanValue> | CapabilitiesOfPlan<RightPlanValue>,
5340
- "set"
5341
- > => buildSetOperation("intersect", false, left as never, right as never) as QueryPlan<
5342
- SelectionOfPlan<LeftPlanValue>,
5343
- never,
5344
- {},
5345
- PlanDialectOf<LeftPlanValue> | PlanDialectOf<RightPlanValue>,
5346
- GroupedOfPlan<LeftPlanValue>,
5347
- never,
5348
- never,
5349
- TrueFormula,
5350
- CapabilitiesOfPlan<LeftPlanValue> | CapabilitiesOfPlan<RightPlanValue>,
5351
- "set"
5352
5000
  >
5353
5001
 
5354
- const intersectAll = <
5355
- LeftPlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>,
5356
- RightPlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>
5357
- >(
5358
- left: SetCompatiblePlan<LeftPlanValue, Dialect>,
5359
- right: SetCompatibleRightPlan<LeftPlanValue, RightPlanValue, Dialect>
5360
- ): QueryPlan<
5361
- SelectionOfPlan<LeftPlanValue>,
5362
- never,
5363
- {},
5364
- PlanDialectOf<LeftPlanValue> | PlanDialectOf<RightPlanValue>,
5365
- GroupedOfPlan<LeftPlanValue>,
5366
- never,
5367
- never,
5368
- TrueFormula,
5369
- CapabilitiesOfPlan<LeftPlanValue> | CapabilitiesOfPlan<RightPlanValue>,
5370
- "set"
5371
- > => buildSetOperation("intersect", true, left as never, right as never) as QueryPlan<
5372
- SelectionOfPlan<LeftPlanValue>,
5373
- never,
5374
- {},
5375
- PlanDialectOf<LeftPlanValue> | PlanDialectOf<RightPlanValue>,
5376
- GroupedOfPlan<LeftPlanValue>,
5377
- never,
5378
- never,
5379
- TrueFormula,
5380
- CapabilitiesOfPlan<LeftPlanValue> | CapabilitiesOfPlan<RightPlanValue>,
5381
- "set"
5382
- >
5002
+ const {
5003
+ values,
5004
+ unnest,
5005
+ generateSeries,
5006
+ select,
5007
+ groupBy,
5008
+ returning
5009
+ } = makeDslQueryRuntime({
5010
+ profile,
5011
+ ValuesInputProto,
5012
+ normalizeValuesRow,
5013
+ normalizeUnnestColumns,
5014
+ makeColumnReferenceSelection,
5015
+ toDialectNumericExpression,
5016
+ extractRequiredRuntime,
5017
+ makePlan,
5018
+ getAst,
5019
+ getQueryState,
5020
+ currentRequiredList,
5021
+ dedupeGroupedExpressions
5022
+ }) as {
5023
+ readonly values: ValuesApi
5024
+ readonly unnest: UnnestApi
5025
+ readonly generateSeries: GenerateSeriesApi
5026
+ readonly select: SelectApi
5027
+ readonly groupBy: GroupByApi
5028
+ readonly returning: ReturningApi
5029
+ }
5383
5030
 
5384
- const except = <
5031
+ type SetOperationResult<
5385
5032
  LeftPlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>,
5386
5033
  RightPlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>
5387
- >(
5388
- left: SetCompatiblePlan<LeftPlanValue, Dialect>,
5389
- right: SetCompatibleRightPlan<LeftPlanValue, RightPlanValue, Dialect>
5390
- ): QueryPlan<
5391
- SelectionOfPlan<LeftPlanValue>,
5392
- never,
5393
- {},
5394
- PlanDialectOf<LeftPlanValue> | PlanDialectOf<RightPlanValue>,
5395
- GroupedOfPlan<LeftPlanValue>,
5396
- never,
5397
- never,
5398
- TrueFormula,
5399
- CapabilitiesOfPlan<LeftPlanValue> | CapabilitiesOfPlan<RightPlanValue>,
5400
- "set"
5401
- > => buildSetOperation("except", false, left as never, right as never) as QueryPlan<
5034
+ > = QueryPlan<
5402
5035
  SelectionOfPlan<LeftPlanValue>,
5403
5036
  never,
5404
5037
  {},
@@ -5411,42 +5044,20 @@ type AsCurriedResult<
5411
5044
  "set"
5412
5045
  >
5413
5046
 
5414
- const exceptAll = <
5047
+ type SetOperationApi = <
5415
5048
  LeftPlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>,
5416
5049
  RightPlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>
5417
5050
  >(
5418
5051
  left: SetCompatiblePlan<LeftPlanValue, Dialect>,
5419
5052
  right: SetCompatibleRightPlan<LeftPlanValue, RightPlanValue, Dialect>
5420
- ): QueryPlan<
5421
- SelectionOfPlan<LeftPlanValue>,
5422
- never,
5423
- {},
5424
- PlanDialectOf<LeftPlanValue> | PlanDialectOf<RightPlanValue>,
5425
- GroupedOfPlan<LeftPlanValue>,
5426
- never,
5427
- never,
5428
- TrueFormula,
5429
- CapabilitiesOfPlan<LeftPlanValue> | CapabilitiesOfPlan<RightPlanValue>,
5430
- "set"
5431
- > => buildSetOperation("except", true, left as never, right as never) as QueryPlan<
5432
- SelectionOfPlan<LeftPlanValue>,
5433
- never,
5434
- {},
5435
- PlanDialectOf<LeftPlanValue> | PlanDialectOf<RightPlanValue>,
5436
- GroupedOfPlan<LeftPlanValue>,
5437
- never,
5438
- never,
5439
- TrueFormula,
5440
- CapabilitiesOfPlan<LeftPlanValue> | CapabilitiesOfPlan<RightPlanValue>,
5441
- "set"
5442
- >
5053
+ ) => SetOperationResult<LeftPlanValue, RightPlanValue>
5443
5054
 
5444
- const where = <Predicate extends PredicateInput>(
5055
+ type WhereApi = <Predicate extends PredicateInput>(
5445
5056
  predicate: Predicate
5446
5057
  ) =>
5447
5058
  <PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
5448
5059
  plan: PlanValue & RequireWhereStatement<PlanValue>
5449
- ): QueryPlan<
5060
+ ) => QueryPlan<
5450
5061
  SelectionOfPlan<PlanValue>,
5451
5062
  AddExpressionRequired<RequiredOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, Predicate>,
5452
5063
  AvailableOfPlan<PlanValue>,
@@ -5457,131 +5068,21 @@ type AsCurriedResult<
5457
5068
  PlanAssumptionsAfterWhere<PlanValue, Predicate, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
5458
5069
  CapabilitiesOfPlan<PlanValue>,
5459
5070
  StatementOfPlan<PlanValue>
5460
- > => {
5461
- const current = plan[Plan.TypeId]
5462
- const currentAst = getAst(plan)
5463
- const currentQuery = getQueryState(plan)
5464
- const predicateExpression = toDialectExpression(predicate)
5465
- const predicateRequired = extractRequiredFromDialectInputRuntime(predicate)
5466
- return makePlan({
5467
- selection: current.selection,
5468
- required: [...currentRequiredList(current.required), ...predicateRequired].filter((name, index, values) =>
5469
- !(name in current.available) && values.indexOf(name) === index) as AddExpressionRequired<RequiredOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, Predicate>,
5470
- available: current.available,
5471
- dialect: current.dialect as PlanDialectOf<PlanValue> | DialectOfDialectInput<Predicate, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
5472
- }, {
5473
- ...currentAst,
5474
- where: [...currentAst.where, {
5475
- kind: "where",
5476
- predicate: predicateExpression
5477
- }]
5478
- },
5479
- assumeFormulaTrue(
5480
- currentQuery.assumptions,
5481
- formulaOfExpressionRuntime(predicateExpression)
5482
- ) as PlanAssumptionsAfterWhere<PlanValue, Predicate, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
5483
- currentQuery.capabilities,
5484
- currentQuery.statement as StatementOfPlan<PlanValue>)
5485
- }
5071
+ >
5486
5072
 
5487
- const from = <CurrentSource extends FromInput>(
5073
+ export type FromApi = <CurrentSource extends FromInput>(
5488
5074
  source: CurrentSource
5489
5075
  ) =>
5490
5076
  <PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
5491
5077
  plan: PlanValue & FromPlanConstraint<PlanValue, CurrentSource, Dialect>
5492
- ): FromPlanResult<PlanValue, CurrentSource, Dialect> => {
5493
- const current = plan[Plan.TypeId]
5494
- const currentAst = getAst(plan)
5495
- const currentQuery = getQueryState(plan)
5496
-
5497
- if (currentQuery.statement === "insert") {
5498
- return attachInsertSource(
5499
- plan as QueryPlan<any, any, any, any, any, any, any, any, any, "insert", MutationTargetLike, "missing">,
5500
- source as AnyValuesInput | AnyValuesSource | AnyUnnestSource | CompletePlan<QueryPlan<any, any, any, any, any, any, any, any, any, any>>
5501
- ) as FromPlanResult<PlanValue, CurrentSource, Dialect>
5502
- }
5503
-
5504
- if (
5505
- typeof source !== "object" ||
5506
- source === null ||
5507
- ("kind" in source && source.kind === "values" && !("name" in source)) ||
5508
- (!(Table.TypeId in source) && !("name" in source && "baseName" in source))
5509
- ) {
5510
- throw new Error("from(...) requires an aliased source in select/update statements")
5511
- }
5078
+ ) => FromPlanResult<PlanValue, CurrentSource, Dialect>
5512
5079
 
5513
- const sourceLike = source as SourceLike
5514
- const { sourceName, sourceBaseName } = sourceDetails(sourceLike)
5515
- const presenceWitnesses = presenceWitnessesOfSourceLike(sourceLike)
5516
-
5517
- if (currentQuery.statement === "select") {
5518
- const nextAst = {
5519
- ...currentAst,
5520
- from: {
5521
- kind: "from",
5522
- tableName: sourceName,
5523
- baseTableName: sourceBaseName,
5524
- source: sourceLike
5525
- }
5526
- } as QueryAst.Ast<Record<string, unknown>, any, "select">
5527
- return makePlan({
5528
- selection: current.selection,
5529
- required: currentRequiredList(current.required).filter((name) =>
5530
- name !== sourceName),
5531
- available: {
5532
- [sourceName]: {
5533
- name: sourceName,
5534
- mode: "required",
5535
- baseName: sourceBaseName,
5536
- _presentFormula: trueFormula(),
5537
- _presenceWitnesses: presenceWitnesses
5538
- }
5539
- } as AddAvailable<{}, string, "required", TrueFormula, PresenceWitnessKeysOfSource<Extract<CurrentSource, SourceLike>>>,
5540
- dialect: current.dialect
5541
- }, nextAst, currentQuery.assumptions, currentQuery.capabilities, currentQuery.statement) as FromPlanResult<PlanValue, CurrentSource, Dialect>
5542
- }
5543
-
5544
- if (currentQuery.statement === "update") {
5545
- const nextAvailable = {
5546
- ...current.available,
5547
- [sourceName]: {
5548
- name: sourceName,
5549
- mode: "required" as const,
5550
- baseName: sourceBaseName,
5551
- _presentFormula: trueFormula(),
5552
- _presenceWitnesses: presenceWitnesses
5553
- }
5554
- }
5555
- const nextAst = {
5556
- ...currentAst,
5557
- fromSources: [
5558
- ...(currentAst.fromSources ?? []),
5559
- {
5560
- kind: "from" as const,
5561
- tableName: sourceName,
5562
- baseTableName: sourceBaseName,
5563
- source: sourceLike
5564
- }
5565
- ]
5566
- } as QueryAst.Ast<Record<string, unknown>, any, "update">
5567
- return makePlan({
5568
- selection: current.selection,
5569
- required: currentRequiredList(current.required).filter((name) =>
5570
- !(name in nextAvailable)),
5571
- available: nextAvailable,
5572
- dialect: current.dialect
5573
- }, nextAst, currentQuery.assumptions, currentQuery.capabilities, currentQuery.statement) as FromPlanResult<PlanValue, CurrentSource, Dialect>
5574
- }
5575
-
5576
- throw new Error(`from(...) is not supported for ${currentQuery.statement} statements`)
5577
- }
5578
-
5579
- const having = <Predicate extends HavingPredicateInput>(
5080
+ type HavingApi = <Predicate extends HavingPredicateInput>(
5580
5081
  predicate: Predicate
5581
5082
  ) =>
5582
5083
  <PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
5583
5084
  plan: PlanValue & RequireSelectStatement<PlanValue>
5584
- ): QueryPlan<
5085
+ ) => QueryPlan<
5585
5086
  SelectionOfPlan<PlanValue>,
5586
5087
  AddExpressionRequired<RequiredOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, Predicate>,
5587
5088
  AvailableOfPlan<PlanValue>,
@@ -5592,57 +5093,9 @@ type AsCurriedResult<
5592
5093
  PlanAssumptionsAfterHaving<PlanValue, Predicate, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
5593
5094
  CapabilitiesOfPlan<PlanValue>,
5594
5095
  StatementOfPlan<PlanValue>
5595
- > => {
5596
- const current = plan[Plan.TypeId]
5597
- const currentAst = getAst(plan)
5598
- const currentQuery = getQueryState(plan)
5599
- const predicateExpression = toDialectExpression(predicate)
5600
- const predicateRequired = extractRequiredFromDialectInputRuntime(predicate)
5601
- return makePlan({
5602
- selection: current.selection,
5603
- required: [...currentRequiredList(current.required), ...predicateRequired].filter((name, index, values) =>
5604
- !(name in current.available) && values.indexOf(name) === index) as AddExpressionRequired<RequiredOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, Predicate>,
5605
- available: current.available,
5606
- dialect: current.dialect as PlanDialectOf<PlanValue> | DialectOfDialectInput<Predicate, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
5607
- }, {
5608
- ...currentAst,
5609
- having: [...currentAst.having, {
5610
- kind: "having",
5611
- predicate: predicateExpression
5612
- }]
5613
- }, assumeFormulaTrue(
5614
- currentQuery.assumptions,
5615
- formulaOfExpressionRuntime(predicateExpression)
5616
- ) as PlanAssumptionsAfterHaving<PlanValue, Predicate, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
5617
- currentQuery.capabilities,
5618
- currentQuery.statement as StatementOfPlan<PlanValue>)
5619
- }
5620
-
5621
- const innerJoin = <CurrentTable extends SourceLike, Predicate extends PredicateInput>(
5622
- table: CurrentTable,
5623
- on: Predicate
5624
- ) =>
5625
- join("inner", table, on)
5626
-
5627
- const leftJoin = <CurrentTable extends SourceLike, Predicate extends PredicateInput>(
5628
- table: CurrentTable,
5629
- on: Predicate
5630
- ) =>
5631
- join("left", table, on)
5632
-
5633
- const rightJoin = <CurrentTable extends SourceLike, Predicate extends PredicateInput>(
5634
- table: CurrentTable,
5635
- on: Predicate
5636
- ) =>
5637
- join("right", table, on)
5638
-
5639
- const fullJoin = <CurrentTable extends SourceLike, Predicate extends PredicateInput>(
5640
- table: CurrentTable,
5641
- on: Predicate
5642
- ) =>
5643
- join("full", table, on)
5096
+ >
5644
5097
 
5645
- const crossJoin = <CurrentTable extends SourceLike>(
5098
+ type CrossJoinApi = <CurrentTable extends SourceLike>(
5646
5099
  table: CurrentTable
5647
5100
  ) =>
5648
5101
  <PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
@@ -5651,7 +5104,7 @@ type AsCurriedResult<
5651
5104
  ) & (
5652
5105
  SourceNameOf<CurrentTable> extends ScopedNamesOfPlan<PlanValue> ? never : unknown
5653
5106
  )
5654
- ): QueryPlan<
5107
+ ) => QueryPlan<
5655
5108
  SelectionOfPlan<PlanValue>,
5656
5109
  AddJoinRequired<RequiredOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, never, "cross">,
5657
5110
  AddAvailable<
@@ -5668,49 +5121,9 @@ type AsCurriedResult<
5668
5121
  AssumptionsOfPlan<PlanValue>,
5669
5122
  MergeCapabilities<CapabilitiesOfPlan<PlanValue>, SourceCapabilitiesOf<CurrentTable>>,
5670
5123
  StatementOfPlan<PlanValue>
5671
- > => {
5672
- const current = plan[Plan.TypeId]
5673
- const currentAst = getAst(plan)
5674
- const currentQuery = getQueryState(plan)
5675
- const { sourceName, sourceBaseName } = sourceDetails(table)
5676
- const presenceWitnesses = presenceWitnessesOfSourceLike(table)
5677
- const nextAvailable = Object.assign(
5678
- {},
5679
- current.available as AvailableOfPlan<PlanValue>,
5680
- {
5681
- [sourceName]: {
5682
- name: sourceName,
5683
- mode: "required",
5684
- baseName: sourceBaseName,
5685
- _presentFormula: trueFormula(),
5686
- _presenceWitnesses: presenceWitnesses
5687
- }
5688
- }
5689
- ) as AddAvailable<
5690
- AvailableOfPlan<PlanValue>,
5691
- SourceNameOf<CurrentTable>,
5692
- "required",
5693
- TrueFormula,
5694
- PresenceWitnessKeysOfSource<CurrentTable>
5695
- >
5696
- return makePlan({
5697
- selection: current.selection,
5698
- required: currentRequiredList(current.required).filter((name) =>
5699
- !(name in nextAvailable)) as AddJoinRequired<RequiredOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, never, "cross">,
5700
- available: nextAvailable,
5701
- dialect: current.dialect as PlanDialectOf<PlanValue> | SourceDialectOf<CurrentTable>
5702
- }, {
5703
- ...currentAst,
5704
- joins: [...currentAst.joins, {
5705
- kind: "cross",
5706
- tableName: sourceName,
5707
- baseTableName: sourceBaseName,
5708
- source: table
5709
- }]
5710
- }, currentQuery.assumptions, currentQuery.capabilities as MergeCapabilities<CapabilitiesOfPlan<PlanValue>, SourceCapabilitiesOf<CurrentTable>>, currentQuery.statement as StatementOfPlan<PlanValue>)
5711
- }
5124
+ >
5712
5125
 
5713
- const join = <
5126
+ type JoinApi = <
5714
5127
  Kind extends QueryAst.JoinKind,
5715
5128
  CurrentTable extends SourceLike,
5716
5129
  Predicate extends PredicateInput
@@ -5725,7 +5138,7 @@ type AsCurriedResult<
5725
5138
  ) & (
5726
5139
  SourceNameOf<CurrentTable> extends ScopedNamesOfPlan<PlanValue> ? never : unknown
5727
5140
  )
5728
- ): QueryPlan<
5141
+ ) => QueryPlan<
5729
5142
  SelectionOfPlan<PlanValue>,
5730
5143
  AddJoinRequired<RequiredOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, Predicate, Kind>,
5731
5144
  AvailableAfterJoin<
@@ -5742,72 +5155,47 @@ type AsCurriedResult<
5742
5155
  PlanAssumptionsAfterJoin<PlanValue, Predicate, Kind, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
5743
5156
  MergeCapabilities<CapabilitiesOfPlan<PlanValue>, SourceCapabilitiesOf<CurrentTable>>,
5744
5157
  StatementOfPlan<PlanValue>
5745
- > => {
5746
- const current = plan[Plan.TypeId]
5747
- const currentAst = getAst(plan)
5748
- const currentQuery = getQueryState(plan)
5749
- const onExpression = toDialectExpression(on)
5750
- const onFormula = formulaOfExpressionRuntime(onExpression)
5751
- const { sourceName, sourceBaseName } = sourceDetails(table)
5752
- const presenceWitnesses = presenceWitnessesOfSourceLike(table)
5753
- const baseAvailable = (kind === "right" || kind === "full"
5754
- ? Object.fromEntries(
5755
- Object.entries(current.available as Record<string, Plan.AnySource>).map(([name, source]) => [name, {
5756
- name: source.name,
5757
- mode: "optional" as const,
5758
- baseName: source.baseName,
5759
- _presentFormula: source._presentFormula,
5760
- _presenceWitnesses: source._presenceWitnesses
5761
- }])
5762
- )
5763
- : current.available) as AvailableOfPlan<PlanValue>
5764
- const nextAvailable = {
5765
- ...baseAvailable,
5766
- [sourceName]: {
5767
- name: sourceName,
5768
- mode: (kind === "left" || kind === "full" ? "optional" : "required") as JoinSourceMode<Kind>,
5769
- baseName: sourceBaseName,
5770
- _presentFormula: (kind === "inner" || kind === "left") ? onFormula : trueFormula(),
5771
- _presenceWitnesses: presenceWitnesses
5772
- }
5773
- } as AvailableAfterJoin<
5158
+ >
5159
+
5160
+ type BinaryJoinApi<Kind extends QueryAst.JoinKind> = <
5161
+ CurrentTable extends SourceLike,
5162
+ Predicate extends PredicateInput
5163
+ >(
5164
+ table: CurrentTable,
5165
+ on: Predicate
5166
+ ) =>
5167
+ <PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
5168
+ plan: PlanValue & RequireJoinStatement<PlanValue> & (
5169
+ keyof AvailableOfPlan<PlanValue> extends never ? never : unknown
5170
+ ) & (
5171
+ SourceNameOf<CurrentTable> extends ScopedNamesOfPlan<PlanValue> ? never : unknown
5172
+ )
5173
+ ) => QueryPlan<
5174
+ SelectionOfPlan<PlanValue>,
5175
+ AddJoinRequired<RequiredOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, Predicate, Kind>,
5176
+ AvailableAfterJoin<
5774
5177
  AvailableOfPlan<PlanValue>,
5775
5178
  SourceNameOf<CurrentTable>,
5776
5179
  Kind,
5777
5180
  JoinPresenceFormula<Kind, Predicate, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
5778
5181
  PresenceWitnessKeysOfSource<CurrentTable>
5779
- >
5780
- return makePlan({
5781
- selection: current.selection,
5782
- required: [...currentRequiredList(current.required), ...extractRequiredFromDialectInputRuntime(on)].filter((name, index, values) =>
5783
- !(name in nextAvailable) && values.indexOf(name) === index) as AddJoinRequired<RequiredOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, Predicate, Kind>,
5784
- available: nextAvailable,
5785
- dialect: current.dialect as PlanDialectOf<PlanValue> | SourceDialectOf<CurrentTable> | DialectOfDialectInput<Predicate, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
5786
- }, {
5787
- ...currentAst,
5788
- joins: [...currentAst.joins, {
5789
- kind,
5790
- tableName: sourceName,
5791
- baseTableName: sourceBaseName,
5792
- source: table,
5793
- on: onExpression
5794
- }]
5795
- }, (
5796
- kind === "inner"
5797
- ? assumeFormulaTrue(currentQuery.assumptions, onFormula)
5798
- : currentQuery.assumptions
5799
- ) as PlanAssumptionsAfterJoin<PlanValue, Predicate, Kind, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
5800
- currentQuery.capabilities as MergeCapabilities<CapabilitiesOfPlan<PlanValue>, SourceCapabilitiesOf<CurrentTable>>,
5801
- currentQuery.statement as StatementOfPlan<PlanValue>)
5802
- }
5182
+ >,
5183
+ PlanDialectOf<PlanValue> | SourceDialectOf<CurrentTable> | DialectOfDialectInput<Predicate, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
5184
+ GroupedOfPlan<PlanValue>,
5185
+ ScopedNamesOfPlan<PlanValue> | SourceNameOf<CurrentTable>,
5186
+ AddJoinRequired<OutstandingOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, Predicate, Kind>,
5187
+ PlanAssumptionsAfterJoin<PlanValue, Predicate, Kind, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
5188
+ MergeCapabilities<CapabilitiesOfPlan<PlanValue>, SourceCapabilitiesOf<CurrentTable>>,
5189
+ StatementOfPlan<PlanValue>
5190
+ >
5803
5191
 
5804
- const orderBy = <Value extends ExpressionInput>(
5192
+ type OrderByApi = <Value extends ExpressionInput>(
5805
5193
  value: Value,
5806
- direction: OrderDirection = "asc"
5194
+ direction?: OrderDirection
5807
5195
  ) =>
5808
5196
  <PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
5809
5197
  plan: PlanValue & MutationOrderLimitSupported<PlanValue, Dialect>
5810
- ): QueryPlan<
5198
+ ) => QueryPlan<
5811
5199
  SelectionOfPlan<PlanValue>,
5812
5200
  AddExpressionRequired<RequiredOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, Value>,
5813
5201
  AvailableOfPlan<PlanValue>,
@@ -5818,79 +5206,12 @@ type AsCurriedResult<
5818
5206
  AssumptionsOfPlan<PlanValue>,
5819
5207
  CapabilitiesOfPlan<PlanValue>,
5820
5208
  StatementOfPlan<PlanValue>
5821
- > => {
5822
- const current = plan[Plan.TypeId]
5823
- const currentAst = getAst(plan)
5824
- const currentQuery = getQueryState(plan)
5825
- const expression = toDialectExpression(value)
5826
- const required = extractRequiredFromDialectInputRuntime(value)
5827
- return makePlan({
5828
- selection: current.selection,
5829
- required: [...currentRequiredList(current.required), ...required].filter((name, index, values) =>
5830
- !(name in current.available) && values.indexOf(name) === index) as AddExpressionRequired<RequiredOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, Value>,
5831
- available: current.available,
5832
- dialect: current.dialect as PlanDialectOf<PlanValue> | DialectOfDialectInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
5833
- }, {
5834
- ...currentAst,
5835
- orderBy: [...currentAst.orderBy, {
5836
- kind: "orderBy",
5837
- value: expression,
5838
- direction
5839
- }]
5840
- }, currentQuery.assumptions, currentQuery.capabilities, currentQuery.statement as StatementOfPlan<PlanValue>)
5841
- }
5209
+ >
5842
5210
 
5843
- function lock(
5844
- mode: "update" | "share",
5845
- options?: LockOptions
5846
- ): <PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
5847
- plan: PlanValue & (StatementOfPlan<PlanValue> extends "select" ? unknown : never)
5848
- ) => QueryPlan<
5849
- SelectionOfPlan<PlanValue>,
5850
- RequiredOfPlan<PlanValue>,
5851
- AvailableOfPlan<PlanValue>,
5852
- PlanDialectOf<PlanValue>,
5853
- GroupedOfPlan<PlanValue>,
5854
- ScopedNamesOfPlan<PlanValue>,
5855
- OutstandingOfPlan<PlanValue>,
5856
- AssumptionsOfPlan<PlanValue>,
5857
- MergeCapabilities<CapabilitiesOfPlan<PlanValue>, "transaction">,
5858
- StatementOfPlan<PlanValue>
5859
- >
5860
- function lock<
5861
- Mode extends Dialect extends "mysql" ? "lowPriority" | "ignore" | "quick" : never
5862
- >(
5863
- mode: Mode,
5864
- options?: LockOptions
5865
- ): <PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
5866
- plan: PlanValue & (
5867
- Dialect extends "mysql"
5868
- ? StatementOfPlan<PlanValue> extends "update"
5869
- ? Mode extends MutationLockModeForStatement<"update", Dialect> ? unknown : never
5870
- : StatementOfPlan<PlanValue> extends "delete"
5871
- ? Mode extends MutationLockModeForStatement<"delete", Dialect> ? unknown : never
5872
- : never
5873
- : never
5874
- )
5875
- ) => QueryPlan<
5876
- SelectionOfPlan<PlanValue>,
5877
- RequiredOfPlan<PlanValue>,
5878
- AvailableOfPlan<PlanValue>,
5879
- PlanDialectOf<PlanValue>,
5880
- GroupedOfPlan<PlanValue>,
5881
- ScopedNamesOfPlan<PlanValue>,
5882
- OutstandingOfPlan<PlanValue>,
5883
- AssumptionsOfPlan<PlanValue>,
5884
- MergeCapabilities<CapabilitiesOfPlan<PlanValue>, "transaction">,
5885
- StatementOfPlan<PlanValue>
5886
- >
5887
- function lock(
5888
- mode: QueryAst.LockClause["mode"],
5889
- options: LockOptions = {}
5890
- ) {
5891
- return <PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
5892
- plan: PlanValue
5893
- ): QueryPlan<
5211
+ interface LockApi {
5212
+ (mode: "update" | "share", options?: LockOptions): <PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
5213
+ plan: PlanValue & (StatementOfPlan<PlanValue> extends "select" ? unknown : never)
5214
+ ) => QueryPlan<
5894
5215
  SelectionOfPlan<PlanValue>,
5895
5216
  RequiredOfPlan<PlanValue>,
5896
5217
  AvailableOfPlan<PlanValue>,
@@ -5901,31 +5222,38 @@ type AsCurriedResult<
5901
5222
  AssumptionsOfPlan<PlanValue>,
5902
5223
  MergeCapabilities<CapabilitiesOfPlan<PlanValue>, "transaction">,
5903
5224
  StatementOfPlan<PlanValue>
5904
- > => {
5905
- const current = plan[Plan.TypeId]
5906
- const currentAst = getAst(plan)
5907
- const currentQuery = getQueryState(plan)
5908
- return makePlan({
5909
- selection: current.selection,
5910
- required: current.required as RequiredOfPlan<PlanValue>,
5911
- available: current.available,
5912
- dialect: current.dialect as PlanDialectOf<PlanValue>
5913
- }, {
5914
- ...currentAst,
5915
- lock: {
5916
- kind: "lock",
5917
- mode,
5918
- nowait: options.nowait ?? false,
5919
- skipLocked: options.skipLocked ?? false
5920
- }
5921
- }, currentQuery.assumptions, currentQuery.capabilities, currentQuery.statement as StatementOfPlan<PlanValue>)
5922
- }
5225
+ >
5226
+ <Mode extends Dialect extends "mysql" ? "lowPriority" | "ignore" | "quick" : never>(
5227
+ mode: Mode,
5228
+ options?: LockOptions
5229
+ ): <PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
5230
+ plan: PlanValue & (
5231
+ Dialect extends "mysql"
5232
+ ? StatementOfPlan<PlanValue> extends "update"
5233
+ ? Mode extends MutationLockModeForStatement<"update", Dialect> ? unknown : never
5234
+ : StatementOfPlan<PlanValue> extends "delete"
5235
+ ? Mode extends MutationLockModeForStatement<"delete", Dialect> ? unknown : never
5236
+ : never
5237
+ : never
5238
+ )
5239
+ ) => QueryPlan<
5240
+ SelectionOfPlan<PlanValue>,
5241
+ RequiredOfPlan<PlanValue>,
5242
+ AvailableOfPlan<PlanValue>,
5243
+ PlanDialectOf<PlanValue>,
5244
+ GroupedOfPlan<PlanValue>,
5245
+ ScopedNamesOfPlan<PlanValue>,
5246
+ OutstandingOfPlan<PlanValue>,
5247
+ AssumptionsOfPlan<PlanValue>,
5248
+ MergeCapabilities<CapabilitiesOfPlan<PlanValue>, "transaction">,
5249
+ StatementOfPlan<PlanValue>
5250
+ >
5923
5251
  }
5924
5252
 
5925
- const distinct = () =>
5253
+ type DistinctApi = () =>
5926
5254
  <PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
5927
5255
  plan: PlanValue & RequireSelectStatement<PlanValue>
5928
- ): QueryPlan<
5256
+ ) => QueryPlan<
5929
5257
  SelectionOfPlan<PlanValue>,
5930
5258
  RequiredOfPlan<PlanValue>,
5931
5259
  AvailableOfPlan<PlanValue>,
@@ -5936,33 +5264,14 @@ type AsCurriedResult<
5936
5264
  AssumptionsOfPlan<PlanValue>,
5937
5265
  CapabilitiesOfPlan<PlanValue>,
5938
5266
  StatementOfPlan<PlanValue>
5939
- > => {
5940
- const current = plan[Plan.TypeId]
5941
- const currentAst = getAst(plan)
5942
- const currentQuery = getQueryState(plan)
5943
- return makePlan({
5944
- selection: current.selection,
5945
- required: current.required as RequiredOfPlan<PlanValue>,
5946
- available: current.available,
5947
- dialect: current.dialect as PlanDialectOf<PlanValue>
5948
- }, {
5949
- ...currentAst,
5950
- distinct: true
5951
- }, currentQuery.assumptions, currentQuery.capabilities, currentQuery.statement as StatementOfPlan<PlanValue>)
5952
- }
5953
-
5954
- const distinctOn = {
5955
- __effect_qb_error__: "effect-qb: distinctOn(...) is only supported by the postgres dialect",
5956
- __effect_qb_dialect__: profile.dialect,
5957
- __effect_qb_hint__: "Use postgres.Query.distinctOn(...) or regular distinct()/grouping logic"
5958
- } as DistinctOnApi<Dialect>
5267
+ >
5959
5268
 
5960
- const limit = <Value extends NumericExpressionInput>(
5269
+ type LimitApi = <Value extends NumericExpressionInput>(
5961
5270
  value: Value
5962
5271
  ) =>
5963
5272
  <PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
5964
5273
  plan: PlanValue & MutationOrderLimitSupported<PlanValue, Dialect>
5965
- ): QueryPlan<
5274
+ ) => QueryPlan<
5966
5275
  SelectionOfPlan<PlanValue>,
5967
5276
  AddExpressionRequired<RequiredOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, DialectAsNumericExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
5968
5277
  AvailableOfPlan<PlanValue>,
@@ -5973,30 +5282,14 @@ type AsCurriedResult<
5973
5282
  AssumptionsOfPlan<PlanValue>,
5974
5283
  CapabilitiesOfPlan<PlanValue>,
5975
5284
  StatementOfPlan<PlanValue>
5976
- > => {
5977
- const current = plan[Plan.TypeId]
5978
- const currentAst = getAst(plan)
5979
- const currentQuery = getQueryState(plan)
5980
- const expression = toDialectNumericExpression(value)
5981
- const required = extractRequiredFromDialectNumericInputRuntime(value)
5982
- return makePlan({
5983
- selection: current.selection,
5984
- required: [...currentRequiredList(current.required), ...required].filter((name, index, values) =>
5985
- !(name in current.available) && values.indexOf(name) === index) as AddExpressionRequired<RequiredOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, DialectAsNumericExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
5986
- available: current.available,
5987
- dialect: current.dialect as PlanDialectOf<PlanValue> | DialectOfDialectNumericInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
5988
- }, {
5989
- ...currentAst,
5990
- limit: expression
5991
- }, currentQuery.assumptions, currentQuery.capabilities, currentQuery.statement as StatementOfPlan<PlanValue>)
5992
- }
5285
+ >
5993
5286
 
5994
- const offset = <Value extends NumericExpressionInput>(
5287
+ type OffsetApi = <Value extends NumericExpressionInput>(
5995
5288
  value: Value
5996
5289
  ) =>
5997
5290
  <PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
5998
5291
  plan: PlanValue & RequireSelectStatement<PlanValue>
5999
- ): QueryPlan<
5292
+ ) => QueryPlan<
6000
5293
  SelectionOfPlan<PlanValue>,
6001
5294
  AddExpressionRequired<RequiredOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, DialectAsNumericExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
6002
5295
  AvailableOfPlan<PlanValue>,
@@ -6007,30 +5300,88 @@ type AsCurriedResult<
6007
5300
  AssumptionsOfPlan<PlanValue>,
6008
5301
  CapabilitiesOfPlan<PlanValue>,
6009
5302
  StatementOfPlan<PlanValue>
6010
- > => {
6011
- const current = plan[Plan.TypeId]
6012
- const currentAst = getAst(plan)
6013
- const currentQuery = getQueryState(plan)
6014
- const expression = toDialectNumericExpression(value)
6015
- const required = extractRequiredFromDialectNumericInputRuntime(value)
6016
- return makePlan({
6017
- selection: current.selection,
6018
- required: [...currentRequiredList(current.required), ...required].filter((name, index, values) =>
6019
- !(name in current.available) && values.indexOf(name) === index) as AddExpressionRequired<RequiredOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, DialectAsNumericExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
6020
- available: current.available,
6021
- dialect: current.dialect as PlanDialectOf<PlanValue> | DialectOfDialectNumericInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
6022
- }, {
6023
- ...currentAst,
6024
- offset: expression
6025
- }, currentQuery.assumptions, currentQuery.capabilities, currentQuery.statement as StatementOfPlan<PlanValue>)
6026
- }
5303
+ >
5304
+
5305
+ const {
5306
+ buildSetOperation,
5307
+ where,
5308
+ from,
5309
+ having,
5310
+ crossJoin,
5311
+ join,
5312
+ orderBy,
5313
+ lock,
5314
+ distinct,
5315
+ limit,
5316
+ offset
5317
+ } = makeDslPlanRuntime({
5318
+ profile,
5319
+ makePlan,
5320
+ getAst,
5321
+ getQueryState,
5322
+ currentRequiredList,
5323
+ toDialectExpression,
5324
+ toDialectNumericExpression,
5325
+ extractRequiredFromDialectInputRuntime,
5326
+ extractRequiredFromDialectNumericInputRuntime,
5327
+ formulaOfExpressionRuntime,
5328
+ assumeFormulaTrue,
5329
+ trueFormula,
5330
+ sourceDetails,
5331
+ presenceWitnessesOfSourceLike,
5332
+ attachInsertSource: (...args) => attachInsertSource(args[0], args[1])
5333
+ }) as {
5334
+ readonly buildSetOperation: (kind: QueryAst.SetOperatorKind, all: boolean, left: any, right: any) => any
5335
+ readonly where: WhereApi
5336
+ readonly from: FromApi
5337
+ readonly having: HavingApi
5338
+ readonly crossJoin: CrossJoinApi
5339
+ readonly join: JoinApi
5340
+ readonly orderBy: OrderByApi
5341
+ readonly lock: LockApi
5342
+ readonly distinct: DistinctApi
5343
+ readonly limit: LimitApi
5344
+ readonly offset: OffsetApi
5345
+ }
5346
+
5347
+ const union = ((left, right) =>
5348
+ buildSetOperation("union", false, left as never, right as never)) as SetOperationApi
5349
+
5350
+ const unionAll = ((left, right) =>
5351
+ buildSetOperation("union", true, left as never, right as never)) as SetOperationApi
5352
+
5353
+ const intersect = ((left, right) =>
5354
+ buildSetOperation("intersect", false, left as never, right as never)) as SetOperationApi
5355
+
5356
+ const intersectAll = ((left, right) =>
5357
+ buildSetOperation("intersect", true, left as never, right as never)) as SetOperationApi
5358
+
5359
+ const except = ((left, right) =>
5360
+ buildSetOperation("except", false, left as never, right as never)) as SetOperationApi
5361
+
5362
+ const exceptAll = ((left, right) =>
5363
+ buildSetOperation("except", true, left as never, right as never)) as SetOperationApi
6027
5364
 
6028
- const groupBy = <Values extends readonly [GroupByInput, ...GroupByInput[]]>(
5365
+ const innerJoin = ((table, on) => (join as any)("inner", table, on)) as BinaryJoinApi<"inner">
5366
+
5367
+ const leftJoin = ((table, on) => (join as any)("left", table, on)) as BinaryJoinApi<"left">
5368
+
5369
+ const rightJoin = ((table, on) => (join as any)("right", table, on)) as BinaryJoinApi<"right">
5370
+
5371
+ const fullJoin = ((table, on) => (join as any)("full", table, on)) as BinaryJoinApi<"full">
5372
+
5373
+ const distinctOn = {
5374
+ __effect_qb_error__: "effect-qb: distinctOn(...) is only supported by the postgres dialect",
5375
+ __effect_qb_dialect__: profile.dialect,
5376
+ __effect_qb_hint__: "Use postgres.Query.distinctOn(...) or regular distinct()/grouping logic"
5377
+ } as DistinctOnApi<Dialect>
5378
+
5379
+ type GroupByApi = <Values extends readonly [GroupByInput, ...GroupByInput[]]>(
6029
5380
  ...values: Values
6030
5381
  ) =>
6031
5382
  <PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
6032
5383
  plan: PlanValue & RequireSelectStatement<PlanValue>
6033
- ): QueryPlan<
5384
+ ) => QueryPlan<
6034
5385
  SelectionOfPlan<PlanValue>,
6035
5386
  Exclude<RequiredOfPlan<PlanValue> | RequiredFromDependencies<TupleDependencies<Values>>, AvailableNames<AvailableOfPlan<PlanValue>>>,
6036
5387
  AvailableOfPlan<PlanValue>,
@@ -6041,30 +5392,14 @@ type AsCurriedResult<
6041
5392
  AssumptionsOfPlan<PlanValue>,
6042
5393
  CapabilitiesOfPlan<PlanValue>,
6043
5394
  StatementOfPlan<PlanValue>
6044
- > => {
6045
- const current = plan[Plan.TypeId]
6046
- const currentAst = getAst(plan)
6047
- const currentQuery = getQueryState(plan)
6048
- const required = [...values.flatMap((value) => Object.keys(value[Expression.TypeId].dependencies))].filter((name, index, list) =>
6049
- !(name in current.available) && list.indexOf(name) === index)
6050
- return makePlan({
6051
- selection: current.selection,
6052
- required: [...currentRequiredList(current.required), ...required].filter((name, index, list) =>
6053
- !(name in current.available) && list.indexOf(name) === index) as Exclude<RequiredOfPlan<PlanValue> | RequiredFromDependencies<TupleDependencies<Values>>, AvailableNames<AvailableOfPlan<PlanValue>>>,
6054
- available: current.available,
6055
- dialect: current.dialect as PlanDialectOf<PlanValue> | TupleDialect<Values>
6056
- }, {
6057
- ...currentAst,
6058
- groupBy: dedupeGroupedExpressions([...currentAst.groupBy, ...values])
6059
- }, currentQuery.assumptions, currentQuery.capabilities, currentQuery.statement as StatementOfPlan<PlanValue>)
6060
- }
5395
+ >
6061
5396
 
6062
- const returning = <Selection extends SelectionShape>(
5397
+ type ReturningApi = <Selection extends SelectionShape>(
6063
5398
  selection: Selection
6064
5399
  ) =>
6065
5400
  <PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
6066
5401
  plan: PlanValue & RequireMutationStatement<PlanValue>
6067
- ): QueryPlan<
5402
+ ) => QueryPlan<
6068
5403
  Selection,
6069
5404
  Exclude<RequiredOfPlan<PlanValue> | ExtractRequired<Selection>, AvailableNames<AvailableOfPlan<PlanValue>>>,
6070
5405
  AvailableOfPlan<PlanValue>,
@@ -6077,169 +5412,264 @@ type AsCurriedResult<
6077
5412
  StatementOfPlan<PlanValue>,
6078
5413
  MutationTargetOfPlan<PlanValue>,
6079
5414
  InsertSourceStateOfPlan<PlanValue>
6080
- > => {
6081
- const current = plan[Plan.TypeId]
6082
- const currentAst = getAst(plan)
6083
- const currentQuery = getQueryState(plan)
6084
- return makePlan({
6085
- selection,
6086
- required: [...currentRequiredList(current.required), ...extractRequiredRuntime(selection)].filter((name, index, list) =>
6087
- !(name in current.available) && list.indexOf(name) === index) as Exclude<RequiredOfPlan<PlanValue> | ExtractRequired<Selection>, AvailableNames<AvailableOfPlan<PlanValue>>>,
6088
- available: current.available,
6089
- dialect: current.dialect as PlanDialectOf<PlanValue> | ExtractDialect<Selection>
6090
- }, {
6091
- ...currentAst,
6092
- select: selection
6093
- }, currentQuery.assumptions, currentQuery.capabilities, currentQuery.statement as StatementOfPlan<PlanValue>, currentQuery.target, currentQuery.insertSource)
6094
- }
5415
+ >
6095
5416
 
6096
- function insert<
6097
- Target extends MutationTargetLike
5417
+ export interface InsertApi {
5418
+ <Target extends MutationTargetLike>(
5419
+ target: Target
5420
+ ): QueryPlan<
5421
+ {},
5422
+ never,
5423
+ AddAvailable<{}, SourceNameOf<Target>>,
5424
+ TableDialectOf<Target>,
5425
+ never,
5426
+ SourceNameOf<Target>,
5427
+ never,
5428
+ TrueFormula,
5429
+ "write",
5430
+ "insert",
5431
+ Target,
5432
+ "missing"
5433
+ >
5434
+ <Target extends MutationTargetLike, Values extends Record<string, unknown>>(
5435
+ target: Target,
5436
+ values: MutationValuesInput<"insert", Target, Values>
5437
+ ): QueryPlan<
5438
+ {},
5439
+ Exclude<MutationRequiredFromValues<Values>, SourceNameOf<Target>>,
5440
+ AddAvailable<{}, SourceNameOf<Target>>,
5441
+ TableDialectOf<Target>,
5442
+ never,
5443
+ SourceNameOf<Target>,
5444
+ Exclude<MutationRequiredFromValues<Values>, SourceNameOf<Target>>,
5445
+ TrueFormula,
5446
+ "write",
5447
+ "insert",
5448
+ Target,
5449
+ "ready"
5450
+ >
5451
+ }
5452
+
5453
+ type AttachInsertSourceApi = (
5454
+ plan: QueryPlan<any, any, any, any, any, any, any, any, any, "insert", MutationTargetLike, "missing">,
5455
+ source: AnyValuesInput | AnyValuesSource | AnyUnnestSource | CompletePlan<QueryPlan<any, any, any, any, any, any, any, any, any, any>>
5456
+ ) => QueryPlan<any, any, any, any, any, any, any, any, any, "insert", MutationTargetLike, "ready">
5457
+
5458
+ type OnConflictApi = <
5459
+ Target extends MutationTargetLike,
5460
+ const Columns extends DdlColumnInput,
5461
+ UpdateValues extends MutationInputOf<Table.UpdateOf<Target>> | undefined = MutationInputOf<Table.UpdateOf<Target>> | undefined,
5462
+ Options extends ConflictActionInput<Target, Dialect, UpdateValues> = ConflictActionInput<Target, Dialect, UpdateValues>
6098
5463
  >(
6099
- target: Target
6100
- ): QueryPlan<
5464
+ target: ConflictTargetInput<Target, Dialect, Columns>,
5465
+ options?: Options
5466
+ ) =>
5467
+ <PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
5468
+ plan: PlanValue & RequireInsertStatement<PlanValue>
5469
+ ) => QueryPlan<
5470
+ SelectionOfPlan<PlanValue>,
5471
+ Exclude<RequiredOfPlan<PlanValue> | MutationRequiredFromValues<Exclude<UpdateValues, undefined>> | RequiredFromInput<Extract<Options["where"], PredicateInput>>, AvailableNames<AvailableOfPlan<PlanValue>>>,
5472
+ AvailableOfPlan<PlanValue>,
5473
+ PlanDialectOf<PlanValue>,
5474
+ GroupedOfPlan<PlanValue>,
5475
+ ScopedNamesOfPlan<PlanValue>,
5476
+ Exclude<OutstandingOfPlan<PlanValue> | MutationRequiredFromValues<Exclude<UpdateValues, undefined>> | RequiredFromInput<Extract<Options["where"], PredicateInput>>, AvailableNames<AvailableOfPlan<PlanValue>>>,
5477
+ AssumptionsOfPlan<PlanValue>,
5478
+ CapabilitiesOfPlan<PlanValue>,
5479
+ StatementOfPlan<PlanValue>,
5480
+ MutationTargetOfPlan<PlanValue>,
5481
+ InsertSourceStateOfPlan<PlanValue>
5482
+ >
5483
+
5484
+ interface UpdateApi {
5485
+ <Targets extends MutationTargetTuple, Values extends UpdateInputOfTarget<Targets>>(
5486
+ target: Dialect extends "mysql" ? Targets : never,
5487
+ values: Values
5488
+ ): QueryPlan<
5489
+ {},
5490
+ Exclude<NestedMutationRequiredFromValues<Values>, MutationTargetNamesOf<Targets>>,
5491
+ AddAvailableMany<{}, MutationTargetNamesOf<Targets>>,
5492
+ TableDialectOf<Targets[0]>,
5493
+ never,
5494
+ MutationTargetNamesOf<Targets>,
5495
+ Exclude<NestedMutationRequiredFromValues<Values>, MutationTargetNamesOf<Targets>>,
5496
+ TrueFormula,
5497
+ "write",
5498
+ "update"
5499
+ >
5500
+ <Target extends MutationTargetLike, Values extends Record<string, unknown>>(
5501
+ target: Target,
5502
+ values: MutationValuesInput<"update", Target, Values>
5503
+ ): QueryPlan<
5504
+ {},
5505
+ Exclude<MutationRequiredFromValues<Values>, SourceNameOf<Target>>,
5506
+ AddAvailable<{}, SourceNameOf<Target>>,
5507
+ TableDialectOf<Target>,
5508
+ never,
5509
+ SourceNameOf<Target>,
5510
+ Exclude<MutationRequiredFromValues<Values>, SourceNameOf<Target>>,
5511
+ TrueFormula,
5512
+ "write",
5513
+ "update"
5514
+ >
5515
+ }
5516
+
5517
+ type UpsertApi = <
5518
+ Target extends MutationTargetLike,
5519
+ Values extends MutationInputOf<Table.InsertOf<Target>>,
5520
+ const Columns extends DdlColumnInput,
5521
+ UpdateValues extends MutationInputOf<Table.UpdateOf<Target>>
5522
+ >(
5523
+ target: Target,
5524
+ values: Values,
5525
+ conflictColumns: ValidateTargetColumns<Target, NormalizeDdlColumns<Columns>>,
5526
+ updateValues?: UpdateValues
5527
+ ) => QueryPlan<
5528
+ {},
5529
+ Exclude<MutationRequiredFromValues<Values> | MutationRequiredFromValues<UpdateValues>, SourceNameOf<Target>>,
5530
+ AddAvailable<{}, SourceNameOf<Target>>,
5531
+ TableDialectOf<Target>,
5532
+ never,
5533
+ SourceNameOf<Target>,
5534
+ Exclude<MutationRequiredFromValues<Values> | MutationRequiredFromValues<UpdateValues>, SourceNameOf<Target>>,
5535
+ TrueFormula,
5536
+ "write",
5537
+ "insert",
5538
+ Target,
5539
+ "ready"
5540
+ >
5541
+
5542
+ interface DeleteApi {
5543
+ <Target extends MutationTargetLike>(
5544
+ target: Target
5545
+ ): QueryPlan<
5546
+ {},
5547
+ never,
5548
+ AddAvailable<{}, SourceNameOf<Target>>,
5549
+ TableDialectOf<Target>,
5550
+ never,
5551
+ SourceNameOf<Target>,
5552
+ never,
5553
+ TrueFormula,
5554
+ "write",
5555
+ "delete"
5556
+ >
5557
+ <Targets extends MutationTargetTuple>(
5558
+ target: Dialect extends "mysql" ? Targets : never
5559
+ ): QueryPlan<
5560
+ {},
5561
+ never,
5562
+ AddAvailableMany<{}, MutationTargetNamesOf<Targets>>,
5563
+ TableDialectOf<Targets[0]>,
5564
+ never,
5565
+ MutationTargetNamesOf<Targets>,
5566
+ never,
5567
+ TrueFormula,
5568
+ "write",
5569
+ "delete"
5570
+ >
5571
+ }
5572
+
5573
+ type TruncateApi = <Target extends MutationTargetLike>(
5574
+ target: Target,
5575
+ options?: TruncateOptions
5576
+ ) => QueryPlan<
6101
5577
  {},
6102
5578
  never,
6103
- AddAvailable<{}, SourceNameOf<Target>>,
5579
+ {},
6104
5580
  TableDialectOf<Target>,
6105
5581
  never,
6106
- SourceNameOf<Target>,
5582
+ never,
6107
5583
  never,
6108
5584
  TrueFormula,
6109
5585
  "write",
6110
- "insert",
6111
- Target,
6112
- "missing"
5586
+ "truncate"
6113
5587
  >
6114
- function insert<
5588
+
5589
+ type MergeApi = <
6115
5590
  Target extends MutationTargetLike,
6116
- Values extends Record<string, unknown>
5591
+ Source extends SourceLike,
5592
+ On extends PredicateInput,
5593
+ MatchedValues extends MutationInputOf<Table.UpdateOf<Target>> = MutationInputOf<Table.UpdateOf<Target>>,
5594
+ InsertValues extends MutationInputOf<Table.InsertOf<Target>> = MutationInputOf<Table.InsertOf<Target>>,
5595
+ MatchedPredicate extends PredicateInput | undefined = undefined,
5596
+ NotMatchedPredicate extends PredicateInput | undefined = undefined
6117
5597
  >(
6118
5598
  target: Target,
6119
- values: MutationValuesInput<"insert", Target, Values>
6120
- ): QueryPlan<
5599
+ source: Source & (
5600
+ SourceRequiredOf<Source> extends never ? unknown : SourceRequirementError<Source>
5601
+ ),
5602
+ on: On,
5603
+ options?: MergeOptions<Target, MatchedValues, InsertValues, MatchedPredicate, NotMatchedPredicate>
5604
+ ) => QueryPlan<
6121
5605
  {},
6122
- Exclude<MutationRequiredFromValues<Values>, SourceNameOf<Target>>,
6123
- AddAvailable<{}, SourceNameOf<Target>>,
6124
- TableDialectOf<Target>,
5606
+ Exclude<
5607
+ AddExpressionRequired<
5608
+ MergeRequiredFromPredicate<
5609
+ MatchedPredicate,
5610
+ AddAvailable<AddAvailable<{}, SourceNameOf<Target>>, SourceNameOf<Source>>
5611
+ > | MergeRequiredFromPredicate<
5612
+ NotMatchedPredicate,
5613
+ AddAvailable<AddAvailable<{}, SourceNameOf<Target>>, SourceNameOf<Source>>
5614
+ > | MutationRequiredFromValues<MatchedValues> | MutationRequiredFromValues<InsertValues>,
5615
+ AddAvailable<AddAvailable<{}, SourceNameOf<Target>>, SourceNameOf<Source>>,
5616
+ On
5617
+ >,
5618
+ SourceNameOf<Target> | SourceNameOf<Source>
5619
+ >,
5620
+ AddAvailable<AddAvailable<{}, SourceNameOf<Target>>, SourceNameOf<Source>>,
5621
+ TableDialectOf<Target> | SourceDialectOf<Source>,
6125
5622
  never,
6126
- SourceNameOf<Target>,
6127
- Exclude<MutationRequiredFromValues<Values>, SourceNameOf<Target>>,
5623
+ SourceNameOf<Target> | SourceNameOf<Source>,
5624
+ Exclude<
5625
+ AddExpressionRequired<
5626
+ MergeRequiredFromPredicate<
5627
+ MatchedPredicate,
5628
+ AddAvailable<AddAvailable<{}, SourceNameOf<Target>>, SourceNameOf<Source>>
5629
+ > | MergeRequiredFromPredicate<
5630
+ NotMatchedPredicate,
5631
+ AddAvailable<AddAvailable<{}, SourceNameOf<Target>>, SourceNameOf<Source>>
5632
+ > | MutationRequiredFromValues<MatchedValues> | MutationRequiredFromValues<InsertValues>,
5633
+ AddAvailable<AddAvailable<{}, SourceNameOf<Target>>, SourceNameOf<Source>>,
5634
+ On
5635
+ >,
5636
+ SourceNameOf<Target> | SourceNameOf<Source>
5637
+ >,
6128
5638
  TrueFormula,
6129
- "write",
6130
- "insert",
6131
- Target,
6132
- "ready"
5639
+ MergeCapabilities<"write", SourceCapabilitiesOf<Source>>,
5640
+ "merge"
6133
5641
  >
6134
- function insert(
5642
+
5643
+ const mutationRuntime = makeDslMutationRuntime({
5644
+ makePlan,
5645
+ getAst,
5646
+ getQueryState,
5647
+ currentRequiredList,
5648
+ toDialectExpression,
5649
+ buildMutationAssignments,
5650
+ buildInsertValuesRows,
5651
+ normalizeInsertUnnestValues,
5652
+ normalizeInsertSelectColumns,
5653
+ buildConflictTarget,
5654
+ mutationTargetClauses,
5655
+ mutationAvailableSources,
5656
+ normalizeColumnList,
5657
+ targetSourceDetails,
5658
+ sourceDetails
5659
+ })
5660
+
5661
+ const insert: InsertApi = ((
6135
5662
  target: MutationTargetLike,
6136
5663
  values?: Record<string, unknown>
6137
- ): QueryPlan<any, any, any, any, any, any, any, any, any, "insert", MutationTargetLike, "missing" | "ready"> {
6138
- const { sourceName, sourceBaseName } = targetSourceDetails(target)
6139
- const assignments = values === undefined
6140
- ? []
6141
- : buildMutationAssignments(target, values)
6142
- const required = assignments.flatMap((entry) => Object.keys(entry.value[Expression.TypeId].dependencies))
6143
- const insertState = values === undefined ? "missing" : "ready"
6144
- return makePlan({
6145
- selection: {},
6146
- required: required.filter((name, index, list) => name !== sourceName && list.indexOf(name) === index),
6147
- available: {
6148
- [sourceName]: {
6149
- name: sourceName,
6150
- mode: "required",
6151
- baseName: sourceBaseName
6152
- }
6153
- } as AddAvailable<{}, string>,
6154
- dialect: target[Plan.TypeId].dialect
6155
- }, {
6156
- kind: "insert",
6157
- select: {},
6158
- into: {
6159
- kind: "from",
6160
- tableName: sourceName,
6161
- baseTableName: sourceBaseName,
6162
- source: target
6163
- },
6164
- values: assignments,
6165
- conflict: undefined,
6166
- where: [],
6167
- having: [],
6168
- joins: [],
6169
- groupBy: [],
6170
- orderBy: []
6171
- }, undefined as unknown as TrueFormula, "write", "insert", target, insertState)
6172
- }
5664
+ ) => mutationRuntime.insert(target, values)) as InsertApi
6173
5665
 
6174
5666
  const attachInsertSource = (
6175
5667
  plan: QueryPlan<any, any, any, any, any, any, any, any, any, "insert", MutationTargetLike, "missing">,
6176
5668
  source: AnyValuesInput | AnyValuesSource | AnyUnnestSource | CompletePlan<QueryPlan<any, any, any, any, any, any, any, any, any, any>>
6177
- ): QueryPlan<any, any, any, any, any, any, any, any, any, "insert", MutationTargetLike, "ready"> => {
6178
- const current = plan[Plan.TypeId]
6179
- const currentAst = getAst(plan)
6180
- const currentQuery = getQueryState(plan)
6181
- const target = currentQuery.target as MutationTargetLike
6182
- const targetSource = currentAst.into!
6183
- const sourceName = targetSource.tableName
6184
-
6185
- if (typeof source === "object" && source !== null && "kind" in source && source.kind === "values") {
6186
- const valuesSource = source as AnyValuesInput | AnyValuesSource
6187
- const normalized = buildInsertValuesRows(target, valuesSource.rows as readonly [InsertRowInput<MutationTargetLike>, ...InsertRowInput<MutationTargetLike>[]])
6188
- return makePlan({
6189
- selection: current.selection,
6190
- required: normalized.required.filter((name) => name !== sourceName),
6191
- available: current.available,
6192
- dialect: current.dialect
6193
- }, {
6194
- ...currentAst,
6195
- values: [],
6196
- insertSource: {
6197
- kind: "values",
6198
- columns: normalized.columns,
6199
- rows: normalized.rows
6200
- }
6201
- }, currentQuery.assumptions, currentQuery.capabilities, currentQuery.statement, currentQuery.target, "ready")
6202
- }
6203
-
6204
- if (typeof source === "object" && source !== null && "kind" in source && source.kind === "unnest") {
6205
- const unnestSource = source as AnyUnnestSource
6206
- const normalized = normalizeInsertUnnestValues(target, unnestSource.values as any)
6207
- return makePlan({
6208
- selection: current.selection,
6209
- required: [] as never,
6210
- available: current.available,
6211
- dialect: current.dialect
6212
- }, {
6213
- ...currentAst,
6214
- values: [],
6215
- insertSource: {
6216
- kind: "unnest",
6217
- columns: normalized.columns,
6218
- values: normalized.values
6219
- }
6220
- }, currentQuery.assumptions, currentQuery.capabilities, currentQuery.statement, currentQuery.target, "ready")
6221
- }
6222
-
6223
- const sourcePlan = source as CompletePlan<QueryPlan<any, any, any, any, any, any, any, any, any, any>>
6224
- const selection = sourcePlan[Plan.TypeId].selection as Record<string, Expression.Any>
6225
- const columns = normalizeInsertSelectColumns(selection)
6226
- return makePlan({
6227
- selection: current.selection,
6228
- required: currentRequiredList(sourcePlan[Plan.TypeId].required).filter((name) => name !== sourceName),
6229
- available: current.available,
6230
- dialect: current.dialect
6231
- }, {
6232
- ...currentAst,
6233
- values: [],
6234
- insertSource: {
6235
- kind: "query",
6236
- columns,
6237
- query: sourcePlan
6238
- }
6239
- }, currentQuery.assumptions, currentQuery.capabilities as MergeCapabilities<typeof currentQuery.capabilities, CapabilitiesOfPlan<typeof sourcePlan>>, currentQuery.statement, currentQuery.target, "ready")
6240
- }
5669
+ ): QueryPlan<any, any, any, any, any, any, any, any, any, "insert", MutationTargetLike, "ready"> =>
5670
+ mutationRuntime.attachInsertSource(plan, source)
6241
5671
 
6242
- const onConflict = <
5672
+ const onConflict: OnConflictApi = <
6243
5673
  Target extends MutationTargetLike,
6244
5674
  const Columns extends DdlColumnInput,
6245
5675
  UpdateValues extends MutationInputOf<Table.UpdateOf<Target>> | undefined = MutationInputOf<Table.UpdateOf<Target>> | undefined,
@@ -6263,108 +5693,14 @@ type AsCurriedResult<
6263
5693
  StatementOfPlan<PlanValue>,
6264
5694
  MutationTargetOfPlan<PlanValue>,
6265
5695
  InsertSourceStateOfPlan<PlanValue>
6266
- > => {
6267
- const current = plan[Plan.TypeId]
6268
- const currentAst = getAst(plan)
6269
- const currentQuery = getQueryState(plan)
6270
- const insertTarget = currentAst.into!.source as Target
6271
- const conflictTarget = buildConflictTarget(insertTarget, target as readonly string[] | { readonly columns: readonly string[]; readonly where?: PredicateInput } | { readonly constraint: string })
6272
- const updateAssignments = options.update
6273
- ? buildMutationAssignments(insertTarget, options.update)
6274
- : []
6275
- const updateWhere = options.where === undefined
6276
- ? undefined
6277
- : toDialectExpression(options.where as PredicateInput)
6278
- const required = [
6279
- ...currentRequiredList(current.required),
6280
- ...updateAssignments.flatMap((entry) => Object.keys(entry.value[Expression.TypeId].dependencies)),
6281
- ...(updateWhere ? Object.keys(updateWhere[Expression.TypeId].dependencies) : [])
6282
- ].filter((name, index, list) =>
6283
- !(name in current.available) && list.indexOf(name) === index)
6284
- return makePlan({
6285
- selection: current.selection,
6286
- required: required as Exclude<RequiredOfPlan<PlanValue> | MutationRequiredFromValues<Exclude<UpdateValues, undefined>> | RequiredFromInput<Extract<Options["where"], PredicateInput>>, AvailableNames<AvailableOfPlan<PlanValue>>>,
6287
- available: current.available,
6288
- dialect: current.dialect as PlanDialectOf<PlanValue>
6289
- }, {
6290
- ...currentAst,
6291
- conflict: {
6292
- kind: "conflict",
6293
- target: conflictTarget,
6294
- action: updateAssignments.length === 0 ? "doNothing" : "doUpdate",
6295
- values: updateAssignments.length === 0 ? undefined : updateAssignments,
6296
- where: updateWhere
6297
- }
6298
- }, currentQuery.assumptions, currentQuery.capabilities, currentQuery.statement as StatementOfPlan<PlanValue>, currentQuery.target, currentQuery.insertSource)
6299
- }
5696
+ > => mutationRuntime.onConflict(target, options)(plan)
6300
5697
 
6301
- function update<
6302
- Targets extends MutationTargetTuple,
6303
- Values extends UpdateInputOfTarget<Targets>
6304
- >(
6305
- target: Dialect extends "mysql" ? Targets : never,
6306
- values: Values
6307
- ): QueryPlan<
6308
- {},
6309
- Exclude<NestedMutationRequiredFromValues<Values>, MutationTargetNamesOf<Targets>>,
6310
- AddAvailableMany<{}, MutationTargetNamesOf<Targets>>,
6311
- TableDialectOf<Targets[0]>,
6312
- never,
6313
- MutationTargetNamesOf<Targets>,
6314
- Exclude<NestedMutationRequiredFromValues<Values>, MutationTargetNamesOf<Targets>>,
6315
- TrueFormula,
6316
- "write",
6317
- "update"
6318
- >
6319
- function update<
6320
- Target extends MutationTargetLike,
6321
- Values extends Record<string, unknown>
6322
- >(
6323
- target: Target,
6324
- values: MutationValuesInput<"update", Target, Values>
6325
- ): QueryPlan<
6326
- {},
6327
- Exclude<MutationRequiredFromValues<Values>, SourceNameOf<Target>>,
6328
- AddAvailable<{}, SourceNameOf<Target>>,
6329
- TableDialectOf<Target>,
6330
- never,
6331
- SourceNameOf<Target>,
6332
- Exclude<MutationRequiredFromValues<Values>, SourceNameOf<Target>>,
6333
- TrueFormula,
6334
- "write",
6335
- "update"
6336
- >
6337
- function update(
5698
+ const update: UpdateApi = ((
6338
5699
  target: MutationTargetInput,
6339
5700
  values: Record<string, unknown>
6340
- ): QueryPlan<any, any, any, any, any, any, any, any, any, "update"> {
6341
- const targets = mutationTargetClauses(target)
6342
- const primaryTarget = targets[0]!
6343
- const assignments = buildMutationAssignments(target, values)
6344
- const targetNames = new Set(targets.map((entry) => entry.tableName))
6345
- const required = assignments
6346
- .flatMap((entry) => Object.keys(entry.value[Expression.TypeId].dependencies))
6347
- .filter((name, index, list) => !targetNames.has(name) && list.indexOf(name) === index)
6348
- return makePlan({
6349
- selection: {},
6350
- required,
6351
- available: mutationAvailableSources(target),
6352
- dialect: (primaryTarget.source as MutationTargetLike)[Plan.TypeId].dialect
6353
- }, {
6354
- kind: "update",
6355
- select: {},
6356
- target: primaryTarget,
6357
- targets,
6358
- set: assignments,
6359
- where: [],
6360
- having: [],
6361
- joins: [],
6362
- groupBy: [],
6363
- orderBy: []
6364
- }, undefined as unknown as TrueFormula, "write", "update")
6365
- }
5701
+ ) => mutationRuntime.update(target, values)) as UpdateApi
6366
5702
 
6367
- const upsert = <
5703
+ const upsert: UpsertApi = <
6368
5704
  Target extends MutationTargetLike,
6369
5705
  Values extends MutationInputOf<Table.InsertOf<Target>>,
6370
5706
  const Columns extends DdlColumnInput,
@@ -6387,108 +5723,13 @@ type AsCurriedResult<
6387
5723
  "insert",
6388
5724
  Target,
6389
5725
  "ready"
6390
- > => {
6391
- const { sourceName, sourceBaseName } = targetSourceDetails(target)
6392
- const assignments = buildMutationAssignments(target, values)
6393
- const updateAssignments = updateValues ? buildMutationAssignments(target, updateValues) : []
6394
- const required = [
6395
- ...assignments.flatMap((entry) => Object.keys(entry.value[Expression.TypeId].dependencies)),
6396
- ...updateAssignments.flatMap((entry) => Object.keys(entry.value[Expression.TypeId].dependencies))
6397
- ]
6398
- return makePlan({
6399
- selection: {},
6400
- required: required.filter((name, index, list) => name !== sourceName && list.indexOf(name) === index) as unknown as Exclude<MutationRequiredFromValues<Values> | MutationRequiredFromValues<UpdateValues>, SourceNameOf<Target>>,
6401
- available: {
6402
- [sourceName]: {
6403
- name: sourceName,
6404
- mode: "required",
6405
- baseName: sourceBaseName
6406
- }
6407
- } as AddAvailable<{}, SourceNameOf<Target>>,
6408
- dialect: target[Plan.TypeId].dialect as TableDialectOf<Target>
6409
- }, {
6410
- kind: "insert",
6411
- select: {},
6412
- into: {
6413
- kind: "from",
6414
- tableName: sourceName,
6415
- baseTableName: sourceBaseName,
6416
- source: target
6417
- },
6418
- values: assignments,
6419
- conflict: {
6420
- kind: "conflict",
6421
- target: {
6422
- kind: "columns",
6423
- columns: normalizeColumnList(conflictColumns as string | readonly string[]) as readonly [string, ...string[]]
6424
- },
6425
- action: updateAssignments.length > 0 ? "doUpdate" : "doNothing",
6426
- values: updateAssignments.length > 0 ? updateAssignments : undefined
6427
- },
6428
- where: [],
6429
- having: [],
6430
- joins: [],
6431
- groupBy: [],
6432
- orderBy: []
6433
- }, undefined as unknown as TrueFormula, "write", "insert", target, "ready")
6434
- }
5726
+ > => mutationRuntime.upsert(target, values, conflictColumns as string | readonly string[], updateValues)
6435
5727
 
6436
- function delete_<
6437
- Target extends MutationTargetLike
6438
- >(
6439
- target: Target
6440
- ): QueryPlan<
6441
- {},
6442
- never,
6443
- AddAvailable<{}, SourceNameOf<Target>>,
6444
- TableDialectOf<Target>,
6445
- never,
6446
- SourceNameOf<Target>,
6447
- never,
6448
- TrueFormula,
6449
- "write",
6450
- "delete"
6451
- >
6452
- function delete_<
6453
- Targets extends MutationTargetTuple
6454
- >(
6455
- target: Dialect extends "mysql" ? Targets : never
6456
- ): QueryPlan<
6457
- {},
6458
- never,
6459
- AddAvailableMany<{}, MutationTargetNamesOf<Targets>>,
6460
- TableDialectOf<Targets[0]>,
6461
- never,
6462
- MutationTargetNamesOf<Targets>,
6463
- never,
6464
- TrueFormula,
6465
- "write",
6466
- "delete"
6467
- >
6468
- function delete_(
5728
+ const delete_: DeleteApi = ((
6469
5729
  target: MutationTargetInput
6470
- ): QueryPlan<any, any, any, any, any, any, any, any, any, "delete"> {
6471
- const targets = mutationTargetClauses(target)
6472
- const primaryTarget = targets[0]!
6473
- return makePlan({
6474
- selection: {},
6475
- required: [] as never,
6476
- available: mutationAvailableSources(target),
6477
- dialect: (primaryTarget.source as MutationTargetLike)[Plan.TypeId].dialect
6478
- }, {
6479
- kind: "delete",
6480
- select: {},
6481
- target: primaryTarget,
6482
- targets,
6483
- where: [],
6484
- having: [],
6485
- joins: [],
6486
- groupBy: [],
6487
- orderBy: []
6488
- }, undefined as unknown as TrueFormula, "write", "delete")
6489
- }
5730
+ ) => mutationRuntime.delete_(target)) as DeleteApi
6490
5731
 
6491
- const truncate = <
5732
+ const truncate: TruncateApi = <
6492
5733
  Target extends MutationTargetLike
6493
5734
  >(
6494
5735
  target: Target,
@@ -6504,36 +5745,9 @@ type AsCurriedResult<
6504
5745
  TrueFormula,
6505
5746
  "write",
6506
5747
  "truncate"
6507
- > => {
6508
- const { sourceName, sourceBaseName } = targetSourceDetails(target)
6509
- return makePlan({
6510
- selection: {},
6511
- required: [] as never,
6512
- available: {},
6513
- dialect: target[Plan.TypeId].dialect as TableDialectOf<Target>
6514
- }, {
6515
- kind: "truncate",
6516
- select: {},
6517
- target: {
6518
- kind: "from",
6519
- tableName: sourceName,
6520
- baseTableName: sourceBaseName,
6521
- source: target
6522
- },
6523
- truncate: {
6524
- kind: "truncate",
6525
- restartIdentity: options.restartIdentity ?? false,
6526
- cascade: options.cascade ?? false
6527
- },
6528
- where: [],
6529
- having: [],
6530
- joins: [],
6531
- groupBy: [],
6532
- orderBy: []
6533
- }, undefined as unknown as TrueFormula, "write", "truncate")
6534
- }
5748
+ > => mutationRuntime.truncate(target, options)
6535
5749
 
6536
- const merge = <
5750
+ const merge: MergeApi = <
6537
5751
  Target extends MutationTargetLike,
6538
5752
  Source extends SourceLike,
6539
5753
  On extends PredicateInput,
@@ -6585,109 +5799,9 @@ type AsCurriedResult<
6585
5799
  TrueFormula,
6586
5800
  MergeCapabilities<"write", SourceCapabilitiesOf<Source>>,
6587
5801
  "merge"
6588
- > => {
6589
- const { sourceName: targetName, sourceBaseName: targetBaseName } = targetSourceDetails(target)
6590
- const { sourceName: usingName, sourceBaseName: usingBaseName } = sourceDetails(source)
6591
- const onExpression = toDialectExpression(on)
6592
- const matched = options.whenMatched
6593
- const notMatched = options.whenNotMatched
6594
- if (matched && "delete" in matched && "update" in matched) {
6595
- throw new Error("merge whenMatched cannot specify both update and delete")
6596
- }
6597
- const matchedPredicate = matched?.predicate ? toDialectExpression(matched.predicate) : undefined
6598
- const matchedAssignments = matched && "update" in matched && matched.update
6599
- ? buildMutationAssignments(target, matched.update)
6600
- : []
6601
- const notMatchedPredicate = notMatched?.predicate ? toDialectExpression(notMatched.predicate) : undefined
6602
- const notMatchedAssignments = notMatched
6603
- ? buildMutationAssignments(target, notMatched.values)
6604
- : []
6605
- const required = [
6606
- ...Object.keys(onExpression[Expression.TypeId].dependencies),
6607
- ...matchedAssignments.flatMap((entry) => Object.keys(entry.value[Expression.TypeId].dependencies)),
6608
- ...notMatchedAssignments.flatMap((entry) => Object.keys(entry.value[Expression.TypeId].dependencies)),
6609
- ...(matchedPredicate ? Object.keys(matchedPredicate[Expression.TypeId].dependencies) : []),
6610
- ...(notMatchedPredicate ? Object.keys(notMatchedPredicate[Expression.TypeId].dependencies) : [])
6611
- ].filter((name, index, values) =>
6612
- name !== targetName && name !== usingName && values.indexOf(name) === index)
6613
- return makePlan({
6614
- selection: {},
6615
- required: required as unknown as Exclude<
6616
- AddExpressionRequired<
6617
- MergeRequiredFromPredicate<
6618
- MatchedPredicate,
6619
- AddAvailable<AddAvailable<{}, SourceNameOf<Target>>, SourceNameOf<Source>>
6620
- > | MergeRequiredFromPredicate<
6621
- NotMatchedPredicate,
6622
- AddAvailable<AddAvailable<{}, SourceNameOf<Target>>, SourceNameOf<Source>>
6623
- > | MutationRequiredFromValues<MatchedValues> | MutationRequiredFromValues<InsertValues>,
6624
- AddAvailable<AddAvailable<{}, SourceNameOf<Target>>, SourceNameOf<Source>>,
6625
- On
6626
- >,
6627
- SourceNameOf<Target> | SourceNameOf<Source>
6628
- >,
6629
- available: {
6630
- [targetName]: {
6631
- name: targetName,
6632
- mode: "required",
6633
- baseName: targetBaseName
6634
- },
6635
- [usingName]: {
6636
- name: usingName,
6637
- mode: "required",
6638
- baseName: usingBaseName
6639
- }
6640
- } as AddAvailable<AddAvailable<{}, SourceNameOf<Target>>, SourceNameOf<Source>>,
6641
- dialect: target[Plan.TypeId].dialect as TableDialectOf<Target> | SourceDialectOf<Source>
6642
- }, {
6643
- kind: "merge",
6644
- select: {},
6645
- target: {
6646
- kind: "from",
6647
- tableName: targetName,
6648
- baseTableName: targetBaseName,
6649
- source: target
6650
- },
6651
- using: {
6652
- kind: "from",
6653
- tableName: usingName,
6654
- baseTableName: usingBaseName,
6655
- source
6656
- },
6657
- merge: {
6658
- kind: "merge",
6659
- on: onExpression,
6660
- whenMatched: matched
6661
- ? ("delete" in matched && matched.delete
6662
- ? {
6663
- kind: "delete",
6664
- predicate: matchedPredicate
6665
- }
6666
- : {
6667
- kind: "update",
6668
- values: matchedAssignments,
6669
- predicate: matchedPredicate
6670
- })
6671
- : undefined,
6672
- whenNotMatched: notMatched
6673
- ? {
6674
- kind: "insert",
6675
- values: notMatchedAssignments,
6676
- predicate: notMatchedPredicate
6677
- }
6678
- : undefined
6679
- },
6680
- where: [],
6681
- having: [],
6682
- joins: [],
6683
- groupBy: [],
6684
- orderBy: []
6685
- }, undefined as unknown as TrueFormula, "write" as MergeCapabilities<"write", SourceCapabilitiesOf<Source>>, "merge")
6686
- }
5802
+ > => mutationRuntime.merge(target, source, on, options)
6687
5803
 
6688
- const transaction = (
6689
- options: TransactionOptions = {}
6690
- ): QueryPlan<
5804
+ type TransactionApi = (options?: TransactionOptions) => QueryPlan<
6691
5805
  {},
6692
5806
  never,
6693
5807
  {},
@@ -6698,28 +5812,9 @@ type AsCurriedResult<
6698
5812
  TrueFormula,
6699
5813
  "transaction",
6700
5814
  "transaction"
6701
- > =>
6702
- makePlan({
6703
- selection: {},
6704
- required: [] as never,
6705
- available: {},
6706
- dialect: profile.dialect as Dialect
6707
- }, {
6708
- kind: "transaction",
6709
- select: {},
6710
- transaction: {
6711
- kind: "transaction",
6712
- isolationLevel: options.isolationLevel,
6713
- readOnly: options.readOnly
6714
- },
6715
- where: [],
6716
- having: [],
6717
- joins: [],
6718
- groupBy: [],
6719
- orderBy: []
6720
- }, undefined as unknown as TrueFormula, "transaction", "transaction")
6721
-
6722
- const commit = (): QueryPlan<
5815
+ >
5816
+
5817
+ type CommitApi = () => QueryPlan<
6723
5818
  {},
6724
5819
  never,
6725
5820
  {},
@@ -6730,26 +5825,9 @@ type AsCurriedResult<
6730
5825
  TrueFormula,
6731
5826
  "transaction",
6732
5827
  "commit"
6733
- > =>
6734
- makePlan({
6735
- selection: {},
6736
- required: [] as never,
6737
- available: {},
6738
- dialect: profile.dialect as Dialect
6739
- }, {
6740
- kind: "commit",
6741
- select: {},
6742
- transaction: {
6743
- kind: "commit"
6744
- },
6745
- where: [],
6746
- having: [],
6747
- joins: [],
6748
- groupBy: [],
6749
- orderBy: []
6750
- }, undefined as unknown as TrueFormula, "transaction", "commit")
6751
-
6752
- const rollback = (): QueryPlan<
5828
+ >
5829
+
5830
+ type RollbackApi = () => QueryPlan<
6753
5831
  {},
6754
5832
  never,
6755
5833
  {},
@@ -6760,28 +5838,9 @@ type AsCurriedResult<
6760
5838
  TrueFormula,
6761
5839
  "transaction",
6762
5840
  "rollback"
6763
- > =>
6764
- makePlan({
6765
- selection: {},
6766
- required: [] as never,
6767
- available: {},
6768
- dialect: profile.dialect as Dialect
6769
- }, {
6770
- kind: "rollback",
6771
- select: {},
6772
- transaction: {
6773
- kind: "rollback"
6774
- },
6775
- where: [],
6776
- having: [],
6777
- joins: [],
6778
- groupBy: [],
6779
- orderBy: []
6780
- }, undefined as unknown as TrueFormula, "transaction", "rollback")
6781
-
6782
- const savepoint = <Name extends string>(
6783
- name: Name
6784
- ): QueryPlan<
5841
+ >
5842
+
5843
+ type SavepointApi = <Name extends string>(name: Name) => QueryPlan<
6785
5844
  {},
6786
5845
  never,
6787
5846
  {},
@@ -6792,29 +5851,9 @@ type AsCurriedResult<
6792
5851
  TrueFormula,
6793
5852
  "transaction",
6794
5853
  "savepoint"
6795
- > =>
6796
- makePlan({
6797
- selection: {},
6798
- required: [] as never,
6799
- available: {},
6800
- dialect: profile.dialect as Dialect
6801
- }, {
6802
- kind: "savepoint",
6803
- select: {},
6804
- transaction: {
6805
- kind: "savepoint",
6806
- name
6807
- },
6808
- where: [],
6809
- having: [],
6810
- joins: [],
6811
- groupBy: [],
6812
- orderBy: []
6813
- }, undefined as unknown as TrueFormula, "transaction", "savepoint")
6814
-
6815
- const rollbackTo = <Name extends string>(
6816
- name: Name
6817
- ): QueryPlan<
5854
+ >
5855
+
5856
+ type RollbackToApi = <Name extends string>(name: Name) => QueryPlan<
6818
5857
  {},
6819
5858
  never,
6820
5859
  {},
@@ -6825,29 +5864,9 @@ type AsCurriedResult<
6825
5864
  TrueFormula,
6826
5865
  "transaction",
6827
5866
  "rollbackTo"
6828
- > =>
6829
- makePlan({
6830
- selection: {},
6831
- required: [] as never,
6832
- available: {},
6833
- dialect: profile.dialect as Dialect
6834
- }, {
6835
- kind: "rollbackTo",
6836
- select: {},
6837
- transaction: {
6838
- kind: "rollbackTo",
6839
- name
6840
- },
6841
- where: [],
6842
- having: [],
6843
- joins: [],
6844
- groupBy: [],
6845
- orderBy: []
6846
- }, undefined as unknown as TrueFormula, "transaction", "rollbackTo")
6847
-
6848
- const releaseSavepoint = <Name extends string>(
6849
- name: Name
6850
- ): QueryPlan<
5867
+ >
5868
+
5869
+ type ReleaseSavepointApi = <Name extends string>(name: Name) => QueryPlan<
6851
5870
  {},
6852
5871
  never,
6853
5872
  {},
@@ -6858,32 +5877,12 @@ type AsCurriedResult<
6858
5877
  TrueFormula,
6859
5878
  "transaction",
6860
5879
  "releaseSavepoint"
6861
- > =>
6862
- makePlan({
6863
- selection: {},
6864
- required: [] as never,
6865
- available: {},
6866
- dialect: profile.dialect as Dialect
6867
- }, {
6868
- kind: "releaseSavepoint",
6869
- select: {},
6870
- transaction: {
6871
- kind: "releaseSavepoint",
6872
- name
6873
- },
6874
- where: [],
6875
- having: [],
6876
- joins: [],
6877
- groupBy: [],
6878
- orderBy: []
6879
- }, undefined as unknown as TrueFormula, "transaction", "releaseSavepoint")
6880
-
6881
- const createTable = <
6882
- Target extends SchemaTableLike
6883
- >(
5880
+ >
5881
+
5882
+ type CreateTableApi = <Target extends SchemaTableLike>(
6884
5883
  target: Target,
6885
- options: CreateTableOptions = {}
6886
- ): QueryPlan<
5884
+ options?: CreateTableOptions
5885
+ ) => QueryPlan<
6887
5886
  {},
6888
5887
  never,
6889
5888
  {},
@@ -6894,40 +5893,12 @@ type AsCurriedResult<
6894
5893
  TrueFormula,
6895
5894
  "ddl",
6896
5895
  "createTable"
6897
- > => {
6898
- const { sourceName, sourceBaseName } = targetSourceDetails(target)
6899
- return makePlan({
6900
- selection: {},
6901
- required: [] as never,
6902
- available: {},
6903
- dialect: target[Plan.TypeId].dialect as TableDialectOf<Target>
6904
- }, {
6905
- kind: "createTable",
6906
- select: {},
6907
- target: {
6908
- kind: "from",
6909
- tableName: sourceName,
6910
- baseTableName: sourceBaseName,
6911
- source: target
6912
- },
6913
- ddl: {
6914
- kind: "createTable",
6915
- ifNotExists: options.ifNotExists ?? false
6916
- },
6917
- where: [],
6918
- having: [],
6919
- joins: [],
6920
- groupBy: [],
6921
- orderBy: []
6922
- }, undefined as unknown as TrueFormula, "ddl", "createTable")
6923
- }
5896
+ >
6924
5897
 
6925
- const dropTable = <
6926
- Target extends SchemaTableLike
6927
- >(
5898
+ type DropTableApi = <Target extends SchemaTableLike>(
6928
5899
  target: Target,
6929
- options: DropTableOptions = {}
6930
- ): QueryPlan<
5900
+ options?: DropTableOptions
5901
+ ) => QueryPlan<
6931
5902
  {},
6932
5903
  never,
6933
5904
  {},
@@ -6938,42 +5909,13 @@ type AsCurriedResult<
6938
5909
  TrueFormula,
6939
5910
  "ddl",
6940
5911
  "dropTable"
6941
- > => {
6942
- const { sourceName, sourceBaseName } = targetSourceDetails(target)
6943
- return makePlan({
6944
- selection: {},
6945
- required: [] as never,
6946
- available: {},
6947
- dialect: target[Plan.TypeId].dialect as TableDialectOf<Target>
6948
- }, {
6949
- kind: "dropTable",
6950
- select: {},
6951
- target: {
6952
- kind: "from",
6953
- tableName: sourceName,
6954
- baseTableName: sourceBaseName,
6955
- source: target
6956
- },
6957
- ddl: {
6958
- kind: "dropTable",
6959
- ifExists: options.ifExists ?? false
6960
- },
6961
- where: [],
6962
- having: [],
6963
- joins: [],
6964
- groupBy: [],
6965
- orderBy: []
6966
- }, undefined as unknown as TrueFormula, "ddl", "dropTable")
6967
- }
5912
+ >
6968
5913
 
6969
- const createIndex = <
6970
- Target extends SchemaTableLike,
6971
- const Columns extends DdlColumnInput
6972
- >(
5914
+ type CreateIndexApi = <Target extends SchemaTableLike, const Columns extends DdlColumnInput>(
6973
5915
  target: Target,
6974
5916
  columns: Columns & ValidateDdlColumns<Target, NormalizeDdlColumns<Columns>>,
6975
- options: CreateIndexOptions = {}
6976
- ): QueryPlan<
5917
+ options?: CreateIndexOptions
5918
+ ) => QueryPlan<
6977
5919
  {},
6978
5920
  never,
6979
5921
  {},
@@ -6984,46 +5926,13 @@ type AsCurriedResult<
6984
5926
  TrueFormula,
6985
5927
  "ddl",
6986
5928
  "createIndex"
6987
- > => {
6988
- const normalizedColumns = normalizeColumnList(columns as string | readonly string[])
6989
- const { sourceName, sourceBaseName } = targetSourceDetails(target)
6990
- return makePlan({
6991
- selection: {},
6992
- required: [] as never,
6993
- available: {},
6994
- dialect: target[Plan.TypeId].dialect as TableDialectOf<Target>
6995
- }, {
6996
- kind: "createIndex",
6997
- select: {},
6998
- target: {
6999
- kind: "from",
7000
- tableName: sourceName,
7001
- baseTableName: sourceBaseName,
7002
- source: target
7003
- },
7004
- ddl: {
7005
- kind: "createIndex",
7006
- name: options.name ?? defaultIndexName(sourceBaseName, normalizedColumns, options.unique ?? false),
7007
- columns: normalizedColumns,
7008
- unique: options.unique ?? false,
7009
- ifNotExists: options.ifNotExists ?? false
7010
- },
7011
- where: [],
7012
- having: [],
7013
- joins: [],
7014
- groupBy: [],
7015
- orderBy: []
7016
- }, undefined as unknown as TrueFormula, "ddl", "createIndex")
7017
- }
5929
+ >
7018
5930
 
7019
- const dropIndex = <
7020
- Target extends SchemaTableLike,
7021
- const Columns extends DdlColumnInput
7022
- >(
5931
+ type DropIndexApi = <Target extends SchemaTableLike, const Columns extends DdlColumnInput>(
7023
5932
  target: Target,
7024
5933
  columns: Columns & ValidateDdlColumns<Target, NormalizeDdlColumns<Columns>>,
7025
- options: DropIndexOptions = {}
7026
- ): QueryPlan<
5934
+ options?: DropIndexOptions
5935
+ ) => QueryPlan<
7027
5936
  {},
7028
5937
  never,
7029
5938
  {},
@@ -7034,107 +5943,9 @@ type AsCurriedResult<
7034
5943
  TrueFormula,
7035
5944
  "ddl",
7036
5945
  "dropIndex"
7037
- > => {
7038
- const normalizedColumns = normalizeColumnList(columns as string | readonly string[])
7039
- const { sourceName, sourceBaseName } = targetSourceDetails(target)
7040
- return makePlan({
7041
- selection: {},
7042
- required: [] as never,
7043
- available: {},
7044
- dialect: target[Plan.TypeId].dialect as TableDialectOf<Target>
7045
- }, {
7046
- kind: "dropIndex",
7047
- select: {},
7048
- target: {
7049
- kind: "from",
7050
- tableName: sourceName,
7051
- baseTableName: sourceBaseName,
7052
- source: target
7053
- },
7054
- ddl: {
7055
- kind: "dropIndex",
7056
- name: options.name ?? defaultIndexName(sourceBaseName, normalizedColumns, false),
7057
- ifExists: options.ifExists ?? false
7058
- },
7059
- where: [],
7060
- having: [],
7061
- joins: [],
7062
- groupBy: [],
7063
- orderBy: []
7064
- }, undefined as unknown as TrueFormula, "ddl", "dropIndex")
7065
- }
5946
+ >
7066
5947
 
7067
- const api = {
7068
- literal,
7069
- column,
7070
- cast,
7071
- type,
7072
- json,
7073
- jsonb,
7074
- eq,
7075
- neq,
7076
- lt,
7077
- lte,
7078
- gt,
7079
- gte,
7080
- isNull,
7081
- isNotNull,
7082
- upper,
7083
- lower,
7084
- like,
7085
- ilike,
7086
- regexMatch,
7087
- regexIMatch,
7088
- regexNotMatch,
7089
- regexNotIMatch,
7090
- and,
7091
- or,
7092
- not,
7093
- all: all_,
7094
- any: any_,
7095
- case: case_,
7096
- match,
7097
- coalesce,
7098
- call,
7099
- uuidGenerateV4,
7100
- nextVal,
7101
- in: in_,
7102
- notIn,
7103
- between,
7104
- contains,
7105
- containedBy,
7106
- overlaps,
7107
- concat,
7108
- exists,
7109
- over,
7110
- rowNumber,
7111
- rank,
7112
- denseRank,
7113
- count,
7114
- max,
7115
- min,
7116
- isDistinctFrom,
7117
- isNotDistinctFrom,
7118
- excluded,
7119
- as,
7120
- with: with_,
7121
- withRecursive: withRecursive_,
7122
- lateral,
7123
- scalar,
7124
- inSubquery,
7125
- compareAny,
7126
- compareAll,
7127
- values,
7128
- unnest,
7129
- generateSeries,
7130
- returning,
7131
- onConflict,
7132
- insert,
7133
- update,
7134
- upsert,
7135
- delete: delete_,
7136
- truncate,
7137
- merge,
5948
+ const {
7138
5949
  transaction,
7139
5950
  commit,
7140
5951
  rollback,
@@ -7144,30 +5955,161 @@ type AsCurriedResult<
7144
5955
  createTable,
7145
5956
  dropTable,
7146
5957
  createIndex,
7147
- dropIndex,
7148
- union,
7149
- unionAll,
7150
- intersect,
7151
- intersectAll,
7152
- except,
7153
- exceptAll,
5958
+ dropIndex
5959
+ } = makeDslTransactionDdlRuntime({
5960
+ profile,
5961
+ makePlan,
5962
+ targetSourceDetails,
5963
+ normalizeColumnList,
5964
+ defaultIndexName
5965
+ }) as {
5966
+ readonly transaction: TransactionApi
5967
+ readonly commit: CommitApi
5968
+ readonly rollback: RollbackApi
5969
+ readonly savepoint: SavepointApi
5970
+ readonly rollbackTo: RollbackToApi
5971
+ readonly releaseSavepoint: ReleaseSavepointApi
5972
+ readonly createTable: CreateTableApi
5973
+ readonly dropTable: DropTableApi
5974
+ readonly createIndex: CreateIndexApi
5975
+ readonly dropIndex: DropIndexApi
5976
+ }
5977
+
5978
+ const {
5979
+ values: exportedValues,
5980
+ unnest: exportedUnnest,
5981
+ select: exportedSelect,
5982
+ from: exportedFrom,
5983
+ insert: exportedInsert
5984
+ } = {
5985
+ values,
5986
+ unnest,
7154
5987
  select,
7155
- where,
7156
- having,
7157
5988
  from,
7158
- innerJoin,
7159
- leftJoin,
7160
- rightJoin,
7161
- fullJoin,
7162
- crossJoin,
7163
- distinct,
7164
- distinctOn,
7165
- limit,
7166
- offset,
7167
- lock,
7168
- orderBy,
7169
- groupBy
5989
+ insert
5990
+ } as {
5991
+ readonly values: ValuesApi
5992
+ readonly unnest: UnnestApi
5993
+ readonly select: SelectApi
5994
+ readonly from: FromApi
5995
+ readonly insert: InsertApi
7170
5996
  }
7171
5997
 
7172
- return api
7173
- })()
5998
+ export const mysqlDsl = {
5999
+ values: exportedValues,
6000
+ unnest: exportedUnnest,
6001
+ select: exportedSelect,
6002
+ from: exportedFrom,
6003
+ insert: exportedInsert
6004
+ } as {
6005
+ readonly values: ValuesApi
6006
+ readonly unnest: UnnestApi
6007
+ readonly select: SelectApi
6008
+ readonly from: FromApi
6009
+ readonly insert: InsertApi
6010
+ }
6011
+
6012
+ export {
6013
+ literal,
6014
+ column,
6015
+ cast,
6016
+ type,
6017
+ json,
6018
+ jsonb,
6019
+ eq,
6020
+ neq,
6021
+ lt,
6022
+ lte,
6023
+ gt,
6024
+ gte,
6025
+ isNull,
6026
+ isNotNull,
6027
+ upper,
6028
+ lower,
6029
+ like,
6030
+ ilike,
6031
+ regexMatch,
6032
+ regexIMatch,
6033
+ regexNotMatch,
6034
+ regexNotIMatch,
6035
+ and,
6036
+ or,
6037
+ not,
6038
+ all_ as all,
6039
+ any_ as any,
6040
+ case_,
6041
+ match,
6042
+ coalesce,
6043
+ call,
6044
+ uuidGenerateV4,
6045
+ nextVal,
6046
+ in_,
6047
+ notIn,
6048
+ between,
6049
+ contains,
6050
+ containedBy,
6051
+ overlaps,
6052
+ concat,
6053
+ exists,
6054
+ over,
6055
+ rowNumber,
6056
+ rank,
6057
+ denseRank,
6058
+ count,
6059
+ max,
6060
+ min,
6061
+ isDistinctFrom,
6062
+ isNotDistinctFrom,
6063
+ excluded,
6064
+ as,
6065
+ with_,
6066
+ withRecursive_ as withRecursive,
6067
+ lateral,
6068
+ scalar,
6069
+ inSubquery,
6070
+ compareAny,
6071
+ compareAll,
6072
+ exportedValues as values,
6073
+ exportedUnnest as unnest,
6074
+ generateSeries,
6075
+ returning,
6076
+ onConflict,
6077
+ exportedInsert as insert,
6078
+ update,
6079
+ upsert,
6080
+ delete_,
6081
+ truncate,
6082
+ merge,
6083
+ transaction,
6084
+ commit,
6085
+ rollback,
6086
+ savepoint,
6087
+ rollbackTo,
6088
+ releaseSavepoint,
6089
+ createTable,
6090
+ dropTable,
6091
+ createIndex,
6092
+ dropIndex,
6093
+ union,
6094
+ unionAll,
6095
+ intersect,
6096
+ intersectAll,
6097
+ except,
6098
+ exceptAll,
6099
+ exportedSelect as select,
6100
+ where,
6101
+ having,
6102
+ exportedFrom as from,
6103
+ innerJoin,
6104
+ leftJoin,
6105
+ rightJoin,
6106
+ fullJoin,
6107
+ crossJoin,
6108
+ distinct,
6109
+ distinctOn,
6110
+ limit,
6111
+ offset,
6112
+ lock,
6113
+ orderBy,
6114
+ groupBy
6115
+ }