effect-qb 0.13.0 → 0.14.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 (54) hide show
  1. package/README.md +6 -1431
  2. package/dist/mysql.js +1678 -355
  3. package/dist/postgres/metadata.js +2724 -0
  4. package/dist/postgres.js +7197 -5433
  5. package/package.json +8 -10
  6. package/src/internal/column-state.ts +84 -10
  7. package/src/internal/column.ts +556 -34
  8. package/src/internal/datatypes/define.ts +0 -30
  9. package/src/internal/executor.ts +45 -11
  10. package/src/internal/expression-ast.ts +4 -0
  11. package/src/internal/expression.ts +1 -1
  12. package/src/internal/implication-runtime.ts +171 -0
  13. package/src/internal/mysql-query.ts +7173 -0
  14. package/src/internal/mysql-renderer.ts +2 -2
  15. package/src/internal/plan.ts +14 -4
  16. package/src/internal/{query-factory.ts → postgres-query.ts} +619 -167
  17. package/src/internal/postgres-renderer.ts +2 -2
  18. package/src/internal/postgres-schema-model.ts +144 -0
  19. package/src/internal/predicate-analysis.ts +10 -0
  20. package/src/internal/predicate-context.ts +112 -36
  21. package/src/internal/predicate-formula.ts +31 -19
  22. package/src/internal/predicate-normalize.ts +177 -106
  23. package/src/internal/predicate-runtime.ts +676 -0
  24. package/src/internal/query.ts +455 -39
  25. package/src/internal/renderer.ts +2 -2
  26. package/src/internal/runtime-schema.ts +74 -20
  27. package/src/internal/schema-ddl.ts +55 -0
  28. package/src/internal/schema-derivation.ts +93 -21
  29. package/src/internal/schema-expression.ts +44 -0
  30. package/src/internal/sql-expression-renderer.ts +95 -31
  31. package/src/internal/table-options.ts +87 -7
  32. package/src/internal/table.ts +104 -41
  33. package/src/mysql/column.ts +1 -0
  34. package/src/mysql/datatypes/index.ts +17 -2
  35. package/src/mysql/function/core.ts +1 -0
  36. package/src/mysql/function/index.ts +1 -0
  37. package/src/mysql/private/query.ts +1 -13
  38. package/src/mysql/query.ts +5 -0
  39. package/src/postgres/cast.ts +31 -0
  40. package/src/postgres/column.ts +26 -0
  41. package/src/postgres/datatypes/index.ts +40 -5
  42. package/src/postgres/function/core.ts +12 -0
  43. package/src/postgres/function/index.ts +2 -1
  44. package/src/postgres/function/json.ts +499 -2
  45. package/src/postgres/metadata.ts +31 -0
  46. package/src/postgres/private/query.ts +1 -13
  47. package/src/postgres/query.ts +5 -2
  48. package/src/postgres/schema-expression.ts +16 -0
  49. package/src/postgres/schema-management.ts +204 -0
  50. package/src/postgres/schema.ts +35 -0
  51. package/src/postgres/table.ts +307 -41
  52. package/src/postgres/type.ts +4 -0
  53. package/src/postgres.ts +14 -0
  54. package/CHANGELOG.md +0 -134
@@ -1,6 +1,8 @@
1
1
  import { pipeArguments } from "effect/Pipeable"
2
2
  import * as Schema from "effect/Schema"
3
3
 
4
+ import { postgresDatatypes } from "../postgres/datatypes/index.js"
5
+
4
6
  import * as Expression from "./expression.js"
5
7
  import * as Plan from "./plan.js"
6
8
  import * as Table from "./table.js"
@@ -54,6 +56,7 @@ import {
54
56
  type OrderDirection,
55
57
  type OutstandingOfPlan,
56
58
  type PlanDialectOf,
59
+ type PresenceWitnessKeysOfSource,
57
60
  type PredicateInput,
58
61
  type QueryPlan,
59
62
  type OutputOfSelection,
@@ -76,6 +79,7 @@ import {
76
79
  type MutationTargetOfPlan,
77
80
  type MergeCapabilities,
78
81
  type MutationTargetInput,
82
+ type MutationValuesInput,
79
83
  type SourceOf,
80
84
  type SourceDialectOf,
81
85
  type SourceLike,
@@ -98,6 +102,7 @@ import {
98
102
  type ResultRow
99
103
  } from "./query.js"
100
104
  import * as ExpressionAst from "./expression-ast.js"
105
+ import { presenceWitnessesOfSourceLike } from "./implication-runtime.js"
101
106
  import type { JsonNode } from "./json/ast.js"
102
107
  import type { JsonPathUsageError } from "./json/errors.js"
103
108
  import * as JsonPath from "./json/path.js"
@@ -116,7 +121,9 @@ import type {
116
121
  NormalizeJsonLiteral
117
122
  } from "./json/types.js"
118
123
  import type { AssumeTrue } from "./predicate-analysis.js"
124
+ import type { FormulaOfPredicate } from "./predicate-normalize.js"
119
125
  import type { TrueFormula } from "./predicate-formula.js"
126
+ import { assumeFormulaTrue, formulaOfExpression as formulaOfExpressionRuntime, trueFormula } from "./predicate-runtime.js"
120
127
  import { dedupeGroupedExpressions } from "./grouping-key.js"
121
128
  import { makeCteSource, makeDerivedSource, makeLateralSource } from "./derived-table.js"
122
129
  import * as ProjectionAlias from "./projection-alias.js"
@@ -246,6 +253,19 @@ type DialectDbTypeOfInput<
246
253
  NullDb extends Expression.DbType.Any
247
254
  > = Expression.DbTypeOf<DialectAsExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>
248
255
 
256
+ type JoinPresenceFormula<
257
+ Kind extends QueryAst.JoinKind,
258
+ Predicate extends PredicateInput,
259
+ Dialect extends string,
260
+ TextDb extends Expression.DbType.Any,
261
+ NumericDb extends Expression.DbType.Any,
262
+ BoolDb extends Expression.DbType.Any,
263
+ TimestampDb extends Expression.DbType.Any,
264
+ NullDb extends Expression.DbType.Any
265
+ > = Kind extends "inner" | "left"
266
+ ? FormulaOfPredicate<DialectAsExpression<Predicate, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>
267
+ : TrueFormula
268
+
249
269
  type ComparableInput<
250
270
  Left extends ExpressionInput,
251
271
  Right extends ExpressionInput,
@@ -757,7 +777,7 @@ type DialectStringExpressionTuple<
757
777
  }
758
778
 
759
779
  /** Names of sources already available to a plan. */
760
- type AvailableNames<Available extends Record<string, Plan.Source>> = Extract<keyof Available, string>
780
+ type AvailableNames<Available extends Record<string, Plan.AnySource>> = Extract<keyof Available, string>
761
781
 
762
782
  type PlanAssumptionsAfterWhere<
763
783
  PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>,
@@ -773,6 +793,37 @@ type PlanAssumptionsAfterWhere<
773
793
  DialectAsExpression<Predicate, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
774
794
  >
775
795
 
796
+ type PlanAssumptionsAfterHaving<
797
+ PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>,
798
+ Predicate extends HavingPredicateInput,
799
+ Dialect extends string,
800
+ TextDb extends Expression.DbType.Any,
801
+ NumericDb extends Expression.DbType.Any,
802
+ BoolDb extends Expression.DbType.Any,
803
+ TimestampDb extends Expression.DbType.Any,
804
+ NullDb extends Expression.DbType.Any
805
+ > = AssumeTrue<
806
+ AssumptionsOfPlan<PlanValue>,
807
+ DialectAsExpression<Predicate, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
808
+ >
809
+
810
+ type PlanAssumptionsAfterJoin<
811
+ PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>,
812
+ Predicate extends PredicateInput,
813
+ Kind extends QueryAst.JoinKind,
814
+ Dialect extends string,
815
+ TextDb extends Expression.DbType.Any,
816
+ NumericDb extends Expression.DbType.Any,
817
+ BoolDb extends Expression.DbType.Any,
818
+ TimestampDb extends Expression.DbType.Any,
819
+ NullDb extends Expression.DbType.Any
820
+ > = Kind extends "inner"
821
+ ? AssumeTrue<
822
+ AssumptionsOfPlan<PlanValue>,
823
+ DialectAsExpression<Predicate, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
824
+ >
825
+ : AssumptionsOfPlan<PlanValue>
826
+
776
827
  type ScalarSubqueryInput<
777
828
  PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>,
778
829
  EngineDialect extends string
@@ -803,6 +854,53 @@ type AstBackedExpression<
803
854
  readonly [ExpressionAst.TypeId]: Ast
804
855
  }
805
856
 
857
+ type AppendDialectExpressionTuple<
858
+ Current extends readonly Expression.Any[],
859
+ More extends readonly ExpressionInput[],
860
+ Dialect extends string,
861
+ TextDb extends Expression.DbType.Any,
862
+ NumericDb extends Expression.DbType.Any,
863
+ BoolDb extends Expression.DbType.Any,
864
+ TimestampDb extends Expression.DbType.Any,
865
+ NullDb extends Expression.DbType.Any
866
+ > = readonly [
867
+ ...Current,
868
+ ...DialectExpressionTuple<More, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
869
+ ]
870
+
871
+ type VariadicBooleanExpression<
872
+ Kind extends "and" | "or",
873
+ Values extends readonly Expression.Any[],
874
+ Dialect extends string,
875
+ TextDb extends Expression.DbType.Any,
876
+ NumericDb extends Expression.DbType.Any,
877
+ BoolDb extends Expression.DbType.Any,
878
+ TimestampDb extends Expression.DbType.Any,
879
+ NullDb extends Expression.DbType.Any
880
+ > = AstBackedExpression<
881
+ boolean,
882
+ BoolDb,
883
+ MergeNullabilityTuple<Values>,
884
+ TupleDialect<Values>,
885
+ MergeAggregationTuple<Values>,
886
+ TupleSource<Values>,
887
+ TupleDependencies<Values>,
888
+ ExpressionAst.VariadicNode<Kind, Values>
889
+ > & {
890
+ pipe<More extends readonly [ExpressionInput, ...ExpressionInput[]]>(
891
+ ...values: More
892
+ ): VariadicBooleanExpression<
893
+ Kind,
894
+ AppendDialectExpressionTuple<Values, More, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
895
+ Dialect,
896
+ TextDb,
897
+ NumericDb,
898
+ BoolDb,
899
+ TimestampDb,
900
+ NullDb
901
+ >
902
+ }
903
+
806
904
  type JsonRuntime<Value> = NormalizeJsonLiteral<Value> extends never
807
905
  ? unknown
808
906
  : NormalizeJsonLiteral<Value>
@@ -845,6 +943,29 @@ type JsonExpressionLike<Runtime = unknown> = Expression.Expression<
845
943
  Expression.SourceNullabilityMode
846
944
  >
847
945
 
946
+ type JsonDbOfExpression<Value extends JsonExpressionLike<any>> = Expression.DbTypeOf<Value>
947
+
948
+ type JsonKindOfInput<
949
+ Value,
950
+ Fallback extends string = "json"
951
+ > = Value extends Expression.Any
952
+ ? Expression.DbTypeOf<Value> extends Expression.DbType.Json<any, infer Kind> ? Kind : Fallback
953
+ : Fallback
954
+
955
+ type JsonConcatKind<
956
+ Left,
957
+ Right,
958
+ EngineDialect extends string
959
+ > = EngineDialect extends "postgres"
960
+ ? "jsonb"
961
+ : JsonKindOfInput<Left> extends "jsonb"
962
+ ? "jsonb"
963
+ : JsonKindOfInput<Right> extends "jsonb"
964
+ ? "jsonb"
965
+ : "json"
966
+
967
+ type JsonbKindForDialect<EngineDialect extends string> = EngineDialect extends "postgres" ? "jsonb" : "json"
968
+
848
969
  type JsonValueInput = JsonLiteralInput | Expression.Any
849
970
 
850
971
  type JsonPathInput = JsonPath.Path<any> | JsonPath.CanonicalSegment
@@ -1268,17 +1389,24 @@ type NumberWindowExpression<
1268
1389
  * that manufacture new expressions are specialized to the supplied dialect DB
1269
1390
  * types instead of relying on the Postgres-default root module.
1270
1391
  */
1271
- export function makeDialectQuery<
1272
- Dialect extends string,
1273
- TextDb extends Expression.DbType.Any,
1274
- NumericDb extends Expression.DbType.Any,
1275
- BoolDb extends Expression.DbType.Any,
1276
- TimestampDb extends Expression.DbType.Any,
1277
- NullDb extends Expression.DbType.Any,
1278
- TypeWitnesses extends object = object
1279
- >(
1280
- profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, TypeWitnesses>
1281
- ) {
1392
+ export const postgresQuery = (() => {
1393
+ type Dialect = "postgres"
1394
+ type TextDb = Expression.DbType.PgText
1395
+ type NumericDb = Expression.DbType.PgFloat8
1396
+ type BoolDb = Expression.DbType.PgBool
1397
+ type TimestampDb = Expression.DbType.PgTimestamp
1398
+ type NullDb = Expression.DbType.Base<"postgres", "null">
1399
+ type TypeWitnesses = typeof postgresDatatypes
1400
+
1401
+ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, TypeWitnesses> = {
1402
+ dialect: "postgres",
1403
+ textDb: { dialect: "postgres", kind: "text" } as TextDb,
1404
+ numericDb: { dialect: "postgres", kind: "float8" } as NumericDb,
1405
+ boolDb: { dialect: "postgres", kind: "bool" } as BoolDb,
1406
+ timestampDb: { dialect: "postgres", kind: "timestamp" } as TimestampDb,
1407
+ nullDb: { dialect: "postgres", kind: "null" } as NullDb,
1408
+ type: postgresDatatypes
1409
+ }
1282
1410
  const ValuesInputProto = {
1283
1411
  pipe(this: unknown) {
1284
1412
  return pipeArguments(this, arguments)
@@ -1318,6 +1446,51 @@ export function makeDialectQuery<
1318
1446
  value
1319
1447
  })
1320
1448
 
1449
+ const column = <
1450
+ Name extends string,
1451
+ Db extends Expression.DbType.Any
1452
+ >(
1453
+ name: Name,
1454
+ dbType: Db,
1455
+ nullable = false
1456
+ ): Expression.Expression<
1457
+ Expression.RuntimeOfDbType<Db> | null,
1458
+ Db,
1459
+ Expression.Nullability,
1460
+ Dialect,
1461
+ "scalar",
1462
+ never,
1463
+ {},
1464
+ "resolved"
1465
+ > & {
1466
+ readonly [ExpressionAst.TypeId]: ExpressionAst.ColumnNode<"", Name>
1467
+ } =>
1468
+ makeExpression({
1469
+ runtime: undefined as unknown as Expression.RuntimeOfDbType<Db> | (typeof nullable extends true ? null : never),
1470
+ dbType,
1471
+ nullability: (nullable ? "maybe" : "never") as typeof nullable extends true ? "maybe" : "never",
1472
+ dialect: profile.dialect as Dialect,
1473
+ aggregation: "scalar",
1474
+ source: undefined as never,
1475
+ sourceNullability: "resolved" as const,
1476
+ dependencies: {}
1477
+ }, {
1478
+ kind: "column",
1479
+ tableName: "",
1480
+ columnName: name
1481
+ }) as Expression.Expression<
1482
+ Expression.RuntimeOfDbType<Db> | null,
1483
+ Db,
1484
+ Expression.Nullability,
1485
+ Dialect,
1486
+ "scalar",
1487
+ never,
1488
+ {},
1489
+ "resolved"
1490
+ > & {
1491
+ readonly [ExpressionAst.TypeId]: ExpressionAst.ColumnNode<"", Name>
1492
+ }
1493
+
1321
1494
  const toDialectExpression = <Value extends ExpressionInput>(
1322
1495
  value: Value
1323
1496
  ): DialectAsExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> => {
@@ -1349,6 +1522,69 @@ export function makeDialectQuery<
1349
1522
  ? literal(value)
1350
1523
  : value) as DialectAsNumericExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
1351
1524
 
1525
+ const flattenVariadicBooleanExpressions = <
1526
+ Kind extends "and" | "or",
1527
+ Values extends readonly Expression.Any[]
1528
+ >(
1529
+ kind: Kind,
1530
+ values: Values
1531
+ ): readonly Expression.Any[] => {
1532
+ const flattened: Array<Expression.Any> = []
1533
+ for (const value of values) {
1534
+ const ast = (value as unknown as { readonly [ExpressionAst.TypeId]: ExpressionAst.Any })[ExpressionAst.TypeId]
1535
+ if (ast.kind === kind) {
1536
+ flattened.push(...ast.values)
1537
+ } else {
1538
+ flattened.push(value)
1539
+ }
1540
+ }
1541
+ return flattened
1542
+ }
1543
+
1544
+ const makeVariadicBooleanExpression = <
1545
+ Kind extends "and" | "or",
1546
+ Values extends readonly Expression.Any[]
1547
+ >(
1548
+ kind: Kind,
1549
+ values: Values
1550
+ ): VariadicBooleanExpression<Kind, Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> => {
1551
+ const expressions = flattenVariadicBooleanExpressions(kind, values) as Values
1552
+ const expression = makeExpression({
1553
+ runtime: true as boolean,
1554
+ dbType: profile.boolDb as BoolDb,
1555
+ nullability: mergeNullabilityManyRuntime(expressions) as MergeNullabilityTuple<Values>,
1556
+ dialect: (expressions.find((value) => value[Expression.TypeId].dialect !== undefined)?.[Expression.TypeId].dialect ?? profile.dialect) as TupleDialect<Values>,
1557
+ aggregation: mergeAggregationManyRuntime(expressions) as MergeAggregationTuple<Values>,
1558
+ source: mergeManySources(expressions) as TupleSource<Values>,
1559
+ sourceNullability: "propagate" as const,
1560
+ dependencies: mergeManyDependencies(expressions) as TupleDependencies<Values>
1561
+ }, {
1562
+ kind,
1563
+ values: expressions
1564
+ }) as VariadicBooleanExpression<Kind, Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
1565
+
1566
+ Object.defineProperty(expression, "pipe", {
1567
+ configurable: true,
1568
+ writable: true,
1569
+ value(this: Expression.Any) {
1570
+ if (arguments.length === 0) {
1571
+ return this
1572
+ }
1573
+ const operations = Array.from(arguments)
1574
+ if (operations.every((operation) => typeof operation !== "function")) {
1575
+ const appended = operations.map((operation) => toDialectExpression(operation as ExpressionInput)) as readonly Expression.Any[]
1576
+ return makeVariadicBooleanExpression(kind, [...expressions, ...appended] as const)
1577
+ }
1578
+ if (operations.every((operation) => typeof operation === "function")) {
1579
+ return pipeArguments(this, arguments)
1580
+ }
1581
+ throw new TypeError(`Cannot mix query expressions and pipe functions inside ${kind}(...).pipe(...)`)
1582
+ }
1583
+ })
1584
+
1585
+ return expression
1586
+ }
1587
+
1352
1588
  const extractRequiredFromDialectInputRuntime = (value: ExpressionInput): readonly string[] => {
1353
1589
  const expression = toDialectExpression(value)
1354
1590
  return Object.keys(expression[Expression.TypeId].dependencies)
@@ -1584,6 +1820,46 @@ export function makeDialectQuery<
1584
1820
  return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "ilike")
1585
1821
  }
1586
1822
 
1823
+ const regexMatch = <
1824
+ Left extends StringExpressionInput,
1825
+ Right extends StringExpressionInput
1826
+ >(
1827
+ ...args: TextArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "regexMatch">
1828
+ ): BinaryPredicateExpression<Left, Right, "regexMatch"> => {
1829
+ const [left, right] = args as [Left, Right]
1830
+ return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "regexMatch")
1831
+ }
1832
+
1833
+ const regexIMatch = <
1834
+ Left extends StringExpressionInput,
1835
+ Right extends StringExpressionInput
1836
+ >(
1837
+ ...args: TextArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "regexIMatch">
1838
+ ): BinaryPredicateExpression<Left, Right, "regexIMatch"> => {
1839
+ const [left, right] = args as [Left, Right]
1840
+ return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "regexIMatch")
1841
+ }
1842
+
1843
+ const regexNotMatch = <
1844
+ Left extends StringExpressionInput,
1845
+ Right extends StringExpressionInput
1846
+ >(
1847
+ ...args: TextArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "regexNotMatch">
1848
+ ): BinaryPredicateExpression<Left, Right, "regexNotMatch"> => {
1849
+ const [left, right] = args as [Left, Right]
1850
+ return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "regexNotMatch")
1851
+ }
1852
+
1853
+ const regexNotIMatch = <
1854
+ Left extends StringExpressionInput,
1855
+ Right extends StringExpressionInput
1856
+ >(
1857
+ ...args: TextArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "regexNotIMatch">
1858
+ ): BinaryPredicateExpression<Left, Right, "regexNotIMatch"> => {
1859
+ const [left, right] = args as [Left, Right]
1860
+ return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "regexNotIMatch")
1861
+ }
1862
+
1587
1863
  const isDistinctFrom = <
1588
1864
  Left extends ExpressionInput,
1589
1865
  Right extends ExpressionInput
@@ -1812,6 +2088,13 @@ export function makeDialectQuery<
1812
2088
  variant: "set"
1813
2089
  })
1814
2090
 
2091
+ const custom = <Kind extends string>(
2092
+ kind: Kind
2093
+ ): Expression.DbType.Base<Dialect, Kind> => ({
2094
+ dialect: profile.dialect,
2095
+ kind
2096
+ })
2097
+
1815
2098
  const type = {
1816
2099
  ...profile.type,
1817
2100
  array,
@@ -1820,7 +2103,8 @@ export function makeDialectQuery<
1820
2103
  record,
1821
2104
  domain,
1822
2105
  enum: enum_,
1823
- set
2106
+ set,
2107
+ custom
1824
2108
  }
1825
2109
 
1826
2110
  const makeJsonDb = <Kind extends string>(
@@ -1828,11 +2112,11 @@ export function makeDialectQuery<
1828
2112
  ): JsonDb<Dialect, Kind> => ({
1829
2113
  dialect: profile.dialect,
1830
2114
  kind,
1831
- variant: "json"
2115
+ variant: (kind === "jsonb" ? "jsonb" : "json") as Kind extends "jsonb" ? "jsonb" : "json"
1832
2116
  })
1833
2117
 
1834
2118
  const jsonDb = makeJsonDb("json")
1835
- const jsonbDb = makeJsonDb((profile.dialect === "postgres" ? "jsonb" : "json") as string)
2119
+ const jsonbDb = makeJsonDb("jsonb" as JsonbKindForDialect<Dialect>)
1836
2120
 
1837
2121
  const isExpressionValue = (value: unknown): value is Expression.Any =>
1838
2122
  value !== null && typeof value === "object" && Expression.TypeId in value
@@ -1901,6 +2185,14 @@ export function makeDialectQuery<
1901
2185
  SourceNullability
1902
2186
  >
1903
2187
 
2188
+ const jsonDbTypeOf = <Base extends JsonExpressionLike<any>>(
2189
+ base: Base
2190
+ ): JsonDbOfExpression<Base> => base[Expression.TypeId].dbType as JsonDbOfExpression<Base>
2191
+
2192
+ const resolveJsonMergeDbType = (
2193
+ ..._values: readonly Expression.Any[]
2194
+ ): Expression.DbType.Json<any, any> => jsonbDb
2195
+
1904
2196
  const makeJsonLiteralExpression = <Value extends JsonLiteralInput>(
1905
2197
  value: Value,
1906
2198
  dbType: Expression.DbType.Json<any, any> = jsonDb
@@ -1961,7 +2253,7 @@ export function makeDialectQuery<
1961
2253
  target: Target & JsonPathGuard<Expression.RuntimeOf<Base>, Target, "json.get">
1962
2254
  ): JsonExpression<
1963
2255
  JsonPathOutputOf<Expression.RuntimeOf<Base>, Target, "json.get">,
1964
- JsonDb<Dialect>,
2256
+ JsonDbOfExpression<Base>,
1965
2257
  JsonNullabilityOf<JsonPathOutputOf<Expression.RuntimeOf<Base>, Target, "json.get">>,
1966
2258
  DialectOf<Base>,
1967
2259
  AggregationOf<Base>,
@@ -1977,7 +2269,7 @@ export function makeDialectQuery<
1977
2269
  [base],
1978
2270
  {
1979
2271
  runtime: undefined as unknown as JsonPathOutputOf<Expression.RuntimeOf<Base>, Target, "json.get">,
1980
- dbType: jsonDb,
2272
+ dbType: jsonDbTypeOf(base),
1981
2273
  nullability: undefined as unknown as JsonNullabilityOf<JsonPathOutputOf<Expression.RuntimeOf<Base>, Target, "json.get">>
1982
2274
  },
1983
2275
  {
@@ -1987,7 +2279,7 @@ export function makeDialectQuery<
1987
2279
  }
1988
2280
  ) as JsonExpression<
1989
2281
  JsonPathOutputOf<Expression.RuntimeOf<Base>, Target, "json.get">,
1990
- JsonDb<Dialect>,
2282
+ JsonDbOfExpression<Base>,
1991
2283
  JsonNullabilityOf<JsonPathOutputOf<Expression.RuntimeOf<Base>, Target, "json.get">>,
1992
2284
  DialectOf<Base>,
1993
2285
  AggregationOf<Base>,
@@ -2056,7 +2348,7 @@ export function makeDialectQuery<
2056
2348
  [base],
2057
2349
  {
2058
2350
  runtime: undefined as unknown as JsonPathOutputOf<Expression.RuntimeOf<Base>, Target, "json.access">,
2059
- dbType: jsonDb,
2351
+ dbType: jsonDbTypeOf(base),
2060
2352
  nullability: undefined as unknown as JsonNullabilityOf<JsonPathOutputOf<Expression.RuntimeOf<Base>, Target, "json.access">>
2061
2353
  },
2062
2354
  {
@@ -2079,7 +2371,7 @@ export function makeDialectQuery<
2079
2371
  [base],
2080
2372
  {
2081
2373
  runtime: undefined as unknown as JsonPathOutputOf<Expression.RuntimeOf<Base>, Target, "json.traverse">,
2082
- dbType: jsonDb,
2374
+ dbType: jsonDbTypeOf(base),
2083
2375
  nullability: undefined as unknown as JsonNullabilityOf<JsonPathOutputOf<Expression.RuntimeOf<Base>, Target, "json.traverse">>
2084
2376
  },
2085
2377
  {
@@ -2225,7 +2517,7 @@ export function makeDialectQuery<
2225
2517
  target: Target & JsonDeleteGuard<Expression.RuntimeOf<Base>, Target, "json.delete">
2226
2518
  ): JsonExpression<
2227
2519
  JsonDeleteOutputOf<Expression.RuntimeOf<Base>, Target, "json.delete">,
2228
- JsonDb<Dialect>,
2520
+ JsonDbOfExpression<Base>,
2229
2521
  JsonNullabilityOf<JsonDeleteOutputOf<Expression.RuntimeOf<Base>, Target, "json.delete">>,
2230
2522
  DialectOf<Base>,
2231
2523
  AggregationOf<Base>,
@@ -2238,7 +2530,7 @@ export function makeDialectQuery<
2238
2530
  [base],
2239
2531
  {
2240
2532
  runtime: undefined as unknown as JsonDeleteOutputOf<Expression.RuntimeOf<Base>, Target, "json.delete">,
2241
- dbType: jsonDb,
2533
+ dbType: jsonDbTypeOf(base),
2242
2534
  nullability: undefined as unknown as JsonNullabilityOf<JsonDeleteOutputOf<Expression.RuntimeOf<Base>, Target, "json.delete">>
2243
2535
  },
2244
2536
  {
@@ -2248,7 +2540,7 @@ export function makeDialectQuery<
2248
2540
  }
2249
2541
  ) as JsonExpression<
2250
2542
  JsonDeleteOutputOf<Expression.RuntimeOf<Base>, Target, "json.delete">,
2251
- JsonDb<Dialect>,
2543
+ JsonDbOfExpression<Base>,
2252
2544
  JsonNullabilityOf<JsonDeleteOutputOf<Expression.RuntimeOf<Base>, Target, "json.delete">>,
2253
2545
  DialectOf<Base>,
2254
2546
  AggregationOf<Base>,
@@ -2266,7 +2558,7 @@ export function makeDialectQuery<
2266
2558
  target: Target & JsonDeleteGuard<Expression.RuntimeOf<Base>, Target, "json.remove">
2267
2559
  ): JsonExpression<
2268
2560
  JsonDeleteOutputOf<Expression.RuntimeOf<Base>, Target, "json.remove">,
2269
- JsonDb<Dialect>,
2561
+ JsonDbOfExpression<Base>,
2270
2562
  JsonNullabilityOf<JsonDeleteOutputOf<Expression.RuntimeOf<Base>, Target, "json.remove">>,
2271
2563
  DialectOf<Base>,
2272
2564
  AggregationOf<Base>,
@@ -2279,7 +2571,7 @@ export function makeDialectQuery<
2279
2571
  [base],
2280
2572
  {
2281
2573
  runtime: undefined as unknown as JsonDeleteOutputOf<Expression.RuntimeOf<Base>, Target, "json.remove">,
2282
- dbType: jsonDb,
2574
+ dbType: jsonDbTypeOf(base),
2283
2575
  nullability: undefined as unknown as JsonNullabilityOf<JsonDeleteOutputOf<Expression.RuntimeOf<Base>, Target, "json.remove">>
2284
2576
  },
2285
2577
  {
@@ -2289,7 +2581,7 @@ export function makeDialectQuery<
2289
2581
  }
2290
2582
  ) as JsonExpression<
2291
2583
  JsonDeleteOutputOf<Expression.RuntimeOf<Base>, Target, "json.remove">,
2292
- JsonDb<Dialect>,
2584
+ JsonDbOfExpression<Base>,
2293
2585
  JsonNullabilityOf<JsonDeleteOutputOf<Expression.RuntimeOf<Base>, Target, "json.remove">>,
2294
2586
  DialectOf<Base>,
2295
2587
  AggregationOf<Base>,
@@ -2312,7 +2604,7 @@ export function makeDialectQuery<
2312
2604
  } = {}
2313
2605
  ): JsonExpression<
2314
2606
  JsonSetOutputOf<Expression.RuntimeOf<Base>, Target, Next, "json.set">,
2315
- JsonDb<Dialect>,
2607
+ JsonDbOfExpression<Base>,
2316
2608
  JsonNullabilityOf<JsonSetOutputOf<Expression.RuntimeOf<Base>, Target, Next, "json.set">>,
2317
2609
  DialectOf<Base>,
2318
2610
  AggregationOf<Base>,
@@ -2326,7 +2618,7 @@ export function makeDialectQuery<
2326
2618
  [base, newValue],
2327
2619
  {
2328
2620
  runtime: undefined as unknown as JsonSetOutputOf<Expression.RuntimeOf<Base>, Target, Next, "json.set">,
2329
- dbType: jsonDb,
2621
+ dbType: jsonDbTypeOf(base),
2330
2622
  nullability: undefined as unknown as JsonNullabilityOf<JsonSetOutputOf<Expression.RuntimeOf<Base>, Target, Next, "json.set">>
2331
2623
  },
2332
2624
  {
@@ -2338,7 +2630,7 @@ export function makeDialectQuery<
2338
2630
  }
2339
2631
  ) as JsonExpression<
2340
2632
  JsonSetOutputOf<Expression.RuntimeOf<Base>, Target, Next, "json.set">,
2341
- JsonDb<Dialect>,
2633
+ JsonDbOfExpression<Base>,
2342
2634
  JsonNullabilityOf<JsonSetOutputOf<Expression.RuntimeOf<Base>, Target, Next, "json.set">>,
2343
2635
  DialectOf<Base>,
2344
2636
  AggregationOf<Base>,
@@ -2362,7 +2654,7 @@ export function makeDialectQuery<
2362
2654
  } = {}
2363
2655
  ): JsonExpression<
2364
2656
  JsonInsertOutputOf<Expression.RuntimeOf<Base>, Target, Next, InsertAfter, "json.insert">,
2365
- JsonDb<Dialect>,
2657
+ JsonDbOfExpression<Base>,
2366
2658
  JsonNullabilityOf<JsonInsertOutputOf<Expression.RuntimeOf<Base>, Target, Next, InsertAfter, "json.insert">>,
2367
2659
  DialectOf<Base>,
2368
2660
  AggregationOf<Base>,
@@ -2377,7 +2669,7 @@ export function makeDialectQuery<
2377
2669
  [base, insert],
2378
2670
  {
2379
2671
  runtime: undefined as unknown as JsonInsertOutputOf<Expression.RuntimeOf<Base>, Target, Next, InsertAfter, "json.insert">,
2380
- dbType: jsonDb,
2672
+ dbType: jsonDbTypeOf(base),
2381
2673
  nullability: undefined as unknown as JsonNullabilityOf<JsonInsertOutputOf<Expression.RuntimeOf<Base>, Target, Next, InsertAfter, "json.insert">>
2382
2674
  },
2383
2675
  {
@@ -2389,7 +2681,7 @@ export function makeDialectQuery<
2389
2681
  }
2390
2682
  ) as JsonExpression<
2391
2683
  JsonInsertOutputOf<Expression.RuntimeOf<Base>, Target, Next, InsertAfter, "json.insert">,
2392
- JsonDb<Dialect>,
2684
+ JsonDbOfExpression<Base>,
2393
2685
  JsonNullabilityOf<JsonInsertOutputOf<Expression.RuntimeOf<Base>, Target, Next, InsertAfter, "json.insert">>,
2394
2686
  DialectOf<Base>,
2395
2687
  AggregationOf<Base>,
@@ -2399,7 +2691,11 @@ export function makeDialectQuery<
2399
2691
  >
2400
2692
  }
2401
2693
 
2402
- const jsonConcat = <
2694
+ const jsonConcatAs = <
2695
+ Db extends Expression.DbType.Json<any, any>
2696
+ >(
2697
+ dbType: Db
2698
+ ) => <
2403
2699
  Left extends JsonValueInput,
2404
2700
  Right extends JsonValueInput
2405
2701
  >(
@@ -2407,7 +2703,7 @@ export function makeDialectQuery<
2407
2703
  right: Right
2408
2704
  ): JsonExpression<
2409
2705
  JsonConcatResult<JsonOutputOfInput<Left>, JsonOutputOfInput<Right>>,
2410
- JsonDb<Dialect>,
2706
+ Db,
2411
2707
  "maybe",
2412
2708
  Dialect,
2413
2709
  Expression.AggregationKind,
@@ -2421,7 +2717,7 @@ export function makeDialectQuery<
2421
2717
  [leftExpression, rightExpression],
2422
2718
  {
2423
2719
  runtime: undefined as unknown as JsonConcatResult<JsonOutputOfInput<Left>, JsonOutputOfInput<Right>>,
2424
- dbType: jsonDb,
2720
+ dbType,
2425
2721
  nullability: "maybe" as const
2426
2722
  },
2427
2723
  {
@@ -2431,7 +2727,7 @@ export function makeDialectQuery<
2431
2727
  }
2432
2728
  ) as JsonExpression<
2433
2729
  JsonConcatResult<JsonOutputOfInput<Left>, JsonOutputOfInput<Right>>,
2434
- JsonDb<Dialect>,
2730
+ Db,
2435
2731
  "maybe",
2436
2732
  Dialect,
2437
2733
  Expression.AggregationKind,
@@ -2441,7 +2737,11 @@ export function makeDialectQuery<
2441
2737
  >
2442
2738
  }
2443
2739
 
2444
- const jsonMerge = <
2740
+ const jsonMergeAs = <
2741
+ Db extends Expression.DbType.Json<any, any>
2742
+ >(
2743
+ dbType: Db
2744
+ ) => <
2445
2745
  Left extends JsonValueInput,
2446
2746
  Right extends JsonValueInput
2447
2747
  >(
@@ -2454,7 +2754,7 @@ export function makeDialectQuery<
2454
2754
  [leftExpression, rightExpression],
2455
2755
  {
2456
2756
  runtime: undefined as unknown as JsonConcatResult<JsonOutputOfInput<Left>, JsonOutputOfInput<Right>>,
2457
- dbType: jsonDb,
2757
+ dbType,
2458
2758
  nullability: "maybe" as const
2459
2759
  },
2460
2760
  {
@@ -2465,6 +2765,9 @@ export function makeDialectQuery<
2465
2765
  )
2466
2766
  }
2467
2767
 
2768
+ const jsonConcat = jsonConcatAs(resolveJsonMergeDbType())
2769
+ const jsonMerge = jsonMergeAs(resolveJsonMergeDbType())
2770
+
2468
2771
  const jsonKeyExists = <
2469
2772
  Base extends JsonExpressionLike<any>,
2470
2773
  Key extends string
@@ -2486,7 +2789,11 @@ export function makeDialectQuery<
2486
2789
  }
2487
2790
  )
2488
2791
 
2489
- const jsonBuildObject = <
2792
+ const jsonBuildObjectAs = <
2793
+ Db extends Expression.DbType.Json<any, any>
2794
+ >(
2795
+ dbType: Db
2796
+ ) => <
2490
2797
  Shape extends Record<string, JsonValueInput>
2491
2798
  >(
2492
2799
  shape: Shape
@@ -2499,7 +2806,7 @@ export function makeDialectQuery<
2499
2806
  entries.map((entry) => entry.value),
2500
2807
  {
2501
2808
  runtime: {} as JsonObjectOutput<Shape>,
2502
- dbType: jsonDb,
2809
+ dbType,
2503
2810
  nullability: "never" as const,
2504
2811
  sourceNullability: "resolved" as const
2505
2812
  },
@@ -2510,7 +2817,11 @@ export function makeDialectQuery<
2510
2817
  )
2511
2818
  }
2512
2819
 
2513
- const jsonBuildArray = <
2820
+ const jsonBuildArrayAs = <
2821
+ Db extends Expression.DbType.Json<any, any>
2822
+ >(
2823
+ dbType: Db
2824
+ ) => <
2514
2825
  Values extends readonly JsonValueInput[]
2515
2826
  >(
2516
2827
  ...values: Values
@@ -2520,7 +2831,7 @@ export function makeDialectQuery<
2520
2831
  expressions,
2521
2832
  {
2522
2833
  runtime: [] as JsonArrayOutput<Values>,
2523
- dbType: jsonDb,
2834
+ dbType,
2524
2835
  nullability: "never" as const,
2525
2836
  sourceNullability: "resolved" as const
2526
2837
  },
@@ -2531,6 +2842,11 @@ export function makeDialectQuery<
2531
2842
  )
2532
2843
  }
2533
2844
 
2845
+ const jsonBuildObject = jsonBuildObjectAs(jsonDb)
2846
+ const jsonBuildArray = jsonBuildArrayAs(jsonDb)
2847
+ const jsonbBuildObject = jsonBuildObjectAs(jsonbDb)
2848
+ const jsonbBuildArray = jsonBuildArrayAs(jsonbDb)
2849
+
2534
2850
  const jsonToJson = <Value extends JsonValueInput>(
2535
2851
  value: Value
2536
2852
  ) => toJsonValueExpression(value, "jsonToJson", jsonDb) as JsonExpression<
@@ -2548,7 +2864,7 @@ export function makeDialectQuery<
2548
2864
  value: Value
2549
2865
  ) => toJsonValueExpression(value, "jsonToJsonb", jsonbDb) as JsonExpression<
2550
2866
  JsonOutputOfInput<Value>,
2551
- JsonDb<Dialect, string>,
2867
+ JsonDb<Dialect, JsonbKindForDialect<Dialect>>,
2552
2868
  JsonNullabilityOf<JsonOutputOfInput<Value>>,
2553
2869
  string,
2554
2870
  Expression.AggregationKind,
@@ -2645,7 +2961,7 @@ export function makeDialectQuery<
2645
2961
  [base],
2646
2962
  {
2647
2963
  runtime: undefined as unknown as JsonStripNullsResult<Expression.RuntimeOf<Base>>,
2648
- dbType: jsonDb,
2964
+ dbType: jsonDbTypeOf(base),
2649
2965
  nullability: undefined as unknown as JsonNullabilityOf<JsonStripNullsResult<Expression.RuntimeOf<Base>>>
2650
2966
  },
2651
2967
  {
@@ -2728,83 +3044,79 @@ export function makeDialectQuery<
2728
3044
  pathMatch: jsonPathMatch
2729
3045
  }
2730
3046
 
3047
+ const jsonb = {
3048
+ key: JsonPath.key,
3049
+ index: JsonPath.index,
3050
+ wildcard: JsonPath.wildcard,
3051
+ slice: JsonPath.slice,
3052
+ descend: JsonPath.descend,
3053
+ path: JsonPath.path,
3054
+ get: jsonGet,
3055
+ access: jsonAccess,
3056
+ traverse: jsonTraverse,
3057
+ text: jsonText,
3058
+ accessText: jsonAccessText,
3059
+ traverseText: jsonTraverseText,
3060
+ contains: jsonContains,
3061
+ containedBy: jsonContainedBy,
3062
+ hasKey: jsonHasKey,
3063
+ keyExists: jsonKeyExists,
3064
+ hasAnyKeys: jsonHasAnyKeys,
3065
+ hasAllKeys: jsonHasAllKeys,
3066
+ delete: jsonDelete,
3067
+ remove: jsonRemove,
3068
+ set: jsonSet,
3069
+ insert: jsonInsert,
3070
+ concat: jsonConcatAs(jsonbDb),
3071
+ merge: jsonMergeAs(jsonbDb),
3072
+ buildObject: jsonbBuildObject,
3073
+ buildArray: jsonbBuildArray,
3074
+ toJsonb: jsonToJsonb,
3075
+ typeOf: jsonTypeOf,
3076
+ length: jsonLength,
3077
+ keys: jsonKeys,
3078
+ stripNulls: jsonStripNulls,
3079
+ pathExists: jsonPathExists,
3080
+ pathMatch: jsonPathMatch
3081
+ }
3082
+
2731
3083
  const and = <
2732
3084
  Values extends readonly [ExpressionInput, ...ExpressionInput[]]
2733
3085
  >(
2734
3086
  ...values: Values
2735
- ): AstBackedExpression<
2736
- boolean,
3087
+ ): VariadicBooleanExpression<
3088
+ "and",
3089
+ { readonly [K in keyof Values]: DialectAsExpression<Values[K], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> } & readonly Expression.Any[],
3090
+ Dialect,
3091
+ TextDb,
3092
+ NumericDb,
2737
3093
  BoolDb,
2738
- MergeNullabilityTuple<{ readonly [K in keyof Values]: DialectAsExpression<Values[K], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> } & readonly Expression.Any[]>,
2739
- TupleDialect<{ readonly [K in keyof Values]: DialectAsExpression<Values[K], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> } & readonly Expression.Any[]>,
2740
- MergeAggregationTuple<{ readonly [K in keyof Values]: DialectAsExpression<Values[K], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> } & readonly Expression.Any[]>,
2741
- TupleSource<{ readonly [K in keyof Values]: DialectAsExpression<Values[K], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> } & readonly Expression.Any[]>,
2742
- TupleDependencies<{ readonly [K in keyof Values]: DialectAsExpression<Values[K], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> } & readonly Expression.Any[]>,
2743
- ExpressionAst.VariadicNode<"and", { readonly [K in keyof Values]: DialectAsExpression<Values[K], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> } & readonly Expression.Any[]>
2744
- > => {
2745
- const expressions = values.map((value) => toDialectExpression(value)) as readonly Expression.Any[]
2746
- return makeExpression({
2747
- runtime: true as boolean,
2748
- dbType: profile.boolDb as BoolDb,
2749
- nullability: mergeNullabilityManyRuntime(expressions) as MergeNullabilityTuple<{ readonly [K in keyof Values]: DialectAsExpression<Values[K], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> } & readonly Expression.Any[]>,
2750
- dialect: (expressions.find((value) => value[Expression.TypeId].dialect !== undefined)?.[Expression.TypeId].dialect ?? profile.dialect) as TupleDialect<{ readonly [K in keyof Values]: DialectAsExpression<Values[K], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> } & readonly Expression.Any[]>,
2751
- aggregation: mergeAggregationManyRuntime(expressions) as MergeAggregationTuple<{ readonly [K in keyof Values]: DialectAsExpression<Values[K], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> } & readonly Expression.Any[]>,
2752
- source: mergeManySources(expressions) as TupleSource<{ readonly [K in keyof Values]: DialectAsExpression<Values[K], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> } & readonly Expression.Any[]>,
2753
- sourceNullability: "propagate" as const,
2754
- dependencies: mergeManyDependencies(expressions) as TupleDependencies<{ readonly [K in keyof Values]: DialectAsExpression<Values[K], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> } & readonly Expression.Any[]>
2755
- }, {
2756
- kind: "and",
2757
- values: expressions
2758
- }) as AstBackedExpression<
2759
- boolean,
2760
- BoolDb,
2761
- MergeNullabilityTuple<{ readonly [K in keyof Values]: DialectAsExpression<Values[K], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> } & readonly Expression.Any[]>,
2762
- TupleDialect<{ readonly [K in keyof Values]: DialectAsExpression<Values[K], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> } & readonly Expression.Any[]>,
2763
- MergeAggregationTuple<{ readonly [K in keyof Values]: DialectAsExpression<Values[K], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> } & readonly Expression.Any[]>,
2764
- TupleSource<{ readonly [K in keyof Values]: DialectAsExpression<Values[K], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> } & readonly Expression.Any[]>,
2765
- TupleDependencies<{ readonly [K in keyof Values]: DialectAsExpression<Values[K], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> } & readonly Expression.Any[]>,
2766
- ExpressionAst.VariadicNode<"and", { readonly [K in keyof Values]: DialectAsExpression<Values[K], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> } & readonly Expression.Any[]>
2767
- >
2768
- }
3094
+ TimestampDb,
3095
+ NullDb
3096
+ > =>
3097
+ makeVariadicBooleanExpression(
3098
+ "and",
3099
+ values.map((value) => toDialectExpression(value)) as { readonly [K in keyof Values]: DialectAsExpression<Values[K], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> } & readonly Expression.Any[]
3100
+ )
2769
3101
 
2770
3102
  const or = <
2771
3103
  Values extends readonly [ExpressionInput, ...ExpressionInput[]]
2772
3104
  >(
2773
3105
  ...values: Values
2774
- ): AstBackedExpression<
2775
- boolean,
3106
+ ): VariadicBooleanExpression<
3107
+ "or",
3108
+ { readonly [K in keyof Values]: DialectAsExpression<Values[K], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> } & readonly Expression.Any[],
3109
+ Dialect,
3110
+ TextDb,
3111
+ NumericDb,
2776
3112
  BoolDb,
2777
- MergeNullabilityTuple<{ readonly [K in keyof Values]: DialectAsExpression<Values[K], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> } & readonly Expression.Any[]>,
2778
- TupleDialect<{ readonly [K in keyof Values]: DialectAsExpression<Values[K], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> } & readonly Expression.Any[]>,
2779
- MergeAggregationTuple<{ readonly [K in keyof Values]: DialectAsExpression<Values[K], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> } & readonly Expression.Any[]>,
2780
- TupleSource<{ readonly [K in keyof Values]: DialectAsExpression<Values[K], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> } & readonly Expression.Any[]>,
2781
- TupleDependencies<{ readonly [K in keyof Values]: DialectAsExpression<Values[K], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> } & readonly Expression.Any[]>,
2782
- ExpressionAst.VariadicNode<"or", { readonly [K in keyof Values]: DialectAsExpression<Values[K], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> } & readonly Expression.Any[]>
2783
- > => {
2784
- const expressions = values.map((value) => toDialectExpression(value)) as readonly Expression.Any[]
2785
- return makeExpression({
2786
- runtime: true as boolean,
2787
- dbType: profile.boolDb as BoolDb,
2788
- nullability: mergeNullabilityManyRuntime(expressions) as MergeNullabilityTuple<{ readonly [K in keyof Values]: DialectAsExpression<Values[K], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> } & readonly Expression.Any[]>,
2789
- dialect: (expressions.find((value) => value[Expression.TypeId].dialect !== undefined)?.[Expression.TypeId].dialect ?? profile.dialect) as TupleDialect<{ readonly [K in keyof Values]: DialectAsExpression<Values[K], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> } & readonly Expression.Any[]>,
2790
- aggregation: mergeAggregationManyRuntime(expressions) as MergeAggregationTuple<{ readonly [K in keyof Values]: DialectAsExpression<Values[K], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> } & readonly Expression.Any[]>,
2791
- source: mergeManySources(expressions) as TupleSource<{ readonly [K in keyof Values]: DialectAsExpression<Values[K], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> } & readonly Expression.Any[]>,
2792
- sourceNullability: "propagate" as const,
2793
- dependencies: mergeManyDependencies(expressions) as TupleDependencies<{ readonly [K in keyof Values]: DialectAsExpression<Values[K], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> } & readonly Expression.Any[]>
2794
- }, {
2795
- kind: "or",
2796
- values: expressions
2797
- }) as AstBackedExpression<
2798
- boolean,
2799
- BoolDb,
2800
- MergeNullabilityTuple<{ readonly [K in keyof Values]: DialectAsExpression<Values[K], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> } & readonly Expression.Any[]>,
2801
- TupleDialect<{ readonly [K in keyof Values]: DialectAsExpression<Values[K], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> } & readonly Expression.Any[]>,
2802
- MergeAggregationTuple<{ readonly [K in keyof Values]: DialectAsExpression<Values[K], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> } & readonly Expression.Any[]>,
2803
- TupleSource<{ readonly [K in keyof Values]: DialectAsExpression<Values[K], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> } & readonly Expression.Any[]>,
2804
- TupleDependencies<{ readonly [K in keyof Values]: DialectAsExpression<Values[K], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> } & readonly Expression.Any[]>,
2805
- ExpressionAst.VariadicNode<"or", { readonly [K in keyof Values]: DialectAsExpression<Values[K], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> } & readonly Expression.Any[]>
2806
- >
2807
- }
3113
+ TimestampDb,
3114
+ NullDb
3115
+ > =>
3116
+ makeVariadicBooleanExpression(
3117
+ "or",
3118
+ values.map((value) => toDialectExpression(value)) as { readonly [K in keyof Values]: DialectAsExpression<Values[K], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> } & readonly Expression.Any[]
3119
+ )
2808
3120
 
2809
3121
  const not = <Value extends ExpressionInput>(
2810
3122
  value: Value
@@ -3370,6 +3682,84 @@ export function makeDialectQuery<
3370
3682
  >
3371
3683
  }
3372
3684
 
3685
+ const call = <
3686
+ Name extends string,
3687
+ Args extends readonly ExpressionInput[]
3688
+ >(
3689
+ name: Name,
3690
+ ...args: Args
3691
+ ): Expression.Any => {
3692
+ const expressions = args.map((value) => toDialectExpression(value)) as readonly Expression.Any[]
3693
+ return makeExpression({
3694
+ runtime: undefined as never,
3695
+ dbType: profile.textDb,
3696
+ nullability: "maybe",
3697
+ dialect: (expressions.find((value) => value[Expression.TypeId].dialect !== undefined)?.[Expression.TypeId].dialect ?? profile.dialect) as Dialect,
3698
+ aggregation: mergeAggregationManyRuntime(expressions),
3699
+ source: mergeManySources(expressions),
3700
+ sourceNullability: "resolved" as const,
3701
+ dependencies: mergeManyDependencies(expressions)
3702
+ }, {
3703
+ kind: "function",
3704
+ name,
3705
+ args: expressions
3706
+ }) as Expression.Any
3707
+ }
3708
+
3709
+ const uuidGenerateV4 = (): Expression.Expression<
3710
+ string,
3711
+ Expression.DbType.PgUuid,
3712
+ "never",
3713
+ Dialect,
3714
+ "scalar",
3715
+ never,
3716
+ {},
3717
+ "resolved"
3718
+ > & {
3719
+ readonly [ExpressionAst.TypeId]: ExpressionAst.FunctionCallNode<"uuid_generate_v4", readonly []>
3720
+ } => makeExpression({
3721
+ runtime: undefined as unknown as string,
3722
+ dbType: { dialect: "postgres", kind: "uuid" } as Expression.DbType.PgUuid,
3723
+ nullability: "never",
3724
+ dialect: profile.dialect as Dialect,
3725
+ aggregation: "scalar",
3726
+ source: undefined as never,
3727
+ sourceNullability: "resolved" as const,
3728
+ dependencies: {}
3729
+ }, {
3730
+ kind: "function",
3731
+ name: "uuid_generate_v4",
3732
+ args: []
3733
+ })
3734
+
3735
+ const nextVal = <Value extends ExpressionInput>(
3736
+ value: Value
3737
+ ): Expression.Expression<
3738
+ Expression.RuntimeOfDbType<Expression.DbType.PgInt8>,
3739
+ Expression.DbType.PgInt8,
3740
+ "never",
3741
+ Dialect,
3742
+ "scalar",
3743
+ never,
3744
+ {},
3745
+ "resolved"
3746
+ > & {
3747
+ readonly [ExpressionAst.TypeId]: ExpressionAst.FunctionCallNode<"nextval", readonly [Expression.Any]>
3748
+ } => makeExpression({
3749
+ runtime: undefined as unknown as Expression.RuntimeOfDbType<Expression.DbType.PgInt8>,
3750
+ dbType: { dialect: "postgres", kind: "int8" } as Expression.DbType.PgInt8,
3751
+ nullability: "never",
3752
+ dialect: profile.dialect as Dialect,
3753
+ aggregation: "scalar",
3754
+ source: undefined as never,
3755
+ sourceNullability: "resolved" as const,
3756
+ dependencies: {}
3757
+ }, {
3758
+ kind: "function",
3759
+ name: "nextval",
3760
+ args: [toDialectExpression(value as any)]
3761
+ })
3762
+
3373
3763
  type RuntimeCaseBranch = {
3374
3764
  readonly when: Expression.Any
3375
3765
  readonly then: Expression.Any
@@ -3916,10 +4306,12 @@ type DdlColumnInput = string | readonly string[]
3916
4306
  type NormalizeDdlColumns<Columns extends DdlColumnInput> =
3917
4307
  Columns extends readonly [infer Head extends string, ...infer Tail extends string[]]
3918
4308
  ? readonly [Head, ...Tail]
4309
+ : Columns extends [infer Head extends string, ...infer Tail extends string[]]
4310
+ ? readonly [Head, ...Tail]
3919
4311
  : Columns extends readonly string[]
3920
- ? Columns extends readonly [string, ...string[]]
3921
- ? Columns
3922
- : never
4312
+ ? Columns[number] extends never
4313
+ ? never
4314
+ : readonly [Columns[number], ...Columns[number][]]
3923
4315
  : Columns extends string
3924
4316
  ? readonly [Columns]
3925
4317
  : never
@@ -4298,7 +4690,7 @@ type AstOf<Value extends Expression.Any> =
4298
4690
  ? Ast
4299
4691
  : never
4300
4692
 
4301
- type AvailableNames<Available extends Record<string, Plan.Source>> = Extract<keyof Available, string>
4693
+ type AvailableNames<Available extends Record<string, Plan.AnySource>> = Extract<keyof Available, string>
4302
4694
 
4303
4695
  type RequiredFromInput<Value extends ExpressionInput> =
4304
4696
  Value extends Expression.Any
@@ -4356,7 +4748,7 @@ type SelectFromResult<
4356
4748
  > = QueryPlan<
4357
4749
  SelectionOfPlan<PlanValue>,
4358
4750
  Exclude<RequiredOfPlan<PlanValue>, SourceNameOf<CurrentSource>>,
4359
- AddAvailable<{}, SourceNameOf<CurrentSource>>,
4751
+ AddAvailable<{}, SourceNameOf<CurrentSource>, "required", TrueFormula, PresenceWitnessKeysOfSource<CurrentSource>>,
4360
4752
  PlanDialectOf<PlanValue> | SourceDialectOf<CurrentSource>,
4361
4753
  GroupedOfPlan<PlanValue>,
4362
4754
  SourceNameOf<CurrentSource>,
@@ -4372,7 +4764,13 @@ type UpdateFromResult<
4372
4764
  > = QueryPlan<
4373
4765
  SelectionOfPlan<PlanValue>,
4374
4766
  Exclude<RequiredOfPlan<PlanValue>, SourceNameOf<CurrentSource>>,
4375
- AddAvailable<AvailableOfPlan<PlanValue>, SourceNameOf<CurrentSource>>,
4767
+ AddAvailable<
4768
+ AvailableOfPlan<PlanValue>,
4769
+ SourceNameOf<CurrentSource>,
4770
+ "required",
4771
+ TrueFormula,
4772
+ PresenceWitnessKeysOfSource<CurrentSource>
4773
+ >,
4376
4774
  PlanDialectOf<PlanValue> | SourceDialectOf<CurrentSource>,
4377
4775
  GroupedOfPlan<PlanValue>,
4378
4776
  ScopedNamesOfPlan<PlanValue> | SourceNameOf<CurrentSource>,
@@ -4447,7 +4845,7 @@ type FromPlanResult<
4447
4845
 
4448
4846
  type MergeRequiredFromPredicate<
4449
4847
  Predicate extends PredicateInput | undefined,
4450
- Available extends Record<string, Plan.Source>
4848
+ Available extends Record<string, Plan.AnySource>
4451
4849
  > = Predicate extends PredicateInput ? AddExpressionRequired<never, Available, Predicate> : never
4452
4850
 
4453
4851
  type AsCurriedInput<Dialect extends string> =
@@ -5075,7 +5473,10 @@ type AsCurriedResult<
5075
5473
  predicate: predicateExpression
5076
5474
  }]
5077
5475
  },
5078
- undefined as unknown as PlanAssumptionsAfterWhere<PlanValue, Predicate, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
5476
+ assumeFormulaTrue(
5477
+ currentQuery.assumptions,
5478
+ formulaOfExpressionRuntime(predicateExpression)
5479
+ ) as PlanAssumptionsAfterWhere<PlanValue, Predicate, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
5079
5480
  currentQuery.capabilities,
5080
5481
  currentQuery.statement as StatementOfPlan<PlanValue>)
5081
5482
  }
@@ -5108,6 +5509,7 @@ type AsCurriedResult<
5108
5509
 
5109
5510
  const sourceLike = source as SourceLike
5110
5511
  const { sourceName, sourceBaseName } = sourceDetails(sourceLike)
5512
+ const presenceWitnesses = presenceWitnessesOfSourceLike(sourceLike)
5111
5513
 
5112
5514
  if (currentQuery.statement === "select") {
5113
5515
  const nextAst = {
@@ -5127,9 +5529,11 @@ type AsCurriedResult<
5127
5529
  [sourceName]: {
5128
5530
  name: sourceName,
5129
5531
  mode: "required",
5130
- baseName: sourceBaseName
5532
+ baseName: sourceBaseName,
5533
+ _presentFormula: trueFormula(),
5534
+ _presenceWitnesses: presenceWitnesses
5131
5535
  }
5132
- } as AddAvailable<{}, string>,
5536
+ } as AddAvailable<{}, string, "required", TrueFormula, PresenceWitnessKeysOfSource<Extract<CurrentSource, SourceLike>>>,
5133
5537
  dialect: current.dialect
5134
5538
  }, nextAst, currentQuery.assumptions, currentQuery.capabilities, currentQuery.statement) as FromPlanResult<PlanValue, CurrentSource, Dialect>
5135
5539
  }
@@ -5140,7 +5544,9 @@ type AsCurriedResult<
5140
5544
  [sourceName]: {
5141
5545
  name: sourceName,
5142
5546
  mode: "required" as const,
5143
- baseName: sourceBaseName
5547
+ baseName: sourceBaseName,
5548
+ _presentFormula: trueFormula(),
5549
+ _presenceWitnesses: presenceWitnesses
5144
5550
  }
5145
5551
  }
5146
5552
  const nextAst = {
@@ -5180,7 +5586,7 @@ type AsCurriedResult<
5180
5586
  GroupedOfPlan<PlanValue>,
5181
5587
  ScopedNamesOfPlan<PlanValue>,
5182
5588
  AddExpressionRequired<OutstandingOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, Predicate>,
5183
- AssumptionsOfPlan<PlanValue>,
5589
+ PlanAssumptionsAfterHaving<PlanValue, Predicate, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
5184
5590
  CapabilitiesOfPlan<PlanValue>,
5185
5591
  StatementOfPlan<PlanValue>
5186
5592
  > => {
@@ -5201,7 +5607,12 @@ type AsCurriedResult<
5201
5607
  kind: "having",
5202
5608
  predicate: predicateExpression
5203
5609
  }]
5204
- }, currentQuery.assumptions, currentQuery.capabilities, currentQuery.statement as StatementOfPlan<PlanValue>)
5610
+ }, assumeFormulaTrue(
5611
+ currentQuery.assumptions,
5612
+ formulaOfExpressionRuntime(predicateExpression)
5613
+ ) as PlanAssumptionsAfterHaving<PlanValue, Predicate, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
5614
+ currentQuery.capabilities,
5615
+ currentQuery.statement as StatementOfPlan<PlanValue>)
5205
5616
  }
5206
5617
 
5207
5618
  const innerJoin = <CurrentTable extends SourceLike, Predicate extends PredicateInput>(
@@ -5240,7 +5651,13 @@ type AsCurriedResult<
5240
5651
  ): QueryPlan<
5241
5652
  SelectionOfPlan<PlanValue>,
5242
5653
  AddJoinRequired<RequiredOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, never, "cross">,
5243
- AddAvailable<AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, "required">,
5654
+ AddAvailable<
5655
+ AvailableOfPlan<PlanValue>,
5656
+ SourceNameOf<CurrentTable>,
5657
+ "required",
5658
+ TrueFormula,
5659
+ PresenceWitnessKeysOfSource<CurrentTable>
5660
+ >,
5244
5661
  PlanDialectOf<PlanValue> | SourceDialectOf<CurrentTable>,
5245
5662
  GroupedOfPlan<PlanValue>,
5246
5663
  ScopedNamesOfPlan<PlanValue> | SourceNameOf<CurrentTable>,
@@ -5253,6 +5670,7 @@ type AsCurriedResult<
5253
5670
  const currentAst = getAst(plan)
5254
5671
  const currentQuery = getQueryState(plan)
5255
5672
  const { sourceName, sourceBaseName } = sourceDetails(table)
5673
+ const presenceWitnesses = presenceWitnessesOfSourceLike(table)
5256
5674
  const nextAvailable = Object.assign(
5257
5675
  {},
5258
5676
  current.available as AvailableOfPlan<PlanValue>,
@@ -5260,10 +5678,18 @@ type AsCurriedResult<
5260
5678
  [sourceName]: {
5261
5679
  name: sourceName,
5262
5680
  mode: "required",
5263
- baseName: sourceBaseName
5681
+ baseName: sourceBaseName,
5682
+ _presentFormula: trueFormula(),
5683
+ _presenceWitnesses: presenceWitnesses
5264
5684
  }
5265
5685
  }
5266
- ) as AddAvailable<AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, "required">
5686
+ ) as AddAvailable<
5687
+ AvailableOfPlan<PlanValue>,
5688
+ SourceNameOf<CurrentTable>,
5689
+ "required",
5690
+ TrueFormula,
5691
+ PresenceWitnessKeysOfSource<CurrentTable>
5692
+ >
5267
5693
  return makePlan({
5268
5694
  selection: current.selection,
5269
5695
  required: currentRequiredList(current.required).filter((name) =>
@@ -5299,12 +5725,18 @@ type AsCurriedResult<
5299
5725
  ): QueryPlan<
5300
5726
  SelectionOfPlan<PlanValue>,
5301
5727
  AddJoinRequired<RequiredOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, Predicate, Kind>,
5302
- AvailableAfterJoin<AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, Kind>,
5728
+ AvailableAfterJoin<
5729
+ AvailableOfPlan<PlanValue>,
5730
+ SourceNameOf<CurrentTable>,
5731
+ Kind,
5732
+ JoinPresenceFormula<Kind, Predicate, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
5733
+ PresenceWitnessKeysOfSource<CurrentTable>
5734
+ >,
5303
5735
  PlanDialectOf<PlanValue> | SourceDialectOf<CurrentTable> | DialectOfDialectInput<Predicate, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
5304
5736
  GroupedOfPlan<PlanValue>,
5305
5737
  ScopedNamesOfPlan<PlanValue> | SourceNameOf<CurrentTable>,
5306
5738
  AddJoinRequired<OutstandingOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, Predicate, Kind>,
5307
- AssumptionsOfPlan<PlanValue>,
5739
+ PlanAssumptionsAfterJoin<PlanValue, Predicate, Kind, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
5308
5740
  MergeCapabilities<CapabilitiesOfPlan<PlanValue>, SourceCapabilitiesOf<CurrentTable>>,
5309
5741
  StatementOfPlan<PlanValue>
5310
5742
  > => {
@@ -5312,13 +5744,17 @@ type AsCurriedResult<
5312
5744
  const currentAst = getAst(plan)
5313
5745
  const currentQuery = getQueryState(plan)
5314
5746
  const onExpression = toDialectExpression(on)
5747
+ const onFormula = formulaOfExpressionRuntime(onExpression)
5315
5748
  const { sourceName, sourceBaseName } = sourceDetails(table)
5749
+ const presenceWitnesses = presenceWitnessesOfSourceLike(table)
5316
5750
  const baseAvailable = (kind === "right" || kind === "full"
5317
5751
  ? Object.fromEntries(
5318
- Object.entries(current.available as Record<string, Plan.Source>).map(([name, source]) => [name, {
5752
+ Object.entries(current.available as Record<string, Plan.AnySource>).map(([name, source]) => [name, {
5319
5753
  name: source.name,
5320
5754
  mode: "optional" as const,
5321
- baseName: source.baseName
5755
+ baseName: source.baseName,
5756
+ _presentFormula: source._presentFormula,
5757
+ _presenceWitnesses: source._presenceWitnesses
5322
5758
  }])
5323
5759
  )
5324
5760
  : current.available) as AvailableOfPlan<PlanValue>
@@ -5327,9 +5763,17 @@ type AsCurriedResult<
5327
5763
  [sourceName]: {
5328
5764
  name: sourceName,
5329
5765
  mode: (kind === "left" || kind === "full" ? "optional" : "required") as JoinSourceMode<Kind>,
5330
- baseName: sourceBaseName
5766
+ baseName: sourceBaseName,
5767
+ _presentFormula: (kind === "inner" || kind === "left") ? onFormula : trueFormula(),
5768
+ _presenceWitnesses: presenceWitnesses
5331
5769
  }
5332
- } as AvailableAfterJoin<AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, Kind>
5770
+ } as AvailableAfterJoin<
5771
+ AvailableOfPlan<PlanValue>,
5772
+ SourceNameOf<CurrentTable>,
5773
+ Kind,
5774
+ JoinPresenceFormula<Kind, Predicate, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
5775
+ PresenceWitnessKeysOfSource<CurrentTable>
5776
+ >
5333
5777
  return makePlan({
5334
5778
  selection: current.selection,
5335
5779
  required: [...currentRequiredList(current.required), ...extractRequiredFromDialectInputRuntime(on)].filter((name, index, values) =>
@@ -5345,7 +5789,13 @@ type AsCurriedResult<
5345
5789
  source: table,
5346
5790
  on: onExpression
5347
5791
  }]
5348
- }, currentQuery.assumptions, currentQuery.capabilities as MergeCapabilities<CapabilitiesOfPlan<PlanValue>, SourceCapabilitiesOf<CurrentTable>>, currentQuery.statement as StatementOfPlan<PlanValue>)
5792
+ }, (
5793
+ kind === "inner"
5794
+ ? assumeFormulaTrue(currentQuery.assumptions, onFormula)
5795
+ : currentQuery.assumptions
5796
+ ) as PlanAssumptionsAfterJoin<PlanValue, Predicate, Kind, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
5797
+ currentQuery.capabilities as MergeCapabilities<CapabilitiesOfPlan<PlanValue>, SourceCapabilitiesOf<CurrentTable>>,
5798
+ currentQuery.statement as StatementOfPlan<PlanValue>)
5349
5799
  }
5350
5800
 
5351
5801
  const orderBy = <Value extends ExpressionInput>(
@@ -5500,13 +5950,6 @@ type AsCurriedResult<
5500
5950
 
5501
5951
  const distinctOn = ((...values: readonly ExpressionInput[]) => {
5502
5952
  const expressions = values.map((value) => toDialectExpression(value)) as Expression.Any[]
5503
- if (profile.dialect !== "postgres") {
5504
- return {
5505
- __effect_qb_error__: "effect-qb: distinctOn(...) is only supported by the postgres dialect",
5506
- __effect_qb_dialect__: profile.dialect,
5507
- __effect_qb_hint__: "Use postgres.Query.distinctOn(...) or regular distinct()/grouping logic"
5508
- } as DistinctOnUnsupportedError<Dialect>
5509
- }
5510
5953
  return <PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
5511
5954
  plan: PlanValue & RequireSelectStatement<PlanValue>
5512
5955
  ): QueryPlan<
@@ -5693,10 +6136,10 @@ type AsCurriedResult<
5693
6136
  >
5694
6137
  function insert<
5695
6138
  Target extends MutationTargetLike,
5696
- Values extends MutationInputOf<Table.InsertOf<Target>>
6139
+ Values extends Record<string, unknown>
5697
6140
  >(
5698
6141
  target: Target,
5699
- values: Values
6142
+ values: MutationValuesInput<"insert", Target, Values>
5700
6143
  ): QueryPlan<
5701
6144
  {},
5702
6145
  Exclude<MutationRequiredFromValues<Values>, SourceNameOf<Target>>,
@@ -5821,7 +6264,7 @@ type AsCurriedResult<
5821
6264
 
5822
6265
  const onConflict = <
5823
6266
  Target extends MutationTargetLike,
5824
- Columns extends DdlColumnInput,
6267
+ const Columns extends DdlColumnInput,
5825
6268
  UpdateValues extends MutationInputOf<Table.UpdateOf<Target>> | undefined = MutationInputOf<Table.UpdateOf<Target>> | undefined,
5826
6269
  Options extends ConflictActionInput<Target, Dialect, UpdateValues> = ConflictActionInput<Target, Dialect, UpdateValues>
5827
6270
  >(
@@ -5879,37 +6322,37 @@ type AsCurriedResult<
5879
6322
  }
5880
6323
 
5881
6324
  function update<
5882
- Target extends MutationTargetLike,
5883
- Values extends MutationInputOf<Table.UpdateOf<Target>>
6325
+ Targets extends MutationTargetTuple,
6326
+ Values extends UpdateInputOfTarget<Targets>
5884
6327
  >(
5885
- target: Target,
6328
+ target: Dialect extends "mysql" ? Targets : never,
5886
6329
  values: Values
5887
6330
  ): QueryPlan<
5888
6331
  {},
5889
- Exclude<MutationRequiredFromValues<Values>, SourceNameOf<Target>>,
5890
- AddAvailable<{}, SourceNameOf<Target>>,
5891
- TableDialectOf<Target>,
6332
+ Exclude<NestedMutationRequiredFromValues<Values>, MutationTargetNamesOf<Targets>>,
6333
+ AddAvailableMany<{}, MutationTargetNamesOf<Targets>>,
6334
+ TableDialectOf<Targets[0]>,
5892
6335
  never,
5893
- SourceNameOf<Target>,
5894
- Exclude<MutationRequiredFromValues<Values>, SourceNameOf<Target>>,
6336
+ MutationTargetNamesOf<Targets>,
6337
+ Exclude<NestedMutationRequiredFromValues<Values>, MutationTargetNamesOf<Targets>>,
5895
6338
  TrueFormula,
5896
6339
  "write",
5897
6340
  "update"
5898
6341
  >
5899
6342
  function update<
5900
- Targets extends MutationTargetTuple,
5901
- Values extends UpdateInputOfTarget<Targets>
6343
+ Target extends MutationTargetLike,
6344
+ Values extends Record<string, unknown>
5902
6345
  >(
5903
- target: Dialect extends "mysql" ? Targets : never,
5904
- values: Values
6346
+ target: Target,
6347
+ values: MutationValuesInput<"update", Target, Values>
5905
6348
  ): QueryPlan<
5906
6349
  {},
5907
- Exclude<NestedMutationRequiredFromValues<Values>, MutationTargetNamesOf<Targets>>,
5908
- AddAvailableMany<{}, MutationTargetNamesOf<Targets>>,
5909
- TableDialectOf<Targets[0]>,
6350
+ Exclude<MutationRequiredFromValues<Values>, SourceNameOf<Target>>,
6351
+ AddAvailable<{}, SourceNameOf<Target>>,
6352
+ TableDialectOf<Target>,
5910
6353
  never,
5911
- MutationTargetNamesOf<Targets>,
5912
- Exclude<NestedMutationRequiredFromValues<Values>, MutationTargetNamesOf<Targets>>,
6354
+ SourceNameOf<Target>,
6355
+ Exclude<MutationRequiredFromValues<Values>, SourceNameOf<Target>>,
5913
6356
  TrueFormula,
5914
6357
  "write",
5915
6358
  "update"
@@ -5947,7 +6390,7 @@ type AsCurriedResult<
5947
6390
  const upsert = <
5948
6391
  Target extends MutationTargetLike,
5949
6392
  Values extends MutationInputOf<Table.InsertOf<Target>>,
5950
- Columns extends DdlColumnInput,
6393
+ const Columns extends DdlColumnInput,
5951
6394
  UpdateValues extends MutationInputOf<Table.UpdateOf<Target>>
5952
6395
  >(
5953
6396
  target: Target,
@@ -6548,10 +6991,10 @@ type AsCurriedResult<
6548
6991
 
6549
6992
  const createIndex = <
6550
6993
  Target extends SchemaTableLike,
6551
- Columns extends DdlColumnInput
6994
+ const Columns extends DdlColumnInput
6552
6995
  >(
6553
6996
  target: Target,
6554
- columns: ValidateDdlColumns<Target, NormalizeDdlColumns<Columns>>,
6997
+ columns: Columns & ValidateDdlColumns<Target, NormalizeDdlColumns<Columns>>,
6555
6998
  options: CreateIndexOptions = {}
6556
6999
  ): QueryPlan<
6557
7000
  {},
@@ -6598,10 +7041,10 @@ type AsCurriedResult<
6598
7041
 
6599
7042
  const dropIndex = <
6600
7043
  Target extends SchemaTableLike,
6601
- Columns extends DdlColumnInput
7044
+ const Columns extends DdlColumnInput
6602
7045
  >(
6603
7046
  target: Target,
6604
- columns: ValidateDdlColumns<Target, NormalizeDdlColumns<Columns>>,
7047
+ columns: Columns & ValidateDdlColumns<Target, NormalizeDdlColumns<Columns>>,
6605
7048
  options: DropIndexOptions = {}
6606
7049
  ): QueryPlan<
6607
7050
  {},
@@ -6646,9 +7089,11 @@ type AsCurriedResult<
6646
7089
 
6647
7090
  const api = {
6648
7091
  literal,
7092
+ column,
6649
7093
  cast,
6650
7094
  type,
6651
7095
  json,
7096
+ jsonb,
6652
7097
  eq,
6653
7098
  neq,
6654
7099
  lt,
@@ -6661,6 +7106,10 @@ type AsCurriedResult<
6661
7106
  lower,
6662
7107
  like,
6663
7108
  ilike,
7109
+ regexMatch,
7110
+ regexIMatch,
7111
+ regexNotMatch,
7112
+ regexNotIMatch,
6664
7113
  and,
6665
7114
  or,
6666
7115
  not,
@@ -6669,6 +7118,9 @@ type AsCurriedResult<
6669
7118
  case: case_,
6670
7119
  match,
6671
7120
  coalesce,
7121
+ call,
7122
+ uuidGenerateV4,
7123
+ nextVal,
6672
7124
  in: in_,
6673
7125
  notIn,
6674
7126
  between,
@@ -6740,5 +7192,5 @@ type AsCurriedResult<
6740
7192
  groupBy
6741
7193
  }
6742
7194
 
6743
- return api
6744
- }
7195
+ return api
7196
+ })()