effect-qb 0.16.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.
- package/README.md +4 -0
- package/dist/index.js +8065 -0
- package/dist/mysql.js +4036 -2418
- package/dist/postgres/metadata.js +2536 -625
- package/dist/postgres.js +8248 -7857
- package/dist/sqlite.js +8854 -0
- package/dist/standard.js +8019 -0
- package/package.json +15 -3
- package/src/casing.ts +71 -0
- package/src/index.ts +2 -0
- package/src/internal/casing.ts +89 -0
- package/src/internal/column-state.ts +11 -6
- package/src/internal/column.ts +44 -7
- package/src/internal/datatypes/define.ts +2 -1
- package/src/internal/datatypes/enrich.ts +23 -0
- package/src/internal/datatypes/lookup.ts +14 -7
- package/src/internal/derived-table.ts +7 -13
- package/src/internal/dialect-renderers/mysql.ts +2046 -0
- package/src/{postgres/internal/sql-expression-renderer.ts → internal/dialect-renderers/postgres.ts} +867 -283
- package/src/{mysql/internal/sql-expression-renderer.ts → internal/dialect-renderers/sqlite.ts} +834 -358
- package/src/internal/dialect.ts +37 -0
- package/src/internal/dsl-mutation-runtime.ts +29 -10
- package/src/internal/dsl-plan-runtime.ts +41 -24
- package/src/internal/dsl-query-runtime.ts +11 -31
- package/src/internal/dsl-transaction-ddl-runtime.ts +61 -15
- package/src/internal/executor.ts +57 -15
- package/src/internal/expression-ast.ts +3 -2
- package/src/internal/grouping-key.ts +216 -9
- package/src/internal/implication-runtime.ts +3 -2
- package/src/internal/json/types.ts +155 -40
- package/src/internal/predicate/context.ts +14 -1
- package/src/internal/predicate/key.ts +19 -2
- package/src/internal/predicate/runtime.ts +30 -3
- package/src/internal/query.d.ts +38 -11
- package/src/internal/query.ts +315 -54
- package/src/internal/renderer.ts +51 -6
- package/src/internal/runtime/driver-value-mapping.ts +58 -0
- package/src/internal/runtime/normalize.ts +74 -43
- package/src/internal/runtime/schema.ts +5 -3
- package/src/internal/runtime/value.ts +153 -30
- package/src/internal/scalar.ts +6 -1
- package/src/internal/schema-derivation.d.ts +12 -61
- package/src/internal/schema-derivation.ts +90 -38
- package/src/internal/schema-expression.ts +2 -2
- package/src/internal/sql-expression-renderer.ts +19 -0
- package/src/internal/standard-dsl.ts +6885 -0
- package/src/internal/table-options.ts +229 -62
- package/src/internal/table.d.ts +33 -32
- package/src/internal/table.ts +469 -160
- package/src/mysql/column-extension.ts +3 -0
- package/src/mysql/column.ts +27 -12
- package/src/mysql/datatypes/index.ts +24 -2
- package/src/mysql/errors/catalog.ts +5 -5
- package/src/mysql/errors/normalize.ts +2 -2
- package/src/mysql/executor.ts +7 -5
- package/src/mysql/internal/dialect.ts +9 -4
- package/src/mysql/internal/dsl.ts +906 -324
- package/src/mysql/internal/renderer.ts +7 -2
- package/src/mysql/json.ts +37 -0
- package/src/mysql/query-extension.ts +16 -0
- package/src/mysql/query.ts +9 -2
- package/src/mysql/renderer.ts +31 -4
- package/src/mysql.ts +4 -12
- package/src/postgres/column-extension.ts +28 -0
- package/src/postgres/column.ts +9 -13
- package/src/postgres/datatypes/index.d.ts +2 -1
- package/src/postgres/datatypes/index.ts +3 -2
- package/src/postgres/errors/normalize.ts +2 -2
- package/src/postgres/executor.ts +55 -10
- package/src/postgres/function/core.ts +20 -4
- package/src/postgres/function/index.ts +1 -17
- package/src/postgres/internal/dialect.ts +9 -4
- package/src/postgres/internal/dsl.ts +850 -359
- package/src/postgres/internal/renderer.ts +7 -2
- package/src/postgres/internal/schema-ddl.ts +22 -9
- package/src/postgres/internal/schema-model.ts +244 -10
- package/src/postgres/json.ts +100 -24
- package/src/postgres/jsonb.ts +38 -0
- package/src/postgres/query-extension.ts +2 -0
- package/src/postgres/query.ts +9 -2
- package/src/postgres/renderer.ts +31 -4
- package/src/postgres/schema-management.ts +108 -16
- package/src/postgres/schema.ts +98 -15
- package/src/postgres/table.ts +203 -398
- package/src/postgres/type.ts +8 -7
- package/src/postgres.ts +9 -11
- package/src/sqlite/column-extension.ts +3 -0
- package/src/sqlite/column.ts +127 -0
- package/src/sqlite/datatypes/index.ts +80 -0
- package/src/sqlite/datatypes/spec.ts +98 -0
- package/src/sqlite/errors/catalog.ts +103 -0
- package/src/sqlite/errors/fields.ts +19 -0
- package/src/sqlite/errors/index.ts +19 -0
- package/src/sqlite/errors/normalize.ts +229 -0
- package/src/sqlite/errors/requirements.ts +71 -0
- package/src/sqlite/errors/types.ts +29 -0
- package/src/sqlite/executor.ts +229 -0
- package/src/sqlite/function/aggregate.ts +2 -0
- package/src/sqlite/function/core.ts +2 -0
- package/src/sqlite/function/index.ts +19 -0
- package/src/sqlite/function/string.ts +2 -0
- package/src/sqlite/function/temporal.ts +100 -0
- package/src/sqlite/function/window.ts +2 -0
- package/src/sqlite/internal/dialect.ts +42 -0
- package/src/sqlite/internal/dsl.ts +6979 -0
- package/src/sqlite/internal/renderer.ts +51 -0
- package/src/sqlite/json.ts +39 -0
- package/src/sqlite/query-extension.ts +2 -0
- package/src/sqlite/query.ts +196 -0
- package/src/sqlite/renderer.ts +51 -0
- package/src/sqlite.ts +14 -0
- package/src/standard/column.ts +163 -0
- package/src/standard/datatypes/index.ts +83 -0
- package/src/standard/datatypes/spec.ts +98 -0
- package/src/standard/dialect.ts +40 -0
- package/src/standard/function/aggregate.ts +2 -0
- package/src/standard/function/core.ts +2 -0
- package/src/standard/function/index.ts +18 -0
- package/src/standard/function/string.ts +2 -0
- package/src/standard/function/temporal.ts +78 -0
- package/src/standard/function/window.ts +2 -0
- package/src/standard/internal/renderer.ts +45 -0
- package/src/standard/query.ts +152 -0
- package/src/standard/renderer.ts +21 -0
- package/src/standard/table.ts +147 -0
- package/src/standard.ts +18 -0
- package/src/internal/aggregation-validation.ts +0 -57
- package/src/mysql/table.ts +0 -157
|
@@ -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,9 +6,17 @@ 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"
|
|
19
|
+
import { normalizeDbValue } from "../../internal/runtime/normalize.js"
|
|
12
20
|
import {
|
|
13
21
|
currentRequiredList,
|
|
14
22
|
extractRequiredRuntime,
|
|
@@ -30,11 +38,15 @@ import {
|
|
|
30
38
|
type AssumptionsOfPlan,
|
|
31
39
|
type AvailableOfPlan,
|
|
32
40
|
type CapabilitiesOfPlan,
|
|
41
|
+
type CommonSetFacts,
|
|
33
42
|
type DialectCompatibleNestedPlan,
|
|
34
43
|
type DependenciesOf,
|
|
35
44
|
type DependencyRecord,
|
|
36
45
|
type DialectOf,
|
|
37
46
|
type DerivedSelectionOf,
|
|
47
|
+
type DerivedTableCompatiblePlan,
|
|
48
|
+
type LateralSourceCompatiblePlan,
|
|
49
|
+
type DerivedSourceCompatiblePlan,
|
|
38
50
|
type DerivedSource,
|
|
39
51
|
type CompletePlan,
|
|
40
52
|
type ExpressionInput,
|
|
@@ -66,6 +78,7 @@ import {
|
|
|
66
78
|
type ScopedNamesOfPlan,
|
|
67
79
|
type SelectionOfPlan,
|
|
68
80
|
type SelectionShape,
|
|
81
|
+
type SelectionProjectionAliasCollisionConstraint,
|
|
69
82
|
type SetCompatiblePlan,
|
|
70
83
|
type SetCompatibleRightPlan,
|
|
71
84
|
type SchemaTableLike,
|
|
@@ -75,10 +88,8 @@ import {
|
|
|
75
88
|
type TableDialectOf,
|
|
76
89
|
type StatementOfPlan,
|
|
77
90
|
type MutationInputOf,
|
|
78
|
-
type MutationTargetLike,
|
|
79
91
|
type MutationTargetOfPlan,
|
|
80
92
|
type MergeCapabilities,
|
|
81
|
-
type MutationTargetInput,
|
|
82
93
|
type MutationValuesInput,
|
|
83
94
|
type SourceDialectOf,
|
|
84
95
|
type SourceLike,
|
|
@@ -95,7 +106,6 @@ import {
|
|
|
95
106
|
type TableLike,
|
|
96
107
|
type UpdateInputOfTarget,
|
|
97
108
|
type MutationTargetNamesOf,
|
|
98
|
-
type MutationTargetTuple,
|
|
99
109
|
type TupleDependencies,
|
|
100
110
|
type TupleDialect,
|
|
101
111
|
type ResultRow
|
|
@@ -133,6 +143,10 @@ import * as ProjectionAlias from "../../internal/projection-alias.js"
|
|
|
133
143
|
import * as QueryAst from "../../internal/query-ast.js"
|
|
134
144
|
import { normalizeColumnList } from "../../internal/table-options.js"
|
|
135
145
|
|
|
146
|
+
type MutationTargetLike = Table.AnyTable<Dialect | "standard">
|
|
147
|
+
type MutationTargetTuple = readonly [MutationTargetLike, MutationTargetLike, ...MutationTargetLike[]]
|
|
148
|
+
type MutationTargetInput = MutationTargetLike | MutationTargetTuple
|
|
149
|
+
|
|
136
150
|
/**
|
|
137
151
|
* Dialect-specific DB type profile used to specialize the shared query
|
|
138
152
|
* operator surface.
|
|
@@ -217,6 +231,13 @@ type DialectAsExpression<
|
|
|
217
231
|
? Value
|
|
218
232
|
: DialectLiteralExpression<Extract<Value, LiteralValue>, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
219
233
|
|
|
234
|
+
type ProjectionAliasedExpression<
|
|
235
|
+
Value extends Expression.Any,
|
|
236
|
+
Alias extends string
|
|
237
|
+
> = Value & {
|
|
238
|
+
readonly [ProjectionAlias.TypeId]: ProjectionAlias.State<Alias>
|
|
239
|
+
}
|
|
240
|
+
|
|
220
241
|
/** Normalizes a generic string-capable input into the expression form used internally. */
|
|
221
242
|
type DialectAsStringExpression<
|
|
222
243
|
Value extends ExpressionInput,
|
|
@@ -690,6 +711,21 @@ type DialectOfDialectNumericInput<
|
|
|
690
711
|
NullDb extends Expression.DbType.Any
|
|
691
712
|
> = DialectOf<DialectAsNumericExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>
|
|
692
713
|
|
|
714
|
+
type NumericExpressionDialectInput<
|
|
715
|
+
Value extends NumericExpressionInput,
|
|
716
|
+
Dialect extends string,
|
|
717
|
+
TextDb extends Expression.DbType.Any,
|
|
718
|
+
NumericDb extends Expression.DbType.Any,
|
|
719
|
+
BoolDb extends Expression.DbType.Any,
|
|
720
|
+
TimestampDb extends Expression.DbType.Any,
|
|
721
|
+
NullDb extends Expression.DbType.Any
|
|
722
|
+
> = Exclude<DialectOfDialectNumericInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>, Dialect | "standard"> extends never
|
|
723
|
+
? unknown
|
|
724
|
+
: {
|
|
725
|
+
readonly __effect_qb_error__: "effect-qb: numeric expressions cannot mix dialects"
|
|
726
|
+
readonly __effect_qb_dialect__: DialectOfDialectNumericInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
727
|
+
}
|
|
728
|
+
|
|
693
729
|
/** Dependency map carried by a numeric-clause input after coercion. */
|
|
694
730
|
type DependenciesOfDialectNumericInput<
|
|
695
731
|
Value extends NumericExpressionInput,
|
|
@@ -776,6 +812,35 @@ type DialectExpressionArray<
|
|
|
776
812
|
? Tuple
|
|
777
813
|
: never
|
|
778
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
|
+
|
|
779
844
|
/** Normalized expression tuple for generic string operator inputs. */
|
|
780
845
|
type DialectStringExpressionTuple<
|
|
781
846
|
Values extends readonly ExpressionInput[],
|
|
@@ -1042,6 +1107,9 @@ type JsonPathInput = JsonPath.Path<any> | JsonPath.CanonicalSegment
|
|
|
1042
1107
|
|
|
1043
1108
|
type JsonQueryInput = JsonPath.Path<any> | StringExpressionInput
|
|
1044
1109
|
|
|
1110
|
+
type JsonQueryValue<Query extends JsonQueryInput> =
|
|
1111
|
+
Query extends string ? LiteralStringInput<Query> : Query
|
|
1112
|
+
|
|
1045
1113
|
type JsonPathSegmentsOf<Target extends JsonPathInput> =
|
|
1046
1114
|
Target extends JsonPath.Path<any>
|
|
1047
1115
|
? JsonPath.SegmentsOf<Target>
|
|
@@ -1478,7 +1546,7 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
|
|
|
1478
1546
|
type: postgresDatatypes
|
|
1479
1547
|
}
|
|
1480
1548
|
const ValuesInputProto = {
|
|
1481
|
-
pipe(this:
|
|
1549
|
+
pipe(this: Pipeable) {
|
|
1482
1550
|
return pipeArguments(this, arguments)
|
|
1483
1551
|
}
|
|
1484
1552
|
}
|
|
@@ -1489,7 +1557,7 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
|
|
|
1489
1557
|
if (value === null || value instanceof Date) {
|
|
1490
1558
|
return undefined
|
|
1491
1559
|
}
|
|
1492
|
-
return Schema.Literal(value) as
|
|
1560
|
+
return Schema.Literal(value) as Schema.Schema.Any
|
|
1493
1561
|
}
|
|
1494
1562
|
|
|
1495
1563
|
const literal = <const Value extends LiteralValue>(
|
|
@@ -1576,7 +1644,7 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
|
|
|
1576
1644
|
value: Expression.Any,
|
|
1577
1645
|
target: Expression.Any
|
|
1578
1646
|
): Expression.Any => {
|
|
1579
|
-
const ast = (value as
|
|
1647
|
+
const ast = (value as Expression.Any & { readonly [ExpressionAst.TypeId]: ExpressionAst.Any })[ExpressionAst.TypeId]
|
|
1580
1648
|
if (ast.kind !== "literal") {
|
|
1581
1649
|
return value
|
|
1582
1650
|
}
|
|
@@ -1597,8 +1665,8 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
|
|
|
1597
1665
|
left: Expression.Any,
|
|
1598
1666
|
right: Expression.Any
|
|
1599
1667
|
): readonly [Expression.Any, Expression.Any] => {
|
|
1600
|
-
const leftAst = (left as
|
|
1601
|
-
const rightAst = (right as
|
|
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]
|
|
1602
1670
|
if (leftAst.kind === "literal" && rightAst.kind !== "literal") {
|
|
1603
1671
|
return [retargetLiteralExpression(left, right), right]
|
|
1604
1672
|
}
|
|
@@ -1631,7 +1699,7 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
|
|
|
1631
1699
|
): readonly Expression.Any[] => {
|
|
1632
1700
|
const flattened: Array<Expression.Any> = []
|
|
1633
1701
|
for (const value of values) {
|
|
1634
|
-
const ast = (value as
|
|
1702
|
+
const ast = (value as Expression.Any & { readonly [ExpressionAst.TypeId]: ExpressionAst.Any })[ExpressionAst.TypeId]
|
|
1635
1703
|
if (ast.kind === kind) {
|
|
1636
1704
|
flattened.push(...ast.values)
|
|
1637
1705
|
} else {
|
|
@@ -1677,7 +1745,33 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
|
|
|
1677
1745
|
if (operations.every((operation) => typeof operation === "function")) {
|
|
1678
1746
|
return pipeArguments(this, arguments)
|
|
1679
1747
|
}
|
|
1680
|
-
|
|
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
|
|
1681
1775
|
}
|
|
1682
1776
|
})
|
|
1683
1777
|
|
|
@@ -1696,10 +1790,13 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
|
|
|
1696
1790
|
spec: WindowSpecInput<PartitionBy, OrderBy> | OrderedWindowSpecInput<PartitionBy, Extract<OrderBy, NonEmptyWindowOrderTerms>> | undefined
|
|
1697
1791
|
) => {
|
|
1698
1792
|
const partitionBy = [...(spec?.partitionBy ?? [])] as unknown as PartitionBy
|
|
1699
|
-
const orderBy = (spec?.orderBy ?? []).map((term) =>
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1793
|
+
const orderBy = (spec?.orderBy ?? []).map((term) => {
|
|
1794
|
+
const direction = term.direction ?? "asc"
|
|
1795
|
+
return {
|
|
1796
|
+
value: term.value,
|
|
1797
|
+
direction
|
|
1798
|
+
}
|
|
1799
|
+
}) as {
|
|
1703
1800
|
readonly [K in keyof OrderBy]: OrderBy[K] extends WindowOrderTermInput<infer Value extends WindowOrderInput>
|
|
1704
1801
|
? { readonly value: Value; readonly direction: OrderDirection }
|
|
1705
1802
|
: never
|
|
@@ -1835,7 +1932,8 @@ type BinaryPredicateExpression<
|
|
|
1835
1932
|
>(
|
|
1836
1933
|
...args: ComparableArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "eq">
|
|
1837
1934
|
): BinaryPredicateExpression<Left, Right, "eq"> => {
|
|
1838
|
-
const
|
|
1935
|
+
const left = args[0] as Left
|
|
1936
|
+
const right = args[1] as Right
|
|
1839
1937
|
return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "eq")
|
|
1840
1938
|
}
|
|
1841
1939
|
|
|
@@ -1845,7 +1943,8 @@ type BinaryPredicateExpression<
|
|
|
1845
1943
|
>(
|
|
1846
1944
|
...args: ComparableArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "neq">
|
|
1847
1945
|
): BinaryPredicateExpression<Left, Right, "neq"> => {
|
|
1848
|
-
const
|
|
1946
|
+
const left = args[0] as Left
|
|
1947
|
+
const right = args[1] as Right
|
|
1849
1948
|
return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "neq")
|
|
1850
1949
|
}
|
|
1851
1950
|
|
|
@@ -1855,7 +1954,8 @@ type BinaryPredicateExpression<
|
|
|
1855
1954
|
>(
|
|
1856
1955
|
...args: ComparableArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "lt">
|
|
1857
1956
|
): BinaryPredicateExpression<Left, Right, "lt"> => {
|
|
1858
|
-
const
|
|
1957
|
+
const left = args[0] as Left
|
|
1958
|
+
const right = args[1] as Right
|
|
1859
1959
|
return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "lt")
|
|
1860
1960
|
}
|
|
1861
1961
|
|
|
@@ -1865,7 +1965,8 @@ type BinaryPredicateExpression<
|
|
|
1865
1965
|
>(
|
|
1866
1966
|
...args: ComparableArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "lte">
|
|
1867
1967
|
): BinaryPredicateExpression<Left, Right, "lte"> => {
|
|
1868
|
-
const
|
|
1968
|
+
const left = args[0] as Left
|
|
1969
|
+
const right = args[1] as Right
|
|
1869
1970
|
return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "lte")
|
|
1870
1971
|
}
|
|
1871
1972
|
|
|
@@ -1875,7 +1976,8 @@ type BinaryPredicateExpression<
|
|
|
1875
1976
|
>(
|
|
1876
1977
|
...args: ComparableArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "gt">
|
|
1877
1978
|
): BinaryPredicateExpression<Left, Right, "gt"> => {
|
|
1878
|
-
const
|
|
1979
|
+
const left = args[0] as Left
|
|
1980
|
+
const right = args[1] as Right
|
|
1879
1981
|
return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "gt")
|
|
1880
1982
|
}
|
|
1881
1983
|
|
|
@@ -1885,7 +1987,8 @@ type BinaryPredicateExpression<
|
|
|
1885
1987
|
>(
|
|
1886
1988
|
...args: ComparableArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "gte">
|
|
1887
1989
|
): BinaryPredicateExpression<Left, Right, "gte"> => {
|
|
1888
|
-
const
|
|
1990
|
+
const left = args[0] as Left
|
|
1991
|
+
const right = args[1] as Right
|
|
1889
1992
|
return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "gte")
|
|
1890
1993
|
}
|
|
1891
1994
|
|
|
@@ -1895,7 +1998,8 @@ type BinaryPredicateExpression<
|
|
|
1895
1998
|
>(
|
|
1896
1999
|
...args: TextArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "like">
|
|
1897
2000
|
): BinaryPredicateExpression<Left, Right, "like"> => {
|
|
1898
|
-
const
|
|
2001
|
+
const left = args[0] as Left
|
|
2002
|
+
const right = args[1] as Right
|
|
1899
2003
|
return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "like")
|
|
1900
2004
|
}
|
|
1901
2005
|
|
|
@@ -1905,7 +2009,8 @@ type BinaryPredicateExpression<
|
|
|
1905
2009
|
>(
|
|
1906
2010
|
...args: TextArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "ilike">
|
|
1907
2011
|
): BinaryPredicateExpression<Left, Right, "ilike"> => {
|
|
1908
|
-
const
|
|
2012
|
+
const left = args[0] as Left
|
|
2013
|
+
const right = args[1] as Right
|
|
1909
2014
|
return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "ilike")
|
|
1910
2015
|
}
|
|
1911
2016
|
|
|
@@ -1915,7 +2020,8 @@ type BinaryPredicateExpression<
|
|
|
1915
2020
|
>(
|
|
1916
2021
|
...args: TextArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "regexMatch">
|
|
1917
2022
|
): BinaryPredicateExpression<Left, Right, "regexMatch"> => {
|
|
1918
|
-
const
|
|
2023
|
+
const left = args[0] as Left
|
|
2024
|
+
const right = args[1] as Right
|
|
1919
2025
|
return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "regexMatch")
|
|
1920
2026
|
}
|
|
1921
2027
|
|
|
@@ -1925,7 +2031,8 @@ type BinaryPredicateExpression<
|
|
|
1925
2031
|
>(
|
|
1926
2032
|
...args: TextArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "regexIMatch">
|
|
1927
2033
|
): BinaryPredicateExpression<Left, Right, "regexIMatch"> => {
|
|
1928
|
-
const
|
|
2034
|
+
const left = args[0] as Left
|
|
2035
|
+
const right = args[1] as Right
|
|
1929
2036
|
return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "regexIMatch")
|
|
1930
2037
|
}
|
|
1931
2038
|
|
|
@@ -1935,7 +2042,8 @@ type BinaryPredicateExpression<
|
|
|
1935
2042
|
>(
|
|
1936
2043
|
...args: TextArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "regexNotMatch">
|
|
1937
2044
|
): BinaryPredicateExpression<Left, Right, "regexNotMatch"> => {
|
|
1938
|
-
const
|
|
2045
|
+
const left = args[0] as Left
|
|
2046
|
+
const right = args[1] as Right
|
|
1939
2047
|
return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "regexNotMatch")
|
|
1940
2048
|
}
|
|
1941
2049
|
|
|
@@ -1945,7 +2053,8 @@ type BinaryPredicateExpression<
|
|
|
1945
2053
|
>(
|
|
1946
2054
|
...args: TextArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "regexNotIMatch">
|
|
1947
2055
|
): BinaryPredicateExpression<Left, Right, "regexNotIMatch"> => {
|
|
1948
|
-
const
|
|
2056
|
+
const left = args[0] as Left
|
|
2057
|
+
const right = args[1] as Right
|
|
1949
2058
|
return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "regexNotIMatch")
|
|
1950
2059
|
}
|
|
1951
2060
|
|
|
@@ -1955,7 +2064,8 @@ type BinaryPredicateExpression<
|
|
|
1955
2064
|
>(
|
|
1956
2065
|
...args: ComparableArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "isDistinctFrom">
|
|
1957
2066
|
): BinaryPredicateExpression<Left, Right, "isDistinctFrom", "never"> => {
|
|
1958
|
-
const
|
|
2067
|
+
const left = args[0] as Left
|
|
2068
|
+
const right = args[1] as Right
|
|
1959
2069
|
return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "isDistinctFrom", "never")
|
|
1960
2070
|
}
|
|
1961
2071
|
|
|
@@ -1965,7 +2075,8 @@ type BinaryPredicateExpression<
|
|
|
1965
2075
|
>(
|
|
1966
2076
|
...args: ComparableArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "isNotDistinctFrom">
|
|
1967
2077
|
): BinaryPredicateExpression<Left, Right, "isNotDistinctFrom", "never"> => {
|
|
1968
|
-
const
|
|
2078
|
+
const left = args[0] as Left
|
|
2079
|
+
const right = args[1] as Right
|
|
1969
2080
|
return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "isNotDistinctFrom", "never")
|
|
1970
2081
|
}
|
|
1971
2082
|
|
|
@@ -2073,9 +2184,15 @@ type BinaryPredicateExpression<
|
|
|
2073
2184
|
})
|
|
2074
2185
|
}
|
|
2075
2186
|
|
|
2076
|
-
|
|
2187
|
+
type NormalizedCollation<Collation extends string | readonly [string, ...string[]]> =
|
|
2188
|
+
Collation extends string ? readonly [Collation] : Collation
|
|
2189
|
+
|
|
2190
|
+
const collate = <
|
|
2191
|
+
Value extends ExpressionInput,
|
|
2192
|
+
Collation extends string | readonly [string, ...string[]]
|
|
2193
|
+
>(
|
|
2077
2194
|
value: Value & TextInput<NoInfer<Value>, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "collate">,
|
|
2078
|
-
collation:
|
|
2195
|
+
collation: CollationIdentifierInput<Collation>
|
|
2079
2196
|
): AstBackedExpression<
|
|
2080
2197
|
Expression.RuntimeOf<DialectAsStringExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
|
|
2081
2198
|
Expression.DbTypeOf<DialectAsStringExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
|
|
@@ -2083,10 +2200,10 @@ type BinaryPredicateExpression<
|
|
|
2083
2200
|
DialectOfDialectStringInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
2084
2201
|
KindOf<DialectAsStringExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
|
|
2085
2202
|
DependenciesOfDialectStringInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
2086
|
-
ExpressionAst.CollateNode<DialectAsStringExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>
|
|
2203
|
+
ExpressionAst.CollateNode<DialectAsStringExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>, NormalizedCollation<Collation>>
|
|
2087
2204
|
> => {
|
|
2088
2205
|
const expression = toDialectStringExpression(value as any)
|
|
2089
|
-
const normalizedCollation
|
|
2206
|
+
const normalizedCollation = (typeof collation === "string" ? [collation] : collation) as unknown as NormalizedCollation<Collation>
|
|
2090
2207
|
return makeExpression({
|
|
2091
2208
|
runtime: expression[Expression.TypeId].runtime as Expression.RuntimeOf<DialectAsStringExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
|
|
2092
2209
|
dbType: expression[Expression.TypeId].dbType as Expression.DbTypeOf<DialectAsStringExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
|
|
@@ -2106,7 +2223,7 @@ type BinaryPredicateExpression<
|
|
|
2106
2223
|
DialectOfDialectStringInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
2107
2224
|
KindOf<DialectAsStringExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
|
|
2108
2225
|
DependenciesOfDialectStringInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
2109
|
-
ExpressionAst.CollateNode<DialectAsStringExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>
|
|
2226
|
+
ExpressionAst.CollateNode<DialectAsStringExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>, NormalizedCollation<Collation>>
|
|
2110
2227
|
>
|
|
2111
2228
|
}
|
|
2112
2229
|
|
|
@@ -2153,62 +2270,62 @@ type BinaryPredicateExpression<
|
|
|
2153
2270
|
})
|
|
2154
2271
|
|
|
2155
2272
|
const range = <Kind extends string, Subtype extends Expression.DbType.Any>(
|
|
2156
|
-
kind: Kind
|
|
2273
|
+
kind: NonEmptyStringInput<Kind>,
|
|
2157
2274
|
subtype: Subtype
|
|
2158
2275
|
): Expression.DbType.Range<Dialect, Subtype, Kind> => ({
|
|
2159
2276
|
dialect: profile.dialect,
|
|
2160
|
-
kind,
|
|
2277
|
+
kind: kind as Kind,
|
|
2161
2278
|
subtype
|
|
2162
2279
|
})
|
|
2163
2280
|
|
|
2164
2281
|
const multirange = <Kind extends string, Subtype extends Expression.DbType.Any>(
|
|
2165
|
-
kind: Kind
|
|
2282
|
+
kind: NonEmptyStringInput<Kind>,
|
|
2166
2283
|
subtype: Subtype
|
|
2167
2284
|
): Expression.DbType.Multirange<Dialect, Subtype, Kind> => ({
|
|
2168
2285
|
dialect: profile.dialect,
|
|
2169
|
-
kind,
|
|
2286
|
+
kind: kind as Kind,
|
|
2170
2287
|
subtype
|
|
2171
2288
|
})
|
|
2172
2289
|
|
|
2173
2290
|
const record = <Kind extends string, Fields extends Record<string, Expression.DbType.Any>>(
|
|
2174
|
-
kind: Kind
|
|
2291
|
+
kind: NonEmptyStringInput<Kind>,
|
|
2175
2292
|
fields: Fields
|
|
2176
2293
|
): Expression.DbType.Composite<Dialect, Fields, Kind> => ({
|
|
2177
2294
|
dialect: profile.dialect,
|
|
2178
|
-
kind,
|
|
2295
|
+
kind: kind as Kind,
|
|
2179
2296
|
fields
|
|
2180
2297
|
})
|
|
2181
2298
|
|
|
2182
2299
|
const domain = <Kind extends string, Base extends Expression.DbType.Any>(
|
|
2183
|
-
kind: Kind
|
|
2300
|
+
kind: NonEmptyStringInput<Kind>,
|
|
2184
2301
|
base: Base
|
|
2185
2302
|
): Expression.DbType.Domain<Dialect, Base, Kind> => ({
|
|
2186
2303
|
dialect: profile.dialect,
|
|
2187
|
-
kind,
|
|
2304
|
+
kind: kind as Kind,
|
|
2188
2305
|
base
|
|
2189
2306
|
})
|
|
2190
2307
|
|
|
2191
2308
|
const enum_ = <Kind extends string>(
|
|
2192
|
-
kind: Kind
|
|
2309
|
+
kind: NonEmptyStringInput<Kind>
|
|
2193
2310
|
): Expression.DbType.Enum<Dialect, Kind> => ({
|
|
2194
2311
|
dialect: profile.dialect,
|
|
2195
|
-
kind,
|
|
2312
|
+
kind: kind as Kind,
|
|
2196
2313
|
variant: "enum"
|
|
2197
2314
|
})
|
|
2198
2315
|
|
|
2199
2316
|
const set = <Kind extends string>(
|
|
2200
|
-
kind: Kind
|
|
2317
|
+
kind: NonEmptyStringInput<Kind>
|
|
2201
2318
|
): Expression.DbType.Set<Dialect, Kind> => ({
|
|
2202
2319
|
dialect: profile.dialect,
|
|
2203
|
-
kind,
|
|
2320
|
+
kind: kind as Kind,
|
|
2204
2321
|
variant: "set"
|
|
2205
2322
|
})
|
|
2206
2323
|
|
|
2207
2324
|
const custom = <Kind extends string>(
|
|
2208
|
-
kind: Kind
|
|
2325
|
+
kind: NonEmptyStringInput<Kind>
|
|
2209
2326
|
): Expression.DbType.Base<Dialect, Kind> => ({
|
|
2210
2327
|
dialect: profile.dialect,
|
|
2211
|
-
kind
|
|
2328
|
+
kind: kind as Kind
|
|
2212
2329
|
})
|
|
2213
2330
|
|
|
2214
2331
|
const driverValueMapping = <Db extends Expression.DbType.Any>(
|
|
@@ -2702,7 +2819,7 @@ type BinaryPredicateExpression<
|
|
|
2702
2819
|
Next extends JsonValueInput
|
|
2703
2820
|
>(
|
|
2704
2821
|
base: Base,
|
|
2705
|
-
target: Target & JsonSetGuard<Expression.RuntimeOf<Base>, Target, Next
|
|
2822
|
+
target: Target & JsonSetGuard<Expression.RuntimeOf<Base>, Target, NoInfer<Next>, "json.set">,
|
|
2706
2823
|
next: Next,
|
|
2707
2824
|
options: {
|
|
2708
2825
|
readonly createMissing?: boolean
|
|
@@ -2750,7 +2867,7 @@ type BinaryPredicateExpression<
|
|
|
2750
2867
|
InsertAfter extends boolean = false
|
|
2751
2868
|
>(
|
|
2752
2869
|
base: Base,
|
|
2753
|
-
target: Target & JsonInsertGuard<Expression.RuntimeOf<Base>, Target, Next
|
|
2870
|
+
target: Target & JsonInsertGuard<Expression.RuntimeOf<Base>, Target, NoInfer<Next>, NoInfer<InsertAfter>, "json.insert">,
|
|
2754
2871
|
next: Next,
|
|
2755
2872
|
options: {
|
|
2756
2873
|
readonly insertAfter?: InsertAfter
|
|
@@ -3012,9 +3129,12 @@ type BinaryPredicateExpression<
|
|
|
3012
3129
|
}
|
|
3013
3130
|
)
|
|
3014
3131
|
|
|
3015
|
-
const jsonPathExists = <
|
|
3132
|
+
const jsonPathExists = <
|
|
3133
|
+
Base extends JsonExpressionLike<any>,
|
|
3134
|
+
Query extends JsonQueryInput
|
|
3135
|
+
>(
|
|
3016
3136
|
base: Base,
|
|
3017
|
-
query:
|
|
3137
|
+
query: JsonQueryValue<Query>
|
|
3018
3138
|
) => {
|
|
3019
3139
|
if (isJsonPathValue(query)) {
|
|
3020
3140
|
return buildJsonNodeExpression(
|
|
@@ -3062,9 +3182,12 @@ type BinaryPredicateExpression<
|
|
|
3062
3182
|
}
|
|
3063
3183
|
)
|
|
3064
3184
|
|
|
3065
|
-
const jsonPathMatch = <
|
|
3185
|
+
const jsonPathMatch = <
|
|
3186
|
+
Base extends JsonExpressionLike<any>,
|
|
3187
|
+
Query extends JsonQueryInput
|
|
3188
|
+
>(
|
|
3066
3189
|
base: Base,
|
|
3067
|
-
query:
|
|
3190
|
+
query: JsonQueryValue<Query>
|
|
3068
3191
|
) => {
|
|
3069
3192
|
if (isJsonPathValue(query)) {
|
|
3070
3193
|
return buildJsonNodeExpression(
|
|
@@ -3291,7 +3414,8 @@ type BinaryPredicateExpression<
|
|
|
3291
3414
|
>(
|
|
3292
3415
|
...args: ContainmentArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "contains">
|
|
3293
3416
|
): BinaryPredicateExpression<Left, Right, "contains"> => {
|
|
3294
|
-
const
|
|
3417
|
+
const left = args[0] as Left
|
|
3418
|
+
const right = args[1] as Right
|
|
3295
3419
|
return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "contains")
|
|
3296
3420
|
}
|
|
3297
3421
|
|
|
@@ -3301,7 +3425,8 @@ type BinaryPredicateExpression<
|
|
|
3301
3425
|
>(
|
|
3302
3426
|
...args: ContainmentArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "containedBy">
|
|
3303
3427
|
): BinaryPredicateExpression<Left, Right, "containedBy"> => {
|
|
3304
|
-
const
|
|
3428
|
+
const left = args[0] as Left
|
|
3429
|
+
const right = args[1] as Right
|
|
3305
3430
|
return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "containedBy")
|
|
3306
3431
|
}
|
|
3307
3432
|
|
|
@@ -3311,7 +3436,8 @@ type BinaryPredicateExpression<
|
|
|
3311
3436
|
>(
|
|
3312
3437
|
...args: ContainmentArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "overlaps">
|
|
3313
3438
|
): BinaryPredicateExpression<Left, Right, "overlaps"> => {
|
|
3314
|
-
const
|
|
3439
|
+
const left = args[0] as Left
|
|
3440
|
+
const right = args[1] as Right
|
|
3315
3441
|
return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "overlaps")
|
|
3316
3442
|
}
|
|
3317
3443
|
|
|
@@ -3738,12 +3864,9 @@ type BinaryPredicateExpression<
|
|
|
3738
3864
|
>
|
|
3739
3865
|
}
|
|
3740
3866
|
|
|
3741
|
-
const call =
|
|
3742
|
-
|
|
3743
|
-
|
|
3744
|
-
>(
|
|
3745
|
-
name: Name,
|
|
3746
|
-
...args: Args
|
|
3867
|
+
const call: FunctionCallApi = (
|
|
3868
|
+
name: string,
|
|
3869
|
+
...args: readonly ExpressionInput[]
|
|
3747
3870
|
): Expression.Any => {
|
|
3748
3871
|
const expressions = args.map((value) => toDialectExpression(value)) as readonly Expression.Any[]
|
|
3749
3872
|
return makeExpression({
|
|
@@ -3964,7 +4087,9 @@ type BinaryPredicateExpression<
|
|
|
3964
4087
|
string,
|
|
3965
4088
|
"scalar",
|
|
3966
4089
|
Expression.BindingId
|
|
3967
|
-
>
|
|
4090
|
+
> & {
|
|
4091
|
+
readonly [ExpressionAst.TypeId]: ExpressionAst.ColumnNode<any, string>
|
|
4092
|
+
}
|
|
3968
4093
|
>(
|
|
3969
4094
|
value: Value
|
|
3970
4095
|
): AstBackedExpression<
|
|
@@ -3977,9 +4102,6 @@ type BinaryPredicateExpression<
|
|
|
3977
4102
|
ExpressionAst.ExcludedNode<AstOf<Value> extends ExpressionAst.ColumnNode<any, infer ColumnName extends string> ? ColumnName : string>
|
|
3978
4103
|
> => {
|
|
3979
4104
|
const ast = ((value as unknown) as Expression.Any & { readonly [ExpressionAst.TypeId]: ExpressionAst.Any })[ExpressionAst.TypeId]
|
|
3980
|
-
if (ast.kind !== "column") {
|
|
3981
|
-
throw new Error("excluded(...) only accepts bound table columns")
|
|
3982
|
-
}
|
|
3983
4105
|
return makeExpression({
|
|
3984
4106
|
runtime: undefined as Expression.RuntimeOf<Value>,
|
|
3985
4107
|
dbType: value[Expression.TypeId].dbType as Expression.DbTypeOf<Value>,
|
|
@@ -3992,7 +4114,7 @@ type BinaryPredicateExpression<
|
|
|
3992
4114
|
dependencies: {}
|
|
3993
4115
|
}, {
|
|
3994
4116
|
kind: "excluded",
|
|
3995
|
-
columnName: ast.columnName
|
|
4117
|
+
columnName: (ast as ExpressionAst.ColumnNode<any, string>).columnName
|
|
3996
4118
|
}) as unknown as AstBackedExpression<
|
|
3997
4119
|
Expression.RuntimeOf<Value>,
|
|
3998
4120
|
Expression.DbTypeOf<Value>,
|
|
@@ -4008,22 +4130,56 @@ type BinaryPredicateExpression<
|
|
|
4008
4130
|
value: Value,
|
|
4009
4131
|
column: Expression.Any
|
|
4010
4132
|
): Expression.Any => {
|
|
4133
|
+
const columnState = column[Expression.TypeId]
|
|
4134
|
+
const normalizeMutationValue = (candidate: unknown): unknown => {
|
|
4135
|
+
if (candidate === null && columnState.nullability !== "never") {
|
|
4136
|
+
return null
|
|
4137
|
+
}
|
|
4138
|
+
const runtimeSchemaAccepts = columnState.runtimeSchema !== undefined &&
|
|
4139
|
+
(Schema.is(columnState.runtimeSchema) as (input: unknown) => boolean)(candidate)
|
|
4140
|
+
if (runtimeSchemaAccepts) {
|
|
4141
|
+
return candidate
|
|
4142
|
+
}
|
|
4143
|
+
const normalized = normalizeDbValue(columnState.dbType, candidate)
|
|
4144
|
+
return columnState.runtimeSchema === undefined
|
|
4145
|
+
? normalized
|
|
4146
|
+
: (Schema.decodeUnknownSync as any)(columnState.runtimeSchema)(normalized)
|
|
4147
|
+
}
|
|
4011
4148
|
if (value !== null && typeof value === "object" && Expression.TypeId in value) {
|
|
4149
|
+
const expression = value as unknown as Expression.Any
|
|
4150
|
+
const ast = (expression as Expression.Any & { readonly [ExpressionAst.TypeId]: ExpressionAst.Any })[ExpressionAst.TypeId]
|
|
4151
|
+
if (ast.kind === "literal") {
|
|
4152
|
+
const normalizedValue = normalizeMutationValue(ast.value)
|
|
4153
|
+
return makeExpression({
|
|
4154
|
+
runtime: normalizedValue,
|
|
4155
|
+
dbType: columnState.dbType,
|
|
4156
|
+
runtimeSchema: columnState.runtimeSchema,
|
|
4157
|
+
driverValueMapping: columnState.driverValueMapping,
|
|
4158
|
+
nullability: normalizedValue === null ? "always" : "never",
|
|
4159
|
+
dialect: columnState.dialect,
|
|
4160
|
+
kind: "scalar",
|
|
4161
|
+
dependencies: {}
|
|
4162
|
+
}, {
|
|
4163
|
+
kind: "literal",
|
|
4164
|
+
value: normalizedValue
|
|
4165
|
+
})
|
|
4166
|
+
}
|
|
4012
4167
|
return retargetLiteralExpression(value as unknown as Expression.Any, column)
|
|
4013
4168
|
}
|
|
4169
|
+
const normalizedValue = normalizeMutationValue(value)
|
|
4014
4170
|
return makeExpression({
|
|
4015
|
-
runtime:
|
|
4016
|
-
dbType:
|
|
4017
|
-
runtimeSchema:
|
|
4018
|
-
driverValueMapping:
|
|
4019
|
-
nullability:
|
|
4020
|
-
dialect:
|
|
4171
|
+
runtime: normalizedValue as Value,
|
|
4172
|
+
dbType: columnState.dbType,
|
|
4173
|
+
runtimeSchema: columnState.runtimeSchema,
|
|
4174
|
+
driverValueMapping: columnState.driverValueMapping,
|
|
4175
|
+
nullability: normalizedValue === null ? "always" : "never",
|
|
4176
|
+
dialect: columnState.dialect,
|
|
4021
4177
|
kind: "scalar",
|
|
4022
4178
|
|
|
4023
4179
|
dependencies: {}
|
|
4024
4180
|
}, {
|
|
4025
4181
|
kind: "literal",
|
|
4026
|
-
value
|
|
4182
|
+
value: normalizedValue
|
|
4027
4183
|
})
|
|
4028
4184
|
}
|
|
4029
4185
|
|
|
@@ -4060,8 +4216,8 @@ type BinaryPredicateExpression<
|
|
|
4060
4216
|
: ">="
|
|
4061
4217
|
|
|
4062
4218
|
const targetSourceDetails = (table: MutationTargetLike | SchemaTableLike) => {
|
|
4063
|
-
const sourceName = (table as
|
|
4064
|
-
const sourceBaseName = (table as
|
|
4219
|
+
const sourceName = (table as TableLike)[Table.TypeId].name
|
|
4220
|
+
const sourceBaseName = (table as TableLike)[Table.TypeId].baseName
|
|
4065
4221
|
return {
|
|
4066
4222
|
sourceName,
|
|
4067
4223
|
sourceBaseName
|
|
@@ -4111,16 +4267,16 @@ type BinaryPredicateExpression<
|
|
|
4111
4267
|
Alias extends string
|
|
4112
4268
|
>(
|
|
4113
4269
|
rows: readonly [Record<string, Expression.Any>, ...Record<string, Expression.Any>[]],
|
|
4114
|
-
selection: ValuesOutputShape<Rows
|
|
4270
|
+
selection: ValuesOutputShape<Rows, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
4115
4271
|
alias: Alias
|
|
4116
4272
|
): ValuesSource<
|
|
4117
4273
|
Rows,
|
|
4118
|
-
ValuesOutputShape<Rows
|
|
4274
|
+
ValuesOutputShape<Rows, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
4119
4275
|
Alias,
|
|
4120
4276
|
Dialect
|
|
4121
4277
|
> => {
|
|
4122
4278
|
const columns = makeColumnReferenceSelection(alias, selection as Record<string, Expression.Any>) as unknown as ValuesOutputShape<
|
|
4123
|
-
Rows
|
|
4279
|
+
Rows,
|
|
4124
4280
|
Dialect,
|
|
4125
4281
|
TextDb,
|
|
4126
4282
|
NumericDb,
|
|
@@ -4138,7 +4294,7 @@ type BinaryPredicateExpression<
|
|
|
4138
4294
|
}
|
|
4139
4295
|
return Object.assign(source, columns) as unknown as ValuesSource<
|
|
4140
4296
|
Rows,
|
|
4141
|
-
ValuesOutputShape<Rows
|
|
4297
|
+
ValuesOutputShape<Rows, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
4142
4298
|
Alias,
|
|
4143
4299
|
Dialect
|
|
4144
4300
|
>
|
|
@@ -4194,6 +4350,11 @@ type BinaryPredicateExpression<
|
|
|
4194
4350
|
})
|
|
4195
4351
|
) as unknown as AddAvailableMany<{}, MutationTargetNamesOf<Target>, Mode>
|
|
4196
4352
|
|
|
4353
|
+
const getMutationColumn = (
|
|
4354
|
+
columns: Record<string, unknown>,
|
|
4355
|
+
columnName: string
|
|
4356
|
+
): Expression.Any => columns[columnName] as Expression.Any
|
|
4357
|
+
|
|
4197
4358
|
const buildMutationAssignments = <Target extends MutationTargetInput, Values>(
|
|
4198
4359
|
target: Target,
|
|
4199
4360
|
values: Values
|
|
@@ -4203,18 +4364,18 @@ type BinaryPredicateExpression<
|
|
|
4203
4364
|
const columns = target as unknown as Record<string, Expression.Any>
|
|
4204
4365
|
return Object.entries(values as Record<string, unknown>).map(([columnName, value]) => ({
|
|
4205
4366
|
columnName,
|
|
4206
|
-
value: toMutationValueExpression(value, columns
|
|
4367
|
+
value: toMutationValueExpression(value, getMutationColumn(columns, columnName))
|
|
4207
4368
|
}))
|
|
4208
4369
|
}
|
|
4209
4370
|
const valueMap = values as Record<string, Record<string, unknown> | undefined>
|
|
4210
4371
|
return targets.flatMap((table) => {
|
|
4211
|
-
const targetName = (table as
|
|
4372
|
+
const targetName = (table as TableLike)[Table.TypeId].name
|
|
4212
4373
|
const scopedValues = valueMap[targetName] ?? {}
|
|
4213
4374
|
const columns = table as unknown as Record<string, Expression.Any>
|
|
4214
4375
|
return Object.entries(scopedValues).map(([columnName, value]) => ({
|
|
4215
4376
|
tableName: targetName,
|
|
4216
4377
|
columnName,
|
|
4217
|
-
value: toMutationValueExpression(value, columns
|
|
4378
|
+
value: toMutationValueExpression(value, getMutationColumn(columns, columnName))
|
|
4218
4379
|
}))
|
|
4219
4380
|
})
|
|
4220
4381
|
}
|
|
@@ -4229,20 +4390,17 @@ type BinaryPredicateExpression<
|
|
|
4229
4390
|
} => {
|
|
4230
4391
|
const firstRow = rows[0]
|
|
4231
4392
|
const firstColumns = Object.keys(firstRow)
|
|
4232
|
-
if (firstColumns.length === 0) {
|
|
4233
|
-
throw new Error("values(...) rows must specify at least one column; use insert(target) for default-only inserts instead")
|
|
4234
|
-
}
|
|
4235
4393
|
const columns = firstColumns as [string, ...string[]]
|
|
4236
|
-
const
|
|
4237
|
-
const rowKeys = Object.keys(row)
|
|
4238
|
-
if (rowKeys.length !== columns.length || columns.some((column) => !(column in row))) {
|
|
4239
|
-
throw new Error("All values(...) rows must project the same columns in the same shape")
|
|
4240
|
-
}
|
|
4394
|
+
const normalizeRow = (row: InsertRowInput<Target>) => {
|
|
4241
4395
|
const assignments = buildMutationAssignments(target, row) as readonly QueryAst.AssignmentClause[]
|
|
4242
4396
|
return {
|
|
4243
4397
|
values: columns.map((columnName) => assignments.find((assignment) => assignment.columnName === columnName)!)
|
|
4244
4398
|
} satisfies QueryAst.InsertValuesRowClause
|
|
4245
|
-
}
|
|
4399
|
+
}
|
|
4400
|
+
const normalizedRows: readonly [QueryAst.InsertValuesRowClause, ...QueryAst.InsertValuesRowClause[]] = [
|
|
4401
|
+
normalizeRow(rows[0]),
|
|
4402
|
+
...rows.slice(1).map(normalizeRow)
|
|
4403
|
+
]
|
|
4246
4404
|
const required = normalizedRows.flatMap((row) =>
|
|
4247
4405
|
row.values.flatMap((entry) => Object.keys(entry.value[Expression.TypeId].dependencies))
|
|
4248
4406
|
)
|
|
@@ -4257,9 +4415,6 @@ type BinaryPredicateExpression<
|
|
|
4257
4415
|
selection: Record<string, Expression.Any>
|
|
4258
4416
|
): readonly [string, ...string[]] => {
|
|
4259
4417
|
const columns = Object.keys(selection)
|
|
4260
|
-
if (columns.length === 0) {
|
|
4261
|
-
throw new Error("insert(...).pipe(from(subquery)) requires at least one projected column")
|
|
4262
|
-
}
|
|
4263
4418
|
return columns as [string, ...string[]]
|
|
4264
4419
|
}
|
|
4265
4420
|
|
|
@@ -4274,41 +4429,33 @@ type BinaryPredicateExpression<
|
|
|
4274
4429
|
}[]
|
|
4275
4430
|
} => {
|
|
4276
4431
|
const entries = Object.entries(values)
|
|
4277
|
-
if (entries.length === 0) {
|
|
4278
|
-
throw new Error("unnest(...) requires at least one column array")
|
|
4279
|
-
}
|
|
4280
4432
|
const columns = entries.map(([columnName]) => columnName) as [string, ...string[]]
|
|
4281
|
-
const normalized = entries.map(([columnName, items]) => {
|
|
4282
|
-
|
|
4283
|
-
|
|
4284
|
-
|
|
4285
|
-
return {
|
|
4286
|
-
columnName,
|
|
4287
|
-
values: items
|
|
4288
|
-
}
|
|
4289
|
-
})
|
|
4290
|
-
const expectedLength = normalized[0]!.values.length
|
|
4291
|
-
if (normalized.some((entry) => entry.values.length !== expectedLength)) {
|
|
4292
|
-
throw new Error("unnest(...) expects every column array to have the same length")
|
|
4293
|
-
}
|
|
4294
|
-
const knownColumns = new Set(Object.keys(target[Table.TypeId].fields))
|
|
4295
|
-
if (columns.some((columnName) => !knownColumns.has(columnName))) {
|
|
4296
|
-
throw new Error("unnest(...) received a column that does not exist on the target table")
|
|
4297
|
-
}
|
|
4433
|
+
const normalized = entries.map(([columnName, items]) => ({
|
|
4434
|
+
columnName,
|
|
4435
|
+
values: items
|
|
4436
|
+
}))
|
|
4298
4437
|
return {
|
|
4299
4438
|
columns,
|
|
4300
4439
|
values: normalized
|
|
4301
4440
|
}
|
|
4302
4441
|
}
|
|
4303
4442
|
|
|
4443
|
+
const normalizeConflictColumns = <Target extends MutationTargetLike>(
|
|
4444
|
+
target: Target,
|
|
4445
|
+
columnsInput: string | readonly string[]
|
|
4446
|
+
): readonly [string, ...string[]] => {
|
|
4447
|
+
const columns = normalizeColumnList(columnsInput) as readonly [string, ...string[]]
|
|
4448
|
+
return columns
|
|
4449
|
+
}
|
|
4450
|
+
|
|
4304
4451
|
const buildConflictTarget = <Target extends MutationTargetLike>(
|
|
4305
4452
|
target: Target,
|
|
4306
|
-
input: readonly string[] | { readonly columns: readonly string[]; readonly where?: PredicateInput } | { readonly constraint: string }
|
|
4453
|
+
input: string | readonly string[] | { readonly columns: string | readonly string[]; readonly where?: PredicateInput } | { readonly constraint: string }
|
|
4307
4454
|
): QueryAst.ConflictTargetClause => {
|
|
4308
|
-
if (Array.isArray(input)) {
|
|
4455
|
+
if (typeof input === "string" || Array.isArray(input)) {
|
|
4309
4456
|
return {
|
|
4310
4457
|
kind: "columns",
|
|
4311
|
-
columns:
|
|
4458
|
+
columns: normalizeConflictColumns(target, input)
|
|
4312
4459
|
}
|
|
4313
4460
|
}
|
|
4314
4461
|
if (!Array.isArray(input) && "constraint" in input) {
|
|
@@ -4318,12 +4465,12 @@ type BinaryPredicateExpression<
|
|
|
4318
4465
|
}
|
|
4319
4466
|
}
|
|
4320
4467
|
const columnTarget = input as {
|
|
4321
|
-
readonly columns: readonly string[]
|
|
4468
|
+
readonly columns: string | readonly string[]
|
|
4322
4469
|
readonly where?: PredicateInput
|
|
4323
4470
|
}
|
|
4324
4471
|
return {
|
|
4325
4472
|
kind: "columns",
|
|
4326
|
-
columns:
|
|
4473
|
+
columns: normalizeConflictColumns(target, columnTarget.columns),
|
|
4327
4474
|
where: columnTarget.where === undefined ? undefined : toDialectExpression(columnTarget.where)
|
|
4328
4475
|
}
|
|
4329
4476
|
}
|
|
@@ -4361,19 +4508,29 @@ type ValidateDdlColumns<
|
|
|
4361
4508
|
Columns extends readonly string[]
|
|
4362
4509
|
> = Exclude<Columns[number], SchemaColumnNames<Target>> extends never ? Columns : never
|
|
4363
4510
|
|
|
4511
|
+
type ValidateDdlColumnInput<
|
|
4512
|
+
Target extends SchemaTableLike,
|
|
4513
|
+
Columns extends DdlColumnInput
|
|
4514
|
+
> = ValidateDdlColumns<Target, NormalizeDdlColumns<Columns>> extends never ? never : Columns
|
|
4515
|
+
|
|
4364
4516
|
type ValidateTargetColumns<
|
|
4365
4517
|
Target extends MutationTargetLike,
|
|
4366
4518
|
Columns extends readonly string[]
|
|
4367
4519
|
> = Exclude<Columns[number], Extract<keyof Target[typeof Table.TypeId]["fields"], string>> extends never ? Columns : never
|
|
4368
4520
|
|
|
4369
|
-
type
|
|
4370
|
-
|
|
4521
|
+
type ValidateTargetColumnInput<
|
|
4522
|
+
Target extends MutationTargetLike,
|
|
4523
|
+
Columns extends DdlColumnInput
|
|
4524
|
+
> = ValidateTargetColumns<Target, NormalizeDdlColumns<Columns>> extends never ? never : Columns
|
|
4525
|
+
|
|
4526
|
+
type CreateIndexOptions<Name extends string = string> = {
|
|
4527
|
+
readonly name?: NonEmptyStringInput<Name>
|
|
4371
4528
|
readonly unique?: boolean
|
|
4372
4529
|
readonly ifNotExists?: boolean
|
|
4373
4530
|
}
|
|
4374
4531
|
|
|
4375
|
-
type DropIndexOptions = {
|
|
4376
|
-
readonly name?:
|
|
4532
|
+
type DropIndexOptions<Name extends string = string> = {
|
|
4533
|
+
readonly name?: NonEmptyStringInput<Name>
|
|
4377
4534
|
readonly ifExists?: boolean
|
|
4378
4535
|
}
|
|
4379
4536
|
|
|
@@ -4395,10 +4552,15 @@ type TransactionOptions = {
|
|
|
4395
4552
|
readonly readOnly?: boolean
|
|
4396
4553
|
}
|
|
4397
4554
|
|
|
4398
|
-
type LockOptions =
|
|
4399
|
-
|
|
4400
|
-
|
|
4401
|
-
|
|
4555
|
+
type LockOptions =
|
|
4556
|
+
| {
|
|
4557
|
+
readonly nowait?: boolean
|
|
4558
|
+
readonly skipLocked?: false
|
|
4559
|
+
}
|
|
4560
|
+
| {
|
|
4561
|
+
readonly nowait?: false
|
|
4562
|
+
readonly skipLocked?: boolean
|
|
4563
|
+
}
|
|
4402
4564
|
|
|
4403
4565
|
type UpsertConflictOptions = {
|
|
4404
4566
|
readonly update?: Record<string, unknown>
|
|
@@ -4413,14 +4575,133 @@ type InsertRowInput<Target extends MutationTargetLike> = MutationInputOf<Table.I
|
|
|
4413
4575
|
type ValuesRowInput = Record<string, ExpressionInput>
|
|
4414
4576
|
type ValuesRowsInput = readonly [ValuesRowInput, ...ValuesRowInput[]]
|
|
4415
4577
|
|
|
4578
|
+
type ValuesColumnInput<Row, Key extends PropertyKey> =
|
|
4579
|
+
Row extends ValuesRowInput
|
|
4580
|
+
? Key extends keyof Row ? Row[Key] : never
|
|
4581
|
+
: never
|
|
4582
|
+
|
|
4583
|
+
type ValuesRowShapeMismatch<
|
|
4584
|
+
First extends ValuesRowInput,
|
|
4585
|
+
Row extends ValuesRowInput
|
|
4586
|
+
> =
|
|
4587
|
+
| Exclude<Extract<keyof Row, string>, Extract<keyof First, string>>
|
|
4588
|
+
| Exclude<Extract<keyof First, string>, Extract<keyof Row, string>>
|
|
4589
|
+
|
|
4590
|
+
type ValuesRowsShapeMismatchesFor<
|
|
4591
|
+
First extends ValuesRowInput,
|
|
4592
|
+
Row
|
|
4593
|
+
> = Row extends ValuesRowInput ? ValuesRowShapeMismatch<First, Row> : never
|
|
4594
|
+
|
|
4595
|
+
type ValuesRowsShapeMismatches<Rows extends ValuesRowsInput> =
|
|
4596
|
+
Rows extends readonly [infer First extends ValuesRowInput, ...infer Rest extends ValuesRowInput[]]
|
|
4597
|
+
? ValuesRowsShapeMismatchesFor<First, Rest[number]>
|
|
4598
|
+
: never
|
|
4599
|
+
|
|
4600
|
+
type ValuesRowsColumnKeys<Rows extends ValuesRowsInput> =
|
|
4601
|
+
Rows extends readonly [infer First extends ValuesRowInput, ...ValuesRowInput[]]
|
|
4602
|
+
? Extract<keyof First, string>
|
|
4603
|
+
: never
|
|
4604
|
+
|
|
4605
|
+
type ValuesRowsShapeInput<Rows extends ValuesRowsInput> =
|
|
4606
|
+
[ValuesRowsColumnKeys<Rows>] extends [never]
|
|
4607
|
+
? {
|
|
4608
|
+
readonly __effect_qb_error__: "effect-qb: values rows must project at least one column"
|
|
4609
|
+
}
|
|
4610
|
+
: [ValuesRowsShapeMismatches<Rows>] extends [never]
|
|
4611
|
+
? unknown
|
|
4612
|
+
: {
|
|
4613
|
+
readonly __effect_qb_error__: "effect-qb: values rows must project the same columns"
|
|
4614
|
+
readonly __effect_qb_mismatched_columns__: ValuesRowsShapeMismatches<Rows>
|
|
4615
|
+
}
|
|
4616
|
+
|
|
4617
|
+
type ValuesRowsDialect<
|
|
4618
|
+
Rows extends ValuesRowsInput,
|
|
4619
|
+
Dialect extends string,
|
|
4620
|
+
TextDb extends Expression.DbType.Any,
|
|
4621
|
+
NumericDb extends Expression.DbType.Any,
|
|
4622
|
+
BoolDb extends Expression.DbType.Any,
|
|
4623
|
+
TimestampDb extends Expression.DbType.Any,
|
|
4624
|
+
NullDb extends Expression.DbType.Any
|
|
4625
|
+
> = Rows[number][keyof Rows[number]] extends infer Value extends ExpressionInput
|
|
4626
|
+
? DialectOfDialectInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
4627
|
+
: never
|
|
4628
|
+
|
|
4629
|
+
type ValuesRowsDialectInput<
|
|
4630
|
+
Rows extends ValuesRowsInput,
|
|
4631
|
+
Dialect extends string,
|
|
4632
|
+
TextDb extends Expression.DbType.Any,
|
|
4633
|
+
NumericDb extends Expression.DbType.Any,
|
|
4634
|
+
BoolDb extends Expression.DbType.Any,
|
|
4635
|
+
TimestampDb extends Expression.DbType.Any,
|
|
4636
|
+
NullDb extends Expression.DbType.Any
|
|
4637
|
+
> = Exclude<ValuesRowsDialect<Rows, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>, Dialect | "standard"> extends never
|
|
4638
|
+
? unknown
|
|
4639
|
+
: {
|
|
4640
|
+
readonly __effect_qb_error__: "effect-qb: values rows cannot mix dialects"
|
|
4641
|
+
readonly __effect_qb_dialect__: ValuesRowsDialect<Rows, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
4642
|
+
}
|
|
4643
|
+
|
|
4416
4644
|
type UnnestColumnsInput = Record<string, readonly [ExpressionInput, ...ExpressionInput[]]>
|
|
4417
4645
|
|
|
4646
|
+
type IsNever<Value> = [Value] extends [never] ? true : false
|
|
4647
|
+
|
|
4648
|
+
type IsUnion<Value, All = Value> = Value extends any
|
|
4649
|
+
? ([All] extends [Value] ? false : true)
|
|
4650
|
+
: never
|
|
4651
|
+
|
|
4652
|
+
type UnnestColumnKeys<Columns extends UnnestColumnsInput> =
|
|
4653
|
+
Extract<keyof Columns, string>
|
|
4654
|
+
|
|
4655
|
+
type UnnestColumnLengths<Columns extends UnnestColumnsInput> =
|
|
4656
|
+
Columns[UnnestColumnKeys<Columns>]["length"]
|
|
4657
|
+
|
|
4658
|
+
type UnnestColumnsShapeInput<Columns extends UnnestColumnsInput> =
|
|
4659
|
+
IsNever<UnnestColumnKeys<Columns>> extends true
|
|
4660
|
+
? {
|
|
4661
|
+
readonly __effect_qb_error__: "effect-qb: unnest requires at least one column array"
|
|
4662
|
+
}
|
|
4663
|
+
: number extends UnnestColumnLengths<Columns>
|
|
4664
|
+
? unknown
|
|
4665
|
+
: IsUnion<UnnestColumnLengths<Columns>> extends true
|
|
4666
|
+
? {
|
|
4667
|
+
readonly __effect_qb_error__: "effect-qb: unnest column arrays must have the same length"
|
|
4668
|
+
readonly __effect_qb_column_lengths__: UnnestColumnLengths<Columns>
|
|
4669
|
+
}
|
|
4670
|
+
: unknown
|
|
4671
|
+
|
|
4672
|
+
type UnnestColumnsDialect<
|
|
4673
|
+
Columns extends UnnestColumnsInput,
|
|
4674
|
+
Dialect extends string,
|
|
4675
|
+
TextDb extends Expression.DbType.Any,
|
|
4676
|
+
NumericDb extends Expression.DbType.Any,
|
|
4677
|
+
BoolDb extends Expression.DbType.Any,
|
|
4678
|
+
TimestampDb extends Expression.DbType.Any,
|
|
4679
|
+
NullDb extends Expression.DbType.Any
|
|
4680
|
+
> = Columns[UnnestColumnKeys<Columns>][number] extends infer Value extends ExpressionInput
|
|
4681
|
+
? DialectOfDialectInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
4682
|
+
: never
|
|
4683
|
+
|
|
4684
|
+
type UnnestColumnsDialectInput<
|
|
4685
|
+
Columns extends UnnestColumnsInput,
|
|
4686
|
+
Dialect extends string,
|
|
4687
|
+
TextDb extends Expression.DbType.Any,
|
|
4688
|
+
NumericDb extends Expression.DbType.Any,
|
|
4689
|
+
BoolDb extends Expression.DbType.Any,
|
|
4690
|
+
TimestampDb extends Expression.DbType.Any,
|
|
4691
|
+
NullDb extends Expression.DbType.Any
|
|
4692
|
+
> = Exclude<UnnestColumnsDialect<Columns, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>, Dialect | "standard"> extends never
|
|
4693
|
+
? unknown
|
|
4694
|
+
: {
|
|
4695
|
+
readonly __effect_qb_error__: "effect-qb: unnest columns cannot mix dialects"
|
|
4696
|
+
readonly __effect_qb_dialect__: UnnestColumnsDialect<Columns, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
4697
|
+
}
|
|
4698
|
+
|
|
4418
4699
|
type UnnestRowShape<Shape extends Record<string, readonly unknown[]>> = {
|
|
4419
4700
|
readonly [K in keyof Shape]: Shape[K] extends readonly (infer Item)[] ? Item : never
|
|
4420
4701
|
}
|
|
4421
4702
|
|
|
4422
4703
|
type ValuesOutputShape<
|
|
4423
|
-
|
|
4704
|
+
Rows extends ValuesRowsInput,
|
|
4424
4705
|
Dialect extends string,
|
|
4425
4706
|
TextDb extends Expression.DbType.Any,
|
|
4426
4707
|
NumericDb extends Expression.DbType.Any,
|
|
@@ -4428,7 +4709,7 @@ type ValuesOutputShape<
|
|
|
4428
4709
|
TimestampDb extends Expression.DbType.Any,
|
|
4429
4710
|
NullDb extends Expression.DbType.Any
|
|
4430
4711
|
> = {
|
|
4431
|
-
readonly [K in keyof
|
|
4712
|
+
readonly [K in keyof Rows[0]]: DialectAsExpression<ValuesColumnInput<Rows[number], K>, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
4432
4713
|
}
|
|
4433
4714
|
|
|
4434
4715
|
type UnnestOutputShape<
|
|
@@ -4468,18 +4749,18 @@ type DistinctOnUnsupportedError<Dialect extends string> = {
|
|
|
4468
4749
|
}
|
|
4469
4750
|
|
|
4470
4751
|
type DistinctOnApi<Dialect extends string> = Dialect extends "postgres"
|
|
4471
|
-
? <Values extends readonly ExpressionInput[]>(
|
|
4752
|
+
? <Values extends readonly [ExpressionInput, ...ExpressionInput[]]>(
|
|
4472
4753
|
...values: Values
|
|
4473
4754
|
) => <PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
|
|
4474
4755
|
plan: PlanValue & RequireSelectStatement<PlanValue>
|
|
4475
4756
|
) => QueryPlan<
|
|
4476
4757
|
SelectionOfPlan<PlanValue>,
|
|
4477
|
-
RequiredOfPlan<PlanValue>,
|
|
4758
|
+
AddExpressionRequired<RequiredOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, Values[number]>,
|
|
4478
4759
|
AvailableOfPlan<PlanValue>,
|
|
4479
|
-
PlanDialectOf<PlanValue>,
|
|
4760
|
+
PlanDialectOf<PlanValue> | DialectOfDialectInput<Values[number], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
4480
4761
|
GroupedOfPlan<PlanValue>,
|
|
4481
4762
|
ScopedNamesOfPlan<PlanValue>,
|
|
4482
|
-
OutstandingOfPlan<PlanValue>,
|
|
4763
|
+
AddExpressionRequired<OutstandingOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, Values[number]>,
|
|
4483
4764
|
AssumptionsOfPlan<PlanValue>,
|
|
4484
4765
|
CapabilitiesOfPlan<PlanValue>,
|
|
4485
4766
|
StatementOfPlan<PlanValue>,
|
|
@@ -4515,6 +4796,44 @@ type MysqlConflictWhereError<Values> = Values & {
|
|
|
4515
4796
|
readonly __effect_qb_hint__: "Move the condition into the update assignment expressions or use the Postgres dialect"
|
|
4516
4797
|
}
|
|
4517
4798
|
|
|
4799
|
+
type ConflictActionWhereWithoutUpdateError<Values> = Values & {
|
|
4800
|
+
readonly __effect_qb_error__: "effect-qb: conflict action where(...) requires update assignments"
|
|
4801
|
+
readonly __effect_qb_hint__: "Add update assignments or move the predicate into the conflict target"
|
|
4802
|
+
}
|
|
4803
|
+
|
|
4804
|
+
type ConflictActionWhereInput<Dialect extends string> =
|
|
4805
|
+
Dialect extends "postgres" ? PredicateInput : MysqlConflictWhereError<PredicateInput>
|
|
4806
|
+
|
|
4807
|
+
type UpdateValuesNonEmptyError<Values> = Values & {
|
|
4808
|
+
readonly __effect_qb_error__: "effect-qb: update statements require at least one assignment"
|
|
4809
|
+
}
|
|
4810
|
+
|
|
4811
|
+
type UpdateValuesNonEmptyConstraint<Values> =
|
|
4812
|
+
[Extract<keyof Values, string>] extends [never]
|
|
4813
|
+
? UpdateValuesNonEmptyError<Values>
|
|
4814
|
+
: unknown
|
|
4815
|
+
|
|
4816
|
+
type NestedUpdateValuesNonEmptyConstraint<Values> =
|
|
4817
|
+
[Extract<keyof Values, string>] extends [never]
|
|
4818
|
+
? UpdateValuesNonEmptyError<Values>
|
|
4819
|
+
: true extends {
|
|
4820
|
+
[K in Extract<keyof Values, string>]:
|
|
4821
|
+
Values[K] extends Record<string, unknown>
|
|
4822
|
+
? [Extract<keyof Values[K], string>] extends [never] ? false : true
|
|
4823
|
+
: false
|
|
4824
|
+
}[Extract<keyof Values, string>]
|
|
4825
|
+
? unknown
|
|
4826
|
+
: UpdateValuesNonEmptyError<Values>
|
|
4827
|
+
|
|
4828
|
+
type MergeInsertValuesNonEmptyError<Values> = Values & {
|
|
4829
|
+
readonly __effect_qb_error__: "effect-qb: merge insert actions require at least one value"
|
|
4830
|
+
}
|
|
4831
|
+
|
|
4832
|
+
type MergeInsertValuesNonEmptyConstraint<Values> =
|
|
4833
|
+
[Extract<keyof Values, string>] extends [never]
|
|
4834
|
+
? MergeInsertValuesNonEmptyError<Values>
|
|
4835
|
+
: unknown
|
|
4836
|
+
|
|
4518
4837
|
type InsertShapeExtraKeys<TargetShape, SourceShape> = Exclude<Extract<keyof SourceShape, string>, Extract<keyof TargetShape, string>>
|
|
4519
4838
|
type InsertShapeMissingKeys<TargetShape, SourceShape> = Exclude<RequiredKeys<TargetShape>, Extract<keyof SourceShape, string>>
|
|
4520
4839
|
type InsertShapeMismatchedKeys<TargetShape, SourceShape> = Extract<{
|
|
@@ -4608,10 +4927,15 @@ type InsertSourceRequired<Source> =
|
|
|
4608
4927
|
Source extends QueryPlan<any, any, any, any, any, any, any, any, any, any> ? RequiredOfPlan<Source> :
|
|
4609
4928
|
never
|
|
4610
4929
|
|
|
4930
|
+
type InsertSourceDialect<Source> =
|
|
4931
|
+
Source extends QueryPlan<any, any, any, any, any, any, any, any, any, any> ? PlanDialectOf<Source> :
|
|
4932
|
+
Source extends SourceLike ? SourceDialectOf<Source> :
|
|
4933
|
+
never
|
|
4934
|
+
|
|
4611
4935
|
type ConflictColumnTarget<
|
|
4612
4936
|
Target extends MutationTargetLike,
|
|
4613
4937
|
Columns extends DdlColumnInput
|
|
4614
|
-
> =
|
|
4938
|
+
> = ValidateTargetColumnInput<Target, Columns>
|
|
4615
4939
|
|
|
4616
4940
|
type ConflictTargetInput<
|
|
4617
4941
|
Target extends MutationTargetLike,
|
|
@@ -4632,14 +4956,73 @@ type ConflictTargetInput<
|
|
|
4632
4956
|
readonly constraint?: string
|
|
4633
4957
|
}>)
|
|
4634
4958
|
|
|
4959
|
+
type ConflictConstraintNameConstraint<Target> =
|
|
4960
|
+
Target extends { readonly constraint: infer Constraint extends string }
|
|
4961
|
+
? { readonly constraint: NonEmptyStringInput<Constraint> }
|
|
4962
|
+
: unknown
|
|
4963
|
+
|
|
4635
4964
|
type ConflictActionInput<
|
|
4636
4965
|
Target extends MutationTargetLike,
|
|
4637
4966
|
Dialect extends string,
|
|
4638
4967
|
UpdateValues extends MutationInputOf<Table.UpdateOf<Target>> | undefined = MutationInputOf<Table.UpdateOf<Target>> | undefined
|
|
4968
|
+
> =
|
|
4969
|
+
| {
|
|
4970
|
+
readonly update: Exclude<UpdateValues, undefined>
|
|
4971
|
+
readonly where?: ConflictActionWhereInput<Dialect>
|
|
4972
|
+
}
|
|
4973
|
+
| {
|
|
4974
|
+
readonly update?: undefined
|
|
4975
|
+
readonly where?: ConflictActionWhereWithoutUpdateError<PredicateInput>
|
|
4976
|
+
}
|
|
4977
|
+
|
|
4978
|
+
type ConflictActionUpdateNonEmptyConstraint<Options> =
|
|
4979
|
+
Options extends { readonly update: infer Values }
|
|
4980
|
+
? UpdateValuesNonEmptyConstraint<Values>
|
|
4981
|
+
: unknown
|
|
4982
|
+
|
|
4983
|
+
type ConflictTargetPredicate<Target> =
|
|
4984
|
+
Target extends { readonly where?: infer Predicate } ? Extract<Predicate, PredicateInput> : never
|
|
4985
|
+
|
|
4986
|
+
type ConflictActionPredicate<Options> =
|
|
4987
|
+
Options extends { readonly where?: infer Predicate } ? Extract<Predicate, PredicateInput> : never
|
|
4988
|
+
|
|
4989
|
+
type MutationDialectFromValues<
|
|
4990
|
+
Values extends Record<string, unknown>,
|
|
4991
|
+
Dialect extends string,
|
|
4992
|
+
TextDb extends Expression.DbType.Any,
|
|
4993
|
+
NumericDb extends Expression.DbType.Any,
|
|
4994
|
+
BoolDb extends Expression.DbType.Any,
|
|
4995
|
+
TimestampDb extends Expression.DbType.Any,
|
|
4996
|
+
NullDb extends Expression.DbType.Any
|
|
4639
4997
|
> = {
|
|
4640
|
-
|
|
4641
|
-
|
|
4642
|
-
|
|
4998
|
+
[K in keyof Values]: Values[K] extends ExpressionInput
|
|
4999
|
+
? DialectOfDialectInput<Values[K], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
5000
|
+
: never
|
|
5001
|
+
}[keyof Values]
|
|
5002
|
+
|
|
5003
|
+
type ConflictRequired<
|
|
5004
|
+
UpdateValues extends MutationInputOf<any> | undefined,
|
|
5005
|
+
Options,
|
|
5006
|
+
ConflictTarget
|
|
5007
|
+
> =
|
|
5008
|
+
| MutationRequiredFromValues<Exclude<UpdateValues, undefined>>
|
|
5009
|
+
| RequiredFromInput<ConflictActionPredicate<Options>>
|
|
5010
|
+
| RequiredFromInput<ConflictTargetPredicate<ConflictTarget>>
|
|
5011
|
+
|
|
5012
|
+
type ConflictDialect<
|
|
5013
|
+
UpdateValues extends MutationInputOf<any> | undefined,
|
|
5014
|
+
Options,
|
|
5015
|
+
ConflictTarget,
|
|
5016
|
+
Dialect extends string,
|
|
5017
|
+
TextDb extends Expression.DbType.Any,
|
|
5018
|
+
NumericDb extends Expression.DbType.Any,
|
|
5019
|
+
BoolDb extends Expression.DbType.Any,
|
|
5020
|
+
TimestampDb extends Expression.DbType.Any,
|
|
5021
|
+
NullDb extends Expression.DbType.Any
|
|
5022
|
+
> =
|
|
5023
|
+
| MutationDialectFromValues<Exclude<UpdateValues, undefined>, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
5024
|
+
| DialectOfDialectInput<ConflictActionPredicate<Options>, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
5025
|
+
| DialectOfDialectInput<ConflictTargetPredicate<ConflictTarget>, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
4643
5026
|
|
|
4644
5027
|
type MergeWhenMatchedDelete<
|
|
4645
5028
|
Predicate extends PredicateInput | undefined = undefined
|
|
@@ -4654,7 +5037,7 @@ type MergeWhenMatchedUpdate<
|
|
|
4654
5037
|
Values extends MutationInputOf<Table.UpdateOf<Target>>,
|
|
4655
5038
|
Predicate extends PredicateInput | undefined = undefined
|
|
4656
5039
|
> = {
|
|
4657
|
-
readonly update: Values
|
|
5040
|
+
readonly update: Values & UpdateValuesNonEmptyConstraint<Values>
|
|
4658
5041
|
readonly predicate?: Predicate
|
|
4659
5042
|
readonly delete?: never
|
|
4660
5043
|
}
|
|
@@ -4664,20 +5047,37 @@ type MergeWhenNotMatched<
|
|
|
4664
5047
|
Values extends MutationInputOf<Table.InsertOf<Target>>,
|
|
4665
5048
|
Predicate extends PredicateInput | undefined = undefined
|
|
4666
5049
|
> = {
|
|
4667
|
-
readonly values: Values
|
|
5050
|
+
readonly values: Values & MergeInsertValuesNonEmptyConstraint<Values>
|
|
4668
5051
|
readonly predicate?: Predicate
|
|
4669
5052
|
}
|
|
4670
5053
|
|
|
5054
|
+
type MergeMatchedOption<
|
|
5055
|
+
Target extends MutationTargetLike,
|
|
5056
|
+
MatchedValues extends MutationInputOf<Table.UpdateOf<Target>>,
|
|
5057
|
+
MatchedPredicate extends PredicateInput | undefined = undefined
|
|
5058
|
+
> = MergeWhenMatchedDelete<MatchedPredicate> | MergeWhenMatchedUpdate<Target, MatchedValues, MatchedPredicate>
|
|
5059
|
+
|
|
5060
|
+
type MergeNotMatchedOption<
|
|
5061
|
+
Target extends MutationTargetLike,
|
|
5062
|
+
InsertValues extends MutationInputOf<Table.InsertOf<Target>>,
|
|
5063
|
+
NotMatchedPredicate extends PredicateInput | undefined = undefined
|
|
5064
|
+
> = MergeWhenNotMatched<Target, InsertValues, NotMatchedPredicate>
|
|
5065
|
+
|
|
4671
5066
|
type MergeOptions<
|
|
4672
5067
|
Target extends MutationTargetLike,
|
|
4673
5068
|
MatchedValues extends MutationInputOf<Table.UpdateOf<Target>>,
|
|
4674
5069
|
InsertValues extends MutationInputOf<Table.InsertOf<Target>>,
|
|
4675
5070
|
MatchedPredicate extends PredicateInput | undefined = undefined,
|
|
4676
5071
|
NotMatchedPredicate extends PredicateInput | undefined = undefined
|
|
4677
|
-
> =
|
|
4678
|
-
|
|
4679
|
-
|
|
4680
|
-
|
|
5072
|
+
> =
|
|
5073
|
+
| {
|
|
5074
|
+
readonly whenMatched: MergeMatchedOption<Target, MatchedValues, MatchedPredicate>
|
|
5075
|
+
readonly whenNotMatched?: MergeNotMatchedOption<Target, InsertValues, NotMatchedPredicate>
|
|
5076
|
+
}
|
|
5077
|
+
| {
|
|
5078
|
+
readonly whenMatched?: MergeMatchedOption<Target, MatchedValues, MatchedPredicate>
|
|
5079
|
+
readonly whenNotMatched: MergeNotMatchedOption<Target, InsertValues, NotMatchedPredicate>
|
|
5080
|
+
}
|
|
4681
5081
|
|
|
4682
5082
|
type RequireSelectStatement<PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>> =
|
|
4683
5083
|
StatementOfPlan<PlanValue> extends "select" ? unknown : never
|
|
@@ -4709,6 +5109,11 @@ type MutationOrderLimitSupported<PlanValue extends QueryPlan<any, any, any, any,
|
|
|
4709
5109
|
? StatementOfPlan<PlanValue> extends "update" | "delete" ? unknown : never
|
|
4710
5110
|
: never
|
|
4711
5111
|
|
|
5112
|
+
type MutationTargetTupleDialectConstraint<
|
|
5113
|
+
Targets extends MutationTargetTuple,
|
|
5114
|
+
Dialect extends string
|
|
5115
|
+
> = Exclude<TableDialectOf<Targets[number]>, Dialect | "standard"> extends never ? unknown : never
|
|
5116
|
+
|
|
4712
5117
|
type MutationRequiredFromValues<Values extends Record<string, unknown>> = {
|
|
4713
5118
|
[K in keyof Values]: Values[K] extends Expression.Any ? RequiredFromDependencies<DependenciesOf<Values[K]>> : never
|
|
4714
5119
|
}[keyof Values]
|
|
@@ -4722,6 +5127,59 @@ type NestedMutationRequiredFromValues<Values> =
|
|
|
4722
5127
|
}[keyof Values]
|
|
4723
5128
|
: never
|
|
4724
5129
|
|
|
5130
|
+
type NestedMutationDialectFromValues<
|
|
5131
|
+
Values,
|
|
5132
|
+
Dialect extends string,
|
|
5133
|
+
TextDb extends Expression.DbType.Any,
|
|
5134
|
+
NumericDb extends Expression.DbType.Any,
|
|
5135
|
+
BoolDb extends Expression.DbType.Any,
|
|
5136
|
+
TimestampDb extends Expression.DbType.Any,
|
|
5137
|
+
NullDb extends Expression.DbType.Any
|
|
5138
|
+
> =
|
|
5139
|
+
Values extends ExpressionInput
|
|
5140
|
+
? DialectOfDialectInput<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
5141
|
+
: Values extends Record<string, unknown>
|
|
5142
|
+
? {
|
|
5143
|
+
[K in keyof Values]: NestedMutationDialectFromValues<Values[K], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
5144
|
+
}[keyof Values]
|
|
5145
|
+
: never
|
|
5146
|
+
|
|
5147
|
+
type KnownMutationDialectFromValues<
|
|
5148
|
+
Values,
|
|
5149
|
+
Dialect extends string,
|
|
5150
|
+
TextDb extends Expression.DbType.Any,
|
|
5151
|
+
NumericDb extends Expression.DbType.Any,
|
|
5152
|
+
BoolDb extends Expression.DbType.Any,
|
|
5153
|
+
TimestampDb extends Expression.DbType.Any,
|
|
5154
|
+
NullDb extends Expression.DbType.Any
|
|
5155
|
+
> = NestedMutationDialectFromValues<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> extends infer Current
|
|
5156
|
+
? Current extends string
|
|
5157
|
+
? string extends Current ? never : Current
|
|
5158
|
+
: never
|
|
5159
|
+
: never
|
|
5160
|
+
|
|
5161
|
+
type KnownIncompatibleMutationDialectFromValues<
|
|
5162
|
+
Values,
|
|
5163
|
+
Dialect extends string,
|
|
5164
|
+
TextDb extends Expression.DbType.Any,
|
|
5165
|
+
NumericDb extends Expression.DbType.Any,
|
|
5166
|
+
BoolDb extends Expression.DbType.Any,
|
|
5167
|
+
TimestampDb extends Expression.DbType.Any,
|
|
5168
|
+
NullDb extends Expression.DbType.Any
|
|
5169
|
+
> = Exclude<KnownMutationDialectFromValues<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>, Dialect | "standard">
|
|
5170
|
+
|
|
5171
|
+
type MutationValuesDialectConstraint<
|
|
5172
|
+
Values,
|
|
5173
|
+
Dialect extends string,
|
|
5174
|
+
TextDb extends Expression.DbType.Any,
|
|
5175
|
+
NumericDb extends Expression.DbType.Any,
|
|
5176
|
+
BoolDb extends Expression.DbType.Any,
|
|
5177
|
+
TimestampDb extends Expression.DbType.Any,
|
|
5178
|
+
NullDb extends Expression.DbType.Any
|
|
5179
|
+
> = KnownIncompatibleMutationDialectFromValues<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> extends never
|
|
5180
|
+
? unknown
|
|
5181
|
+
: never
|
|
5182
|
+
|
|
4725
5183
|
type MutationAssignments<Shape extends Record<string, unknown>> = {
|
|
4726
5184
|
readonly [K in keyof Shape]: QueryAst.AssignmentClause
|
|
4727
5185
|
}
|
|
@@ -4755,12 +5213,40 @@ type InsertDirectSource =
|
|
|
4755
5213
|
|
|
4756
5214
|
type FromInput = SourceLike | InsertDirectSource
|
|
4757
5215
|
|
|
5216
|
+
type SourceDialectConstraint<
|
|
5217
|
+
CurrentSource extends SourceLike,
|
|
5218
|
+
Dialect extends string
|
|
5219
|
+
> = [SourceDialectOf<CurrentSource>] extends [never]
|
|
5220
|
+
? unknown
|
|
5221
|
+
: Exclude<SourceDialectOf<CurrentSource>, Dialect | "standard"> extends never
|
|
5222
|
+
? unknown
|
|
5223
|
+
: Dialect extends "standard"
|
|
5224
|
+
? unknown
|
|
5225
|
+
: never
|
|
5226
|
+
|
|
5227
|
+
type SourceRequirementConstraint<
|
|
5228
|
+
PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>,
|
|
5229
|
+
CurrentSource extends SourceLike
|
|
5230
|
+
> = [SourceRequiredOf<CurrentSource>] extends [never]
|
|
5231
|
+
? unknown
|
|
5232
|
+
: Exclude<SourceRequiredOf<CurrentSource>, ScopedNamesOfPlan<PlanValue>> extends never
|
|
5233
|
+
? unknown
|
|
5234
|
+
: SourceRequirementError<CurrentSource>
|
|
5235
|
+
|
|
4758
5236
|
type SelectFromConstraint<
|
|
4759
5237
|
PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>,
|
|
4760
5238
|
CurrentSource extends SourceLike
|
|
4761
5239
|
> =
|
|
4762
5240
|
RequireSelectStatement<PlanValue> &
|
|
4763
|
-
(
|
|
5241
|
+
(
|
|
5242
|
+
SourceNameOf<CurrentSource> extends OutstandingOfPlan<PlanValue>
|
|
5243
|
+
? unknown
|
|
5244
|
+
: [OutstandingOfPlan<PlanValue>] extends [never]
|
|
5245
|
+
? [ScopedNamesOfPlan<PlanValue>] extends [never]
|
|
5246
|
+
? unknown
|
|
5247
|
+
: never
|
|
5248
|
+
: never
|
|
5249
|
+
) &
|
|
4764
5250
|
(SourceRequiredOf<CurrentSource> extends never ? unknown : SourceRequirementError<CurrentSource>)
|
|
4765
5251
|
|
|
4766
5252
|
type UpdateFromConstraint<
|
|
@@ -4777,7 +5263,7 @@ type InsertFromConstraint<
|
|
|
4777
5263
|
Dialect extends string
|
|
4778
5264
|
> =
|
|
4779
5265
|
RequirePendingInsertStatement<PlanValue> &
|
|
4780
|
-
(InsertSourceOfPlanInput<PlanValue, CurrentSource, Dialect>
|
|
5266
|
+
(CurrentSource extends InsertSourceOfPlanInput<PlanValue, CurrentSource, Dialect>
|
|
4781
5267
|
? unknown
|
|
4782
5268
|
: InsertSourceOfPlanInput<PlanValue, CurrentSource, Dialect>)
|
|
4783
5269
|
|
|
@@ -4831,12 +5317,12 @@ type InsertFromResult<
|
|
|
4831
5317
|
Dialect extends string
|
|
4832
5318
|
> = QueryPlan<
|
|
4833
5319
|
SelectionOfPlan<PlanValue>,
|
|
4834
|
-
|
|
5320
|
+
InsertSourceRequired<CurrentSource>,
|
|
4835
5321
|
AvailableOfPlan<PlanValue>,
|
|
4836
|
-
PlanDialectOf<PlanValue>,
|
|
5322
|
+
PlanDialectOf<PlanValue> | InsertSourceDialect<CurrentSource>,
|
|
4837
5323
|
GroupedOfPlan<PlanValue>,
|
|
4838
5324
|
ScopedNamesOfPlan<PlanValue>,
|
|
4839
|
-
|
|
5325
|
+
InsertSourceRequired<CurrentSource>,
|
|
4840
5326
|
AssumptionsOfPlan<PlanValue>,
|
|
4841
5327
|
CurrentSource extends QueryPlan<any, any, any, any, any, any, any, any, any, any>
|
|
4842
5328
|
? MergeCapabilities<CapabilitiesOfPlan<PlanValue>, CapabilitiesOfPlan<CurrentSource>>
|
|
@@ -4853,15 +5339,17 @@ type FromPlanConstraint<
|
|
|
4853
5339
|
Dialect extends string
|
|
4854
5340
|
> =
|
|
4855
5341
|
CurrentSource extends SourceLike
|
|
4856
|
-
?
|
|
4857
|
-
|
|
4858
|
-
|
|
4859
|
-
|
|
4860
|
-
|
|
4861
|
-
|
|
4862
|
-
|
|
4863
|
-
|
|
4864
|
-
|
|
5342
|
+
? SourceDialectConstraint<CurrentSource, Dialect> & (
|
|
5343
|
+
StatementOfPlan<PlanValue> extends "select"
|
|
5344
|
+
? SelectFromConstraint<PlanValue, CurrentSource>
|
|
5345
|
+
: StatementOfPlan<PlanValue> extends "update"
|
|
5346
|
+
? UpdateFromConstraint<PlanValue, CurrentSource>
|
|
5347
|
+
: StatementOfPlan<PlanValue> extends "insert"
|
|
5348
|
+
? CurrentSource extends AnyValuesSource | AnyUnnestSource
|
|
5349
|
+
? InsertFromConstraint<PlanValue, CurrentSource, Dialect>
|
|
5350
|
+
: never
|
|
5351
|
+
: never
|
|
5352
|
+
)
|
|
4865
5353
|
: CurrentSource extends InsertDirectSource
|
|
4866
5354
|
? StatementOfPlan<PlanValue> extends "insert"
|
|
4867
5355
|
? InsertFromConstraint<PlanValue, CurrentSource, Dialect>
|
|
@@ -4916,7 +5404,10 @@ export type PublicStructuredFromResult<
|
|
|
4916
5404
|
Exclude<OutstandingOfPlan<PlanValue>, SourceNameOf<CurrentSource>>,
|
|
4917
5405
|
AssumptionsOfPlan<PlanValue>,
|
|
4918
5406
|
MergeCapabilities<CapabilitiesOfPlan<PlanValue>, SourceCapabilitiesOf<CurrentSource>>,
|
|
4919
|
-
StatementOfPlan<PlanValue
|
|
5407
|
+
StatementOfPlan<PlanValue>,
|
|
5408
|
+
MutationTargetOfPlan<PlanValue>,
|
|
5409
|
+
InsertSourceStateOfPlan<PlanValue>,
|
|
5410
|
+
FactsOfPlan<PlanValue>
|
|
4920
5411
|
>
|
|
4921
5412
|
: StatementOfPlan<PlanValue> extends "update"
|
|
4922
5413
|
? QueryPlan<
|
|
@@ -4929,7 +5420,10 @@ export type PublicStructuredFromResult<
|
|
|
4929
5420
|
Exclude<OutstandingOfPlan<PlanValue>, SourceNameOf<CurrentSource>>,
|
|
4930
5421
|
AssumptionsOfPlan<PlanValue>,
|
|
4931
5422
|
MergeCapabilities<CapabilitiesOfPlan<PlanValue>, SourceCapabilitiesOf<CurrentSource>>,
|
|
4932
|
-
StatementOfPlan<PlanValue
|
|
5423
|
+
StatementOfPlan<PlanValue>,
|
|
5424
|
+
MutationTargetOfPlan<PlanValue>,
|
|
5425
|
+
InsertSourceStateOfPlan<PlanValue>,
|
|
5426
|
+
FactsOfPlan<PlanValue>
|
|
4933
5427
|
>
|
|
4934
5428
|
: StatementOfPlan<PlanValue> extends "insert"
|
|
4935
5429
|
? CurrentSource extends AnyValuesSource | AnyUnnestSource
|
|
@@ -4937,7 +5431,7 @@ export type PublicStructuredFromResult<
|
|
|
4937
5431
|
SelectionOfPlan<PlanValue>,
|
|
4938
5432
|
never,
|
|
4939
5433
|
AvailableOfPlan<PlanValue>,
|
|
4940
|
-
PlanDialectOf<PlanValue>,
|
|
5434
|
+
PlanDialectOf<PlanValue> | SourceDialectOf<CurrentSource>,
|
|
4941
5435
|
GroupedOfPlan<PlanValue>,
|
|
4942
5436
|
ScopedNamesOfPlan<PlanValue>,
|
|
4943
5437
|
never,
|
|
@@ -4945,7 +5439,8 @@ export type PublicStructuredFromResult<
|
|
|
4945
5439
|
CapabilitiesOfPlan<PlanValue>,
|
|
4946
5440
|
StatementOfPlan<PlanValue>,
|
|
4947
5441
|
MutationTargetOfPlan<PlanValue>,
|
|
4948
|
-
"ready"
|
|
5442
|
+
"ready",
|
|
5443
|
+
FactsOfPlan<PlanValue>
|
|
4949
5444
|
>
|
|
4950
5445
|
: FromPlanResult<PlanValue, CurrentSource, Dialect>
|
|
4951
5446
|
: FromPlanResult<PlanValue, CurrentSource, Dialect>
|
|
@@ -4962,6 +5457,36 @@ type MergeRequiredFromPredicate<
|
|
|
4962
5457
|
Available extends Record<string, Plan.AnySource>
|
|
4963
5458
|
> = Predicate extends PredicateInput ? AddExpressionRequired<never, Available, Predicate> : never
|
|
4964
5459
|
|
|
5460
|
+
type BroadString<Value extends string> = string extends Value ? true : false
|
|
5461
|
+
|
|
5462
|
+
type SameSourceName<
|
|
5463
|
+
Left extends string,
|
|
5464
|
+
Right extends string
|
|
5465
|
+
> = [Left] extends [Right] ? [Right] extends [Left] ? true : false : false
|
|
5466
|
+
|
|
5467
|
+
type MergeSourceNameConflictError<
|
|
5468
|
+
TargetName extends string,
|
|
5469
|
+
SourceName extends string
|
|
5470
|
+
> = {
|
|
5471
|
+
readonly __effect_qb_error__: "effect-qb: merge source name must differ from target source name"
|
|
5472
|
+
readonly __effect_qb_target_source_name__: TargetName
|
|
5473
|
+
readonly __effect_qb_using_source_name__: SourceName
|
|
5474
|
+
readonly __effect_qb_hint__: "Alias the merge source with Table.alias(...), Query.as(...), or Query.with(...)"
|
|
5475
|
+
}
|
|
5476
|
+
|
|
5477
|
+
type MergeSourceNameConstraint<
|
|
5478
|
+
Target extends MutationTargetLike,
|
|
5479
|
+
Source extends SourceLike,
|
|
5480
|
+
TargetName extends string = SourceNameOf<Target>,
|
|
5481
|
+
SourceName extends string = SourceNameOf<Source>
|
|
5482
|
+
> = BroadString<TargetName> extends true
|
|
5483
|
+
? unknown
|
|
5484
|
+
: BroadString<SourceName> extends true
|
|
5485
|
+
? unknown
|
|
5486
|
+
: SameSourceName<TargetName, SourceName> extends true
|
|
5487
|
+
? MergeSourceNameConflictError<TargetName, SourceName>
|
|
5488
|
+
: unknown
|
|
5489
|
+
|
|
4965
5490
|
type AsCurriedInput<Dialect extends string> =
|
|
4966
5491
|
| ExpressionInput
|
|
4967
5492
|
| ValuesInput<any, any, Dialect>
|
|
@@ -4991,7 +5516,7 @@ type AsCurriedResult<
|
|
|
4991
5516
|
function as<
|
|
4992
5517
|
Alias extends string
|
|
4993
5518
|
>(
|
|
4994
|
-
alias: Alias
|
|
5519
|
+
alias: LiteralStringInput<Alias>
|
|
4995
5520
|
): <Value extends AsCurriedInput<Dialect>>(
|
|
4996
5521
|
value: Value
|
|
4997
5522
|
) => AsCurriedResult<Value, Alias, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
@@ -5000,21 +5525,21 @@ type AsCurriedResult<
|
|
|
5000
5525
|
Alias extends string
|
|
5001
5526
|
>(
|
|
5002
5527
|
value: Value,
|
|
5003
|
-
alias: Alias
|
|
5004
|
-
): DialectAsExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
5528
|
+
alias: LiteralStringInput<Alias>
|
|
5529
|
+
): ProjectionAliasedExpression<DialectAsExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>, Alias>
|
|
5005
5530
|
function as<
|
|
5006
5531
|
Rows extends ValuesRowsInput,
|
|
5007
5532
|
Alias extends string
|
|
5008
5533
|
>(
|
|
5009
5534
|
value: ValuesInput<
|
|
5010
5535
|
Rows,
|
|
5011
|
-
ValuesOutputShape<Rows
|
|
5536
|
+
ValuesOutputShape<Rows, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5012
5537
|
Dialect
|
|
5013
5538
|
>,
|
|
5014
|
-
alias: Alias
|
|
5539
|
+
alias: LiteralStringInput<Alias>
|
|
5015
5540
|
): ValuesSource<
|
|
5016
5541
|
Rows,
|
|
5017
|
-
ValuesOutputShape<Rows
|
|
5542
|
+
ValuesOutputShape<Rows, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5018
5543
|
Alias,
|
|
5019
5544
|
Dialect
|
|
5020
5545
|
>
|
|
@@ -5022,12 +5547,12 @@ type AsCurriedResult<
|
|
|
5022
5547
|
PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>,
|
|
5023
5548
|
Alias extends string
|
|
5024
5549
|
>(
|
|
5025
|
-
value:
|
|
5026
|
-
alias: Alias
|
|
5550
|
+
value: DerivedTableCompatiblePlan<PlanValue>,
|
|
5551
|
+
alias: LiteralStringInput<Alias>
|
|
5027
5552
|
): DerivedSource<PlanValue, Alias>
|
|
5028
5553
|
function as(valueOrAlias: unknown, alias?: string): unknown {
|
|
5029
5554
|
if (alias === undefined) {
|
|
5030
|
-
return (value: unknown) => as(value as any, valueOrAlias as
|
|
5555
|
+
return (value: unknown) => as(value as any, valueOrAlias as never)
|
|
5031
5556
|
}
|
|
5032
5557
|
const resolvedAlias = alias
|
|
5033
5558
|
const value = valueOrAlias
|
|
@@ -5067,20 +5592,20 @@ type AsCurriedResult<
|
|
|
5067
5592
|
function with_<
|
|
5068
5593
|
Alias extends string
|
|
5069
5594
|
>(
|
|
5070
|
-
alias: Alias
|
|
5595
|
+
alias: LiteralStringInput<Alias>
|
|
5071
5596
|
): <PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
|
|
5072
|
-
value:
|
|
5597
|
+
value: DerivedSourceCompatiblePlan<PlanValue>
|
|
5073
5598
|
) => import("../../internal/query.js").CteSource<PlanValue, Alias>
|
|
5074
5599
|
function with_<
|
|
5075
5600
|
PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>,
|
|
5076
5601
|
Alias extends string
|
|
5077
5602
|
>(
|
|
5078
|
-
value:
|
|
5079
|
-
alias: Alias
|
|
5603
|
+
value: DerivedSourceCompatiblePlan<PlanValue>,
|
|
5604
|
+
alias: LiteralStringInput<Alias>
|
|
5080
5605
|
): import("../../internal/query.js").CteSource<PlanValue, Alias>
|
|
5081
5606
|
function with_(valueOrAlias: unknown, alias?: string): unknown {
|
|
5082
5607
|
if (alias === undefined) {
|
|
5083
|
-
return (value: unknown) => with_(value as any, valueOrAlias as
|
|
5608
|
+
return (value: unknown) => with_(value as any, valueOrAlias as never)
|
|
5084
5609
|
}
|
|
5085
5610
|
return makeCteSource(
|
|
5086
5611
|
valueOrAlias as CompletePlan<QueryPlan<any, any, any, any, any, any, any, any, any, any>>,
|
|
@@ -5091,20 +5616,20 @@ type AsCurriedResult<
|
|
|
5091
5616
|
function withRecursive_<
|
|
5092
5617
|
Alias extends string
|
|
5093
5618
|
>(
|
|
5094
|
-
alias: Alias
|
|
5619
|
+
alias: LiteralStringInput<Alias>
|
|
5095
5620
|
): <PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
|
|
5096
|
-
value:
|
|
5621
|
+
value: DerivedSourceCompatiblePlan<PlanValue>
|
|
5097
5622
|
) => import("../../internal/query.js").CteSource<PlanValue, Alias>
|
|
5098
5623
|
function withRecursive_<
|
|
5099
5624
|
PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>,
|
|
5100
5625
|
Alias extends string
|
|
5101
5626
|
>(
|
|
5102
|
-
value:
|
|
5103
|
-
alias: Alias
|
|
5627
|
+
value: DerivedSourceCompatiblePlan<PlanValue>,
|
|
5628
|
+
alias: LiteralStringInput<Alias>
|
|
5104
5629
|
): import("../../internal/query.js").CteSource<PlanValue, Alias>
|
|
5105
5630
|
function withRecursive_(valueOrAlias: unknown, alias?: string): unknown {
|
|
5106
5631
|
if (alias === undefined) {
|
|
5107
|
-
return (value: unknown) => withRecursive_(value as any, valueOrAlias as
|
|
5632
|
+
return (value: unknown) => withRecursive_(value as any, valueOrAlias as never)
|
|
5108
5633
|
}
|
|
5109
5634
|
return makeCteSource(
|
|
5110
5635
|
valueOrAlias as CompletePlan<QueryPlan<any, any, any, any, any, any, any, any, any, any>>,
|
|
@@ -5116,20 +5641,20 @@ type AsCurriedResult<
|
|
|
5116
5641
|
function lateral<
|
|
5117
5642
|
Alias extends string
|
|
5118
5643
|
>(
|
|
5119
|
-
alias: Alias
|
|
5644
|
+
alias: LiteralStringInput<Alias>
|
|
5120
5645
|
): <PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
|
|
5121
|
-
value: PlanValue
|
|
5646
|
+
value: LateralSourceCompatiblePlan<PlanValue>
|
|
5122
5647
|
) => import("../../internal/query.js").LateralSource<PlanValue, Alias>
|
|
5123
5648
|
function lateral<
|
|
5124
5649
|
PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>,
|
|
5125
5650
|
Alias extends string
|
|
5126
5651
|
>(
|
|
5127
|
-
value: PlanValue
|
|
5128
|
-
alias: Alias
|
|
5652
|
+
value: LateralSourceCompatiblePlan<PlanValue>,
|
|
5653
|
+
alias: LiteralStringInput<Alias>
|
|
5129
5654
|
): import("../../internal/query.js").LateralSource<PlanValue, Alias>
|
|
5130
5655
|
function lateral(valueOrAlias: unknown, alias?: string): unknown {
|
|
5131
5656
|
if (alias === undefined) {
|
|
5132
|
-
return (value: unknown) => lateral(value as any, valueOrAlias as
|
|
5657
|
+
return (value: unknown) => lateral(value as any, valueOrAlias as never)
|
|
5133
5658
|
}
|
|
5134
5659
|
return makeLateralSource(
|
|
5135
5660
|
valueOrAlias as QueryPlan<any, any, any, any, any, any, any, any, any, any>,
|
|
@@ -5141,9 +5666,11 @@ type AsCurriedResult<
|
|
|
5141
5666
|
Rows extends ValuesRowsInput
|
|
5142
5667
|
>(
|
|
5143
5668
|
rows: Rows
|
|
5669
|
+
& ValuesRowsShapeInput<Rows>
|
|
5670
|
+
& ValuesRowsDialectInput<Rows, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
5144
5671
|
) => ValuesInput<
|
|
5145
5672
|
Rows,
|
|
5146
|
-
ValuesOutputShape<Rows
|
|
5673
|
+
ValuesOutputShape<Rows, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5147
5674
|
Dialect
|
|
5148
5675
|
>
|
|
5149
5676
|
|
|
@@ -5151,8 +5678,10 @@ type AsCurriedResult<
|
|
|
5151
5678
|
Columns extends UnnestColumnsInput,
|
|
5152
5679
|
Alias extends string
|
|
5153
5680
|
>(
|
|
5154
|
-
columns: Columns
|
|
5155
|
-
|
|
5681
|
+
columns: Columns
|
|
5682
|
+
& UnnestColumnsShapeInput<Columns>
|
|
5683
|
+
& UnnestColumnsDialectInput<Columns, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5684
|
+
alias: LiteralStringInput<Alias>
|
|
5156
5685
|
) => UnnestSource<
|
|
5157
5686
|
UnnestOutputShape<Columns, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5158
5687
|
Alias,
|
|
@@ -5165,10 +5694,10 @@ type AsCurriedResult<
|
|
|
5165
5694
|
Step extends NumericExpressionInput | undefined = undefined,
|
|
5166
5695
|
Alias extends string = "series"
|
|
5167
5696
|
>(
|
|
5168
|
-
start: Start,
|
|
5169
|
-
stop: Stop,
|
|
5170
|
-
step?: Step,
|
|
5171
|
-
alias?: Alias
|
|
5697
|
+
start: Start & NumericExpressionDialectInput<Start, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5698
|
+
stop: Stop & NumericExpressionDialectInput<Stop, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5699
|
+
step?: Step & (Step extends NumericExpressionInput ? NumericExpressionDialectInput<Step, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> : unknown),
|
|
5700
|
+
alias?: LiteralStringInput<Alias>
|
|
5172
5701
|
) => Dialect extends "postgres"
|
|
5173
5702
|
? TableFunctionSource<
|
|
5174
5703
|
GenerateSeriesOutputShape<Start, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
@@ -5179,12 +5708,15 @@ type AsCurriedResult<
|
|
|
5179
5708
|
: GenerateSeriesUnsupportedError<Dialect>
|
|
5180
5709
|
|
|
5181
5710
|
export type PublicGenerateSeriesApi = <
|
|
5711
|
+
Start extends NumericExpressionInput,
|
|
5712
|
+
Stop extends NumericExpressionInput,
|
|
5713
|
+
Step extends NumericExpressionInput | undefined = undefined,
|
|
5182
5714
|
Alias extends string = "series"
|
|
5183
5715
|
>(
|
|
5184
|
-
start:
|
|
5185
|
-
stop:
|
|
5186
|
-
step?: NumericExpressionInput,
|
|
5187
|
-
alias?: Alias
|
|
5716
|
+
start: Start & NumericExpressionDialectInput<Start, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5717
|
+
stop: Stop & NumericExpressionDialectInput<Stop, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5718
|
+
step?: Step & (Step extends NumericExpressionInput ? NumericExpressionDialectInput<Step, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> : unknown),
|
|
5719
|
+
alias?: LiteralStringInput<Alias>
|
|
5188
5720
|
) => TableFunctionSource<
|
|
5189
5721
|
{
|
|
5190
5722
|
readonly value: Expression.Scalar<number, NumericDb, "never", Dialect, "scalar", never, string>
|
|
@@ -5194,8 +5726,36 @@ type AsCurriedResult<
|
|
|
5194
5726
|
"generate_series"
|
|
5195
5727
|
>
|
|
5196
5728
|
|
|
5197
|
-
|
|
5198
|
-
|
|
5729
|
+
type SelectionRootObjectError<Selection> = Selection & {
|
|
5730
|
+
readonly __effect_qb_error__: "effect-qb: selections must be projection objects"
|
|
5731
|
+
readonly __effect_qb_hint__: "Use select({ value: expression }) or returning({ value: expression })"
|
|
5732
|
+
}
|
|
5733
|
+
|
|
5734
|
+
type SelectionRootObjectConstraint<Selection> =
|
|
5735
|
+
Selection extends Expression.Any ? SelectionRootObjectError<Selection> : unknown
|
|
5736
|
+
|
|
5737
|
+
type SelectionNestedEmptyError<Selection> = Selection & {
|
|
5738
|
+
readonly __effect_qb_error__: "effect-qb: projection objects cannot contain empty nested selections"
|
|
5739
|
+
}
|
|
5740
|
+
|
|
5741
|
+
type SelectionHasEmptyNestedObject<Selection, IsRoot extends boolean> =
|
|
5742
|
+
Selection extends Expression.Any
|
|
5743
|
+
? false
|
|
5744
|
+
: Selection extends Record<string, any>
|
|
5745
|
+
? [Extract<keyof Selection, string>] extends [never]
|
|
5746
|
+
? IsRoot extends true ? false : true
|
|
5747
|
+
: true extends {
|
|
5748
|
+
[K in Extract<keyof Selection, string>]: SelectionHasEmptyNestedObject<Selection[K], false>
|
|
5749
|
+
}[Extract<keyof Selection, string>]
|
|
5750
|
+
? true
|
|
5751
|
+
: false
|
|
5752
|
+
: false
|
|
5753
|
+
|
|
5754
|
+
type SelectionNestedNonEmptyConstraint<Selection> =
|
|
5755
|
+
SelectionHasEmptyNestedObject<Selection, true> extends true ? SelectionNestedEmptyError<Selection> : unknown
|
|
5756
|
+
|
|
5757
|
+
export type SelectApi = <const Selection extends SelectionShape = {}>(
|
|
5758
|
+
selection?: Selection & SelectionRootObjectConstraint<Selection> & SelectionNestedNonEmptyConstraint<Selection> & SelectionProjectionAliasCollisionConstraint<Selection>
|
|
5199
5759
|
) => QueryPlan<
|
|
5200
5760
|
Selection,
|
|
5201
5761
|
ExtractRequired<Selection>,
|
|
@@ -5254,7 +5814,10 @@ type AsCurriedResult<
|
|
|
5254
5814
|
never,
|
|
5255
5815
|
TrueFormula,
|
|
5256
5816
|
CapabilitiesOfPlan<LeftPlanValue> | CapabilitiesOfPlan<RightPlanValue>,
|
|
5257
|
-
"set"
|
|
5817
|
+
"set",
|
|
5818
|
+
any,
|
|
5819
|
+
"ready",
|
|
5820
|
+
CommonSetFacts<LeftPlanValue, RightPlanValue>
|
|
5258
5821
|
>
|
|
5259
5822
|
|
|
5260
5823
|
type SetOperationApi = <
|
|
@@ -5322,10 +5885,10 @@ type AsCurriedResult<
|
|
|
5322
5885
|
keyof AvailableOfPlan<PlanValue> extends never ? never : unknown
|
|
5323
5886
|
) & (
|
|
5324
5887
|
SourceNameOf<CurrentTable> extends ScopedNamesOfPlan<PlanValue> ? never : unknown
|
|
5325
|
-
)
|
|
5888
|
+
) & SourceRequirementConstraint<PlanValue, CurrentTable> & SourceDialectConstraint<CurrentTable, Dialect>
|
|
5326
5889
|
) => QueryPlan<
|
|
5327
5890
|
SelectionOfPlan<PlanValue>,
|
|
5328
|
-
AddJoinRequired<RequiredOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, never, "cross"
|
|
5891
|
+
AddJoinRequired<RequiredOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, never, "cross", SourceRequiredOf<CurrentTable>>,
|
|
5329
5892
|
AddAvailable<
|
|
5330
5893
|
AvailableOfPlan<PlanValue>,
|
|
5331
5894
|
SourceNameOf<CurrentTable>,
|
|
@@ -5336,10 +5899,13 @@ type AsCurriedResult<
|
|
|
5336
5899
|
PlanDialectOf<PlanValue> | SourceDialectOf<CurrentTable>,
|
|
5337
5900
|
GroupedOfPlan<PlanValue>,
|
|
5338
5901
|
ScopedNamesOfPlan<PlanValue> | SourceNameOf<CurrentTable>,
|
|
5339
|
-
AddJoinRequired<OutstandingOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, never, "cross"
|
|
5902
|
+
AddJoinRequired<OutstandingOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, never, "cross", SourceRequiredOf<CurrentTable>>,
|
|
5340
5903
|
AssumptionsOfPlan<PlanValue>,
|
|
5341
5904
|
MergeCapabilities<CapabilitiesOfPlan<PlanValue>, SourceCapabilitiesOf<CurrentTable>>,
|
|
5342
|
-
StatementOfPlan<PlanValue
|
|
5905
|
+
StatementOfPlan<PlanValue>,
|
|
5906
|
+
MutationTargetOfPlan<PlanValue>,
|
|
5907
|
+
InsertSourceStateOfPlan<PlanValue>,
|
|
5908
|
+
FactsOfPlan<PlanValue>
|
|
5343
5909
|
>
|
|
5344
5910
|
|
|
5345
5911
|
type JoinApi = <
|
|
@@ -5356,10 +5922,10 @@ type AsCurriedResult<
|
|
|
5356
5922
|
keyof AvailableOfPlan<PlanValue> extends never ? never : unknown
|
|
5357
5923
|
) & (
|
|
5358
5924
|
SourceNameOf<CurrentTable> extends ScopedNamesOfPlan<PlanValue> ? never : unknown
|
|
5359
|
-
)
|
|
5925
|
+
) & SourceRequirementConstraint<PlanValue, CurrentTable> & SourceDialectConstraint<CurrentTable, Dialect>
|
|
5360
5926
|
) => QueryPlan<
|
|
5361
5927
|
SelectionOfPlan<PlanValue>,
|
|
5362
|
-
AddJoinRequired<RequiredOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, Predicate, Kind
|
|
5928
|
+
AddJoinRequired<RequiredOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, Predicate, Kind, SourceRequiredOf<CurrentTable>>,
|
|
5363
5929
|
AvailableAfterJoin<
|
|
5364
5930
|
AvailableOfPlan<PlanValue>,
|
|
5365
5931
|
SourceNameOf<CurrentTable>,
|
|
@@ -5370,7 +5936,7 @@ type AsCurriedResult<
|
|
|
5370
5936
|
PlanDialectOf<PlanValue> | SourceDialectOf<CurrentTable> | DialectOfDialectInput<Predicate, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5371
5937
|
GroupedOfPlan<PlanValue>,
|
|
5372
5938
|
ScopedNamesOfPlan<PlanValue> | SourceNameOf<CurrentTable>,
|
|
5373
|
-
AddJoinRequired<OutstandingOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, Predicate, Kind
|
|
5939
|
+
AddJoinRequired<OutstandingOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, Predicate, Kind, SourceRequiredOf<CurrentTable>>,
|
|
5374
5940
|
PlanAssumptionsAfterJoin<PlanValue, Predicate, Kind, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5375
5941
|
MergeCapabilities<CapabilitiesOfPlan<PlanValue>, SourceCapabilitiesOf<CurrentTable>>,
|
|
5376
5942
|
StatementOfPlan<PlanValue>,
|
|
@@ -5391,10 +5957,10 @@ type AsCurriedResult<
|
|
|
5391
5957
|
keyof AvailableOfPlan<PlanValue> extends never ? never : unknown
|
|
5392
5958
|
) & (
|
|
5393
5959
|
SourceNameOf<CurrentTable> extends ScopedNamesOfPlan<PlanValue> ? never : unknown
|
|
5394
|
-
)
|
|
5960
|
+
) & SourceRequirementConstraint<PlanValue, CurrentTable> & SourceDialectConstraint<CurrentTable, Dialect>
|
|
5395
5961
|
) => QueryPlan<
|
|
5396
5962
|
SelectionOfPlan<PlanValue>,
|
|
5397
|
-
AddJoinRequired<RequiredOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, Predicate, Kind
|
|
5963
|
+
AddJoinRequired<RequiredOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, Predicate, Kind, SourceRequiredOf<CurrentTable>>,
|
|
5398
5964
|
AvailableAfterJoin<
|
|
5399
5965
|
AvailableOfPlan<PlanValue>,
|
|
5400
5966
|
SourceNameOf<CurrentTable>,
|
|
@@ -5405,7 +5971,7 @@ type AsCurriedResult<
|
|
|
5405
5971
|
PlanDialectOf<PlanValue> | SourceDialectOf<CurrentTable> | DialectOfDialectInput<Predicate, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5406
5972
|
GroupedOfPlan<PlanValue>,
|
|
5407
5973
|
ScopedNamesOfPlan<PlanValue> | SourceNameOf<CurrentTable>,
|
|
5408
|
-
AddJoinRequired<OutstandingOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, Predicate, Kind
|
|
5974
|
+
AddJoinRequired<OutstandingOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, Predicate, Kind, SourceRequiredOf<CurrentTable>>,
|
|
5409
5975
|
PlanAssumptionsAfterJoin<PlanValue, Predicate, Kind, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5410
5976
|
MergeCapabilities<CapabilitiesOfPlan<PlanValue>, SourceCapabilitiesOf<CurrentTable>>,
|
|
5411
5977
|
StatementOfPlan<PlanValue>,
|
|
@@ -5613,18 +6179,18 @@ type AsCurriedResult<
|
|
|
5613
6179
|
|
|
5614
6180
|
const fullJoin = ((table, on) => (join as any)("full", table, on)) as BinaryJoinApi<"full">
|
|
5615
6181
|
|
|
5616
|
-
const distinctOn = (
|
|
6182
|
+
const distinctOn = (<Values extends readonly [ExpressionInput, ...ExpressionInput[]]>(...values: Values) => {
|
|
5617
6183
|
const expressions = values.map((value) => toDialectExpression(value)) as Expression.Any[]
|
|
5618
6184
|
return <PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
|
|
5619
6185
|
plan: PlanValue & RequireSelectStatement<PlanValue>
|
|
5620
6186
|
): QueryPlan<
|
|
5621
6187
|
SelectionOfPlan<PlanValue>,
|
|
5622
|
-
RequiredOfPlan<PlanValue>,
|
|
6188
|
+
AddExpressionRequired<RequiredOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, Values[number]>,
|
|
5623
6189
|
AvailableOfPlan<PlanValue>,
|
|
5624
|
-
PlanDialectOf<PlanValue>,
|
|
6190
|
+
PlanDialectOf<PlanValue> | DialectOfDialectInput<Values[number], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5625
6191
|
GroupedOfPlan<PlanValue>,
|
|
5626
6192
|
ScopedNamesOfPlan<PlanValue>,
|
|
5627
|
-
OutstandingOfPlan<PlanValue>,
|
|
6193
|
+
AddExpressionRequired<OutstandingOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, Values[number]>,
|
|
5628
6194
|
AssumptionsOfPlan<PlanValue>,
|
|
5629
6195
|
CapabilitiesOfPlan<PlanValue>,
|
|
5630
6196
|
StatementOfPlan<PlanValue>
|
|
@@ -5632,11 +6198,13 @@ type AsCurriedResult<
|
|
|
5632
6198
|
const current = plan[Plan.TypeId]
|
|
5633
6199
|
const currentAst = getAst(plan)
|
|
5634
6200
|
const currentQuery = getQueryState(plan)
|
|
6201
|
+
const required = values.flatMap((value) => extractRequiredFromDialectInputRuntime(value))
|
|
5635
6202
|
return makePlan({
|
|
5636
6203
|
selection: current.selection,
|
|
5637
|
-
required: current.required
|
|
6204
|
+
required: [...currentRequiredList(current.required), ...required].filter((name, index, list) =>
|
|
6205
|
+
!(name in current.available) && list.indexOf(name) === index) as AddExpressionRequired<RequiredOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, Values[number]>,
|
|
5638
6206
|
available: current.available,
|
|
5639
|
-
dialect: current.dialect as PlanDialectOf<PlanValue>
|
|
6207
|
+
dialect: current.dialect as PlanDialectOf<PlanValue> | DialectOfDialectInput<Values[number], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
5640
6208
|
}, {
|
|
5641
6209
|
...currentAst,
|
|
5642
6210
|
distinct: true,
|
|
@@ -5666,8 +6234,19 @@ type AsCurriedResult<
|
|
|
5666
6234
|
FactsOfPlan<PlanValue>
|
|
5667
6235
|
>
|
|
5668
6236
|
|
|
5669
|
-
type
|
|
5670
|
-
|
|
6237
|
+
type ReturningSelectionNonEmptyError<Selection> = Selection & {
|
|
6238
|
+
readonly __effect_qb_error__: "effect-qb: returning(...) requires at least one selected expression"
|
|
6239
|
+
}
|
|
6240
|
+
|
|
6241
|
+
type ReturningSelectionNonEmptyConstraint<Selection> =
|
|
6242
|
+
Selection extends Expression.Any
|
|
6243
|
+
? unknown
|
|
6244
|
+
: [Extract<keyof Selection, string>] extends [never]
|
|
6245
|
+
? ReturningSelectionNonEmptyError<Selection>
|
|
6246
|
+
: unknown
|
|
6247
|
+
|
|
6248
|
+
type ReturningApi = <const Selection extends SelectionShape>(
|
|
6249
|
+
selection: Selection & SelectionRootObjectConstraint<Selection> & SelectionNestedNonEmptyConstraint<Selection> & ReturningSelectionNonEmptyConstraint<Selection> & SelectionProjectionAliasCollisionConstraint<Selection>
|
|
5671
6250
|
) =>
|
|
5672
6251
|
<PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
|
|
5673
6252
|
plan: PlanValue & RequireMutationStatement<PlanValue>
|
|
@@ -5707,12 +6286,12 @@ type AsCurriedResult<
|
|
|
5707
6286
|
>
|
|
5708
6287
|
<Target extends MutationTargetLike, Values extends Record<string, unknown>>(
|
|
5709
6288
|
target: Target,
|
|
5710
|
-
values: MutationValuesInput<"insert", Target, Values>
|
|
6289
|
+
values: MutationValuesInput<"insert", Target, Values> & MutationValuesDialectConstraint<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
5711
6290
|
): QueryPlan<
|
|
5712
6291
|
{},
|
|
5713
6292
|
Exclude<MutationRequiredFromValues<Values>, SourceNameOf<Target>>,
|
|
5714
6293
|
AddAvailable<{}, SourceNameOf<Target>>,
|
|
5715
|
-
TableDialectOf<Target>,
|
|
6294
|
+
TableDialectOf<Target> | KnownMutationDialectFromValues<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5716
6295
|
never,
|
|
5717
6296
|
SourceNameOf<Target>,
|
|
5718
6297
|
Exclude<MutationRequiredFromValues<Values>, SourceNameOf<Target>>,
|
|
@@ -5734,21 +6313,22 @@ type AsCurriedResult<
|
|
|
5734
6313
|
Target extends MutationTargetLike,
|
|
5735
6314
|
const Columns extends DdlColumnInput,
|
|
5736
6315
|
UpdateValues extends MutationInputOf<Table.UpdateOf<Target>> | undefined = MutationInputOf<Table.UpdateOf<Target>> | undefined,
|
|
5737
|
-
Options extends ConflictActionInput<Target, Dialect, UpdateValues> = ConflictActionInput<Target, Dialect, UpdateValues
|
|
6316
|
+
Options extends ConflictActionInput<Target, Dialect, UpdateValues> = ConflictActionInput<Target, Dialect, UpdateValues>,
|
|
6317
|
+
const ConflictTarget extends ConflictTargetInput<Target, Dialect, Columns> = ConflictTargetInput<Target, Dialect, Columns>
|
|
5738
6318
|
>(
|
|
5739
|
-
target:
|
|
5740
|
-
options?: Options
|
|
6319
|
+
target: ConflictTarget & ConflictConstraintNameConstraint<ConflictTarget>,
|
|
6320
|
+
options?: Options & ConflictActionUpdateNonEmptyConstraint<Options>
|
|
5741
6321
|
) =>
|
|
5742
6322
|
<PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
|
|
5743
6323
|
plan: PlanValue & RequireInsertStatement<PlanValue>
|
|
5744
6324
|
) => QueryPlan<
|
|
5745
6325
|
SelectionOfPlan<PlanValue>,
|
|
5746
|
-
Exclude<RequiredOfPlan<PlanValue> |
|
|
6326
|
+
Exclude<RequiredOfPlan<PlanValue> | ConflictRequired<UpdateValues, Options, ConflictTarget>, AvailableNames<AvailableOfPlan<PlanValue>>>,
|
|
5747
6327
|
AvailableOfPlan<PlanValue>,
|
|
5748
|
-
PlanDialectOf<PlanValue>,
|
|
6328
|
+
PlanDialectOf<PlanValue> | ConflictDialect<UpdateValues, Options, ConflictTarget, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5749
6329
|
GroupedOfPlan<PlanValue>,
|
|
5750
6330
|
ScopedNamesOfPlan<PlanValue>,
|
|
5751
|
-
Exclude<OutstandingOfPlan<PlanValue> |
|
|
6331
|
+
Exclude<OutstandingOfPlan<PlanValue> | ConflictRequired<UpdateValues, Options, ConflictTarget>, AvailableNames<AvailableOfPlan<PlanValue>>>,
|
|
5752
6332
|
AssumptionsOfPlan<PlanValue>,
|
|
5753
6333
|
CapabilitiesOfPlan<PlanValue>,
|
|
5754
6334
|
StatementOfPlan<PlanValue>,
|
|
@@ -5759,13 +6339,13 @@ type AsCurriedResult<
|
|
|
5759
6339
|
|
|
5760
6340
|
interface UpdateApi {
|
|
5761
6341
|
<Targets extends MutationTargetTuple, Values extends UpdateInputOfTarget<Targets>>(
|
|
5762
|
-
target: Dialect extends "mysql" ? Targets : never,
|
|
5763
|
-
values: Values
|
|
6342
|
+
target: Dialect extends "mysql" ? Targets & MutationTargetTupleDialectConstraint<Targets, Dialect> : never,
|
|
6343
|
+
values: Values & NestedUpdateValuesNonEmptyConstraint<Values> & MutationValuesDialectConstraint<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
5764
6344
|
): QueryPlan<
|
|
5765
6345
|
{},
|
|
5766
6346
|
Exclude<NestedMutationRequiredFromValues<Values>, MutationTargetNamesOf<Targets>>,
|
|
5767
6347
|
AddAvailableMany<{}, MutationTargetNamesOf<Targets>>,
|
|
5768
|
-
TableDialectOf<Targets[0]>,
|
|
6348
|
+
TableDialectOf<Targets[0]> | KnownMutationDialectFromValues<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5769
6349
|
never,
|
|
5770
6350
|
MutationTargetNamesOf<Targets>,
|
|
5771
6351
|
Exclude<NestedMutationRequiredFromValues<Values>, MutationTargetNamesOf<Targets>>,
|
|
@@ -5778,12 +6358,12 @@ type AsCurriedResult<
|
|
|
5778
6358
|
>
|
|
5779
6359
|
<Target extends MutationTargetLike, Values extends Record<string, unknown>>(
|
|
5780
6360
|
target: Target,
|
|
5781
|
-
values: MutationValuesInput<"update", Target, Values>
|
|
6361
|
+
values: MutationValuesInput<"update", Target, Values> & UpdateValuesNonEmptyConstraint<Values> & MutationValuesDialectConstraint<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
5782
6362
|
): QueryPlan<
|
|
5783
6363
|
{},
|
|
5784
6364
|
Exclude<MutationRequiredFromValues<Values>, SourceNameOf<Target>>,
|
|
5785
6365
|
AddAvailable<{}, SourceNameOf<Target>>,
|
|
5786
|
-
TableDialectOf<Target>,
|
|
6366
|
+
TableDialectOf<Target> | KnownMutationDialectFromValues<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5787
6367
|
never,
|
|
5788
6368
|
SourceNameOf<Target>,
|
|
5789
6369
|
Exclude<MutationRequiredFromValues<Values>, SourceNameOf<Target>>,
|
|
@@ -5800,20 +6380,22 @@ type AsCurriedResult<
|
|
|
5800
6380
|
Target extends MutationTargetLike,
|
|
5801
6381
|
Values extends MutationInputOf<Table.InsertOf<Target>>,
|
|
5802
6382
|
const Columns extends DdlColumnInput,
|
|
5803
|
-
UpdateValues extends MutationInputOf<Table.UpdateOf<Target>>
|
|
6383
|
+
UpdateValues extends MutationInputOf<Table.UpdateOf<Target>> | undefined = undefined
|
|
5804
6384
|
>(
|
|
5805
6385
|
target: Target,
|
|
5806
|
-
values: Values,
|
|
5807
|
-
conflictColumns:
|
|
5808
|
-
updateValues?: UpdateValues
|
|
6386
|
+
values: Values & MutationValuesDialectConstraint<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
6387
|
+
conflictColumns: ValidateTargetColumnInput<Target, Columns>,
|
|
6388
|
+
updateValues?: UpdateValues & UpdateValuesNonEmptyConstraint<Exclude<UpdateValues, undefined>> & MutationValuesDialectConstraint<Exclude<UpdateValues, undefined>, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
5809
6389
|
) => QueryPlan<
|
|
5810
6390
|
{},
|
|
5811
|
-
Exclude<MutationRequiredFromValues<Values> | MutationRequiredFromValues<UpdateValues
|
|
6391
|
+
Exclude<MutationRequiredFromValues<Values> | MutationRequiredFromValues<Exclude<UpdateValues, undefined>>, SourceNameOf<Target>>,
|
|
5812
6392
|
AddAvailable<{}, SourceNameOf<Target>>,
|
|
5813
|
-
TableDialectOf<Target
|
|
6393
|
+
| TableDialectOf<Target>
|
|
6394
|
+
| KnownMutationDialectFromValues<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
6395
|
+
| KnownMutationDialectFromValues<Exclude<UpdateValues, undefined>, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5814
6396
|
never,
|
|
5815
6397
|
SourceNameOf<Target>,
|
|
5816
|
-
Exclude<MutationRequiredFromValues<Values> | MutationRequiredFromValues<UpdateValues
|
|
6398
|
+
Exclude<MutationRequiredFromValues<Values> | MutationRequiredFromValues<Exclude<UpdateValues, undefined>>, SourceNameOf<Target>>,
|
|
5817
6399
|
TrueFormula,
|
|
5818
6400
|
"write",
|
|
5819
6401
|
"insert",
|
|
@@ -5841,7 +6423,7 @@ type AsCurriedResult<
|
|
|
5841
6423
|
EmptyFacts
|
|
5842
6424
|
>
|
|
5843
6425
|
<Targets extends MutationTargetTuple>(
|
|
5844
|
-
target: Dialect extends "mysql" ? Targets : never
|
|
6426
|
+
target: Dialect extends "mysql" ? Targets & MutationTargetTupleDialectConstraint<Targets, Dialect> : never
|
|
5845
6427
|
): QueryPlan<
|
|
5846
6428
|
{},
|
|
5847
6429
|
never,
|
|
@@ -5890,9 +6472,9 @@ type AsCurriedResult<
|
|
|
5890
6472
|
target: Target,
|
|
5891
6473
|
source: Source & (
|
|
5892
6474
|
SourceRequiredOf<Source> extends never ? unknown : SourceRequirementError<Source>
|
|
5893
|
-
),
|
|
6475
|
+
) & SourceDialectConstraint<Source, Dialect> & MergeSourceNameConstraint<Target, Source>,
|
|
5894
6476
|
on: On,
|
|
5895
|
-
options
|
|
6477
|
+
options: MergeOptions<Target, MatchedValues, InsertValues, MatchedPredicate, NotMatchedPredicate>
|
|
5896
6478
|
) => QueryPlan<
|
|
5897
6479
|
{},
|
|
5898
6480
|
Exclude<
|
|
@@ -5936,6 +6518,7 @@ type AsCurriedResult<
|
|
|
5936
6518
|
>
|
|
5937
6519
|
|
|
5938
6520
|
const mutationRuntime = makeDslMutationRuntime({
|
|
6521
|
+
profile,
|
|
5939
6522
|
makePlan,
|
|
5940
6523
|
getAst,
|
|
5941
6524
|
getQueryState,
|
|
@@ -5948,7 +6531,7 @@ type AsCurriedResult<
|
|
|
5948
6531
|
buildConflictTarget,
|
|
5949
6532
|
mutationTargetClauses,
|
|
5950
6533
|
mutationAvailableSources,
|
|
5951
|
-
|
|
6534
|
+
normalizeConflictColumns,
|
|
5952
6535
|
targetSourceDetails,
|
|
5953
6536
|
sourceDetails
|
|
5954
6537
|
})
|
|
@@ -5964,63 +6547,21 @@ type AsCurriedResult<
|
|
|
5964
6547
|
): QueryPlan<any, any, any, any, any, any, any, any, any, "insert", MutationTargetLike, "ready"> =>
|
|
5965
6548
|
mutationRuntime.attachInsertSource(plan, source)
|
|
5966
6549
|
|
|
5967
|
-
const onConflict:
|
|
5968
|
-
|
|
5969
|
-
|
|
5970
|
-
UpdateValues extends MutationInputOf<Table.UpdateOf<Target>> | undefined = MutationInputOf<Table.UpdateOf<Target>> | undefined,
|
|
5971
|
-
Options extends ConflictActionInput<Target, Dialect, UpdateValues> = ConflictActionInput<Target, Dialect, UpdateValues>
|
|
5972
|
-
>(
|
|
5973
|
-
target: ConflictTargetInput<Target, Dialect, Columns>,
|
|
5974
|
-
options: Options = {} as Options
|
|
5975
|
-
) =>
|
|
5976
|
-
<PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
|
|
5977
|
-
plan: PlanValue & RequireInsertStatement<PlanValue>
|
|
5978
|
-
): QueryPlan<
|
|
5979
|
-
SelectionOfPlan<PlanValue>,
|
|
5980
|
-
Exclude<RequiredOfPlan<PlanValue> | MutationRequiredFromValues<Exclude<UpdateValues, undefined>> | RequiredFromInput<Extract<Options["where"], PredicateInput>>, AvailableNames<AvailableOfPlan<PlanValue>>>,
|
|
5981
|
-
AvailableOfPlan<PlanValue>,
|
|
5982
|
-
PlanDialectOf<PlanValue>,
|
|
5983
|
-
GroupedOfPlan<PlanValue>,
|
|
5984
|
-
ScopedNamesOfPlan<PlanValue>,
|
|
5985
|
-
Exclude<OutstandingOfPlan<PlanValue> | MutationRequiredFromValues<Exclude<UpdateValues, undefined>> | RequiredFromInput<Extract<Options["where"], PredicateInput>>, AvailableNames<AvailableOfPlan<PlanValue>>>,
|
|
5986
|
-
AssumptionsOfPlan<PlanValue>,
|
|
5987
|
-
CapabilitiesOfPlan<PlanValue>,
|
|
5988
|
-
StatementOfPlan<PlanValue>,
|
|
5989
|
-
MutationTargetOfPlan<PlanValue>,
|
|
5990
|
-
InsertSourceStateOfPlan<PlanValue>,
|
|
5991
|
-
FactsOfPlan<PlanValue>
|
|
5992
|
-
> => mutationRuntime.onConflict(target, options)(plan)
|
|
6550
|
+
const onConflict = ((target: unknown, options: unknown = {}) =>
|
|
6551
|
+
(plan: QueryPlan<any, any, any, any, any, any, any, any, any, any>) =>
|
|
6552
|
+
mutationRuntime.onConflict(target, options)(plan)) as OnConflictApi
|
|
5993
6553
|
|
|
5994
6554
|
const update: UpdateApi = ((
|
|
5995
6555
|
target: MutationTargetInput,
|
|
5996
6556
|
values: Record<string, unknown>
|
|
5997
6557
|
) => mutationRuntime.update(target, values)) as UpdateApi
|
|
5998
6558
|
|
|
5999
|
-
const upsert
|
|
6000
|
-
|
|
6001
|
-
|
|
6002
|
-
|
|
6003
|
-
|
|
6004
|
-
|
|
6005
|
-
target: Target,
|
|
6006
|
-
values: Values,
|
|
6007
|
-
conflictColumns: ValidateTargetColumns<Target, NormalizeDdlColumns<Columns>>,
|
|
6008
|
-
updateValues?: UpdateValues
|
|
6009
|
-
): QueryPlan<
|
|
6010
|
-
{},
|
|
6011
|
-
Exclude<MutationRequiredFromValues<Values> | MutationRequiredFromValues<UpdateValues>, SourceNameOf<Target>>,
|
|
6012
|
-
AddAvailable<{}, SourceNameOf<Target>>,
|
|
6013
|
-
TableDialectOf<Target>,
|
|
6014
|
-
never,
|
|
6015
|
-
SourceNameOf<Target>,
|
|
6016
|
-
Exclude<MutationRequiredFromValues<Values> | MutationRequiredFromValues<UpdateValues>, SourceNameOf<Target>>,
|
|
6017
|
-
TrueFormula,
|
|
6018
|
-
"write",
|
|
6019
|
-
"insert",
|
|
6020
|
-
Target,
|
|
6021
|
-
"ready",
|
|
6022
|
-
EmptyFacts
|
|
6023
|
-
> => mutationRuntime.upsert(target, values, conflictColumns as string | readonly string[], updateValues)
|
|
6559
|
+
const upsert = ((
|
|
6560
|
+
target: MutationTargetLike,
|
|
6561
|
+
values: Record<string, unknown>,
|
|
6562
|
+
conflictColumns: DdlColumnInput,
|
|
6563
|
+
updateValues?: Record<string, unknown>
|
|
6564
|
+
) => mutationRuntime.upsert(target, values, conflictColumns as string | readonly string[], updateValues)) as UpsertApi
|
|
6024
6565
|
|
|
6025
6566
|
const delete_: DeleteApi = ((
|
|
6026
6567
|
target: MutationTargetInput
|
|
@@ -6047,62 +6588,12 @@ type AsCurriedResult<
|
|
|
6047
6588
|
EmptyFacts
|
|
6048
6589
|
> => mutationRuntime.truncate(target, options)
|
|
6049
6590
|
|
|
6050
|
-
const merge
|
|
6051
|
-
|
|
6052
|
-
|
|
6053
|
-
|
|
6054
|
-
|
|
6055
|
-
|
|
6056
|
-
MatchedPredicate extends PredicateInput | undefined = undefined,
|
|
6057
|
-
NotMatchedPredicate extends PredicateInput | undefined = undefined
|
|
6058
|
-
>(
|
|
6059
|
-
target: Target,
|
|
6060
|
-
source: Source & (
|
|
6061
|
-
SourceRequiredOf<Source> extends never ? unknown : SourceRequirementError<Source>
|
|
6062
|
-
),
|
|
6063
|
-
on: On,
|
|
6064
|
-
options: MergeOptions<Target, MatchedValues, InsertValues, MatchedPredicate, NotMatchedPredicate> = {}
|
|
6065
|
-
): QueryPlan<
|
|
6066
|
-
{},
|
|
6067
|
-
Exclude<
|
|
6068
|
-
AddExpressionRequired<
|
|
6069
|
-
MergeRequiredFromPredicate<
|
|
6070
|
-
MatchedPredicate,
|
|
6071
|
-
AddAvailable<AddAvailable<{}, SourceNameOf<Target>>, SourceNameOf<Source>>
|
|
6072
|
-
> | MergeRequiredFromPredicate<
|
|
6073
|
-
NotMatchedPredicate,
|
|
6074
|
-
AddAvailable<AddAvailable<{}, SourceNameOf<Target>>, SourceNameOf<Source>>
|
|
6075
|
-
> | MutationRequiredFromValues<MatchedValues> | MutationRequiredFromValues<InsertValues>,
|
|
6076
|
-
AddAvailable<AddAvailable<{}, SourceNameOf<Target>>, SourceNameOf<Source>>,
|
|
6077
|
-
On
|
|
6078
|
-
>,
|
|
6079
|
-
SourceNameOf<Target> | SourceNameOf<Source>
|
|
6080
|
-
>,
|
|
6081
|
-
AddAvailable<AddAvailable<{}, SourceNameOf<Target>>, SourceNameOf<Source>>,
|
|
6082
|
-
TableDialectOf<Target> | SourceDialectOf<Source>,
|
|
6083
|
-
never,
|
|
6084
|
-
SourceNameOf<Target> | SourceNameOf<Source>,
|
|
6085
|
-
Exclude<
|
|
6086
|
-
AddExpressionRequired<
|
|
6087
|
-
MergeRequiredFromPredicate<
|
|
6088
|
-
MatchedPredicate,
|
|
6089
|
-
AddAvailable<AddAvailable<{}, SourceNameOf<Target>>, SourceNameOf<Source>>
|
|
6090
|
-
> | MergeRequiredFromPredicate<
|
|
6091
|
-
NotMatchedPredicate,
|
|
6092
|
-
AddAvailable<AddAvailable<{}, SourceNameOf<Target>>, SourceNameOf<Source>>
|
|
6093
|
-
> | MutationRequiredFromValues<MatchedValues> | MutationRequiredFromValues<InsertValues>,
|
|
6094
|
-
AddAvailable<AddAvailable<{}, SourceNameOf<Target>>, SourceNameOf<Source>>,
|
|
6095
|
-
On
|
|
6096
|
-
>,
|
|
6097
|
-
SourceNameOf<Target> | SourceNameOf<Source>
|
|
6098
|
-
>,
|
|
6099
|
-
TrueFormula,
|
|
6100
|
-
MergeCapabilities<"write", SourceCapabilitiesOf<Source>>,
|
|
6101
|
-
"merge",
|
|
6102
|
-
any,
|
|
6103
|
-
"ready",
|
|
6104
|
-
EmptyFacts
|
|
6105
|
-
> => mutationRuntime.merge(target, source, on, options)
|
|
6591
|
+
const merge = ((
|
|
6592
|
+
target: MutationTargetLike,
|
|
6593
|
+
source: SourceLike,
|
|
6594
|
+
on: PredicateInput,
|
|
6595
|
+
options: Record<string, unknown>
|
|
6596
|
+
) => mutationRuntime.merge(target, source, on, options)) as MergeApi
|
|
6106
6597
|
|
|
6107
6598
|
type TransactionApi = (options?: TransactionOptions) => QueryPlan<
|
|
6108
6599
|
{},
|
|
@@ -6143,7 +6634,7 @@ type AsCurriedResult<
|
|
|
6143
6634
|
"rollback"
|
|
6144
6635
|
>
|
|
6145
6636
|
|
|
6146
|
-
type SavepointApi = <Name extends string>(name: Name) => QueryPlan<
|
|
6637
|
+
type SavepointApi = <Name extends string>(name: NonEmptyStringInput<Name>) => QueryPlan<
|
|
6147
6638
|
{},
|
|
6148
6639
|
never,
|
|
6149
6640
|
{},
|
|
@@ -6156,7 +6647,7 @@ type AsCurriedResult<
|
|
|
6156
6647
|
"savepoint"
|
|
6157
6648
|
>
|
|
6158
6649
|
|
|
6159
|
-
type RollbackToApi = <Name extends string>(name: Name) => QueryPlan<
|
|
6650
|
+
type RollbackToApi = <Name extends string>(name: NonEmptyStringInput<Name>) => QueryPlan<
|
|
6160
6651
|
{},
|
|
6161
6652
|
never,
|
|
6162
6653
|
{},
|
|
@@ -6169,7 +6660,7 @@ type AsCurriedResult<
|
|
|
6169
6660
|
"rollbackTo"
|
|
6170
6661
|
>
|
|
6171
6662
|
|
|
6172
|
-
type ReleaseSavepointApi = <Name extends string>(name: Name) => QueryPlan<
|
|
6663
|
+
type ReleaseSavepointApi = <Name extends string>(name: NonEmptyStringInput<Name>) => QueryPlan<
|
|
6173
6664
|
{},
|
|
6174
6665
|
never,
|
|
6175
6666
|
{},
|
|
@@ -6214,10 +6705,10 @@ type AsCurriedResult<
|
|
|
6214
6705
|
"dropTable"
|
|
6215
6706
|
>
|
|
6216
6707
|
|
|
6217
|
-
type CreateIndexApi = <Target extends SchemaTableLike, const Columns extends DdlColumnInput>(
|
|
6708
|
+
type CreateIndexApi = <Target extends SchemaTableLike, const Columns extends DdlColumnInput, Name extends string = string>(
|
|
6218
6709
|
target: Target,
|
|
6219
|
-
columns: Columns &
|
|
6220
|
-
options?: CreateIndexOptions
|
|
6710
|
+
columns: Columns & ValidateDdlColumnInput<Target, Columns>,
|
|
6711
|
+
options?: CreateIndexOptions<Name>
|
|
6221
6712
|
) => QueryPlan<
|
|
6222
6713
|
{},
|
|
6223
6714
|
never,
|
|
@@ -6231,10 +6722,10 @@ type AsCurriedResult<
|
|
|
6231
6722
|
"createIndex"
|
|
6232
6723
|
>
|
|
6233
6724
|
|
|
6234
|
-
type DropIndexApi = <Target extends SchemaTableLike, const Columns extends DdlColumnInput>(
|
|
6725
|
+
type DropIndexApi = <Target extends SchemaTableLike, const Columns extends DdlColumnInput, Name extends string = string>(
|
|
6235
6726
|
target: Target,
|
|
6236
|
-
columns: Columns &
|
|
6237
|
-
options?: DropIndexOptions
|
|
6727
|
+
columns: Columns & ValidateDdlColumnInput<Target, Columns>,
|
|
6728
|
+
options?: DropIndexOptions<Name>
|
|
6238
6729
|
) => QueryPlan<
|
|
6239
6730
|
{},
|
|
6240
6731
|
never,
|