effect-qb 0.17.0 → 0.20.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 (137) hide show
  1. package/README.md +11 -1
  2. package/dist/index.js +9376 -0
  3. package/dist/mysql.js +4092 -2671
  4. package/dist/postgres/metadata.js +2589 -1402
  5. package/dist/postgres.js +3953 -3583
  6. package/dist/sqlite.js +5527 -4088
  7. package/dist/standard.js +9330 -0
  8. package/package.json +9 -4
  9. package/src/casing.ts +71 -0
  10. package/src/index.ts +2 -0
  11. package/src/internal/casing.ts +89 -0
  12. package/src/internal/coercion/rules.ts +13 -1
  13. package/src/internal/column-state.d.ts +3 -3
  14. package/src/internal/column-state.ts +24 -18
  15. package/src/internal/column.ts +52 -15
  16. package/src/internal/datatypes/define.ts +7 -1
  17. package/src/internal/datatypes/enrich.ts +23 -0
  18. package/src/internal/datatypes/lookup.ts +81 -25
  19. package/src/internal/datatypes/matrix.ts +903 -0
  20. package/src/internal/datatypes/shape.ts +2 -0
  21. package/src/internal/derived-table.ts +4 -36
  22. package/src/{mysql/internal/sql-expression-renderer.ts → internal/dialect-renderers/mysql.ts} +552 -361
  23. package/src/{postgres/internal/sql-expression-renderer.ts → internal/dialect-renderers/postgres.ts} +657 -400
  24. package/src/{sqlite/internal/sql-expression-renderer.ts → internal/dialect-renderers/sqlite.ts} +505 -347
  25. package/src/internal/dialect.ts +36 -1
  26. package/src/internal/dsl-mutation-runtime.ts +12 -162
  27. package/src/internal/dsl-plan-runtime.ts +10 -138
  28. package/src/internal/dsl-query-runtime.ts +5 -79
  29. package/src/internal/dsl-transaction-ddl-runtime.ts +41 -65
  30. package/src/internal/executor.ts +66 -49
  31. package/src/internal/grouping-key.ts +87 -20
  32. package/src/internal/implication-runtime.ts +1 -1
  33. package/src/internal/json/path-access.ts +351 -0
  34. package/src/internal/predicate/runtime.ts +3 -0
  35. package/src/internal/query.d.ts +39 -12
  36. package/src/internal/query.ts +65 -26
  37. package/src/internal/renderer.ts +26 -14
  38. package/src/internal/runtime/driver-value-mapping.ts +3 -3
  39. package/src/internal/runtime/normalize.ts +12 -5
  40. package/src/internal/runtime/schema.ts +28 -38
  41. package/src/internal/runtime/value.ts +20 -23
  42. package/src/internal/scalar.d.ts +1 -1
  43. package/src/internal/scalar.ts +8 -2
  44. package/src/internal/schema-derivation.d.ts +12 -61
  45. package/src/internal/schema-derivation.ts +95 -43
  46. package/src/internal/schema-expression.ts +2 -2
  47. package/src/internal/sql-expression-renderer.ts +19 -0
  48. package/src/internal/standard-dsl.ts +6978 -0
  49. package/src/internal/table-options.ts +126 -66
  50. package/src/internal/table.ts +819 -237
  51. package/src/mysql/column-extension.ts +3 -0
  52. package/src/mysql/column.ts +14 -15
  53. package/src/mysql/datatypes/index.ts +4 -2
  54. package/src/mysql/datatypes/spec.ts +6 -176
  55. package/src/mysql/errors/normalize.ts +0 -1
  56. package/src/mysql/executor.ts +11 -11
  57. package/src/mysql/function/temporal.ts +1 -1
  58. package/src/mysql/internal/dialect.ts +9 -4
  59. package/src/mysql/internal/dsl.ts +334 -170
  60. package/src/mysql/internal/renderer.ts +6 -2
  61. package/src/mysql/json.ts +7 -2
  62. package/src/mysql/query-extension.ts +16 -0
  63. package/src/mysql/renderer.ts +37 -3
  64. package/src/mysql/type.ts +60 -0
  65. package/src/mysql.ts +7 -13
  66. package/src/postgres/check.ts +1 -0
  67. package/src/postgres/column-extension.ts +28 -0
  68. package/src/postgres/column.ts +13 -19
  69. package/src/postgres/datatypes/index.d.ts +2 -1
  70. package/src/postgres/datatypes/index.ts +4 -2
  71. package/src/postgres/datatypes/spec.ts +6 -260
  72. package/src/postgres/errors/normalize.ts +0 -1
  73. package/src/postgres/executor.ts +11 -11
  74. package/src/postgres/foreign-key.ts +24 -0
  75. package/src/postgres/function/core.ts +1 -3
  76. package/src/postgres/function/index.ts +1 -17
  77. package/src/postgres/function/temporal.ts +1 -1
  78. package/src/postgres/index.ts +1 -0
  79. package/src/postgres/internal/dialect.ts +9 -4
  80. package/src/postgres/internal/dsl.ts +328 -179
  81. package/src/postgres/internal/renderer.ts +6 -2
  82. package/src/postgres/internal/schema-ddl.ts +22 -10
  83. package/src/postgres/internal/schema-model.ts +238 -7
  84. package/src/postgres/json-extension.ts +7 -0
  85. package/src/postgres/json.ts +762 -173
  86. package/src/postgres/jsonb.ts +37 -0
  87. package/src/postgres/primary-key.ts +24 -0
  88. package/src/postgres/query-extension.ts +2 -0
  89. package/src/postgres/renderer.ts +37 -3
  90. package/src/postgres/schema-management.ts +13 -13
  91. package/src/postgres/schema.ts +106 -15
  92. package/src/postgres/table.ts +205 -538
  93. package/src/postgres/type.ts +93 -10
  94. package/src/postgres/unique.ts +32 -0
  95. package/src/postgres.ts +20 -16
  96. package/src/sqlite/column-extension.ts +3 -0
  97. package/src/sqlite/column.ts +14 -15
  98. package/src/sqlite/datatypes/index.ts +4 -2
  99. package/src/sqlite/datatypes/spec.ts +6 -94
  100. package/src/sqlite/errors/normalize.ts +0 -1
  101. package/src/sqlite/executor.ts +11 -11
  102. package/src/sqlite/function/temporal.ts +1 -1
  103. package/src/sqlite/internal/dialect.ts +9 -4
  104. package/src/sqlite/internal/dsl.ts +307 -159
  105. package/src/sqlite/internal/renderer.ts +6 -2
  106. package/src/sqlite/json.ts +8 -2
  107. package/src/sqlite/query-extension.ts +2 -0
  108. package/src/sqlite/renderer.ts +37 -3
  109. package/src/sqlite/type.ts +40 -0
  110. package/src/sqlite.ts +7 -13
  111. package/src/standard/cast.ts +113 -0
  112. package/src/standard/check.ts +17 -0
  113. package/src/standard/column.ts +163 -0
  114. package/src/standard/datatypes/index.ts +83 -0
  115. package/src/standard/datatypes/spec.ts +12 -0
  116. package/src/standard/dialect.ts +40 -0
  117. package/src/standard/foreign-key.ts +37 -0
  118. package/src/standard/function/aggregate.ts +2 -0
  119. package/src/standard/function/core.ts +2 -0
  120. package/src/standard/function/index.ts +18 -0
  121. package/src/standard/function/string.ts +2 -0
  122. package/src/standard/function/temporal.ts +78 -0
  123. package/src/standard/function/window.ts +2 -0
  124. package/src/standard/index.ts +17 -0
  125. package/src/standard/internal/renderer.ts +45 -0
  126. package/src/standard/json.ts +883 -0
  127. package/src/standard/primary-key.ts +17 -0
  128. package/src/standard/query.ts +152 -0
  129. package/src/standard/renderer.ts +49 -0
  130. package/src/standard/table.ts +151 -0
  131. package/src/standard/unique.ts +17 -0
  132. package/src/standard.ts +32 -0
  133. package/src/internal/aggregation-validation.ts +0 -57
  134. package/src/internal/table.d.ts +0 -173
  135. package/src/mysql/table.ts +0 -183
  136. package/src/postgres/cast.ts +0 -45
  137. package/src/sqlite/table.ts +0 -183
@@ -1,4 +1,4 @@
1
- import { pipeArguments } from "effect/Pipeable"
1
+ import { pipeArguments, type Pipeable } from "effect/Pipeable"
2
2
  import * as Schema from "effect/Schema"
3
3
 
4
4
  import { postgresDatatypes } from "../datatypes/index.js"
@@ -6,6 +6,13 @@ import { postgresDatatypes } from "../datatypes/index.js"
6
6
  import * as Expression from "../../internal/scalar.js"
7
7
  import * as Plan from "../../internal/row-set.js"
8
8
  import * as Table from "../../internal/table.js"
9
+ import type {
10
+ CollationIdentifierInput,
11
+ LiteralStringInput,
12
+ NonEmptyStringInput,
13
+ SafeSqlIdentifierInput,
14
+ SafeSqlIdentifierPathInput
15
+ } from "../../internal/table-options.js"
9
16
  import type { CastTargetError, OperandCompatibilityError } from "../../internal/coercion/errors.js"
10
17
  import type { RuntimeOfDbType } from "../../internal/coercion/analysis.js"
11
18
  import type { CanCastDbType, CanCompareDbTypes, CanContainDbTypes, CanTextuallyCoerceDbType } from "../../internal/coercion/rules.js"
@@ -71,6 +78,7 @@ import {
71
78
  type ScopedNamesOfPlan,
72
79
  type SelectionOfPlan,
73
80
  type SelectionShape,
81
+ type SelectionProjectionAliasCollisionConstraint,
74
82
  type SetCompatiblePlan,
75
83
  type SetCompatibleRightPlan,
76
84
  type SchemaTableLike,
@@ -80,10 +88,8 @@ import {
80
88
  type TableDialectOf,
81
89
  type StatementOfPlan,
82
90
  type MutationInputOf,
83
- type MutationTargetLike,
84
91
  type MutationTargetOfPlan,
85
92
  type MergeCapabilities,
86
- type MutationTargetInput,
87
93
  type MutationValuesInput,
88
94
  type SourceDialectOf,
89
95
  type SourceLike,
@@ -100,7 +106,6 @@ import {
100
106
  type TableLike,
101
107
  type UpdateInputOfTarget,
102
108
  type MutationTargetNamesOf,
103
- type MutationTargetTuple,
104
109
  type TupleDependencies,
105
110
  type TupleDialect,
106
111
  type ResultRow
@@ -109,6 +114,7 @@ import * as ExpressionAst from "../../internal/expression-ast.js"
109
114
  import { presenceWitnessesOfSourceLike } from "../../internal/implication-runtime.js"
110
115
  import type { JsonNode } from "../../internal/json/ast.js"
111
116
  import type { JsonPathUsageError } from "../../internal/json/errors.js"
117
+ import { withJsonPathAccess } from "../../internal/json/path-access.js"
112
118
  import * as JsonPath from "../../internal/json/path.js"
113
119
  import type {
114
120
  JsonConcatResult,
@@ -138,6 +144,10 @@ import * as ProjectionAlias from "../../internal/projection-alias.js"
138
144
  import * as QueryAst from "../../internal/query-ast.js"
139
145
  import { normalizeColumnList } from "../../internal/table-options.js"
140
146
 
147
+ type MutationTargetLike = Table.AnyTable<Dialect | "standard">
148
+ type MutationTargetTuple = readonly [MutationTargetLike, MutationTargetLike, ...MutationTargetLike[]]
149
+ type MutationTargetInput = MutationTargetLike | MutationTargetTuple
150
+
141
151
  /**
142
152
  * Dialect-specific DB type profile used to specialize the shared query
143
153
  * operator surface.
@@ -710,7 +720,7 @@ type NumericExpressionDialectInput<
710
720
  BoolDb extends Expression.DbType.Any,
711
721
  TimestampDb extends Expression.DbType.Any,
712
722
  NullDb extends Expression.DbType.Any
713
- > = Exclude<DialectOfDialectNumericInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>, Dialect> extends never
723
+ > = Exclude<DialectOfDialectNumericInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>, Dialect | "standard"> extends never
714
724
  ? unknown
715
725
  : {
716
726
  readonly __effect_qb_error__: "effect-qb: numeric expressions cannot mix dialects"
@@ -803,6 +813,35 @@ type DialectExpressionArray<
803
813
  ? Tuple
804
814
  : never
805
815
 
816
+ type ExtractFunctionFieldInput<
817
+ Value extends ExpressionInput
818
+ > = Value extends string
819
+ ? SafeSqlIdentifierInput<Value>
820
+ : Value extends { readonly [ExpressionAst.TypeId]: ExpressionAst.LiteralNode<infer Field extends string> }
821
+ ? SafeSqlIdentifierInput<Field> extends never ? never : Value
822
+ : never
823
+
824
+ type GenericFunctionNameInput<Name extends string> =
825
+ Name extends "current_date" | "extract" ? never : SafeSqlIdentifierPathInput<Name>
826
+
827
+ type FunctionCallApi = {
828
+ (name: "current_date"): Expression.Any
829
+ <Field extends string, Source extends ExpressionInput>(
830
+ name: "extract",
831
+ field: SafeSqlIdentifierInput<Field>,
832
+ source: Source
833
+ ): Expression.Any
834
+ <Field extends Expression.Any, Source extends ExpressionInput>(
835
+ name: "extract",
836
+ field: Field & ExtractFunctionFieldInput<Field>,
837
+ source: Source
838
+ ): Expression.Any
839
+ <Name extends string, Args extends readonly ExpressionInput[]>(
840
+ name: GenericFunctionNameInput<Name>,
841
+ ...args: Args
842
+ ): Expression.Any
843
+ }
844
+
806
845
  /** Normalized expression tuple for generic string operator inputs. */
807
846
  type DialectStringExpressionTuple<
808
847
  Values extends readonly ExpressionInput[],
@@ -1069,6 +1108,9 @@ type JsonPathInput = JsonPath.Path<any> | JsonPath.CanonicalSegment
1069
1108
 
1070
1109
  type JsonQueryInput = JsonPath.Path<any> | StringExpressionInput
1071
1110
 
1111
+ type JsonQueryValue<Query extends JsonQueryInput> =
1112
+ Query extends string ? LiteralStringInput<Query> : Query
1113
+
1072
1114
  type JsonPathSegmentsOf<Target extends JsonPathInput> =
1073
1115
  Target extends JsonPath.Path<any>
1074
1116
  ? JsonPath.SegmentsOf<Target>
@@ -1505,18 +1547,21 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
1505
1547
  type: postgresDatatypes
1506
1548
  }
1507
1549
  const ValuesInputProto = {
1508
- pipe(this: unknown) {
1550
+ pipe(this: Pipeable) {
1509
1551
  return pipeArguments(this, arguments)
1510
1552
  }
1511
1553
  }
1512
1554
 
1513
1555
  const literalSchemaOf = <Value extends LiteralValue>(
1514
1556
  value: Value
1515
- ): Schema.Schema.Any | undefined => {
1557
+ ): Schema.Top | undefined => {
1516
1558
  if (value === null || value instanceof Date) {
1517
1559
  return undefined
1518
1560
  }
1519
- return Schema.Literal(value) as unknown as Schema.Schema.Any
1561
+ if (typeof value === "number" && !Number.isFinite(value)) {
1562
+ return undefined
1563
+ }
1564
+ return Schema.Literal(value) as unknown as Schema.Top
1520
1565
  }
1521
1566
 
1522
1567
  const literal = <const Value extends LiteralValue>(
@@ -1603,7 +1648,7 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
1603
1648
  value: Expression.Any,
1604
1649
  target: Expression.Any
1605
1650
  ): Expression.Any => {
1606
- const ast = (value as unknown as { readonly [ExpressionAst.TypeId]: ExpressionAst.Any })[ExpressionAst.TypeId]
1651
+ const ast = (value as Expression.Any & { readonly [ExpressionAst.TypeId]: ExpressionAst.Any })[ExpressionAst.TypeId]
1607
1652
  if (ast.kind !== "literal") {
1608
1653
  return value
1609
1654
  }
@@ -1624,8 +1669,8 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
1624
1669
  left: Expression.Any,
1625
1670
  right: Expression.Any
1626
1671
  ): readonly [Expression.Any, Expression.Any] => {
1627
- const leftAst = (left as unknown as { readonly [ExpressionAst.TypeId]: ExpressionAst.Any })[ExpressionAst.TypeId]
1628
- const rightAst = (right as unknown as { readonly [ExpressionAst.TypeId]: ExpressionAst.Any })[ExpressionAst.TypeId]
1672
+ const leftAst = (left as Expression.Any & { readonly [ExpressionAst.TypeId]: ExpressionAst.Any })[ExpressionAst.TypeId]
1673
+ const rightAst = (right as Expression.Any & { readonly [ExpressionAst.TypeId]: ExpressionAst.Any })[ExpressionAst.TypeId]
1629
1674
  if (leftAst.kind === "literal" && rightAst.kind !== "literal") {
1630
1675
  return [retargetLiteralExpression(left, right), right]
1631
1676
  }
@@ -1658,7 +1703,7 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
1658
1703
  ): readonly Expression.Any[] => {
1659
1704
  const flattened: Array<Expression.Any> = []
1660
1705
  for (const value of values) {
1661
- const ast = (value as unknown as { readonly [ExpressionAst.TypeId]: ExpressionAst.Any })[ExpressionAst.TypeId]
1706
+ const ast = (value as Expression.Any & { readonly [ExpressionAst.TypeId]: ExpressionAst.Any })[ExpressionAst.TypeId]
1662
1707
  if (ast.kind === kind) {
1663
1708
  flattened.push(...ast.values)
1664
1709
  } else {
@@ -1704,7 +1749,33 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
1704
1749
  if (operations.every((operation) => typeof operation === "function")) {
1705
1750
  return pipeArguments(this, arguments)
1706
1751
  }
1707
- throw new TypeError(`Cannot mix query expressions and pipe functions inside ${kind}(...).pipe(...)`)
1752
+ const valuesForMixedPipe = (value: unknown): readonly Expression.Any[] => {
1753
+ if (typeof value !== "object" || value === null || !(Expression.TypeId in value)) {
1754
+ return []
1755
+ }
1756
+ const expression = value as Expression.Any & {
1757
+ readonly [ExpressionAst.TypeId]: ExpressionAst.Any
1758
+ }
1759
+ const ast = expression[ExpressionAst.TypeId]
1760
+ if (ast.kind === kind) {
1761
+ return (ast as {
1762
+ readonly values: readonly Expression.Any[]
1763
+ }).values
1764
+ }
1765
+ return [expression]
1766
+ }
1767
+ let current: unknown = this
1768
+ for (const operation of operations) {
1769
+ if (typeof operation === "function") {
1770
+ current = (operation as (value: unknown) => unknown)(current)
1771
+ continue
1772
+ }
1773
+ current = makeVariadicBooleanExpression(
1774
+ kind,
1775
+ [...valuesForMixedPipe(current), toDialectExpression(operation as ExpressionInput)] as const
1776
+ )
1777
+ }
1778
+ return current
1708
1779
  }
1709
1780
  })
1710
1781
 
@@ -1725,9 +1796,6 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
1725
1796
  const partitionBy = [...(spec?.partitionBy ?? [])] as unknown as PartitionBy
1726
1797
  const orderBy = (spec?.orderBy ?? []).map((term) => {
1727
1798
  const direction = term.direction ?? "asc"
1728
- if (direction !== "asc" && direction !== "desc") {
1729
- throw new Error("window order direction must be asc or desc")
1730
- }
1731
1799
  return {
1732
1800
  value: term.value,
1733
1801
  direction
@@ -1868,7 +1936,8 @@ type BinaryPredicateExpression<
1868
1936
  >(
1869
1937
  ...args: ComparableArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "eq">
1870
1938
  ): BinaryPredicateExpression<Left, Right, "eq"> => {
1871
- const [left, right] = args as unknown as [Left, Right]
1939
+ const left = args[0] as Left
1940
+ const right = args[1] as Right
1872
1941
  return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "eq")
1873
1942
  }
1874
1943
 
@@ -1878,7 +1947,8 @@ type BinaryPredicateExpression<
1878
1947
  >(
1879
1948
  ...args: ComparableArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "neq">
1880
1949
  ): BinaryPredicateExpression<Left, Right, "neq"> => {
1881
- const [left, right] = args as unknown as [Left, Right]
1950
+ const left = args[0] as Left
1951
+ const right = args[1] as Right
1882
1952
  return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "neq")
1883
1953
  }
1884
1954
 
@@ -1888,7 +1958,8 @@ type BinaryPredicateExpression<
1888
1958
  >(
1889
1959
  ...args: ComparableArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "lt">
1890
1960
  ): BinaryPredicateExpression<Left, Right, "lt"> => {
1891
- const [left, right] = args as unknown as [Left, Right]
1961
+ const left = args[0] as Left
1962
+ const right = args[1] as Right
1892
1963
  return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "lt")
1893
1964
  }
1894
1965
 
@@ -1898,7 +1969,8 @@ type BinaryPredicateExpression<
1898
1969
  >(
1899
1970
  ...args: ComparableArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "lte">
1900
1971
  ): BinaryPredicateExpression<Left, Right, "lte"> => {
1901
- const [left, right] = args as unknown as [Left, Right]
1972
+ const left = args[0] as Left
1973
+ const right = args[1] as Right
1902
1974
  return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "lte")
1903
1975
  }
1904
1976
 
@@ -1908,7 +1980,8 @@ type BinaryPredicateExpression<
1908
1980
  >(
1909
1981
  ...args: ComparableArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "gt">
1910
1982
  ): BinaryPredicateExpression<Left, Right, "gt"> => {
1911
- const [left, right] = args as unknown as [Left, Right]
1983
+ const left = args[0] as Left
1984
+ const right = args[1] as Right
1912
1985
  return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "gt")
1913
1986
  }
1914
1987
 
@@ -1918,7 +1991,8 @@ type BinaryPredicateExpression<
1918
1991
  >(
1919
1992
  ...args: ComparableArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "gte">
1920
1993
  ): BinaryPredicateExpression<Left, Right, "gte"> => {
1921
- const [left, right] = args as unknown as [Left, Right]
1994
+ const left = args[0] as Left
1995
+ const right = args[1] as Right
1922
1996
  return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "gte")
1923
1997
  }
1924
1998
 
@@ -1928,7 +2002,8 @@ type BinaryPredicateExpression<
1928
2002
  >(
1929
2003
  ...args: TextArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "like">
1930
2004
  ): BinaryPredicateExpression<Left, Right, "like"> => {
1931
- const [left, right] = args as unknown as [Left, Right]
2005
+ const left = args[0] as Left
2006
+ const right = args[1] as Right
1932
2007
  return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "like")
1933
2008
  }
1934
2009
 
@@ -1938,7 +2013,8 @@ type BinaryPredicateExpression<
1938
2013
  >(
1939
2014
  ...args: TextArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "ilike">
1940
2015
  ): BinaryPredicateExpression<Left, Right, "ilike"> => {
1941
- const [left, right] = args as unknown as [Left, Right]
2016
+ const left = args[0] as Left
2017
+ const right = args[1] as Right
1942
2018
  return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "ilike")
1943
2019
  }
1944
2020
 
@@ -1948,7 +2024,8 @@ type BinaryPredicateExpression<
1948
2024
  >(
1949
2025
  ...args: TextArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "regexMatch">
1950
2026
  ): BinaryPredicateExpression<Left, Right, "regexMatch"> => {
1951
- const [left, right] = args as unknown as [Left, Right]
2027
+ const left = args[0] as Left
2028
+ const right = args[1] as Right
1952
2029
  return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "regexMatch")
1953
2030
  }
1954
2031
 
@@ -1958,7 +2035,8 @@ type BinaryPredicateExpression<
1958
2035
  >(
1959
2036
  ...args: TextArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "regexIMatch">
1960
2037
  ): BinaryPredicateExpression<Left, Right, "regexIMatch"> => {
1961
- const [left, right] = args as unknown as [Left, Right]
2038
+ const left = args[0] as Left
2039
+ const right = args[1] as Right
1962
2040
  return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "regexIMatch")
1963
2041
  }
1964
2042
 
@@ -1968,7 +2046,8 @@ type BinaryPredicateExpression<
1968
2046
  >(
1969
2047
  ...args: TextArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "regexNotMatch">
1970
2048
  ): BinaryPredicateExpression<Left, Right, "regexNotMatch"> => {
1971
- const [left, right] = args as unknown as [Left, Right]
2049
+ const left = args[0] as Left
2050
+ const right = args[1] as Right
1972
2051
  return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "regexNotMatch")
1973
2052
  }
1974
2053
 
@@ -1978,7 +2057,8 @@ type BinaryPredicateExpression<
1978
2057
  >(
1979
2058
  ...args: TextArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "regexNotIMatch">
1980
2059
  ): BinaryPredicateExpression<Left, Right, "regexNotIMatch"> => {
1981
- const [left, right] = args as unknown as [Left, Right]
2060
+ const left = args[0] as Left
2061
+ const right = args[1] as Right
1982
2062
  return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "regexNotIMatch")
1983
2063
  }
1984
2064
 
@@ -1988,7 +2068,8 @@ type BinaryPredicateExpression<
1988
2068
  >(
1989
2069
  ...args: ComparableArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "isDistinctFrom">
1990
2070
  ): BinaryPredicateExpression<Left, Right, "isDistinctFrom", "never"> => {
1991
- const [left, right] = args as unknown as [Left, Right]
2071
+ const left = args[0] as Left
2072
+ const right = args[1] as Right
1992
2073
  return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "isDistinctFrom", "never")
1993
2074
  }
1994
2075
 
@@ -1998,7 +2079,8 @@ type BinaryPredicateExpression<
1998
2079
  >(
1999
2080
  ...args: ComparableArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "isNotDistinctFrom">
2000
2081
  ): BinaryPredicateExpression<Left, Right, "isNotDistinctFrom", "never"> => {
2001
- const [left, right] = args as unknown as [Left, Right]
2082
+ const left = args[0] as Left
2083
+ const right = args[1] as Right
2002
2084
  return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "isNotDistinctFrom", "never")
2003
2085
  }
2004
2086
 
@@ -2114,7 +2196,7 @@ type BinaryPredicateExpression<
2114
2196
  Collation extends string | readonly [string, ...string[]]
2115
2197
  >(
2116
2198
  value: Value & TextInput<NoInfer<Value>, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "collate">,
2117
- collation: Collation
2199
+ collation: CollationIdentifierInput<Collation>
2118
2200
  ): AstBackedExpression<
2119
2201
  Expression.RuntimeOf<DialectAsStringExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
2120
2202
  Expression.DbTypeOf<DialectAsStringExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
@@ -2125,7 +2207,7 @@ type BinaryPredicateExpression<
2125
2207
  ExpressionAst.CollateNode<DialectAsStringExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>, NormalizedCollation<Collation>>
2126
2208
  > => {
2127
2209
  const expression = toDialectStringExpression(value as any)
2128
- const normalizedCollation = (typeof collation === "string" ? [collation] : collation) as NormalizedCollation<Collation>
2210
+ const normalizedCollation = (typeof collation === "string" ? [collation] : collation) as unknown as NormalizedCollation<Collation>
2129
2211
  return makeExpression({
2130
2212
  runtime: expression[Expression.TypeId].runtime as Expression.RuntimeOf<DialectAsStringExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
2131
2213
  dbType: expression[Expression.TypeId].dbType as Expression.DbTypeOf<DialectAsStringExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
@@ -2192,62 +2274,62 @@ type BinaryPredicateExpression<
2192
2274
  })
2193
2275
 
2194
2276
  const range = <Kind extends string, Subtype extends Expression.DbType.Any>(
2195
- kind: Kind,
2277
+ kind: NonEmptyStringInput<Kind>,
2196
2278
  subtype: Subtype
2197
2279
  ): Expression.DbType.Range<Dialect, Subtype, Kind> => ({
2198
2280
  dialect: profile.dialect,
2199
- kind,
2281
+ kind: kind as Kind,
2200
2282
  subtype
2201
2283
  })
2202
2284
 
2203
2285
  const multirange = <Kind extends string, Subtype extends Expression.DbType.Any>(
2204
- kind: Kind,
2286
+ kind: NonEmptyStringInput<Kind>,
2205
2287
  subtype: Subtype
2206
2288
  ): Expression.DbType.Multirange<Dialect, Subtype, Kind> => ({
2207
2289
  dialect: profile.dialect,
2208
- kind,
2290
+ kind: kind as Kind,
2209
2291
  subtype
2210
2292
  })
2211
2293
 
2212
2294
  const record = <Kind extends string, Fields extends Record<string, Expression.DbType.Any>>(
2213
- kind: Kind,
2295
+ kind: NonEmptyStringInput<Kind>,
2214
2296
  fields: Fields
2215
2297
  ): Expression.DbType.Composite<Dialect, Fields, Kind> => ({
2216
2298
  dialect: profile.dialect,
2217
- kind,
2299
+ kind: kind as Kind,
2218
2300
  fields
2219
2301
  })
2220
2302
 
2221
2303
  const domain = <Kind extends string, Base extends Expression.DbType.Any>(
2222
- kind: Kind,
2304
+ kind: NonEmptyStringInput<Kind>,
2223
2305
  base: Base
2224
2306
  ): Expression.DbType.Domain<Dialect, Base, Kind> => ({
2225
2307
  dialect: profile.dialect,
2226
- kind,
2308
+ kind: kind as Kind,
2227
2309
  base
2228
2310
  })
2229
2311
 
2230
2312
  const enum_ = <Kind extends string>(
2231
- kind: Kind
2313
+ kind: NonEmptyStringInput<Kind>
2232
2314
  ): Expression.DbType.Enum<Dialect, Kind> => ({
2233
2315
  dialect: profile.dialect,
2234
- kind,
2316
+ kind: kind as Kind,
2235
2317
  variant: "enum"
2236
2318
  })
2237
2319
 
2238
2320
  const set = <Kind extends string>(
2239
- kind: Kind
2321
+ kind: NonEmptyStringInput<Kind>
2240
2322
  ): Expression.DbType.Set<Dialect, Kind> => ({
2241
2323
  dialect: profile.dialect,
2242
- kind,
2324
+ kind: kind as Kind,
2243
2325
  variant: "set"
2244
2326
  })
2245
2327
 
2246
2328
  const custom = <Kind extends string>(
2247
- kind: Kind
2329
+ kind: NonEmptyStringInput<Kind>
2248
2330
  ): Expression.DbType.Base<Dialect, Kind> => ({
2249
2331
  dialect: profile.dialect,
2250
- kind
2332
+ kind: kind as Kind
2251
2333
  })
2252
2334
 
2253
2335
  const driverValueMapping = <Db extends Expression.DbType.Any>(
@@ -2324,7 +2406,7 @@ type BinaryPredicateExpression<
2324
2406
  MergeAggregationTuple<typeof expressions>,
2325
2407
  TupleDependencies<typeof expressions>,
2326
2408
  Ast
2327
- > => makeExpression({
2409
+ > => withJsonPathAccess(makeExpression({
2328
2410
  runtime: state.runtime,
2329
2411
  dbType: state.dbType,
2330
2412
  nullability: state.nullability,
@@ -2332,7 +2414,7 @@ type BinaryPredicateExpression<
2332
2414
  kind: mergeAggregationManyRuntime(expressions) as MergeAggregationTuple<typeof expressions>,
2333
2415
 
2334
2416
  dependencies: mergeManyDependencies(expressions)
2335
- }, ast) as AstBackedExpression<
2417
+ }, ast)) as AstBackedExpression<
2336
2418
  Runtime,
2337
2419
  Db,
2338
2420
  Nullability,
@@ -2353,7 +2435,7 @@ type BinaryPredicateExpression<
2353
2435
  const makeJsonLiteralExpression = <Value extends JsonLiteralInput>(
2354
2436
  value: Value,
2355
2437
  dbType: Expression.DbType.Json<any, any> = jsonDb
2356
- ) => makeExpression({
2438
+ ) => withJsonPathAccess(makeExpression({
2357
2439
  runtime: value as JsonRuntime<Value>,
2358
2440
  dbType,
2359
2441
  nullability: (value === null ? "always" : "never") as JsonNullabilityOf<Value>,
@@ -2364,7 +2446,7 @@ type BinaryPredicateExpression<
2364
2446
  }, {
2365
2447
  kind: "literal",
2366
2448
  value
2367
- })
2449
+ }))
2368
2450
 
2369
2451
  const wrapJsonExpression = (
2370
2452
  value: Expression.Any,
@@ -3051,9 +3133,12 @@ type BinaryPredicateExpression<
3051
3133
  }
3052
3134
  )
3053
3135
 
3054
- const jsonPathExists = <Base extends JsonExpressionLike<any>>(
3136
+ const jsonPathExists = <
3137
+ Base extends JsonExpressionLike<any>,
3138
+ Query extends JsonQueryInput
3139
+ >(
3055
3140
  base: Base,
3056
- query: JsonQueryInput
3141
+ query: JsonQueryValue<Query>
3057
3142
  ) => {
3058
3143
  if (isJsonPathValue(query)) {
3059
3144
  return buildJsonNodeExpression(
@@ -3101,9 +3186,12 @@ type BinaryPredicateExpression<
3101
3186
  }
3102
3187
  )
3103
3188
 
3104
- const jsonPathMatch = <Base extends JsonExpressionLike<any>>(
3189
+ const jsonPathMatch = <
3190
+ Base extends JsonExpressionLike<any>,
3191
+ Query extends JsonQueryInput
3192
+ >(
3105
3193
  base: Base,
3106
- query: JsonQueryInput
3194
+ query: JsonQueryValue<Query>
3107
3195
  ) => {
3108
3196
  if (isJsonPathValue(query)) {
3109
3197
  return buildJsonNodeExpression(
@@ -3330,7 +3418,8 @@ type BinaryPredicateExpression<
3330
3418
  >(
3331
3419
  ...args: ContainmentArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "contains">
3332
3420
  ): BinaryPredicateExpression<Left, Right, "contains"> => {
3333
- const [left, right] = args as unknown as [Left, Right]
3421
+ const left = args[0] as Left
3422
+ const right = args[1] as Right
3334
3423
  return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "contains")
3335
3424
  }
3336
3425
 
@@ -3340,7 +3429,8 @@ type BinaryPredicateExpression<
3340
3429
  >(
3341
3430
  ...args: ContainmentArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "containedBy">
3342
3431
  ): BinaryPredicateExpression<Left, Right, "containedBy"> => {
3343
- const [left, right] = args as unknown as [Left, Right]
3432
+ const left = args[0] as Left
3433
+ const right = args[1] as Right
3344
3434
  return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "containedBy")
3345
3435
  }
3346
3436
 
@@ -3350,7 +3440,8 @@ type BinaryPredicateExpression<
3350
3440
  >(
3351
3441
  ...args: ContainmentArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "overlaps">
3352
3442
  ): BinaryPredicateExpression<Left, Right, "overlaps"> => {
3353
- const [left, right] = args as unknown as [Left, Right]
3443
+ const left = args[0] as Left
3444
+ const right = args[1] as Right
3354
3445
  return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "overlaps")
3355
3446
  }
3356
3447
 
@@ -3777,12 +3868,9 @@ type BinaryPredicateExpression<
3777
3868
  >
3778
3869
  }
3779
3870
 
3780
- const call = <
3781
- Name extends string,
3782
- Args extends readonly ExpressionInput[]
3783
- >(
3784
- name: Name,
3785
- ...args: Args
3871
+ const call: FunctionCallApi = (
3872
+ name: string,
3873
+ ...args: readonly ExpressionInput[]
3786
3874
  ): Expression.Any => {
3787
3875
  const expressions = args.map((value) => toDialectExpression(value)) as readonly Expression.Any[]
3788
3876
  return makeExpression({
@@ -4018,9 +4106,6 @@ type BinaryPredicateExpression<
4018
4106
  ExpressionAst.ExcludedNode<AstOf<Value> extends ExpressionAst.ColumnNode<any, infer ColumnName extends string> ? ColumnName : string>
4019
4107
  > => {
4020
4108
  const ast = ((value as unknown) as Expression.Any & { readonly [ExpressionAst.TypeId]: ExpressionAst.Any })[ExpressionAst.TypeId]
4021
- if (ast.kind !== "column") {
4022
- throw new Error("excluded(...) only accepts bound table columns")
4023
- }
4024
4109
  return makeExpression({
4025
4110
  runtime: undefined as Expression.RuntimeOf<Value>,
4026
4111
  dbType: value[Expression.TypeId].dbType as Expression.DbTypeOf<Value>,
@@ -4033,7 +4118,7 @@ type BinaryPredicateExpression<
4033
4118
  dependencies: {}
4034
4119
  }, {
4035
4120
  kind: "excluded",
4036
- columnName: ast.columnName
4121
+ columnName: (ast as ExpressionAst.ColumnNode<any, string>).columnName
4037
4122
  }) as unknown as AstBackedExpression<
4038
4123
  Expression.RuntimeOf<Value>,
4039
4124
  Expression.DbTypeOf<Value>,
@@ -4066,7 +4151,7 @@ type BinaryPredicateExpression<
4066
4151
  }
4067
4152
  if (value !== null && typeof value === "object" && Expression.TypeId in value) {
4068
4153
  const expression = value as unknown as Expression.Any
4069
- const ast = (expression as unknown as { readonly [ExpressionAst.TypeId]: ExpressionAst.Any })[ExpressionAst.TypeId]
4154
+ const ast = (expression as Expression.Any & { readonly [ExpressionAst.TypeId]: ExpressionAst.Any })[ExpressionAst.TypeId]
4070
4155
  if (ast.kind === "literal") {
4071
4156
  const normalizedValue = normalizeMutationValue(ast.value)
4072
4157
  return makeExpression({
@@ -4135,8 +4220,8 @@ type BinaryPredicateExpression<
4135
4220
  : ">="
4136
4221
 
4137
4222
  const targetSourceDetails = (table: MutationTargetLike | SchemaTableLike) => {
4138
- const sourceName = (table as unknown as TableLike)[Table.TypeId].name
4139
- const sourceBaseName = (table as unknown as TableLike)[Table.TypeId].baseName
4223
+ const sourceName = (table as TableLike)[Table.TypeId].name
4224
+ const sourceBaseName = (table as TableLike)[Table.TypeId].baseName
4140
4225
  return {
4141
4226
  sourceName,
4142
4227
  sourceBaseName
@@ -4226,12 +4311,7 @@ type BinaryPredicateExpression<
4226
4311
 
4227
4312
  const normalizeUnnestColumns = (columns: UnnestColumnsInput): Record<string, readonly Expression.Any[]> =>
4228
4313
  Object.fromEntries(
4229
- Object.entries(columns).map(([key, values]) => {
4230
- if (!Array.isArray(values)) {
4231
- throw new Error("unnest(...) expects every value to be an array")
4232
- }
4233
- return [key, values.map((value) => toDialectExpression(value))]
4234
- })
4314
+ Object.entries(columns).map(([key, values]) => [key, values.map((value) => toDialectExpression(value))])
4235
4315
  ) as Record<string, readonly Expression.Any[]>
4236
4316
 
4237
4317
  const normalizeMutationTargets = (
@@ -4277,13 +4357,7 @@ type BinaryPredicateExpression<
4277
4357
  const getMutationColumn = (
4278
4358
  columns: Record<string, unknown>,
4279
4359
  columnName: string
4280
- ): Expression.Any => {
4281
- const column = columns[columnName]
4282
- if (column === undefined || column === null || typeof column !== "object" || !(Expression.TypeId in column)) {
4283
- throw new Error("effect-qb: unknown mutation column")
4284
- }
4285
- return column as Expression.Any
4286
- }
4360
+ ): Expression.Any => columns[columnName] as Expression.Any
4287
4361
 
4288
4362
  const buildMutationAssignments = <Target extends MutationTargetInput, Values>(
4289
4363
  target: Target,
@@ -4299,7 +4373,7 @@ type BinaryPredicateExpression<
4299
4373
  }
4300
4374
  const valueMap = values as Record<string, Record<string, unknown> | undefined>
4301
4375
  return targets.flatMap((table) => {
4302
- const targetName = (table as unknown as TableLike)[Table.TypeId].name
4376
+ const targetName = (table as TableLike)[Table.TypeId].name
4303
4377
  const scopedValues = valueMap[targetName] ?? {}
4304
4378
  const columns = table as unknown as Record<string, Expression.Any>
4305
4379
  return Object.entries(scopedValues).map(([columnName, value]) => ({
@@ -4320,20 +4394,17 @@ type BinaryPredicateExpression<
4320
4394
  } => {
4321
4395
  const firstRow = rows[0]
4322
4396
  const firstColumns = Object.keys(firstRow)
4323
- if (firstColumns.length === 0) {
4324
- throw new Error("values(...) rows must specify at least one column; use insert(target) for default-only inserts instead")
4325
- }
4326
4397
  const columns = firstColumns as [string, ...string[]]
4327
- const normalizedRows = rows.map((row) => {
4328
- const rowKeys = Object.keys(row)
4329
- if (rowKeys.length !== columns.length || columns.some((column) => !(column in row))) {
4330
- throw new Error("All values(...) rows must project the same columns in the same shape")
4331
- }
4398
+ const normalizeRow = (row: InsertRowInput<Target>) => {
4332
4399
  const assignments = buildMutationAssignments(target, row) as readonly QueryAst.AssignmentClause[]
4333
4400
  return {
4334
4401
  values: columns.map((columnName) => assignments.find((assignment) => assignment.columnName === columnName)!)
4335
4402
  } satisfies QueryAst.InsertValuesRowClause
4336
- }) as unknown as [QueryAst.InsertValuesRowClause, ...QueryAst.InsertValuesRowClause[]]
4403
+ }
4404
+ const normalizedRows: readonly [QueryAst.InsertValuesRowClause, ...QueryAst.InsertValuesRowClause[]] = [
4405
+ normalizeRow(rows[0]),
4406
+ ...rows.slice(1).map(normalizeRow)
4407
+ ]
4337
4408
  const required = normalizedRows.flatMap((row) =>
4338
4409
  row.values.flatMap((entry) => Object.keys(entry.value[Expression.TypeId].dependencies))
4339
4410
  )
@@ -4348,9 +4419,6 @@ type BinaryPredicateExpression<
4348
4419
  selection: Record<string, Expression.Any>
4349
4420
  ): readonly [string, ...string[]] => {
4350
4421
  const columns = Object.keys(selection)
4351
- if (columns.length === 0) {
4352
- throw new Error("insert(...).pipe(from(subquery)) requires at least one projected column")
4353
- }
4354
4422
  return columns as [string, ...string[]]
4355
4423
  }
4356
4424
 
@@ -4365,27 +4433,11 @@ type BinaryPredicateExpression<
4365
4433
  }[]
4366
4434
  } => {
4367
4435
  const entries = Object.entries(values)
4368
- if (entries.length === 0) {
4369
- throw new Error("unnest(...) requires at least one column array")
4370
- }
4371
4436
  const columns = entries.map(([columnName]) => columnName) as [string, ...string[]]
4372
- const normalized = entries.map(([columnName, items]) => {
4373
- if (!Array.isArray(items)) {
4374
- throw new Error("unnest(...) expects every value to be an array")
4375
- }
4376
- return {
4377
- columnName,
4378
- values: items
4379
- }
4380
- })
4381
- const expectedLength = normalized[0]!.values.length
4382
- if (normalized.some((entry) => entry.values.length !== expectedLength)) {
4383
- throw new Error("unnest(...) expects every column array to have the same length")
4384
- }
4385
- const knownColumns = new Set(Object.keys(target[Table.TypeId].fields))
4386
- if (columns.some((columnName) => !knownColumns.has(columnName))) {
4387
- throw new Error("unnest(...) received a column that does not exist on the target table")
4388
- }
4437
+ const normalized = entries.map(([columnName, items]) => ({
4438
+ columnName,
4439
+ values: items
4440
+ }))
4389
4441
  return {
4390
4442
  columns,
4391
4443
  values: normalized
@@ -4397,10 +4449,6 @@ type BinaryPredicateExpression<
4397
4449
  columnsInput: string | readonly string[]
4398
4450
  ): readonly [string, ...string[]] => {
4399
4451
  const columns = normalizeColumnList(columnsInput) as readonly [string, ...string[]]
4400
- const knownColumns = new Set(Object.keys(target[Table.TypeId].fields))
4401
- if (columns.some((columnName) => !knownColumns.has(columnName))) {
4402
- throw new Error("effect-qb: unknown conflict target column")
4403
- }
4404
4452
  return columns
4405
4453
  }
4406
4454
 
@@ -4479,14 +4527,91 @@ type ValidateTargetColumnInput<
4479
4527
  Columns extends DdlColumnInput
4480
4528
  > = ValidateTargetColumns<Target, NormalizeDdlColumns<Columns>> extends never ? never : Columns
4481
4529
 
4482
- type CreateIndexOptions = {
4483
- readonly name?: string
4530
+ type SameColumnSet<
4531
+ Left extends readonly string[],
4532
+ Right extends readonly string[]
4533
+ > = string extends Left[number] | Right[number]
4534
+ ? false
4535
+ : Exclude<Left[number], Right[number]> extends never
4536
+ ? Exclude<Right[number], Left[number]> extends never
4537
+ ? true
4538
+ : false
4539
+ : false
4540
+
4541
+ type ConflictArbitersOf<Target extends MutationTargetLike> =
4542
+ Target[typeof Table.TypeId]["conflictArbiters"][number]
4543
+
4544
+ type MatchingConflictArbiter<
4545
+ Target extends MutationTargetLike,
4546
+ Columns extends readonly string[],
4547
+ AllowPartial extends boolean
4548
+ > = ConflictArbitersOf<Target> extends infer Arbiter extends Table.ConflictArbiter
4549
+ ? Arbiter extends Table.ConflictArbiter
4550
+ ? SameColumnSet<Arbiter["columns"], Columns> extends true
4551
+ ? Arbiter["scope"] extends "unconditional"
4552
+ ? true
4553
+ : AllowPartial extends true ? true : never
4554
+ : never
4555
+ : never
4556
+ : never
4557
+
4558
+ type HasInlineConflictArbiter<
4559
+ Target extends MutationTargetLike,
4560
+ Columns extends readonly string[]
4561
+ > = Columns extends readonly [infer Column extends Extract<keyof Target[typeof Table.TypeId]["fields"], string>]
4562
+ ? Target[typeof Table.TypeId]["fields"][Column] extends { readonly metadata: { readonly primaryKey: true } | { readonly unique: true } }
4563
+ ? true
4564
+ : false
4565
+ : false
4566
+
4567
+ type HasConflictArbiter<
4568
+ Target extends MutationTargetLike,
4569
+ Columns extends readonly string[],
4570
+ AllowPartial extends boolean
4571
+ > = string extends Extract<keyof Target[typeof Table.TypeId]["fields"], string>
4572
+ ? true
4573
+ : HasInlineConflictArbiter<Target, Columns> extends true
4574
+ ? true
4575
+ : true extends MatchingConflictArbiter<Target, Columns, AllowPartial> ? true : false
4576
+
4577
+ type ConflictTargetArbiterError<
4578
+ Columns,
4579
+ AllowPartial extends boolean
4580
+ > = {
4581
+ readonly __effect_qb_error__: "effect-qb: conflict target columns must match a primary key, unique constraint, or unique index"
4582
+ readonly __effect_qb_conflict_columns__: Columns
4583
+ readonly __effect_qb_partial_target__: AllowPartial
4584
+ readonly __effect_qb_hint__: "Declare the target columns as primaryKey/unique, add a table-level Unique.make(...), or use a simple Pg.Index.uniqueIndex(...)"
4585
+ }
4586
+
4587
+ type ValidateConflictColumnInput<
4588
+ Target extends MutationTargetLike,
4589
+ Columns extends DdlColumnInput,
4590
+ AllowPartial extends boolean
4591
+ > = ValidateTargetColumnInput<Target, Columns> extends never
4592
+ ? never
4593
+ : HasConflictArbiter<Target, NormalizeDdlColumns<Columns>, AllowPartial> extends true
4594
+ ? Columns
4595
+ : ConflictTargetArbiterError<NormalizeDdlColumns<Columns>, AllowPartial>
4596
+
4597
+ type ConflictColumnPlanConstraint<
4598
+ Target extends MutationTargetLike,
4599
+ Columns extends DdlColumnInput,
4600
+ AllowPartial extends boolean
4601
+ > = ValidateTargetColumnInput<Target, Columns> extends never
4602
+ ? never
4603
+ : HasConflictArbiter<Target, NormalizeDdlColumns<Columns>, AllowPartial> extends true
4604
+ ? unknown
4605
+ : ConflictTargetArbiterError<NormalizeDdlColumns<Columns>, AllowPartial>
4606
+
4607
+ type CreateIndexOptions<Name extends string = string> = {
4608
+ readonly name?: NonEmptyStringInput<Name>
4484
4609
  readonly unique?: boolean
4485
4610
  readonly ifNotExists?: boolean
4486
4611
  }
4487
4612
 
4488
- type DropIndexOptions = {
4489
- readonly name?: string
4613
+ type DropIndexOptions<Name extends string = string> = {
4614
+ readonly name?: NonEmptyStringInput<Name>
4490
4615
  readonly ifExists?: boolean
4491
4616
  }
4492
4617
 
@@ -4590,7 +4715,7 @@ type ValuesRowsDialectInput<
4590
4715
  BoolDb extends Expression.DbType.Any,
4591
4716
  TimestampDb extends Expression.DbType.Any,
4592
4717
  NullDb extends Expression.DbType.Any
4593
- > = Exclude<ValuesRowsDialect<Rows, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>, Dialect> extends never
4718
+ > = Exclude<ValuesRowsDialect<Rows, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>, Dialect | "standard"> extends never
4594
4719
  ? unknown
4595
4720
  : {
4596
4721
  readonly __effect_qb_error__: "effect-qb: values rows cannot mix dialects"
@@ -4645,7 +4770,7 @@ type UnnestColumnsDialectInput<
4645
4770
  BoolDb extends Expression.DbType.Any,
4646
4771
  TimestampDb extends Expression.DbType.Any,
4647
4772
  NullDb extends Expression.DbType.Any
4648
- > = Exclude<UnnestColumnsDialect<Columns, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>, Dialect> extends never
4773
+ > = Exclude<UnnestColumnsDialect<Columns, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>, Dialect | "standard"> extends never
4649
4774
  ? unknown
4650
4775
  : {
4651
4776
  readonly __effect_qb_error__: "effect-qb: unnest columns cannot mix dialects"
@@ -4912,6 +5037,26 @@ type ConflictTargetInput<
4912
5037
  readonly constraint?: string
4913
5038
  }>)
4914
5039
 
5040
+ type ConflictConstraintNameConstraint<Target> =
5041
+ Target extends { readonly constraint: infer Constraint extends string }
5042
+ ? { readonly constraint: NonEmptyStringInput<Constraint> }
5043
+ : unknown
5044
+
5045
+ type ConflictTargetHasPredicate<Target> =
5046
+ Target extends { readonly where: PredicateInput } ? true : false
5047
+
5048
+ type ConflictTargetPlanConstraint<
5049
+ Target extends MutationTargetLike,
5050
+ ConflictTarget
5051
+ > =
5052
+ ConflictTarget extends { readonly constraint: string }
5053
+ ? unknown
5054
+ : ConflictTarget extends { readonly columns: infer Columns extends DdlColumnInput }
5055
+ ? ConflictColumnPlanConstraint<Target, Columns, ConflictTargetHasPredicate<ConflictTarget>>
5056
+ : ConflictTarget extends DdlColumnInput
5057
+ ? ConflictColumnPlanConstraint<Target, ConflictTarget, false>
5058
+ : unknown
5059
+
4915
5060
  type ConflictActionInput<
4916
5061
  Target extends MutationTargetLike,
4917
5062
  Dialect extends string,
@@ -5063,7 +5208,12 @@ type MutationOrderLimitSupported<PlanValue extends QueryPlan<any, any, any, any,
5063
5208
  type MutationTargetTupleDialectConstraint<
5064
5209
  Targets extends MutationTargetTuple,
5065
5210
  Dialect extends string
5066
- > = Exclude<TableDialectOf<Targets[number]>, Dialect> extends never ? unknown : never
5211
+ > = Exclude<TableDialectOf<Targets[number]>, Dialect | "standard"> extends never ? unknown : never
5212
+
5213
+ type TableDialectConstraint<
5214
+ Target extends TableLike,
5215
+ Dialect extends string
5216
+ > = Exclude<TableDialectOf<Target>, Dialect> extends never ? unknown : never
5067
5217
 
5068
5218
  type MutationRequiredFromValues<Values extends Record<string, unknown>> = {
5069
5219
  [K in keyof Values]: Values[K] extends Expression.Any ? RequiredFromDependencies<DependenciesOf<Values[K]>> : never
@@ -5117,7 +5267,7 @@ type KnownIncompatibleMutationDialectFromValues<
5117
5267
  BoolDb extends Expression.DbType.Any,
5118
5268
  TimestampDb extends Expression.DbType.Any,
5119
5269
  NullDb extends Expression.DbType.Any
5120
- > = Exclude<KnownMutationDialectFromValues<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>, Dialect>
5270
+ > = Exclude<KnownMutationDialectFromValues<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>, Dialect | "standard">
5121
5271
 
5122
5272
  type MutationValuesDialectConstraint<
5123
5273
  Values,
@@ -5169,9 +5319,11 @@ type SourceDialectConstraint<
5169
5319
  Dialect extends string
5170
5320
  > = [SourceDialectOf<CurrentSource>] extends [never]
5171
5321
  ? unknown
5172
- : Extract<SourceDialectOf<CurrentSource>, Dialect> extends never
5173
- ? never
5174
- : unknown
5322
+ : Exclude<SourceDialectOf<CurrentSource>, Dialect | "standard"> extends never
5323
+ ? unknown
5324
+ : Dialect extends "standard"
5325
+ ? unknown
5326
+ : never
5175
5327
 
5176
5328
  type SourceRequirementConstraint<
5177
5329
  PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>,
@@ -5465,7 +5617,7 @@ type AsCurriedResult<
5465
5617
  function as<
5466
5618
  Alias extends string
5467
5619
  >(
5468
- alias: Alias
5620
+ alias: LiteralStringInput<Alias>
5469
5621
  ): <Value extends AsCurriedInput<Dialect>>(
5470
5622
  value: Value
5471
5623
  ) => AsCurriedResult<Value, Alias, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
@@ -5474,7 +5626,7 @@ type AsCurriedResult<
5474
5626
  Alias extends string
5475
5627
  >(
5476
5628
  value: Value,
5477
- alias: Alias
5629
+ alias: LiteralStringInput<Alias>
5478
5630
  ): ProjectionAliasedExpression<DialectAsExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>, Alias>
5479
5631
  function as<
5480
5632
  Rows extends ValuesRowsInput,
@@ -5485,7 +5637,7 @@ type AsCurriedResult<
5485
5637
  ValuesOutputShape<Rows, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
5486
5638
  Dialect
5487
5639
  >,
5488
- alias: Alias
5640
+ alias: LiteralStringInput<Alias>
5489
5641
  ): ValuesSource<
5490
5642
  Rows,
5491
5643
  ValuesOutputShape<Rows, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
@@ -5497,11 +5649,11 @@ type AsCurriedResult<
5497
5649
  Alias extends string
5498
5650
  >(
5499
5651
  value: DerivedTableCompatiblePlan<PlanValue>,
5500
- alias: Alias
5652
+ alias: LiteralStringInput<Alias>
5501
5653
  ): DerivedSource<PlanValue, Alias>
5502
5654
  function as(valueOrAlias: unknown, alias?: string): unknown {
5503
5655
  if (alias === undefined) {
5504
- return (value: unknown) => as(value as any, valueOrAlias as string)
5656
+ return (value: unknown) => as(value as any, valueOrAlias as never)
5505
5657
  }
5506
5658
  const resolvedAlias = alias
5507
5659
  const value = valueOrAlias
@@ -5541,7 +5693,7 @@ type AsCurriedResult<
5541
5693
  function with_<
5542
5694
  Alias extends string
5543
5695
  >(
5544
- alias: Alias
5696
+ alias: LiteralStringInput<Alias>
5545
5697
  ): <PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
5546
5698
  value: DerivedSourceCompatiblePlan<PlanValue>
5547
5699
  ) => import("../../internal/query.js").CteSource<PlanValue, Alias>
@@ -5550,11 +5702,11 @@ type AsCurriedResult<
5550
5702
  Alias extends string
5551
5703
  >(
5552
5704
  value: DerivedSourceCompatiblePlan<PlanValue>,
5553
- alias: Alias
5705
+ alias: LiteralStringInput<Alias>
5554
5706
  ): import("../../internal/query.js").CteSource<PlanValue, Alias>
5555
5707
  function with_(valueOrAlias: unknown, alias?: string): unknown {
5556
5708
  if (alias === undefined) {
5557
- return (value: unknown) => with_(value as any, valueOrAlias as string)
5709
+ return (value: unknown) => with_(value as any, valueOrAlias as never)
5558
5710
  }
5559
5711
  return makeCteSource(
5560
5712
  valueOrAlias as CompletePlan<QueryPlan<any, any, any, any, any, any, any, any, any, any>>,
@@ -5565,7 +5717,7 @@ type AsCurriedResult<
5565
5717
  function withRecursive_<
5566
5718
  Alias extends string
5567
5719
  >(
5568
- alias: Alias
5720
+ alias: LiteralStringInput<Alias>
5569
5721
  ): <PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
5570
5722
  value: DerivedSourceCompatiblePlan<PlanValue>
5571
5723
  ) => import("../../internal/query.js").CteSource<PlanValue, Alias>
@@ -5574,11 +5726,11 @@ type AsCurriedResult<
5574
5726
  Alias extends string
5575
5727
  >(
5576
5728
  value: DerivedSourceCompatiblePlan<PlanValue>,
5577
- alias: Alias
5729
+ alias: LiteralStringInput<Alias>
5578
5730
  ): import("../../internal/query.js").CteSource<PlanValue, Alias>
5579
5731
  function withRecursive_(valueOrAlias: unknown, alias?: string): unknown {
5580
5732
  if (alias === undefined) {
5581
- return (value: unknown) => withRecursive_(value as any, valueOrAlias as string)
5733
+ return (value: unknown) => withRecursive_(value as any, valueOrAlias as never)
5582
5734
  }
5583
5735
  return makeCteSource(
5584
5736
  valueOrAlias as CompletePlan<QueryPlan<any, any, any, any, any, any, any, any, any, any>>,
@@ -5590,7 +5742,7 @@ type AsCurriedResult<
5590
5742
  function lateral<
5591
5743
  Alias extends string
5592
5744
  >(
5593
- alias: Alias
5745
+ alias: LiteralStringInput<Alias>
5594
5746
  ): <PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
5595
5747
  value: LateralSourceCompatiblePlan<PlanValue>
5596
5748
  ) => import("../../internal/query.js").LateralSource<PlanValue, Alias>
@@ -5599,11 +5751,11 @@ type AsCurriedResult<
5599
5751
  Alias extends string
5600
5752
  >(
5601
5753
  value: LateralSourceCompatiblePlan<PlanValue>,
5602
- alias: Alias
5754
+ alias: LiteralStringInput<Alias>
5603
5755
  ): import("../../internal/query.js").LateralSource<PlanValue, Alias>
5604
5756
  function lateral(valueOrAlias: unknown, alias?: string): unknown {
5605
5757
  if (alias === undefined) {
5606
- return (value: unknown) => lateral(value as any, valueOrAlias as string)
5758
+ return (value: unknown) => lateral(value as any, valueOrAlias as never)
5607
5759
  }
5608
5760
  return makeLateralSource(
5609
5761
  valueOrAlias as QueryPlan<any, any, any, any, any, any, any, any, any, any>,
@@ -5630,7 +5782,7 @@ type AsCurriedResult<
5630
5782
  columns: Columns
5631
5783
  & UnnestColumnsShapeInput<Columns>
5632
5784
  & UnnestColumnsDialectInput<Columns, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
5633
- alias: Alias
5785
+ alias: LiteralStringInput<Alias>
5634
5786
  ) => UnnestSource<
5635
5787
  UnnestOutputShape<Columns, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
5636
5788
  Alias,
@@ -5646,7 +5798,7 @@ type AsCurriedResult<
5646
5798
  start: Start & NumericExpressionDialectInput<Start, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
5647
5799
  stop: Stop & NumericExpressionDialectInput<Stop, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
5648
5800
  step?: Step & (Step extends NumericExpressionInput ? NumericExpressionDialectInput<Step, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> : unknown),
5649
- alias?: Alias
5801
+ alias?: LiteralStringInput<Alias>
5650
5802
  ) => Dialect extends "postgres"
5651
5803
  ? TableFunctionSource<
5652
5804
  GenerateSeriesOutputShape<Start, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
@@ -5665,7 +5817,7 @@ type AsCurriedResult<
5665
5817
  start: Start & NumericExpressionDialectInput<Start, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
5666
5818
  stop: Stop & NumericExpressionDialectInput<Stop, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
5667
5819
  step?: Step & (Step extends NumericExpressionInput ? NumericExpressionDialectInput<Step, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> : unknown),
5668
- alias?: Alias
5820
+ alias?: LiteralStringInput<Alias>
5669
5821
  ) => TableFunctionSource<
5670
5822
  {
5671
5823
  readonly value: Expression.Scalar<number, NumericDb, "never", Dialect, "scalar", never, string>
@@ -5703,8 +5855,8 @@ type AsCurriedResult<
5703
5855
  type SelectionNestedNonEmptyConstraint<Selection> =
5704
5856
  SelectionHasEmptyNestedObject<Selection, true> extends true ? SelectionNestedEmptyError<Selection> : unknown
5705
5857
 
5706
- export type SelectApi = <Selection extends SelectionShape = {}>(
5707
- selection?: Selection & SelectionRootObjectConstraint<Selection> & SelectionNestedNonEmptyConstraint<Selection>
5858
+ export type SelectApi = <const Selection extends SelectionShape = {}>(
5859
+ selection?: Selection & SelectionRootObjectConstraint<Selection> & SelectionNestedNonEmptyConstraint<Selection> & SelectionProjectionAliasCollisionConstraint<Selection>
5708
5860
  ) => QueryPlan<
5709
5861
  Selection,
5710
5862
  ExtractRequired<Selection>,
@@ -6129,9 +6281,6 @@ type AsCurriedResult<
6129
6281
  const fullJoin = ((table, on) => (join as any)("full", table, on)) as BinaryJoinApi<"full">
6130
6282
 
6131
6283
  const distinctOn = (<Values extends readonly [ExpressionInput, ...ExpressionInput[]]>(...values: Values) => {
6132
- if (values.length === 0) {
6133
- throw new Error("distinctOn(...) requires at least one expression")
6134
- }
6135
6284
  const expressions = values.map((value) => toDialectExpression(value)) as Expression.Any[]
6136
6285
  return <PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
6137
6286
  plan: PlanValue & RequireSelectStatement<PlanValue>
@@ -6197,8 +6346,8 @@ type AsCurriedResult<
6197
6346
  ? ReturningSelectionNonEmptyError<Selection>
6198
6347
  : unknown
6199
6348
 
6200
- type ReturningApi = <Selection extends SelectionShape>(
6201
- selection: Selection & SelectionRootObjectConstraint<Selection> & SelectionNestedNonEmptyConstraint<Selection> & ReturningSelectionNonEmptyConstraint<Selection>
6349
+ type ReturningApi = <const Selection extends SelectionShape>(
6350
+ selection: Selection & SelectionRootObjectConstraint<Selection> & SelectionNestedNonEmptyConstraint<Selection> & ReturningSelectionNonEmptyConstraint<Selection> & SelectionProjectionAliasCollisionConstraint<Selection>
6202
6351
  ) =>
6203
6352
  <PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
6204
6353
  plan: PlanValue & RequireMutationStatement<PlanValue>
@@ -6220,7 +6369,7 @@ type AsCurriedResult<
6220
6369
 
6221
6370
  export interface InsertApi {
6222
6371
  <Target extends MutationTargetLike>(
6223
- target: Target
6372
+ target: Target & TableDialectConstraint<Target, Dialect>
6224
6373
  ): QueryPlan<
6225
6374
  {},
6226
6375
  never,
@@ -6237,7 +6386,7 @@ type AsCurriedResult<
6237
6386
  EmptyFacts
6238
6387
  >
6239
6388
  <Target extends MutationTargetLike, Values extends Record<string, unknown>>(
6240
- target: Target,
6389
+ target: Target & TableDialectConstraint<Target, Dialect>,
6241
6390
  values: MutationValuesInput<"insert", Target, Values> & MutationValuesDialectConstraint<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
6242
6391
  ): QueryPlan<
6243
6392
  {},
@@ -6266,13 +6415,13 @@ type AsCurriedResult<
6266
6415
  const Columns extends DdlColumnInput,
6267
6416
  UpdateValues extends MutationInputOf<Table.UpdateOf<Target>> | undefined = MutationInputOf<Table.UpdateOf<Target>> | undefined,
6268
6417
  Options extends ConflictActionInput<Target, Dialect, UpdateValues> = ConflictActionInput<Target, Dialect, UpdateValues>,
6269
- ConflictTarget extends ConflictTargetInput<Target, Dialect, Columns> = ConflictTargetInput<Target, Dialect, Columns>
6418
+ const ConflictTarget extends ConflictTargetInput<Target, Dialect, Columns> = ConflictTargetInput<Target, Dialect, Columns>
6270
6419
  >(
6271
- target: ConflictTarget,
6420
+ target: ConflictTarget & ConflictConstraintNameConstraint<ConflictTarget>,
6272
6421
  options?: Options & ConflictActionUpdateNonEmptyConstraint<Options>
6273
- ) =>
6422
+ ) =>
6274
6423
  <PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
6275
- plan: PlanValue & RequireInsertStatement<PlanValue>
6424
+ plan: PlanValue & RequireInsertStatement<PlanValue> & ConflictTargetPlanConstraint<MutationTargetOfPlan<PlanValue>, ConflictTarget>
6276
6425
  ) => QueryPlan<
6277
6426
  SelectionOfPlan<PlanValue>,
6278
6427
  Exclude<RequiredOfPlan<PlanValue> | ConflictRequired<UpdateValues, Options, ConflictTarget>, AvailableNames<AvailableOfPlan<PlanValue>>>,
@@ -6309,7 +6458,7 @@ type AsCurriedResult<
6309
6458
  EmptyFacts
6310
6459
  >
6311
6460
  <Target extends MutationTargetLike, Values extends Record<string, unknown>>(
6312
- target: Target,
6461
+ target: Target & TableDialectConstraint<Target, Dialect>,
6313
6462
  values: MutationValuesInput<"update", Target, Values> & UpdateValuesNonEmptyConstraint<Values> & MutationValuesDialectConstraint<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
6314
6463
  ): QueryPlan<
6315
6464
  {},
@@ -6334,9 +6483,9 @@ type AsCurriedResult<
6334
6483
  const Columns extends DdlColumnInput,
6335
6484
  UpdateValues extends MutationInputOf<Table.UpdateOf<Target>> | undefined = undefined
6336
6485
  >(
6337
- target: Target,
6486
+ target: Target & TableDialectConstraint<Target, Dialect>,
6338
6487
  values: Values & MutationValuesDialectConstraint<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
6339
- conflictColumns: ValidateTargetColumnInput<Target, Columns>,
6488
+ conflictColumns: ValidateConflictColumnInput<Target, Columns, false>,
6340
6489
  updateValues?: UpdateValues & UpdateValuesNonEmptyConstraint<Exclude<UpdateValues, undefined>> & MutationValuesDialectConstraint<Exclude<UpdateValues, undefined>, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
6341
6490
  ) => QueryPlan<
6342
6491
  {},
@@ -6358,7 +6507,7 @@ type AsCurriedResult<
6358
6507
 
6359
6508
  interface DeleteApi {
6360
6509
  <Target extends MutationTargetLike>(
6361
- target: Target
6510
+ target: Target & TableDialectConstraint<Target, Dialect>
6362
6511
  ): QueryPlan<
6363
6512
  {},
6364
6513
  never,
@@ -6394,7 +6543,7 @@ type AsCurriedResult<
6394
6543
  }
6395
6544
 
6396
6545
  type TruncateApi = <Target extends MutationTargetLike>(
6397
- target: Target,
6546
+ target: Target & TableDialectConstraint<Target, Dialect>,
6398
6547
  options?: TruncateOptions
6399
6548
  ) => QueryPlan<
6400
6549
  {},
@@ -6421,10 +6570,10 @@ type AsCurriedResult<
6421
6570
  MatchedPredicate extends PredicateInput | undefined = undefined,
6422
6571
  NotMatchedPredicate extends PredicateInput | undefined = undefined
6423
6572
  >(
6424
- target: Target,
6573
+ target: Target & TableDialectConstraint<Target, Dialect>,
6425
6574
  source: Source & (
6426
6575
  SourceRequiredOf<Source> extends never ? unknown : SourceRequirementError<Source>
6427
- ) & MergeSourceNameConstraint<Target, Source>,
6576
+ ) & MergeSourceNameConstraint<Target, Source> & SourceDialectConstraint<Source, Dialect>,
6428
6577
  on: On,
6429
6578
  options: MergeOptions<Target, MatchedValues, InsertValues, MatchedPredicate, NotMatchedPredicate>
6430
6579
  ) => QueryPlan<
@@ -6586,7 +6735,7 @@ type AsCurriedResult<
6586
6735
  "rollback"
6587
6736
  >
6588
6737
 
6589
- type SavepointApi = <Name extends string>(name: Name) => QueryPlan<
6738
+ type SavepointApi = <Name extends string>(name: NonEmptyStringInput<Name>) => QueryPlan<
6590
6739
  {},
6591
6740
  never,
6592
6741
  {},
@@ -6599,7 +6748,7 @@ type AsCurriedResult<
6599
6748
  "savepoint"
6600
6749
  >
6601
6750
 
6602
- type RollbackToApi = <Name extends string>(name: Name) => QueryPlan<
6751
+ type RollbackToApi = <Name extends string>(name: NonEmptyStringInput<Name>) => QueryPlan<
6603
6752
  {},
6604
6753
  never,
6605
6754
  {},
@@ -6612,7 +6761,7 @@ type AsCurriedResult<
6612
6761
  "rollbackTo"
6613
6762
  >
6614
6763
 
6615
- type ReleaseSavepointApi = <Name extends string>(name: Name) => QueryPlan<
6764
+ type ReleaseSavepointApi = <Name extends string>(name: NonEmptyStringInput<Name>) => QueryPlan<
6616
6765
  {},
6617
6766
  never,
6618
6767
  {},
@@ -6626,7 +6775,7 @@ type AsCurriedResult<
6626
6775
  >
6627
6776
 
6628
6777
  type CreateTableApi = <Target extends SchemaTableLike>(
6629
- target: Target,
6778
+ target: Target & TableDialectConstraint<Target, Dialect>,
6630
6779
  options?: CreateTableOptions
6631
6780
  ) => QueryPlan<
6632
6781
  {},
@@ -6642,7 +6791,7 @@ type AsCurriedResult<
6642
6791
  >
6643
6792
 
6644
6793
  type DropTableApi = <Target extends SchemaTableLike>(
6645
- target: Target,
6794
+ target: Target & TableDialectConstraint<Target, Dialect>,
6646
6795
  options?: DropTableOptions
6647
6796
  ) => QueryPlan<
6648
6797
  {},
@@ -6657,10 +6806,10 @@ type AsCurriedResult<
6657
6806
  "dropTable"
6658
6807
  >
6659
6808
 
6660
- type CreateIndexApi = <Target extends SchemaTableLike, const Columns extends DdlColumnInput>(
6661
- target: Target,
6809
+ type CreateIndexApi = <Target extends SchemaTableLike, const Columns extends DdlColumnInput, Name extends string = string>(
6810
+ target: Target & TableDialectConstraint<Target, Dialect>,
6662
6811
  columns: Columns & ValidateDdlColumnInput<Target, Columns>,
6663
- options?: CreateIndexOptions
6812
+ options?: CreateIndexOptions<Name>
6664
6813
  ) => QueryPlan<
6665
6814
  {},
6666
6815
  never,
@@ -6674,10 +6823,10 @@ type AsCurriedResult<
6674
6823
  "createIndex"
6675
6824
  >
6676
6825
 
6677
- type DropIndexApi = <Target extends SchemaTableLike, const Columns extends DdlColumnInput>(
6678
- target: Target,
6826
+ type DropIndexApi = <Target extends SchemaTableLike, const Columns extends DdlColumnInput, Name extends string = string>(
6827
+ target: Target & TableDialectConstraint<Target, Dialect>,
6679
6828
  columns: Columns & ValidateDdlColumnInput<Target, Columns>,
6680
- options?: DropIndexOptions
6829
+ options?: DropIndexOptions<Name>
6681
6830
  ) => QueryPlan<
6682
6831
  {},
6683
6832
  never,