effect-qb 0.17.0 → 0.19.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 (103) hide show
  1. package/README.md +4 -0
  2. package/dist/index.js +8065 -0
  3. package/dist/mysql.js +3053 -2505
  4. package/dist/postgres/metadata.js +1366 -1250
  5. package/dist/postgres.js +2020 -2719
  6. package/dist/sqlite.js +3226 -2732
  7. package/dist/standard.js +8019 -0
  8. package/package.json +10 -3
  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/column-state.ts +11 -6
  13. package/src/internal/column.ts +44 -7
  14. package/src/internal/datatypes/define.ts +2 -1
  15. package/src/internal/datatypes/enrich.ts +23 -0
  16. package/src/internal/datatypes/lookup.ts +14 -7
  17. package/src/internal/derived-table.ts +4 -36
  18. package/src/{mysql/internal/sql-expression-renderer.ts → internal/dialect-renderers/mysql.ts} +548 -359
  19. package/src/{postgres/internal/sql-expression-renderer.ts → internal/dialect-renderers/postgres.ts} +654 -399
  20. package/src/{sqlite/internal/sql-expression-renderer.ts → internal/dialect-renderers/sqlite.ts} +501 -345
  21. package/src/internal/dialect.ts +35 -0
  22. package/src/internal/dsl-mutation-runtime.ts +12 -162
  23. package/src/internal/dsl-plan-runtime.ts +10 -138
  24. package/src/internal/dsl-query-runtime.ts +5 -79
  25. package/src/internal/dsl-transaction-ddl-runtime.ts +41 -65
  26. package/src/internal/executor.ts +10 -6
  27. package/src/internal/grouping-key.ts +87 -20
  28. package/src/internal/implication-runtime.ts +1 -1
  29. package/src/internal/predicate/runtime.ts +3 -0
  30. package/src/internal/query.d.ts +38 -11
  31. package/src/internal/query.ts +64 -25
  32. package/src/internal/renderer.ts +26 -14
  33. package/src/internal/runtime/normalize.ts +12 -5
  34. package/src/internal/scalar.ts +6 -1
  35. package/src/internal/schema-derivation.d.ts +12 -61
  36. package/src/internal/schema-derivation.ts +90 -38
  37. package/src/internal/schema-expression.ts +2 -2
  38. package/src/internal/sql-expression-renderer.ts +19 -0
  39. package/src/internal/standard-dsl.ts +6885 -0
  40. package/src/internal/table-options.ts +126 -66
  41. package/src/internal/table.d.ts +33 -32
  42. package/src/internal/table.ts +406 -155
  43. package/src/mysql/column-extension.ts +3 -0
  44. package/src/mysql/column.ts +10 -11
  45. package/src/mysql/datatypes/index.ts +3 -2
  46. package/src/mysql/executor.ts +7 -5
  47. package/src/mysql/internal/dialect.ts +9 -4
  48. package/src/mysql/internal/dsl.ts +219 -155
  49. package/src/mysql/internal/renderer.ts +6 -2
  50. package/src/mysql/json.ts +37 -0
  51. package/src/mysql/query-extension.ts +16 -0
  52. package/src/mysql/renderer.ts +31 -4
  53. package/src/mysql.ts +4 -12
  54. package/src/postgres/column-extension.ts +28 -0
  55. package/src/postgres/column.ts +5 -11
  56. package/src/postgres/datatypes/index.d.ts +2 -1
  57. package/src/postgres/datatypes/index.ts +3 -2
  58. package/src/postgres/executor.ts +7 -5
  59. package/src/postgres/function/core.ts +1 -3
  60. package/src/postgres/function/index.ts +1 -17
  61. package/src/postgres/internal/dialect.ts +9 -4
  62. package/src/postgres/internal/dsl.ts +208 -160
  63. package/src/postgres/internal/renderer.ts +6 -2
  64. package/src/postgres/internal/schema-ddl.ts +22 -10
  65. package/src/postgres/internal/schema-model.ts +238 -7
  66. package/src/postgres/json.ts +43 -7
  67. package/src/postgres/jsonb.ts +38 -0
  68. package/src/postgres/query-extension.ts +2 -0
  69. package/src/postgres/renderer.ts +31 -4
  70. package/src/postgres/schema-management.ts +17 -12
  71. package/src/postgres/schema.ts +98 -15
  72. package/src/postgres/table.ts +193 -524
  73. package/src/postgres/type.ts +8 -7
  74. package/src/postgres.ts +9 -11
  75. package/src/sqlite/column-extension.ts +3 -0
  76. package/src/sqlite/column.ts +10 -11
  77. package/src/sqlite/datatypes/index.ts +3 -2
  78. package/src/sqlite/executor.ts +7 -5
  79. package/src/sqlite/internal/dialect.ts +9 -4
  80. package/src/sqlite/internal/dsl.ts +208 -155
  81. package/src/sqlite/internal/renderer.ts +6 -2
  82. package/src/sqlite/json.ts +37 -0
  83. package/src/sqlite/query-extension.ts +2 -0
  84. package/src/sqlite/renderer.ts +31 -4
  85. package/src/sqlite.ts +4 -12
  86. package/src/standard/column.ts +163 -0
  87. package/src/standard/datatypes/index.ts +83 -0
  88. package/src/standard/datatypes/spec.ts +98 -0
  89. package/src/standard/dialect.ts +40 -0
  90. package/src/standard/function/aggregate.ts +2 -0
  91. package/src/standard/function/core.ts +2 -0
  92. package/src/standard/function/index.ts +18 -0
  93. package/src/standard/function/string.ts +2 -0
  94. package/src/standard/function/temporal.ts +78 -0
  95. package/src/standard/function/window.ts +2 -0
  96. package/src/standard/internal/renderer.ts +45 -0
  97. package/src/standard/query.ts +152 -0
  98. package/src/standard/renderer.ts +21 -0
  99. package/src/standard/table.ts +147 -0
  100. package/src/standard.ts +18 -0
  101. package/src/internal/aggregation-validation.ts +0 -57
  102. package/src/mysql/table.ts +0 -183
  103. 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
@@ -138,6 +143,10 @@ import * as ProjectionAlias from "../../internal/projection-alias.js"
138
143
  import * as QueryAst from "../../internal/query-ast.js"
139
144
  import { normalizeColumnList } from "../../internal/table-options.js"
140
145
 
146
+ type MutationTargetLike = Table.AnyTable<Dialect | "standard">
147
+ type MutationTargetTuple = readonly [MutationTargetLike, MutationTargetLike, ...MutationTargetLike[]]
148
+ type MutationTargetInput = MutationTargetLike | MutationTargetTuple
149
+
141
150
  /**
142
151
  * Dialect-specific DB type profile used to specialize the shared query
143
152
  * operator surface.
@@ -710,7 +719,7 @@ type NumericExpressionDialectInput<
710
719
  BoolDb extends Expression.DbType.Any,
711
720
  TimestampDb extends Expression.DbType.Any,
712
721
  NullDb extends Expression.DbType.Any
713
- > = Exclude<DialectOfDialectNumericInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>, Dialect> extends never
722
+ > = Exclude<DialectOfDialectNumericInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>, Dialect | "standard"> extends never
714
723
  ? unknown
715
724
  : {
716
725
  readonly __effect_qb_error__: "effect-qb: numeric expressions cannot mix dialects"
@@ -803,6 +812,35 @@ type DialectExpressionArray<
803
812
  ? Tuple
804
813
  : never
805
814
 
815
+ type ExtractFunctionFieldInput<
816
+ Value extends ExpressionInput
817
+ > = Value extends string
818
+ ? SafeSqlIdentifierInput<Value>
819
+ : Value extends { readonly [ExpressionAst.TypeId]: ExpressionAst.LiteralNode<infer Field extends string> }
820
+ ? SafeSqlIdentifierInput<Field> extends never ? never : Value
821
+ : never
822
+
823
+ type GenericFunctionNameInput<Name extends string> =
824
+ Name extends "current_date" | "extract" ? never : SafeSqlIdentifierPathInput<Name>
825
+
826
+ type FunctionCallApi = {
827
+ (name: "current_date"): Expression.Any
828
+ <Field extends string, Source extends ExpressionInput>(
829
+ name: "extract",
830
+ field: SafeSqlIdentifierInput<Field>,
831
+ source: Source
832
+ ): Expression.Any
833
+ <Field extends Expression.Any, Source extends ExpressionInput>(
834
+ name: "extract",
835
+ field: Field & ExtractFunctionFieldInput<Field>,
836
+ source: Source
837
+ ): Expression.Any
838
+ <Name extends string, Args extends readonly ExpressionInput[]>(
839
+ name: GenericFunctionNameInput<Name>,
840
+ ...args: Args
841
+ ): Expression.Any
842
+ }
843
+
806
844
  /** Normalized expression tuple for generic string operator inputs. */
807
845
  type DialectStringExpressionTuple<
808
846
  Values extends readonly ExpressionInput[],
@@ -1069,6 +1107,9 @@ type JsonPathInput = JsonPath.Path<any> | JsonPath.CanonicalSegment
1069
1107
 
1070
1108
  type JsonQueryInput = JsonPath.Path<any> | StringExpressionInput
1071
1109
 
1110
+ type JsonQueryValue<Query extends JsonQueryInput> =
1111
+ Query extends string ? LiteralStringInput<Query> : Query
1112
+
1072
1113
  type JsonPathSegmentsOf<Target extends JsonPathInput> =
1073
1114
  Target extends JsonPath.Path<any>
1074
1115
  ? JsonPath.SegmentsOf<Target>
@@ -1505,7 +1546,7 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
1505
1546
  type: postgresDatatypes
1506
1547
  }
1507
1548
  const ValuesInputProto = {
1508
- pipe(this: unknown) {
1549
+ pipe(this: Pipeable) {
1509
1550
  return pipeArguments(this, arguments)
1510
1551
  }
1511
1552
  }
@@ -1516,7 +1557,7 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
1516
1557
  if (value === null || value instanceof Date) {
1517
1558
  return undefined
1518
1559
  }
1519
- return Schema.Literal(value) as unknown as Schema.Schema.Any
1560
+ return Schema.Literal(value) as Schema.Schema.Any
1520
1561
  }
1521
1562
 
1522
1563
  const literal = <const Value extends LiteralValue>(
@@ -1603,7 +1644,7 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
1603
1644
  value: Expression.Any,
1604
1645
  target: Expression.Any
1605
1646
  ): Expression.Any => {
1606
- const ast = (value as unknown as { readonly [ExpressionAst.TypeId]: ExpressionAst.Any })[ExpressionAst.TypeId]
1647
+ const ast = (value as Expression.Any & { readonly [ExpressionAst.TypeId]: ExpressionAst.Any })[ExpressionAst.TypeId]
1607
1648
  if (ast.kind !== "literal") {
1608
1649
  return value
1609
1650
  }
@@ -1624,8 +1665,8 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
1624
1665
  left: Expression.Any,
1625
1666
  right: Expression.Any
1626
1667
  ): 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]
1668
+ const leftAst = (left as Expression.Any & { readonly [ExpressionAst.TypeId]: ExpressionAst.Any })[ExpressionAst.TypeId]
1669
+ const rightAst = (right as Expression.Any & { readonly [ExpressionAst.TypeId]: ExpressionAst.Any })[ExpressionAst.TypeId]
1629
1670
  if (leftAst.kind === "literal" && rightAst.kind !== "literal") {
1630
1671
  return [retargetLiteralExpression(left, right), right]
1631
1672
  }
@@ -1658,7 +1699,7 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
1658
1699
  ): readonly Expression.Any[] => {
1659
1700
  const flattened: Array<Expression.Any> = []
1660
1701
  for (const value of values) {
1661
- const ast = (value as unknown as { readonly [ExpressionAst.TypeId]: ExpressionAst.Any })[ExpressionAst.TypeId]
1702
+ const ast = (value as Expression.Any & { readonly [ExpressionAst.TypeId]: ExpressionAst.Any })[ExpressionAst.TypeId]
1662
1703
  if (ast.kind === kind) {
1663
1704
  flattened.push(...ast.values)
1664
1705
  } else {
@@ -1704,7 +1745,33 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
1704
1745
  if (operations.every((operation) => typeof operation === "function")) {
1705
1746
  return pipeArguments(this, arguments)
1706
1747
  }
1707
- throw new TypeError(`Cannot mix query expressions and pipe functions inside ${kind}(...).pipe(...)`)
1748
+ const valuesForMixedPipe = (value: unknown): readonly Expression.Any[] => {
1749
+ if (typeof value !== "object" || value === null || !(Expression.TypeId in value)) {
1750
+ return []
1751
+ }
1752
+ const expression = value as Expression.Any & {
1753
+ readonly [ExpressionAst.TypeId]: ExpressionAst.Any
1754
+ }
1755
+ const ast = expression[ExpressionAst.TypeId]
1756
+ if (ast.kind === kind) {
1757
+ return (ast as {
1758
+ readonly values: readonly Expression.Any[]
1759
+ }).values
1760
+ }
1761
+ return [expression]
1762
+ }
1763
+ let current: unknown = this
1764
+ for (const operation of operations) {
1765
+ if (typeof operation === "function") {
1766
+ current = (operation as (value: unknown) => unknown)(current)
1767
+ continue
1768
+ }
1769
+ current = makeVariadicBooleanExpression(
1770
+ kind,
1771
+ [...valuesForMixedPipe(current), toDialectExpression(operation as ExpressionInput)] as const
1772
+ )
1773
+ }
1774
+ return current
1708
1775
  }
1709
1776
  })
1710
1777
 
@@ -1725,9 +1792,6 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
1725
1792
  const partitionBy = [...(spec?.partitionBy ?? [])] as unknown as PartitionBy
1726
1793
  const orderBy = (spec?.orderBy ?? []).map((term) => {
1727
1794
  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
1795
  return {
1732
1796
  value: term.value,
1733
1797
  direction
@@ -1868,7 +1932,8 @@ type BinaryPredicateExpression<
1868
1932
  >(
1869
1933
  ...args: ComparableArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "eq">
1870
1934
  ): BinaryPredicateExpression<Left, Right, "eq"> => {
1871
- const [left, right] = args as unknown as [Left, Right]
1935
+ const left = args[0] as Left
1936
+ const right = args[1] as Right
1872
1937
  return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "eq")
1873
1938
  }
1874
1939
 
@@ -1878,7 +1943,8 @@ type BinaryPredicateExpression<
1878
1943
  >(
1879
1944
  ...args: ComparableArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "neq">
1880
1945
  ): BinaryPredicateExpression<Left, Right, "neq"> => {
1881
- const [left, right] = args as unknown as [Left, Right]
1946
+ const left = args[0] as Left
1947
+ const right = args[1] as Right
1882
1948
  return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "neq")
1883
1949
  }
1884
1950
 
@@ -1888,7 +1954,8 @@ type BinaryPredicateExpression<
1888
1954
  >(
1889
1955
  ...args: ComparableArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "lt">
1890
1956
  ): BinaryPredicateExpression<Left, Right, "lt"> => {
1891
- const [left, right] = args as unknown as [Left, Right]
1957
+ const left = args[0] as Left
1958
+ const right = args[1] as Right
1892
1959
  return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "lt")
1893
1960
  }
1894
1961
 
@@ -1898,7 +1965,8 @@ type BinaryPredicateExpression<
1898
1965
  >(
1899
1966
  ...args: ComparableArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "lte">
1900
1967
  ): BinaryPredicateExpression<Left, Right, "lte"> => {
1901
- const [left, right] = args as unknown as [Left, Right]
1968
+ const left = args[0] as Left
1969
+ const right = args[1] as Right
1902
1970
  return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "lte")
1903
1971
  }
1904
1972
 
@@ -1908,7 +1976,8 @@ type BinaryPredicateExpression<
1908
1976
  >(
1909
1977
  ...args: ComparableArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "gt">
1910
1978
  ): BinaryPredicateExpression<Left, Right, "gt"> => {
1911
- const [left, right] = args as unknown as [Left, Right]
1979
+ const left = args[0] as Left
1980
+ const right = args[1] as Right
1912
1981
  return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "gt")
1913
1982
  }
1914
1983
 
@@ -1918,7 +1987,8 @@ type BinaryPredicateExpression<
1918
1987
  >(
1919
1988
  ...args: ComparableArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "gte">
1920
1989
  ): BinaryPredicateExpression<Left, Right, "gte"> => {
1921
- const [left, right] = args as unknown as [Left, Right]
1990
+ const left = args[0] as Left
1991
+ const right = args[1] as Right
1922
1992
  return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "gte")
1923
1993
  }
1924
1994
 
@@ -1928,7 +1998,8 @@ type BinaryPredicateExpression<
1928
1998
  >(
1929
1999
  ...args: TextArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "like">
1930
2000
  ): BinaryPredicateExpression<Left, Right, "like"> => {
1931
- const [left, right] = args as unknown as [Left, Right]
2001
+ const left = args[0] as Left
2002
+ const right = args[1] as Right
1932
2003
  return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "like")
1933
2004
  }
1934
2005
 
@@ -1938,7 +2009,8 @@ type BinaryPredicateExpression<
1938
2009
  >(
1939
2010
  ...args: TextArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "ilike">
1940
2011
  ): BinaryPredicateExpression<Left, Right, "ilike"> => {
1941
- const [left, right] = args as unknown as [Left, Right]
2012
+ const left = args[0] as Left
2013
+ const right = args[1] as Right
1942
2014
  return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "ilike")
1943
2015
  }
1944
2016
 
@@ -1948,7 +2020,8 @@ type BinaryPredicateExpression<
1948
2020
  >(
1949
2021
  ...args: TextArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "regexMatch">
1950
2022
  ): BinaryPredicateExpression<Left, Right, "regexMatch"> => {
1951
- const [left, right] = args as unknown as [Left, Right]
2023
+ const left = args[0] as Left
2024
+ const right = args[1] as Right
1952
2025
  return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "regexMatch")
1953
2026
  }
1954
2027
 
@@ -1958,7 +2031,8 @@ type BinaryPredicateExpression<
1958
2031
  >(
1959
2032
  ...args: TextArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "regexIMatch">
1960
2033
  ): BinaryPredicateExpression<Left, Right, "regexIMatch"> => {
1961
- const [left, right] = args as unknown as [Left, Right]
2034
+ const left = args[0] as Left
2035
+ const right = args[1] as Right
1962
2036
  return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "regexIMatch")
1963
2037
  }
1964
2038
 
@@ -1968,7 +2042,8 @@ type BinaryPredicateExpression<
1968
2042
  >(
1969
2043
  ...args: TextArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "regexNotMatch">
1970
2044
  ): BinaryPredicateExpression<Left, Right, "regexNotMatch"> => {
1971
- const [left, right] = args as unknown as [Left, Right]
2045
+ const left = args[0] as Left
2046
+ const right = args[1] as Right
1972
2047
  return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "regexNotMatch")
1973
2048
  }
1974
2049
 
@@ -1978,7 +2053,8 @@ type BinaryPredicateExpression<
1978
2053
  >(
1979
2054
  ...args: TextArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "regexNotIMatch">
1980
2055
  ): BinaryPredicateExpression<Left, Right, "regexNotIMatch"> => {
1981
- const [left, right] = args as unknown as [Left, Right]
2056
+ const left = args[0] as Left
2057
+ const right = args[1] as Right
1982
2058
  return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "regexNotIMatch")
1983
2059
  }
1984
2060
 
@@ -1988,7 +2064,8 @@ type BinaryPredicateExpression<
1988
2064
  >(
1989
2065
  ...args: ComparableArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "isDistinctFrom">
1990
2066
  ): BinaryPredicateExpression<Left, Right, "isDistinctFrom", "never"> => {
1991
- const [left, right] = args as unknown as [Left, Right]
2067
+ const left = args[0] as Left
2068
+ const right = args[1] as Right
1992
2069
  return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "isDistinctFrom", "never")
1993
2070
  }
1994
2071
 
@@ -1998,7 +2075,8 @@ type BinaryPredicateExpression<
1998
2075
  >(
1999
2076
  ...args: ComparableArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "isNotDistinctFrom">
2000
2077
  ): BinaryPredicateExpression<Left, Right, "isNotDistinctFrom", "never"> => {
2001
- const [left, right] = args as unknown as [Left, Right]
2078
+ const left = args[0] as Left
2079
+ const right = args[1] as Right
2002
2080
  return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "isNotDistinctFrom", "never")
2003
2081
  }
2004
2082
 
@@ -2114,7 +2192,7 @@ type BinaryPredicateExpression<
2114
2192
  Collation extends string | readonly [string, ...string[]]
2115
2193
  >(
2116
2194
  value: Value & TextInput<NoInfer<Value>, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "collate">,
2117
- collation: Collation
2195
+ collation: CollationIdentifierInput<Collation>
2118
2196
  ): AstBackedExpression<
2119
2197
  Expression.RuntimeOf<DialectAsStringExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
2120
2198
  Expression.DbTypeOf<DialectAsStringExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
@@ -2125,7 +2203,7 @@ type BinaryPredicateExpression<
2125
2203
  ExpressionAst.CollateNode<DialectAsStringExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>, NormalizedCollation<Collation>>
2126
2204
  > => {
2127
2205
  const expression = toDialectStringExpression(value as any)
2128
- const normalizedCollation = (typeof collation === "string" ? [collation] : collation) as NormalizedCollation<Collation>
2206
+ const normalizedCollation = (typeof collation === "string" ? [collation] : collation) as unknown as NormalizedCollation<Collation>
2129
2207
  return makeExpression({
2130
2208
  runtime: expression[Expression.TypeId].runtime as Expression.RuntimeOf<DialectAsStringExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
2131
2209
  dbType: expression[Expression.TypeId].dbType as Expression.DbTypeOf<DialectAsStringExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
@@ -2192,62 +2270,62 @@ type BinaryPredicateExpression<
2192
2270
  })
2193
2271
 
2194
2272
  const range = <Kind extends string, Subtype extends Expression.DbType.Any>(
2195
- kind: Kind,
2273
+ kind: NonEmptyStringInput<Kind>,
2196
2274
  subtype: Subtype
2197
2275
  ): Expression.DbType.Range<Dialect, Subtype, Kind> => ({
2198
2276
  dialect: profile.dialect,
2199
- kind,
2277
+ kind: kind as Kind,
2200
2278
  subtype
2201
2279
  })
2202
2280
 
2203
2281
  const multirange = <Kind extends string, Subtype extends Expression.DbType.Any>(
2204
- kind: Kind,
2282
+ kind: NonEmptyStringInput<Kind>,
2205
2283
  subtype: Subtype
2206
2284
  ): Expression.DbType.Multirange<Dialect, Subtype, Kind> => ({
2207
2285
  dialect: profile.dialect,
2208
- kind,
2286
+ kind: kind as Kind,
2209
2287
  subtype
2210
2288
  })
2211
2289
 
2212
2290
  const record = <Kind extends string, Fields extends Record<string, Expression.DbType.Any>>(
2213
- kind: Kind,
2291
+ kind: NonEmptyStringInput<Kind>,
2214
2292
  fields: Fields
2215
2293
  ): Expression.DbType.Composite<Dialect, Fields, Kind> => ({
2216
2294
  dialect: profile.dialect,
2217
- kind,
2295
+ kind: kind as Kind,
2218
2296
  fields
2219
2297
  })
2220
2298
 
2221
2299
  const domain = <Kind extends string, Base extends Expression.DbType.Any>(
2222
- kind: Kind,
2300
+ kind: NonEmptyStringInput<Kind>,
2223
2301
  base: Base
2224
2302
  ): Expression.DbType.Domain<Dialect, Base, Kind> => ({
2225
2303
  dialect: profile.dialect,
2226
- kind,
2304
+ kind: kind as Kind,
2227
2305
  base
2228
2306
  })
2229
2307
 
2230
2308
  const enum_ = <Kind extends string>(
2231
- kind: Kind
2309
+ kind: NonEmptyStringInput<Kind>
2232
2310
  ): Expression.DbType.Enum<Dialect, Kind> => ({
2233
2311
  dialect: profile.dialect,
2234
- kind,
2312
+ kind: kind as Kind,
2235
2313
  variant: "enum"
2236
2314
  })
2237
2315
 
2238
2316
  const set = <Kind extends string>(
2239
- kind: Kind
2317
+ kind: NonEmptyStringInput<Kind>
2240
2318
  ): Expression.DbType.Set<Dialect, Kind> => ({
2241
2319
  dialect: profile.dialect,
2242
- kind,
2320
+ kind: kind as Kind,
2243
2321
  variant: "set"
2244
2322
  })
2245
2323
 
2246
2324
  const custom = <Kind extends string>(
2247
- kind: Kind
2325
+ kind: NonEmptyStringInput<Kind>
2248
2326
  ): Expression.DbType.Base<Dialect, Kind> => ({
2249
2327
  dialect: profile.dialect,
2250
- kind
2328
+ kind: kind as Kind
2251
2329
  })
2252
2330
 
2253
2331
  const driverValueMapping = <Db extends Expression.DbType.Any>(
@@ -3051,9 +3129,12 @@ type BinaryPredicateExpression<
3051
3129
  }
3052
3130
  )
3053
3131
 
3054
- const jsonPathExists = <Base extends JsonExpressionLike<any>>(
3132
+ const jsonPathExists = <
3133
+ Base extends JsonExpressionLike<any>,
3134
+ Query extends JsonQueryInput
3135
+ >(
3055
3136
  base: Base,
3056
- query: JsonQueryInput
3137
+ query: JsonQueryValue<Query>
3057
3138
  ) => {
3058
3139
  if (isJsonPathValue(query)) {
3059
3140
  return buildJsonNodeExpression(
@@ -3101,9 +3182,12 @@ type BinaryPredicateExpression<
3101
3182
  }
3102
3183
  )
3103
3184
 
3104
- const jsonPathMatch = <Base extends JsonExpressionLike<any>>(
3185
+ const jsonPathMatch = <
3186
+ Base extends JsonExpressionLike<any>,
3187
+ Query extends JsonQueryInput
3188
+ >(
3105
3189
  base: Base,
3106
- query: JsonQueryInput
3190
+ query: JsonQueryValue<Query>
3107
3191
  ) => {
3108
3192
  if (isJsonPathValue(query)) {
3109
3193
  return buildJsonNodeExpression(
@@ -3330,7 +3414,8 @@ type BinaryPredicateExpression<
3330
3414
  >(
3331
3415
  ...args: ContainmentArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "contains">
3332
3416
  ): BinaryPredicateExpression<Left, Right, "contains"> => {
3333
- const [left, right] = args as unknown as [Left, Right]
3417
+ const left = args[0] as Left
3418
+ const right = args[1] as Right
3334
3419
  return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "contains")
3335
3420
  }
3336
3421
 
@@ -3340,7 +3425,8 @@ type BinaryPredicateExpression<
3340
3425
  >(
3341
3426
  ...args: ContainmentArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "containedBy">
3342
3427
  ): BinaryPredicateExpression<Left, Right, "containedBy"> => {
3343
- const [left, right] = args as unknown as [Left, Right]
3428
+ const left = args[0] as Left
3429
+ const right = args[1] as Right
3344
3430
  return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "containedBy")
3345
3431
  }
3346
3432
 
@@ -3350,7 +3436,8 @@ type BinaryPredicateExpression<
3350
3436
  >(
3351
3437
  ...args: ContainmentArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "overlaps">
3352
3438
  ): BinaryPredicateExpression<Left, Right, "overlaps"> => {
3353
- const [left, right] = args as unknown as [Left, Right]
3439
+ const left = args[0] as Left
3440
+ const right = args[1] as Right
3354
3441
  return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "overlaps")
3355
3442
  }
3356
3443
 
@@ -3777,12 +3864,9 @@ type BinaryPredicateExpression<
3777
3864
  >
3778
3865
  }
3779
3866
 
3780
- const call = <
3781
- Name extends string,
3782
- Args extends readonly ExpressionInput[]
3783
- >(
3784
- name: Name,
3785
- ...args: Args
3867
+ const call: FunctionCallApi = (
3868
+ name: string,
3869
+ ...args: readonly ExpressionInput[]
3786
3870
  ): Expression.Any => {
3787
3871
  const expressions = args.map((value) => toDialectExpression(value)) as readonly Expression.Any[]
3788
3872
  return makeExpression({
@@ -4018,9 +4102,6 @@ type BinaryPredicateExpression<
4018
4102
  ExpressionAst.ExcludedNode<AstOf<Value> extends ExpressionAst.ColumnNode<any, infer ColumnName extends string> ? ColumnName : string>
4019
4103
  > => {
4020
4104
  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
4105
  return makeExpression({
4025
4106
  runtime: undefined as Expression.RuntimeOf<Value>,
4026
4107
  dbType: value[Expression.TypeId].dbType as Expression.DbTypeOf<Value>,
@@ -4033,7 +4114,7 @@ type BinaryPredicateExpression<
4033
4114
  dependencies: {}
4034
4115
  }, {
4035
4116
  kind: "excluded",
4036
- columnName: ast.columnName
4117
+ columnName: (ast as ExpressionAst.ColumnNode<any, string>).columnName
4037
4118
  }) as unknown as AstBackedExpression<
4038
4119
  Expression.RuntimeOf<Value>,
4039
4120
  Expression.DbTypeOf<Value>,
@@ -4066,7 +4147,7 @@ type BinaryPredicateExpression<
4066
4147
  }
4067
4148
  if (value !== null && typeof value === "object" && Expression.TypeId in value) {
4068
4149
  const expression = value as unknown as Expression.Any
4069
- const ast = (expression as unknown as { readonly [ExpressionAst.TypeId]: ExpressionAst.Any })[ExpressionAst.TypeId]
4150
+ const ast = (expression as Expression.Any & { readonly [ExpressionAst.TypeId]: ExpressionAst.Any })[ExpressionAst.TypeId]
4070
4151
  if (ast.kind === "literal") {
4071
4152
  const normalizedValue = normalizeMutationValue(ast.value)
4072
4153
  return makeExpression({
@@ -4135,8 +4216,8 @@ type BinaryPredicateExpression<
4135
4216
  : ">="
4136
4217
 
4137
4218
  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
4219
+ const sourceName = (table as TableLike)[Table.TypeId].name
4220
+ const sourceBaseName = (table as TableLike)[Table.TypeId].baseName
4140
4221
  return {
4141
4222
  sourceName,
4142
4223
  sourceBaseName
@@ -4226,12 +4307,7 @@ type BinaryPredicateExpression<
4226
4307
 
4227
4308
  const normalizeUnnestColumns = (columns: UnnestColumnsInput): Record<string, readonly Expression.Any[]> =>
4228
4309
  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
- })
4310
+ Object.entries(columns).map(([key, values]) => [key, values.map((value) => toDialectExpression(value))])
4235
4311
  ) as Record<string, readonly Expression.Any[]>
4236
4312
 
4237
4313
  const normalizeMutationTargets = (
@@ -4277,13 +4353,7 @@ type BinaryPredicateExpression<
4277
4353
  const getMutationColumn = (
4278
4354
  columns: Record<string, unknown>,
4279
4355
  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
- }
4356
+ ): Expression.Any => columns[columnName] as Expression.Any
4287
4357
 
4288
4358
  const buildMutationAssignments = <Target extends MutationTargetInput, Values>(
4289
4359
  target: Target,
@@ -4299,7 +4369,7 @@ type BinaryPredicateExpression<
4299
4369
  }
4300
4370
  const valueMap = values as Record<string, Record<string, unknown> | undefined>
4301
4371
  return targets.flatMap((table) => {
4302
- const targetName = (table as unknown as TableLike)[Table.TypeId].name
4372
+ const targetName = (table as TableLike)[Table.TypeId].name
4303
4373
  const scopedValues = valueMap[targetName] ?? {}
4304
4374
  const columns = table as unknown as Record<string, Expression.Any>
4305
4375
  return Object.entries(scopedValues).map(([columnName, value]) => ({
@@ -4320,20 +4390,17 @@ type BinaryPredicateExpression<
4320
4390
  } => {
4321
4391
  const firstRow = rows[0]
4322
4392
  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
4393
  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
- }
4394
+ const normalizeRow = (row: InsertRowInput<Target>) => {
4332
4395
  const assignments = buildMutationAssignments(target, row) as readonly QueryAst.AssignmentClause[]
4333
4396
  return {
4334
4397
  values: columns.map((columnName) => assignments.find((assignment) => assignment.columnName === columnName)!)
4335
4398
  } satisfies QueryAst.InsertValuesRowClause
4336
- }) as unknown as [QueryAst.InsertValuesRowClause, ...QueryAst.InsertValuesRowClause[]]
4399
+ }
4400
+ const normalizedRows: readonly [QueryAst.InsertValuesRowClause, ...QueryAst.InsertValuesRowClause[]] = [
4401
+ normalizeRow(rows[0]),
4402
+ ...rows.slice(1).map(normalizeRow)
4403
+ ]
4337
4404
  const required = normalizedRows.flatMap((row) =>
4338
4405
  row.values.flatMap((entry) => Object.keys(entry.value[Expression.TypeId].dependencies))
4339
4406
  )
@@ -4348,9 +4415,6 @@ type BinaryPredicateExpression<
4348
4415
  selection: Record<string, Expression.Any>
4349
4416
  ): readonly [string, ...string[]] => {
4350
4417
  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
4418
  return columns as [string, ...string[]]
4355
4419
  }
4356
4420
 
@@ -4365,27 +4429,11 @@ type BinaryPredicateExpression<
4365
4429
  }[]
4366
4430
  } => {
4367
4431
  const entries = Object.entries(values)
4368
- if (entries.length === 0) {
4369
- throw new Error("unnest(...) requires at least one column array")
4370
- }
4371
4432
  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
- }
4433
+ const normalized = entries.map(([columnName, items]) => ({
4434
+ columnName,
4435
+ values: items
4436
+ }))
4389
4437
  return {
4390
4438
  columns,
4391
4439
  values: normalized
@@ -4397,10 +4445,6 @@ type BinaryPredicateExpression<
4397
4445
  columnsInput: string | readonly string[]
4398
4446
  ): readonly [string, ...string[]] => {
4399
4447
  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
4448
  return columns
4405
4449
  }
4406
4450
 
@@ -4479,14 +4523,14 @@ type ValidateTargetColumnInput<
4479
4523
  Columns extends DdlColumnInput
4480
4524
  > = ValidateTargetColumns<Target, NormalizeDdlColumns<Columns>> extends never ? never : Columns
4481
4525
 
4482
- type CreateIndexOptions = {
4483
- readonly name?: string
4526
+ type CreateIndexOptions<Name extends string = string> = {
4527
+ readonly name?: NonEmptyStringInput<Name>
4484
4528
  readonly unique?: boolean
4485
4529
  readonly ifNotExists?: boolean
4486
4530
  }
4487
4531
 
4488
- type DropIndexOptions = {
4489
- readonly name?: string
4532
+ type DropIndexOptions<Name extends string = string> = {
4533
+ readonly name?: NonEmptyStringInput<Name>
4490
4534
  readonly ifExists?: boolean
4491
4535
  }
4492
4536
 
@@ -4590,7 +4634,7 @@ type ValuesRowsDialectInput<
4590
4634
  BoolDb extends Expression.DbType.Any,
4591
4635
  TimestampDb extends Expression.DbType.Any,
4592
4636
  NullDb extends Expression.DbType.Any
4593
- > = Exclude<ValuesRowsDialect<Rows, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>, Dialect> extends never
4637
+ > = Exclude<ValuesRowsDialect<Rows, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>, Dialect | "standard"> extends never
4594
4638
  ? unknown
4595
4639
  : {
4596
4640
  readonly __effect_qb_error__: "effect-qb: values rows cannot mix dialects"
@@ -4645,7 +4689,7 @@ type UnnestColumnsDialectInput<
4645
4689
  BoolDb extends Expression.DbType.Any,
4646
4690
  TimestampDb extends Expression.DbType.Any,
4647
4691
  NullDb extends Expression.DbType.Any
4648
- > = Exclude<UnnestColumnsDialect<Columns, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>, Dialect> extends never
4692
+ > = Exclude<UnnestColumnsDialect<Columns, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>, Dialect | "standard"> extends never
4649
4693
  ? unknown
4650
4694
  : {
4651
4695
  readonly __effect_qb_error__: "effect-qb: unnest columns cannot mix dialects"
@@ -4912,6 +4956,11 @@ type ConflictTargetInput<
4912
4956
  readonly constraint?: string
4913
4957
  }>)
4914
4958
 
4959
+ type ConflictConstraintNameConstraint<Target> =
4960
+ Target extends { readonly constraint: infer Constraint extends string }
4961
+ ? { readonly constraint: NonEmptyStringInput<Constraint> }
4962
+ : unknown
4963
+
4915
4964
  type ConflictActionInput<
4916
4965
  Target extends MutationTargetLike,
4917
4966
  Dialect extends string,
@@ -5063,7 +5112,7 @@ type MutationOrderLimitSupported<PlanValue extends QueryPlan<any, any, any, any,
5063
5112
  type MutationTargetTupleDialectConstraint<
5064
5113
  Targets extends MutationTargetTuple,
5065
5114
  Dialect extends string
5066
- > = Exclude<TableDialectOf<Targets[number]>, Dialect> extends never ? unknown : never
5115
+ > = Exclude<TableDialectOf<Targets[number]>, Dialect | "standard"> extends never ? unknown : never
5067
5116
 
5068
5117
  type MutationRequiredFromValues<Values extends Record<string, unknown>> = {
5069
5118
  [K in keyof Values]: Values[K] extends Expression.Any ? RequiredFromDependencies<DependenciesOf<Values[K]>> : never
@@ -5117,7 +5166,7 @@ type KnownIncompatibleMutationDialectFromValues<
5117
5166
  BoolDb extends Expression.DbType.Any,
5118
5167
  TimestampDb extends Expression.DbType.Any,
5119
5168
  NullDb extends Expression.DbType.Any
5120
- > = Exclude<KnownMutationDialectFromValues<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>, Dialect>
5169
+ > = Exclude<KnownMutationDialectFromValues<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>, Dialect | "standard">
5121
5170
 
5122
5171
  type MutationValuesDialectConstraint<
5123
5172
  Values,
@@ -5169,9 +5218,11 @@ type SourceDialectConstraint<
5169
5218
  Dialect extends string
5170
5219
  > = [SourceDialectOf<CurrentSource>] extends [never]
5171
5220
  ? unknown
5172
- : Extract<SourceDialectOf<CurrentSource>, Dialect> extends never
5173
- ? never
5174
- : unknown
5221
+ : Exclude<SourceDialectOf<CurrentSource>, Dialect | "standard"> extends never
5222
+ ? unknown
5223
+ : Dialect extends "standard"
5224
+ ? unknown
5225
+ : never
5175
5226
 
5176
5227
  type SourceRequirementConstraint<
5177
5228
  PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>,
@@ -5465,7 +5516,7 @@ type AsCurriedResult<
5465
5516
  function as<
5466
5517
  Alias extends string
5467
5518
  >(
5468
- alias: Alias
5519
+ alias: LiteralStringInput<Alias>
5469
5520
  ): <Value extends AsCurriedInput<Dialect>>(
5470
5521
  value: Value
5471
5522
  ) => AsCurriedResult<Value, Alias, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
@@ -5474,7 +5525,7 @@ type AsCurriedResult<
5474
5525
  Alias extends string
5475
5526
  >(
5476
5527
  value: Value,
5477
- alias: Alias
5528
+ alias: LiteralStringInput<Alias>
5478
5529
  ): ProjectionAliasedExpression<DialectAsExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>, Alias>
5479
5530
  function as<
5480
5531
  Rows extends ValuesRowsInput,
@@ -5485,7 +5536,7 @@ type AsCurriedResult<
5485
5536
  ValuesOutputShape<Rows, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
5486
5537
  Dialect
5487
5538
  >,
5488
- alias: Alias
5539
+ alias: LiteralStringInput<Alias>
5489
5540
  ): ValuesSource<
5490
5541
  Rows,
5491
5542
  ValuesOutputShape<Rows, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
@@ -5497,11 +5548,11 @@ type AsCurriedResult<
5497
5548
  Alias extends string
5498
5549
  >(
5499
5550
  value: DerivedTableCompatiblePlan<PlanValue>,
5500
- alias: Alias
5551
+ alias: LiteralStringInput<Alias>
5501
5552
  ): DerivedSource<PlanValue, Alias>
5502
5553
  function as(valueOrAlias: unknown, alias?: string): unknown {
5503
5554
  if (alias === undefined) {
5504
- return (value: unknown) => as(value as any, valueOrAlias as string)
5555
+ return (value: unknown) => as(value as any, valueOrAlias as never)
5505
5556
  }
5506
5557
  const resolvedAlias = alias
5507
5558
  const value = valueOrAlias
@@ -5541,7 +5592,7 @@ type AsCurriedResult<
5541
5592
  function with_<
5542
5593
  Alias extends string
5543
5594
  >(
5544
- alias: Alias
5595
+ alias: LiteralStringInput<Alias>
5545
5596
  ): <PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
5546
5597
  value: DerivedSourceCompatiblePlan<PlanValue>
5547
5598
  ) => import("../../internal/query.js").CteSource<PlanValue, Alias>
@@ -5550,11 +5601,11 @@ type AsCurriedResult<
5550
5601
  Alias extends string
5551
5602
  >(
5552
5603
  value: DerivedSourceCompatiblePlan<PlanValue>,
5553
- alias: Alias
5604
+ alias: LiteralStringInput<Alias>
5554
5605
  ): import("../../internal/query.js").CteSource<PlanValue, Alias>
5555
5606
  function with_(valueOrAlias: unknown, alias?: string): unknown {
5556
5607
  if (alias === undefined) {
5557
- return (value: unknown) => with_(value as any, valueOrAlias as string)
5608
+ return (value: unknown) => with_(value as any, valueOrAlias as never)
5558
5609
  }
5559
5610
  return makeCteSource(
5560
5611
  valueOrAlias as CompletePlan<QueryPlan<any, any, any, any, any, any, any, any, any, any>>,
@@ -5565,7 +5616,7 @@ type AsCurriedResult<
5565
5616
  function withRecursive_<
5566
5617
  Alias extends string
5567
5618
  >(
5568
- alias: Alias
5619
+ alias: LiteralStringInput<Alias>
5569
5620
  ): <PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
5570
5621
  value: DerivedSourceCompatiblePlan<PlanValue>
5571
5622
  ) => import("../../internal/query.js").CteSource<PlanValue, Alias>
@@ -5574,11 +5625,11 @@ type AsCurriedResult<
5574
5625
  Alias extends string
5575
5626
  >(
5576
5627
  value: DerivedSourceCompatiblePlan<PlanValue>,
5577
- alias: Alias
5628
+ alias: LiteralStringInput<Alias>
5578
5629
  ): import("../../internal/query.js").CteSource<PlanValue, Alias>
5579
5630
  function withRecursive_(valueOrAlias: unknown, alias?: string): unknown {
5580
5631
  if (alias === undefined) {
5581
- return (value: unknown) => withRecursive_(value as any, valueOrAlias as string)
5632
+ return (value: unknown) => withRecursive_(value as any, valueOrAlias as never)
5582
5633
  }
5583
5634
  return makeCteSource(
5584
5635
  valueOrAlias as CompletePlan<QueryPlan<any, any, any, any, any, any, any, any, any, any>>,
@@ -5590,7 +5641,7 @@ type AsCurriedResult<
5590
5641
  function lateral<
5591
5642
  Alias extends string
5592
5643
  >(
5593
- alias: Alias
5644
+ alias: LiteralStringInput<Alias>
5594
5645
  ): <PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
5595
5646
  value: LateralSourceCompatiblePlan<PlanValue>
5596
5647
  ) => import("../../internal/query.js").LateralSource<PlanValue, Alias>
@@ -5599,11 +5650,11 @@ type AsCurriedResult<
5599
5650
  Alias extends string
5600
5651
  >(
5601
5652
  value: LateralSourceCompatiblePlan<PlanValue>,
5602
- alias: Alias
5653
+ alias: LiteralStringInput<Alias>
5603
5654
  ): import("../../internal/query.js").LateralSource<PlanValue, Alias>
5604
5655
  function lateral(valueOrAlias: unknown, alias?: string): unknown {
5605
5656
  if (alias === undefined) {
5606
- return (value: unknown) => lateral(value as any, valueOrAlias as string)
5657
+ return (value: unknown) => lateral(value as any, valueOrAlias as never)
5607
5658
  }
5608
5659
  return makeLateralSource(
5609
5660
  valueOrAlias as QueryPlan<any, any, any, any, any, any, any, any, any, any>,
@@ -5630,7 +5681,7 @@ type AsCurriedResult<
5630
5681
  columns: Columns
5631
5682
  & UnnestColumnsShapeInput<Columns>
5632
5683
  & UnnestColumnsDialectInput<Columns, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
5633
- alias: Alias
5684
+ alias: LiteralStringInput<Alias>
5634
5685
  ) => UnnestSource<
5635
5686
  UnnestOutputShape<Columns, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
5636
5687
  Alias,
@@ -5646,7 +5697,7 @@ type AsCurriedResult<
5646
5697
  start: Start & NumericExpressionDialectInput<Start, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
5647
5698
  stop: Stop & NumericExpressionDialectInput<Stop, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
5648
5699
  step?: Step & (Step extends NumericExpressionInput ? NumericExpressionDialectInput<Step, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> : unknown),
5649
- alias?: Alias
5700
+ alias?: LiteralStringInput<Alias>
5650
5701
  ) => Dialect extends "postgres"
5651
5702
  ? TableFunctionSource<
5652
5703
  GenerateSeriesOutputShape<Start, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
@@ -5665,7 +5716,7 @@ type AsCurriedResult<
5665
5716
  start: Start & NumericExpressionDialectInput<Start, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
5666
5717
  stop: Stop & NumericExpressionDialectInput<Stop, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
5667
5718
  step?: Step & (Step extends NumericExpressionInput ? NumericExpressionDialectInput<Step, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> : unknown),
5668
- alias?: Alias
5719
+ alias?: LiteralStringInput<Alias>
5669
5720
  ) => TableFunctionSource<
5670
5721
  {
5671
5722
  readonly value: Expression.Scalar<number, NumericDb, "never", Dialect, "scalar", never, string>
@@ -5703,8 +5754,8 @@ type AsCurriedResult<
5703
5754
  type SelectionNestedNonEmptyConstraint<Selection> =
5704
5755
  SelectionHasEmptyNestedObject<Selection, true> extends true ? SelectionNestedEmptyError<Selection> : unknown
5705
5756
 
5706
- export type SelectApi = <Selection extends SelectionShape = {}>(
5707
- selection?: Selection & SelectionRootObjectConstraint<Selection> & SelectionNestedNonEmptyConstraint<Selection>
5757
+ export type SelectApi = <const Selection extends SelectionShape = {}>(
5758
+ selection?: Selection & SelectionRootObjectConstraint<Selection> & SelectionNestedNonEmptyConstraint<Selection> & SelectionProjectionAliasCollisionConstraint<Selection>
5708
5759
  ) => QueryPlan<
5709
5760
  Selection,
5710
5761
  ExtractRequired<Selection>,
@@ -6129,9 +6180,6 @@ type AsCurriedResult<
6129
6180
  const fullJoin = ((table, on) => (join as any)("full", table, on)) as BinaryJoinApi<"full">
6130
6181
 
6131
6182
  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
6183
  const expressions = values.map((value) => toDialectExpression(value)) as Expression.Any[]
6136
6184
  return <PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
6137
6185
  plan: PlanValue & RequireSelectStatement<PlanValue>
@@ -6197,8 +6245,8 @@ type AsCurriedResult<
6197
6245
  ? ReturningSelectionNonEmptyError<Selection>
6198
6246
  : unknown
6199
6247
 
6200
- type ReturningApi = <Selection extends SelectionShape>(
6201
- selection: Selection & SelectionRootObjectConstraint<Selection> & SelectionNestedNonEmptyConstraint<Selection> & ReturningSelectionNonEmptyConstraint<Selection>
6248
+ type ReturningApi = <const Selection extends SelectionShape>(
6249
+ selection: Selection & SelectionRootObjectConstraint<Selection> & SelectionNestedNonEmptyConstraint<Selection> & ReturningSelectionNonEmptyConstraint<Selection> & SelectionProjectionAliasCollisionConstraint<Selection>
6202
6250
  ) =>
6203
6251
  <PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
6204
6252
  plan: PlanValue & RequireMutationStatement<PlanValue>
@@ -6266,9 +6314,9 @@ type AsCurriedResult<
6266
6314
  const Columns extends DdlColumnInput,
6267
6315
  UpdateValues extends MutationInputOf<Table.UpdateOf<Target>> | undefined = MutationInputOf<Table.UpdateOf<Target>> | undefined,
6268
6316
  Options extends ConflictActionInput<Target, Dialect, UpdateValues> = ConflictActionInput<Target, Dialect, UpdateValues>,
6269
- ConflictTarget extends ConflictTargetInput<Target, Dialect, Columns> = ConflictTargetInput<Target, Dialect, Columns>
6317
+ const ConflictTarget extends ConflictTargetInput<Target, Dialect, Columns> = ConflictTargetInput<Target, Dialect, Columns>
6270
6318
  >(
6271
- target: ConflictTarget,
6319
+ target: ConflictTarget & ConflictConstraintNameConstraint<ConflictTarget>,
6272
6320
  options?: Options & ConflictActionUpdateNonEmptyConstraint<Options>
6273
6321
  ) =>
6274
6322
  <PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
@@ -6424,7 +6472,7 @@ type AsCurriedResult<
6424
6472
  target: Target,
6425
6473
  source: Source & (
6426
6474
  SourceRequiredOf<Source> extends never ? unknown : SourceRequirementError<Source>
6427
- ) & MergeSourceNameConstraint<Target, Source>,
6475
+ ) & SourceDialectConstraint<Source, Dialect> & MergeSourceNameConstraint<Target, Source>,
6428
6476
  on: On,
6429
6477
  options: MergeOptions<Target, MatchedValues, InsertValues, MatchedPredicate, NotMatchedPredicate>
6430
6478
  ) => QueryPlan<
@@ -6586,7 +6634,7 @@ type AsCurriedResult<
6586
6634
  "rollback"
6587
6635
  >
6588
6636
 
6589
- type SavepointApi = <Name extends string>(name: Name) => QueryPlan<
6637
+ type SavepointApi = <Name extends string>(name: NonEmptyStringInput<Name>) => QueryPlan<
6590
6638
  {},
6591
6639
  never,
6592
6640
  {},
@@ -6599,7 +6647,7 @@ type AsCurriedResult<
6599
6647
  "savepoint"
6600
6648
  >
6601
6649
 
6602
- type RollbackToApi = <Name extends string>(name: Name) => QueryPlan<
6650
+ type RollbackToApi = <Name extends string>(name: NonEmptyStringInput<Name>) => QueryPlan<
6603
6651
  {},
6604
6652
  never,
6605
6653
  {},
@@ -6612,7 +6660,7 @@ type AsCurriedResult<
6612
6660
  "rollbackTo"
6613
6661
  >
6614
6662
 
6615
- type ReleaseSavepointApi = <Name extends string>(name: Name) => QueryPlan<
6663
+ type ReleaseSavepointApi = <Name extends string>(name: NonEmptyStringInput<Name>) => QueryPlan<
6616
6664
  {},
6617
6665
  never,
6618
6666
  {},
@@ -6657,10 +6705,10 @@ type AsCurriedResult<
6657
6705
  "dropTable"
6658
6706
  >
6659
6707
 
6660
- type CreateIndexApi = <Target extends SchemaTableLike, const Columns extends DdlColumnInput>(
6708
+ type CreateIndexApi = <Target extends SchemaTableLike, const Columns extends DdlColumnInput, Name extends string = string>(
6661
6709
  target: Target,
6662
6710
  columns: Columns & ValidateDdlColumnInput<Target, Columns>,
6663
- options?: CreateIndexOptions
6711
+ options?: CreateIndexOptions<Name>
6664
6712
  ) => QueryPlan<
6665
6713
  {},
6666
6714
  never,
@@ -6674,10 +6722,10 @@ type AsCurriedResult<
6674
6722
  "createIndex"
6675
6723
  >
6676
6724
 
6677
- type DropIndexApi = <Target extends SchemaTableLike, const Columns extends DdlColumnInput>(
6725
+ type DropIndexApi = <Target extends SchemaTableLike, const Columns extends DdlColumnInput, Name extends string = string>(
6678
6726
  target: Target,
6679
6727
  columns: Columns & ValidateDdlColumnInput<Target, Columns>,
6680
- options?: DropIndexOptions
6728
+ options?: DropIndexOptions<Name>
6681
6729
  ) => QueryPlan<
6682
6730
  {},
6683
6731
  never,