effect-qb 0.16.0 → 0.17.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/dist/mysql.js +1661 -591
- package/dist/postgres/metadata.js +1930 -135
- package/dist/postgres.js +7808 -6718
- package/dist/sqlite.js +8360 -0
- package/package.json +6 -1
- package/src/internal/derived-table.ts +29 -3
- package/src/internal/dialect.ts +2 -0
- package/src/internal/dsl-mutation-runtime.ts +173 -4
- package/src/internal/dsl-plan-runtime.ts +165 -20
- package/src/internal/dsl-query-runtime.ts +60 -6
- package/src/internal/dsl-transaction-ddl-runtime.ts +72 -2
- package/src/internal/executor.ts +47 -9
- package/src/internal/expression-ast.ts +3 -2
- package/src/internal/grouping-key.ts +141 -1
- package/src/internal/implication-runtime.ts +2 -1
- 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 +27 -3
- package/src/internal/query.ts +252 -30
- package/src/internal/renderer.ts +35 -2
- package/src/internal/runtime/driver-value-mapping.ts +58 -0
- package/src/internal/runtime/normalize.ts +62 -38
- package/src/internal/runtime/schema.ts +5 -3
- package/src/internal/runtime/value.ts +153 -30
- package/src/internal/table-options.ts +108 -1
- package/src/internal/table.ts +87 -29
- package/src/mysql/column.ts +18 -2
- package/src/mysql/datatypes/index.ts +21 -0
- package/src/mysql/errors/catalog.ts +5 -5
- package/src/mysql/errors/normalize.ts +2 -2
- package/src/mysql/internal/dsl.ts +736 -218
- package/src/mysql/internal/renderer.ts +2 -1
- package/src/mysql/internal/sql-expression-renderer.ts +486 -130
- package/src/mysql/query.ts +9 -2
- package/src/mysql/table.ts +38 -12
- package/src/postgres/column.ts +4 -2
- package/src/postgres/errors/normalize.ts +2 -2
- package/src/postgres/executor.ts +48 -5
- package/src/postgres/function/core.ts +19 -1
- package/src/postgres/internal/dsl.ts +683 -240
- package/src/postgres/internal/renderer.ts +2 -1
- package/src/postgres/internal/schema-ddl.ts +2 -1
- package/src/postgres/internal/schema-model.ts +6 -3
- package/src/postgres/internal/sql-expression-renderer.ts +420 -91
- package/src/postgres/json.ts +57 -17
- package/src/postgres/query.ts +9 -2
- package/src/postgres/schema-management.ts +91 -4
- package/src/postgres/schema.ts +1 -1
- package/src/postgres/table.ts +189 -53
- package/src/sqlite/column.ts +128 -0
- package/src/sqlite/datatypes/index.ts +79 -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 +227 -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 +37 -0
- package/src/sqlite/internal/dsl.ts +6926 -0
- package/src/sqlite/internal/renderer.ts +47 -0
- package/src/sqlite/internal/sql-expression-renderer.ts +1821 -0
- package/src/sqlite/json.ts +2 -0
- package/src/sqlite/query.ts +196 -0
- package/src/sqlite/renderer.ts +24 -0
- package/src/sqlite/table.ts +183 -0
- package/src/sqlite.ts +22 -0
|
@@ -9,6 +9,7 @@ import * as Table from "../../internal/table.js"
|
|
|
9
9
|
import type { CastTargetError, OperandCompatibilityError } from "../../internal/coercion/errors.js"
|
|
10
10
|
import type { RuntimeOfDbType } from "../../internal/coercion/analysis.js"
|
|
11
11
|
import type { CanCastDbType, CanCompareDbTypes, CanContainDbTypes, CanTextuallyCoerceDbType } from "../../internal/coercion/rules.js"
|
|
12
|
+
import { normalizeDbValue } from "../../internal/runtime/normalize.js"
|
|
12
13
|
import {
|
|
13
14
|
currentRequiredList,
|
|
14
15
|
extractRequiredRuntime,
|
|
@@ -30,11 +31,15 @@ import {
|
|
|
30
31
|
type AssumptionsOfPlan,
|
|
31
32
|
type AvailableOfPlan,
|
|
32
33
|
type CapabilitiesOfPlan,
|
|
34
|
+
type CommonSetFacts,
|
|
33
35
|
type DialectCompatibleNestedPlan,
|
|
34
36
|
type DependenciesOf,
|
|
35
37
|
type DependencyRecord,
|
|
36
38
|
type DialectOf,
|
|
37
39
|
type DerivedSelectionOf,
|
|
40
|
+
type DerivedTableCompatiblePlan,
|
|
41
|
+
type LateralSourceCompatiblePlan,
|
|
42
|
+
type DerivedSourceCompatiblePlan,
|
|
38
43
|
type DerivedSource,
|
|
39
44
|
type CompletePlan,
|
|
40
45
|
type ExpressionInput,
|
|
@@ -217,6 +222,13 @@ type DialectAsExpression<
|
|
|
217
222
|
? Value
|
|
218
223
|
: DialectLiteralExpression<Extract<Value, LiteralValue>, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
219
224
|
|
|
225
|
+
type ProjectionAliasedExpression<
|
|
226
|
+
Value extends Expression.Any,
|
|
227
|
+
Alias extends string
|
|
228
|
+
> = Value & {
|
|
229
|
+
readonly [ProjectionAlias.TypeId]: ProjectionAlias.State<Alias>
|
|
230
|
+
}
|
|
231
|
+
|
|
220
232
|
/** Normalizes a generic string-capable input into the expression form used internally. */
|
|
221
233
|
type DialectAsStringExpression<
|
|
222
234
|
Value extends ExpressionInput,
|
|
@@ -690,6 +702,21 @@ type DialectOfDialectNumericInput<
|
|
|
690
702
|
NullDb extends Expression.DbType.Any
|
|
691
703
|
> = DialectOf<DialectAsNumericExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>
|
|
692
704
|
|
|
705
|
+
type NumericExpressionDialectInput<
|
|
706
|
+
Value extends NumericExpressionInput,
|
|
707
|
+
Dialect extends string,
|
|
708
|
+
TextDb extends Expression.DbType.Any,
|
|
709
|
+
NumericDb extends Expression.DbType.Any,
|
|
710
|
+
BoolDb extends Expression.DbType.Any,
|
|
711
|
+
TimestampDb extends Expression.DbType.Any,
|
|
712
|
+
NullDb extends Expression.DbType.Any
|
|
713
|
+
> = Exclude<DialectOfDialectNumericInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>, Dialect> extends never
|
|
714
|
+
? unknown
|
|
715
|
+
: {
|
|
716
|
+
readonly __effect_qb_error__: "effect-qb: numeric expressions cannot mix dialects"
|
|
717
|
+
readonly __effect_qb_dialect__: DialectOfDialectNumericInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
718
|
+
}
|
|
719
|
+
|
|
693
720
|
/** Dependency map carried by a numeric-clause input after coercion. */
|
|
694
721
|
type DependenciesOfDialectNumericInput<
|
|
695
722
|
Value extends NumericExpressionInput,
|
|
@@ -1073,6 +1100,16 @@ type JsonSetOutputOf<
|
|
|
1073
1100
|
? JsonSetAtPath<Root, JsonPath.Path<[Target]>, Next, Operation>
|
|
1074
1101
|
: never
|
|
1075
1102
|
|
|
1103
|
+
type JsonSetOutputWithCreateMissing<
|
|
1104
|
+
Root,
|
|
1105
|
+
Target extends JsonPathInput,
|
|
1106
|
+
Next,
|
|
1107
|
+
Operation extends string,
|
|
1108
|
+
CreateMissing extends boolean
|
|
1109
|
+
> = false extends CreateMissing
|
|
1110
|
+
? Root | JsonSetOutputOf<Root, Target, Next, Operation>
|
|
1111
|
+
: JsonSetOutputOf<Root, Target, Next, Operation>
|
|
1112
|
+
|
|
1076
1113
|
type JsonInsertOutputOf<
|
|
1077
1114
|
Root,
|
|
1078
1115
|
Target extends JsonPathInput,
|
|
@@ -1085,6 +1122,27 @@ type JsonInsertOutputOf<
|
|
|
1085
1122
|
? JsonInsertAtPath<Root, JsonPath.Path<[Target]>, Next, InsertAfter, Operation>
|
|
1086
1123
|
: never
|
|
1087
1124
|
|
|
1125
|
+
type MySqlJsonLengthResult<Value> =
|
|
1126
|
+
JsonLengthResult<Value> extends null ? number : JsonLengthResult<Value>
|
|
1127
|
+
|
|
1128
|
+
type MySqlJsonTypeName<Value> =
|
|
1129
|
+
JsonTypeName<Value> extends "object" ? "OBJECT" :
|
|
1130
|
+
JsonTypeName<Value> extends "array" ? "ARRAY" :
|
|
1131
|
+
JsonTypeName<Value> extends "string" ? "STRING" :
|
|
1132
|
+
JsonTypeName<Value> extends "number" ? "INTEGER" | "DOUBLE" | "DECIMAL" :
|
|
1133
|
+
JsonTypeName<Value> extends "boolean" ? "BOOLEAN" :
|
|
1134
|
+
JsonTypeName<Value> extends "null" ? "NULL" :
|
|
1135
|
+
JsonTypeName<Value>
|
|
1136
|
+
|
|
1137
|
+
type MySqlUnsupportedJsonFeatureUsageError<Feature extends string> = {
|
|
1138
|
+
readonly __effect_qb_error__: "effect-qb: unsupported mysql json feature"
|
|
1139
|
+
readonly __effect_qb_json_feature__: Feature
|
|
1140
|
+
}
|
|
1141
|
+
|
|
1142
|
+
type MySqlUnsupportedJsonFeature<Feature extends string> = (
|
|
1143
|
+
feature: MySqlUnsupportedJsonFeatureUsageError<Feature>
|
|
1144
|
+
) => never
|
|
1145
|
+
|
|
1088
1146
|
type JsonPathGuard<
|
|
1089
1147
|
Root,
|
|
1090
1148
|
Target extends JsonPathInput,
|
|
@@ -1686,10 +1744,16 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
|
|
|
1686
1744
|
spec: WindowSpecInput<PartitionBy, OrderBy> | OrderedWindowSpecInput<PartitionBy, Extract<OrderBy, NonEmptyWindowOrderTerms>> | undefined
|
|
1687
1745
|
) => {
|
|
1688
1746
|
const partitionBy = [...(spec?.partitionBy ?? [])] as unknown as PartitionBy
|
|
1689
|
-
const orderBy = (spec?.orderBy ?? []).map((term) =>
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1747
|
+
const orderBy = (spec?.orderBy ?? []).map((term) => {
|
|
1748
|
+
const direction = term.direction ?? "asc"
|
|
1749
|
+
if (direction !== "asc" && direction !== "desc") {
|
|
1750
|
+
throw new Error("window order direction must be asc or desc")
|
|
1751
|
+
}
|
|
1752
|
+
return {
|
|
1753
|
+
value: term.value,
|
|
1754
|
+
direction
|
|
1755
|
+
}
|
|
1756
|
+
}) as {
|
|
1693
1757
|
readonly [K in keyof OrderBy]: OrderBy[K] extends WindowOrderTermInput<infer Value extends WindowOrderInput>
|
|
1694
1758
|
? { readonly value: Value; readonly direction: OrderDirection }
|
|
1695
1759
|
: never
|
|
@@ -2655,18 +2719,19 @@ type BinaryPredicateExpression<
|
|
|
2655
2719
|
const jsonSet = <
|
|
2656
2720
|
Base extends JsonExpressionLike<any>,
|
|
2657
2721
|
Target extends JsonPathInput,
|
|
2658
|
-
Next extends JsonValueInput
|
|
2722
|
+
Next extends JsonValueInput,
|
|
2723
|
+
CreateMissing extends boolean = true
|
|
2659
2724
|
>(
|
|
2660
2725
|
base: Base,
|
|
2661
|
-
target: Target & JsonSetGuard<Expression.RuntimeOf<Base>, Target, Next
|
|
2726
|
+
target: Target & JsonSetGuard<Expression.RuntimeOf<Base>, Target, NoInfer<Next>, "json.set">,
|
|
2662
2727
|
next: Next,
|
|
2663
2728
|
options: {
|
|
2664
|
-
readonly createMissing?:
|
|
2729
|
+
readonly createMissing?: CreateMissing
|
|
2665
2730
|
} = {}
|
|
2666
2731
|
): JsonExpression<
|
|
2667
|
-
|
|
2732
|
+
JsonSetOutputWithCreateMissing<Expression.RuntimeOf<Base>, Target, Next, "json.set", CreateMissing>,
|
|
2668
2733
|
JsonDbOfExpression<Base>,
|
|
2669
|
-
JsonNullabilityOf<
|
|
2734
|
+
JsonNullabilityOf<JsonSetOutputWithCreateMissing<Expression.RuntimeOf<Base>, Target, Next, "json.set", CreateMissing>>,
|
|
2670
2735
|
DialectOf<Base>,
|
|
2671
2736
|
KindOf<Base>,
|
|
2672
2737
|
DependenciesOf<Base>,
|
|
@@ -2677,9 +2742,9 @@ type BinaryPredicateExpression<
|
|
|
2677
2742
|
return buildJsonNodeExpression(
|
|
2678
2743
|
[base, newValue],
|
|
2679
2744
|
{
|
|
2680
|
-
runtime: undefined as unknown as
|
|
2745
|
+
runtime: undefined as unknown as JsonSetOutputWithCreateMissing<Expression.RuntimeOf<Base>, Target, Next, "json.set", CreateMissing>,
|
|
2681
2746
|
dbType: jsonDbTypeOf(base),
|
|
2682
|
-
nullability: undefined as unknown as JsonNullabilityOf<
|
|
2747
|
+
nullability: undefined as unknown as JsonNullabilityOf<JsonSetOutputWithCreateMissing<Expression.RuntimeOf<Base>, Target, Next, "json.set", CreateMissing>>
|
|
2683
2748
|
},
|
|
2684
2749
|
{
|
|
2685
2750
|
kind: "jsonSet",
|
|
@@ -2689,9 +2754,9 @@ type BinaryPredicateExpression<
|
|
|
2689
2754
|
createMissing: options.createMissing ?? true
|
|
2690
2755
|
}
|
|
2691
2756
|
) as JsonExpression<
|
|
2692
|
-
|
|
2757
|
+
JsonSetOutputWithCreateMissing<Expression.RuntimeOf<Base>, Target, Next, "json.set", CreateMissing>,
|
|
2693
2758
|
JsonDbOfExpression<Base>,
|
|
2694
|
-
JsonNullabilityOf<
|
|
2759
|
+
JsonNullabilityOf<JsonSetOutputWithCreateMissing<Expression.RuntimeOf<Base>, Target, Next, "json.set", CreateMissing>>,
|
|
2695
2760
|
DialectOf<Base>,
|
|
2696
2761
|
KindOf<Base>,
|
|
2697
2762
|
DependenciesOf<Base>,
|
|
@@ -2706,7 +2771,7 @@ type BinaryPredicateExpression<
|
|
|
2706
2771
|
InsertAfter extends boolean = false
|
|
2707
2772
|
>(
|
|
2708
2773
|
base: Base,
|
|
2709
|
-
target: Target & JsonInsertGuard<Expression.RuntimeOf<Base>, Target, Next
|
|
2774
|
+
target: Target & JsonInsertGuard<Expression.RuntimeOf<Base>, Target, NoInfer<Next>, NoInfer<InsertAfter>, "json.insert">,
|
|
2710
2775
|
next: Next,
|
|
2711
2776
|
options: {
|
|
2712
2777
|
readonly insertAfter?: InsertAfter
|
|
@@ -2928,7 +2993,7 @@ type BinaryPredicateExpression<
|
|
|
2928
2993
|
) => buildJsonNodeExpression(
|
|
2929
2994
|
[base],
|
|
2930
2995
|
{
|
|
2931
|
-
runtime: undefined as unknown as
|
|
2996
|
+
runtime: undefined as unknown as MySqlJsonTypeName<Expression.RuntimeOf<Base>>,
|
|
2932
2997
|
dbType: profile.textDb as TextDb,
|
|
2933
2998
|
nullability: base[Expression.TypeId].nullability
|
|
2934
2999
|
},
|
|
@@ -2943,9 +3008,9 @@ type BinaryPredicateExpression<
|
|
|
2943
3008
|
) => buildJsonNodeExpression(
|
|
2944
3009
|
[base],
|
|
2945
3010
|
{
|
|
2946
|
-
runtime: undefined as unknown as
|
|
3011
|
+
runtime: undefined as unknown as MySqlJsonLengthResult<Expression.RuntimeOf<Base>>,
|
|
2947
3012
|
dbType: profile.numericDb as NumericDb,
|
|
2948
|
-
nullability: undefined as unknown as JsonNullabilityOf<
|
|
3013
|
+
nullability: undefined as unknown as JsonNullabilityOf<MySqlJsonLengthResult<Expression.RuntimeOf<Base>>>
|
|
2949
3014
|
},
|
|
2950
3015
|
{
|
|
2951
3016
|
kind: "jsonLength",
|
|
@@ -3085,9 +3150,9 @@ type BinaryPredicateExpression<
|
|
|
3085
3150
|
typeOf: jsonTypeOf,
|
|
3086
3151
|
length: jsonLength,
|
|
3087
3152
|
keys: jsonKeys,
|
|
3088
|
-
stripNulls: jsonStripNulls
|
|
3153
|
+
stripNulls: jsonStripNulls as unknown as MySqlUnsupportedJsonFeature<"json.stripNulls">,
|
|
3089
3154
|
pathExists: jsonPathExists,
|
|
3090
|
-
pathMatch: jsonPathMatch
|
|
3155
|
+
pathMatch: jsonPathMatch as unknown as MySqlUnsupportedJsonFeature<"json.pathMatch">
|
|
3091
3156
|
}
|
|
3092
3157
|
|
|
3093
3158
|
const jsonb = {
|
|
@@ -3920,7 +3985,9 @@ type BinaryPredicateExpression<
|
|
|
3920
3985
|
string,
|
|
3921
3986
|
"scalar",
|
|
3922
3987
|
Expression.BindingId
|
|
3923
|
-
>
|
|
3988
|
+
> & {
|
|
3989
|
+
readonly [ExpressionAst.TypeId]: ExpressionAst.ColumnNode<any, string>
|
|
3990
|
+
}
|
|
3924
3991
|
>(
|
|
3925
3992
|
value: Value
|
|
3926
3993
|
): AstBackedExpression<
|
|
@@ -3964,22 +4031,56 @@ type BinaryPredicateExpression<
|
|
|
3964
4031
|
value: Value,
|
|
3965
4032
|
column: Expression.Any
|
|
3966
4033
|
): Expression.Any => {
|
|
4034
|
+
const columnState = column[Expression.TypeId]
|
|
4035
|
+
const normalizeMutationValue = (candidate: unknown): unknown => {
|
|
4036
|
+
if (candidate === null && columnState.nullability !== "never") {
|
|
4037
|
+
return null
|
|
4038
|
+
}
|
|
4039
|
+
const runtimeSchemaAccepts = columnState.runtimeSchema !== undefined &&
|
|
4040
|
+
(Schema.is(columnState.runtimeSchema) as (input: unknown) => boolean)(candidate)
|
|
4041
|
+
if (runtimeSchemaAccepts) {
|
|
4042
|
+
return candidate
|
|
4043
|
+
}
|
|
4044
|
+
const normalized = normalizeDbValue(columnState.dbType, candidate)
|
|
4045
|
+
return columnState.runtimeSchema === undefined
|
|
4046
|
+
? normalized
|
|
4047
|
+
: (Schema.decodeUnknownSync as any)(columnState.runtimeSchema)(normalized)
|
|
4048
|
+
}
|
|
3967
4049
|
if (value !== null && typeof value === "object" && Expression.TypeId in value) {
|
|
4050
|
+
const expression = value as unknown as Expression.Any
|
|
4051
|
+
const ast = (expression as unknown as { readonly [ExpressionAst.TypeId]: ExpressionAst.Any })[ExpressionAst.TypeId]
|
|
4052
|
+
if (ast.kind === "literal") {
|
|
4053
|
+
const normalizedValue = normalizeMutationValue(ast.value)
|
|
4054
|
+
return makeExpression({
|
|
4055
|
+
runtime: normalizedValue,
|
|
4056
|
+
dbType: columnState.dbType,
|
|
4057
|
+
runtimeSchema: columnState.runtimeSchema,
|
|
4058
|
+
driverValueMapping: columnState.driverValueMapping,
|
|
4059
|
+
nullability: normalizedValue === null ? "always" : "never",
|
|
4060
|
+
dialect: columnState.dialect,
|
|
4061
|
+
kind: "scalar",
|
|
4062
|
+
dependencies: {}
|
|
4063
|
+
}, {
|
|
4064
|
+
kind: "literal",
|
|
4065
|
+
value: normalizedValue
|
|
4066
|
+
})
|
|
4067
|
+
}
|
|
3968
4068
|
return retargetLiteralExpression(value as unknown as Expression.Any, column)
|
|
3969
4069
|
}
|
|
4070
|
+
const normalizedValue = normalizeMutationValue(value)
|
|
3970
4071
|
return makeExpression({
|
|
3971
|
-
runtime:
|
|
3972
|
-
dbType:
|
|
3973
|
-
runtimeSchema:
|
|
3974
|
-
driverValueMapping:
|
|
3975
|
-
nullability:
|
|
3976
|
-
dialect:
|
|
4072
|
+
runtime: normalizedValue as Value,
|
|
4073
|
+
dbType: columnState.dbType,
|
|
4074
|
+
runtimeSchema: columnState.runtimeSchema,
|
|
4075
|
+
driverValueMapping: columnState.driverValueMapping,
|
|
4076
|
+
nullability: normalizedValue === null ? "always" : "never",
|
|
4077
|
+
dialect: columnState.dialect,
|
|
3977
4078
|
kind: "scalar",
|
|
3978
4079
|
|
|
3979
4080
|
dependencies: {}
|
|
3980
4081
|
}, {
|
|
3981
4082
|
kind: "literal",
|
|
3982
|
-
value
|
|
4083
|
+
value: normalizedValue
|
|
3983
4084
|
})
|
|
3984
4085
|
}
|
|
3985
4086
|
|
|
@@ -4067,16 +4168,16 @@ type BinaryPredicateExpression<
|
|
|
4067
4168
|
Alias extends string
|
|
4068
4169
|
>(
|
|
4069
4170
|
rows: readonly [Record<string, Expression.Any>, ...Record<string, Expression.Any>[]],
|
|
4070
|
-
selection: ValuesOutputShape<Rows
|
|
4171
|
+
selection: ValuesOutputShape<Rows, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
4071
4172
|
alias: Alias
|
|
4072
4173
|
): ValuesSource<
|
|
4073
4174
|
Rows,
|
|
4074
|
-
ValuesOutputShape<Rows
|
|
4175
|
+
ValuesOutputShape<Rows, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
4075
4176
|
Alias,
|
|
4076
4177
|
Dialect
|
|
4077
4178
|
> => {
|
|
4078
4179
|
const columns = makeColumnReferenceSelection(alias, selection as Record<string, Expression.Any>) as unknown as ValuesOutputShape<
|
|
4079
|
-
Rows
|
|
4180
|
+
Rows,
|
|
4080
4181
|
Dialect,
|
|
4081
4182
|
TextDb,
|
|
4082
4183
|
NumericDb,
|
|
@@ -4094,7 +4195,7 @@ type BinaryPredicateExpression<
|
|
|
4094
4195
|
}
|
|
4095
4196
|
return Object.assign(source, columns) as unknown as ValuesSource<
|
|
4096
4197
|
Rows,
|
|
4097
|
-
ValuesOutputShape<Rows
|
|
4198
|
+
ValuesOutputShape<Rows, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
4098
4199
|
Alias,
|
|
4099
4200
|
Dialect
|
|
4100
4201
|
>
|
|
@@ -4107,7 +4208,12 @@ type BinaryPredicateExpression<
|
|
|
4107
4208
|
|
|
4108
4209
|
const normalizeUnnestColumns = (columns: UnnestColumnsInput): Record<string, readonly Expression.Any[]> =>
|
|
4109
4210
|
Object.fromEntries(
|
|
4110
|
-
Object.entries(columns).map(([key, values]) =>
|
|
4211
|
+
Object.entries(columns).map(([key, values]) => {
|
|
4212
|
+
if (!Array.isArray(values)) {
|
|
4213
|
+
throw new Error("unnest(...) expects every value to be an array")
|
|
4214
|
+
}
|
|
4215
|
+
return [key, values.map((value) => toDialectExpression(value))]
|
|
4216
|
+
})
|
|
4111
4217
|
) as Record<string, readonly Expression.Any[]>
|
|
4112
4218
|
|
|
4113
4219
|
const normalizeMutationTargets = (
|
|
@@ -4150,6 +4256,17 @@ type BinaryPredicateExpression<
|
|
|
4150
4256
|
})
|
|
4151
4257
|
) as unknown as AddAvailableMany<{}, MutationTargetNamesOf<Target>, Mode>
|
|
4152
4258
|
|
|
4259
|
+
const getMutationColumn = (
|
|
4260
|
+
columns: Record<string, unknown>,
|
|
4261
|
+
columnName: string
|
|
4262
|
+
): Expression.Any => {
|
|
4263
|
+
const column = columns[columnName]
|
|
4264
|
+
if (column === undefined || column === null || typeof column !== "object" || !(Expression.TypeId in column)) {
|
|
4265
|
+
throw new Error("effect-qb: unknown mutation column")
|
|
4266
|
+
}
|
|
4267
|
+
return column as Expression.Any
|
|
4268
|
+
}
|
|
4269
|
+
|
|
4153
4270
|
const buildMutationAssignments = <Target extends MutationTargetInput, Values>(
|
|
4154
4271
|
target: Target,
|
|
4155
4272
|
values: Values
|
|
@@ -4159,7 +4276,7 @@ type BinaryPredicateExpression<
|
|
|
4159
4276
|
const columns = target as unknown as Record<string, Expression.Any>
|
|
4160
4277
|
return Object.entries(values as Record<string, unknown>).map(([columnName, value]) => ({
|
|
4161
4278
|
columnName,
|
|
4162
|
-
value: toMutationValueExpression(value, columns
|
|
4279
|
+
value: toMutationValueExpression(value, getMutationColumn(columns, columnName))
|
|
4163
4280
|
}))
|
|
4164
4281
|
}
|
|
4165
4282
|
const valueMap = values as Record<string, Record<string, unknown> | undefined>
|
|
@@ -4170,7 +4287,7 @@ type BinaryPredicateExpression<
|
|
|
4170
4287
|
return Object.entries(scopedValues).map(([columnName, value]) => ({
|
|
4171
4288
|
tableName: targetName,
|
|
4172
4289
|
columnName,
|
|
4173
|
-
value: toMutationValueExpression(value, columns
|
|
4290
|
+
value: toMutationValueExpression(value, getMutationColumn(columns, columnName))
|
|
4174
4291
|
}))
|
|
4175
4292
|
})
|
|
4176
4293
|
}
|
|
@@ -4257,31 +4374,29 @@ type BinaryPredicateExpression<
|
|
|
4257
4374
|
}
|
|
4258
4375
|
}
|
|
4259
4376
|
|
|
4377
|
+
const normalizeConflictColumns = <Target extends MutationTargetLike>(
|
|
4378
|
+
target: Target,
|
|
4379
|
+
columnsInput: string | readonly string[]
|
|
4380
|
+
): readonly [string, ...string[]] => {
|
|
4381
|
+
const columns = normalizeColumnList(columnsInput) as readonly [string, ...string[]]
|
|
4382
|
+
const knownColumns = new Set(Object.keys(target[Table.TypeId].fields))
|
|
4383
|
+
if (columns.some((columnName) => !knownColumns.has(columnName))) {
|
|
4384
|
+
throw new Error("effect-qb: unknown conflict target column")
|
|
4385
|
+
}
|
|
4386
|
+
return columns
|
|
4387
|
+
}
|
|
4388
|
+
|
|
4260
4389
|
const buildConflictTarget = <Target extends MutationTargetLike>(
|
|
4261
4390
|
target: Target,
|
|
4262
|
-
input: readonly string[] | { readonly columns: readonly string[]; readonly where?: PredicateInput } | { readonly constraint: string }
|
|
4391
|
+
input: string | readonly string[] | { readonly columns: string | readonly string[]; readonly where?: PredicateInput } | { readonly constraint: string }
|
|
4263
4392
|
): QueryAst.ConflictTargetClause => {
|
|
4264
|
-
if (Array.isArray(input)) {
|
|
4393
|
+
if (typeof input === "string" || Array.isArray(input)) {
|
|
4265
4394
|
return {
|
|
4266
4395
|
kind: "columns",
|
|
4267
|
-
columns:
|
|
4396
|
+
columns: normalizeConflictColumns(target, input)
|
|
4268
4397
|
}
|
|
4269
4398
|
}
|
|
4270
|
-
|
|
4271
|
-
return {
|
|
4272
|
-
kind: "constraint",
|
|
4273
|
-
name: input.constraint
|
|
4274
|
-
}
|
|
4275
|
-
}
|
|
4276
|
-
const columnTarget = input as {
|
|
4277
|
-
readonly columns: readonly string[]
|
|
4278
|
-
readonly where?: PredicateInput
|
|
4279
|
-
}
|
|
4280
|
-
return {
|
|
4281
|
-
kind: "columns",
|
|
4282
|
-
columns: normalizeColumnList(columnTarget.columns) as readonly [string, ...string[]],
|
|
4283
|
-
where: columnTarget.where === undefined ? undefined : toDialectExpression(columnTarget.where)
|
|
4284
|
-
}
|
|
4399
|
+
throw new Error("Unsupported mysql conflict target")
|
|
4285
4400
|
}
|
|
4286
4401
|
|
|
4287
4402
|
const defaultIndexName = (
|
|
@@ -4317,20 +4432,30 @@ type ValidateDdlColumns<
|
|
|
4317
4432
|
Columns extends readonly string[]
|
|
4318
4433
|
> = Exclude<Columns[number], SchemaColumnNames<Target>> extends never ? Columns : never
|
|
4319
4434
|
|
|
4435
|
+
type ValidateDdlColumnInput<
|
|
4436
|
+
Target extends SchemaTableLike,
|
|
4437
|
+
Columns extends DdlColumnInput
|
|
4438
|
+
> = ValidateDdlColumns<Target, NormalizeDdlColumns<Columns>> extends never ? never : Columns
|
|
4439
|
+
|
|
4320
4440
|
type ValidateTargetColumns<
|
|
4321
4441
|
Target extends MutationTargetLike,
|
|
4322
4442
|
Columns extends readonly string[]
|
|
4323
4443
|
> = Exclude<Columns[number], Extract<keyof Target[typeof Table.TypeId]["fields"], string>> extends never ? Columns : never
|
|
4324
4444
|
|
|
4445
|
+
type ValidateTargetColumnInput<
|
|
4446
|
+
Target extends MutationTargetLike,
|
|
4447
|
+
Columns extends DdlColumnInput
|
|
4448
|
+
> = ValidateTargetColumns<Target, NormalizeDdlColumns<Columns>> extends never ? never : Columns
|
|
4449
|
+
|
|
4325
4450
|
type CreateIndexOptions = {
|
|
4326
4451
|
readonly name?: string
|
|
4327
4452
|
readonly unique?: boolean
|
|
4328
|
-
readonly ifNotExists?:
|
|
4453
|
+
readonly ifNotExists?: never
|
|
4329
4454
|
}
|
|
4330
4455
|
|
|
4331
4456
|
type DropIndexOptions = {
|
|
4332
4457
|
readonly name?: string
|
|
4333
|
-
readonly ifExists?:
|
|
4458
|
+
readonly ifExists?: never
|
|
4334
4459
|
}
|
|
4335
4460
|
|
|
4336
4461
|
type CreateTableOptions = {
|
|
@@ -4342,8 +4467,8 @@ type DropTableOptions = {
|
|
|
4342
4467
|
}
|
|
4343
4468
|
|
|
4344
4469
|
type TruncateOptions = {
|
|
4345
|
-
readonly restartIdentity?:
|
|
4346
|
-
readonly cascade?:
|
|
4470
|
+
readonly restartIdentity?: never
|
|
4471
|
+
readonly cascade?: never
|
|
4347
4472
|
}
|
|
4348
4473
|
|
|
4349
4474
|
type TransactionOptions = {
|
|
@@ -4351,10 +4476,15 @@ type TransactionOptions = {
|
|
|
4351
4476
|
readonly readOnly?: boolean
|
|
4352
4477
|
}
|
|
4353
4478
|
|
|
4354
|
-
type LockOptions =
|
|
4355
|
-
|
|
4356
|
-
|
|
4357
|
-
|
|
4479
|
+
type LockOptions =
|
|
4480
|
+
| {
|
|
4481
|
+
readonly nowait?: boolean
|
|
4482
|
+
readonly skipLocked?: false
|
|
4483
|
+
}
|
|
4484
|
+
| {
|
|
4485
|
+
readonly nowait?: false
|
|
4486
|
+
readonly skipLocked?: boolean
|
|
4487
|
+
}
|
|
4358
4488
|
|
|
4359
4489
|
type UpsertConflictOptions = {
|
|
4360
4490
|
readonly update?: Record<string, unknown>
|
|
@@ -4369,14 +4499,133 @@ type InsertRowInput<Target extends MutationTargetLike> = MutationInputOf<Table.I
|
|
|
4369
4499
|
type ValuesRowInput = Record<string, ExpressionInput>
|
|
4370
4500
|
type ValuesRowsInput = readonly [ValuesRowInput, ...ValuesRowInput[]]
|
|
4371
4501
|
|
|
4502
|
+
type ValuesColumnInput<Row, Key extends PropertyKey> =
|
|
4503
|
+
Row extends ValuesRowInput
|
|
4504
|
+
? Key extends keyof Row ? Row[Key] : never
|
|
4505
|
+
: never
|
|
4506
|
+
|
|
4507
|
+
type ValuesRowShapeMismatch<
|
|
4508
|
+
First extends ValuesRowInput,
|
|
4509
|
+
Row extends ValuesRowInput
|
|
4510
|
+
> =
|
|
4511
|
+
| Exclude<Extract<keyof Row, string>, Extract<keyof First, string>>
|
|
4512
|
+
| Exclude<Extract<keyof First, string>, Extract<keyof Row, string>>
|
|
4513
|
+
|
|
4514
|
+
type ValuesRowsShapeMismatchesFor<
|
|
4515
|
+
First extends ValuesRowInput,
|
|
4516
|
+
Row
|
|
4517
|
+
> = Row extends ValuesRowInput ? ValuesRowShapeMismatch<First, Row> : never
|
|
4518
|
+
|
|
4519
|
+
type ValuesRowsShapeMismatches<Rows extends ValuesRowsInput> =
|
|
4520
|
+
Rows extends readonly [infer First extends ValuesRowInput, ...infer Rest extends ValuesRowInput[]]
|
|
4521
|
+
? ValuesRowsShapeMismatchesFor<First, Rest[number]>
|
|
4522
|
+
: never
|
|
4523
|
+
|
|
4524
|
+
type ValuesRowsColumnKeys<Rows extends ValuesRowsInput> =
|
|
4525
|
+
Rows extends readonly [infer First extends ValuesRowInput, ...ValuesRowInput[]]
|
|
4526
|
+
? Extract<keyof First, string>
|
|
4527
|
+
: never
|
|
4528
|
+
|
|
4529
|
+
type ValuesRowsShapeInput<Rows extends ValuesRowsInput> =
|
|
4530
|
+
[ValuesRowsColumnKeys<Rows>] extends [never]
|
|
4531
|
+
? {
|
|
4532
|
+
readonly __effect_qb_error__: "effect-qb: values rows must project at least one column"
|
|
4533
|
+
}
|
|
4534
|
+
: [ValuesRowsShapeMismatches<Rows>] extends [never]
|
|
4535
|
+
? unknown
|
|
4536
|
+
: {
|
|
4537
|
+
readonly __effect_qb_error__: "effect-qb: values rows must project the same columns"
|
|
4538
|
+
readonly __effect_qb_mismatched_columns__: ValuesRowsShapeMismatches<Rows>
|
|
4539
|
+
}
|
|
4540
|
+
|
|
4541
|
+
type ValuesRowsDialect<
|
|
4542
|
+
Rows extends ValuesRowsInput,
|
|
4543
|
+
Dialect extends string,
|
|
4544
|
+
TextDb extends Expression.DbType.Any,
|
|
4545
|
+
NumericDb extends Expression.DbType.Any,
|
|
4546
|
+
BoolDb extends Expression.DbType.Any,
|
|
4547
|
+
TimestampDb extends Expression.DbType.Any,
|
|
4548
|
+
NullDb extends Expression.DbType.Any
|
|
4549
|
+
> = Rows[number][keyof Rows[number]] extends infer Value extends ExpressionInput
|
|
4550
|
+
? DialectOfDialectInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
4551
|
+
: never
|
|
4552
|
+
|
|
4553
|
+
type ValuesRowsDialectInput<
|
|
4554
|
+
Rows extends ValuesRowsInput,
|
|
4555
|
+
Dialect extends string,
|
|
4556
|
+
TextDb extends Expression.DbType.Any,
|
|
4557
|
+
NumericDb extends Expression.DbType.Any,
|
|
4558
|
+
BoolDb extends Expression.DbType.Any,
|
|
4559
|
+
TimestampDb extends Expression.DbType.Any,
|
|
4560
|
+
NullDb extends Expression.DbType.Any
|
|
4561
|
+
> = Exclude<ValuesRowsDialect<Rows, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>, Dialect> extends never
|
|
4562
|
+
? unknown
|
|
4563
|
+
: {
|
|
4564
|
+
readonly __effect_qb_error__: "effect-qb: values rows cannot mix dialects"
|
|
4565
|
+
readonly __effect_qb_dialect__: ValuesRowsDialect<Rows, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
4566
|
+
}
|
|
4567
|
+
|
|
4372
4568
|
type UnnestColumnsInput = Record<string, readonly [ExpressionInput, ...ExpressionInput[]]>
|
|
4373
4569
|
|
|
4570
|
+
type IsNever<Value> = [Value] extends [never] ? true : false
|
|
4571
|
+
|
|
4572
|
+
type IsUnion<Value, All = Value> = Value extends any
|
|
4573
|
+
? ([All] extends [Value] ? false : true)
|
|
4574
|
+
: never
|
|
4575
|
+
|
|
4576
|
+
type UnnestColumnKeys<Columns extends UnnestColumnsInput> =
|
|
4577
|
+
Extract<keyof Columns, string>
|
|
4578
|
+
|
|
4579
|
+
type UnnestColumnLengths<Columns extends UnnestColumnsInput> =
|
|
4580
|
+
Columns[UnnestColumnKeys<Columns>]["length"]
|
|
4581
|
+
|
|
4582
|
+
type UnnestColumnsShapeInput<Columns extends UnnestColumnsInput> =
|
|
4583
|
+
IsNever<UnnestColumnKeys<Columns>> extends true
|
|
4584
|
+
? {
|
|
4585
|
+
readonly __effect_qb_error__: "effect-qb: unnest requires at least one column array"
|
|
4586
|
+
}
|
|
4587
|
+
: number extends UnnestColumnLengths<Columns>
|
|
4588
|
+
? unknown
|
|
4589
|
+
: IsUnion<UnnestColumnLengths<Columns>> extends true
|
|
4590
|
+
? {
|
|
4591
|
+
readonly __effect_qb_error__: "effect-qb: unnest column arrays must have the same length"
|
|
4592
|
+
readonly __effect_qb_column_lengths__: UnnestColumnLengths<Columns>
|
|
4593
|
+
}
|
|
4594
|
+
: unknown
|
|
4595
|
+
|
|
4596
|
+
type UnnestColumnsDialect<
|
|
4597
|
+
Columns extends UnnestColumnsInput,
|
|
4598
|
+
Dialect extends string,
|
|
4599
|
+
TextDb extends Expression.DbType.Any,
|
|
4600
|
+
NumericDb extends Expression.DbType.Any,
|
|
4601
|
+
BoolDb extends Expression.DbType.Any,
|
|
4602
|
+
TimestampDb extends Expression.DbType.Any,
|
|
4603
|
+
NullDb extends Expression.DbType.Any
|
|
4604
|
+
> = Columns[UnnestColumnKeys<Columns>][number] extends infer Value extends ExpressionInput
|
|
4605
|
+
? DialectOfDialectInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
4606
|
+
: never
|
|
4607
|
+
|
|
4608
|
+
type UnnestColumnsDialectInput<
|
|
4609
|
+
Columns extends UnnestColumnsInput,
|
|
4610
|
+
Dialect extends string,
|
|
4611
|
+
TextDb extends Expression.DbType.Any,
|
|
4612
|
+
NumericDb extends Expression.DbType.Any,
|
|
4613
|
+
BoolDb extends Expression.DbType.Any,
|
|
4614
|
+
TimestampDb extends Expression.DbType.Any,
|
|
4615
|
+
NullDb extends Expression.DbType.Any
|
|
4616
|
+
> = Exclude<UnnestColumnsDialect<Columns, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>, Dialect> extends never
|
|
4617
|
+
? unknown
|
|
4618
|
+
: {
|
|
4619
|
+
readonly __effect_qb_error__: "effect-qb: unnest columns cannot mix dialects"
|
|
4620
|
+
readonly __effect_qb_dialect__: UnnestColumnsDialect<Columns, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
4621
|
+
}
|
|
4622
|
+
|
|
4374
4623
|
type UnnestRowShape<Shape extends Record<string, readonly unknown[]>> = {
|
|
4375
4624
|
readonly [K in keyof Shape]: Shape[K] extends readonly (infer Item)[] ? Item : never
|
|
4376
4625
|
}
|
|
4377
4626
|
|
|
4378
4627
|
type ValuesOutputShape<
|
|
4379
|
-
|
|
4628
|
+
Rows extends ValuesRowsInput,
|
|
4380
4629
|
Dialect extends string,
|
|
4381
4630
|
TextDb extends Expression.DbType.Any,
|
|
4382
4631
|
NumericDb extends Expression.DbType.Any,
|
|
@@ -4384,7 +4633,7 @@ type ValuesOutputShape<
|
|
|
4384
4633
|
TimestampDb extends Expression.DbType.Any,
|
|
4385
4634
|
NullDb extends Expression.DbType.Any
|
|
4386
4635
|
> = {
|
|
4387
|
-
readonly [K in keyof
|
|
4636
|
+
readonly [K in keyof Rows[0]]: DialectAsExpression<ValuesColumnInput<Rows[number], K>, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
4388
4637
|
}
|
|
4389
4638
|
|
|
4390
4639
|
type UnnestOutputShape<
|
|
@@ -4423,19 +4672,44 @@ type DistinctOnUnsupportedError<Dialect extends string> = {
|
|
|
4423
4672
|
readonly __effect_qb_hint__: "Use postgres.Query.distinctOn(...) or regular distinct()/grouping logic"
|
|
4424
4673
|
}
|
|
4425
4674
|
|
|
4675
|
+
type FullJoinUnsupportedError<Dialect extends string> = {
|
|
4676
|
+
readonly __effect_qb_error__: "effect-qb: fullJoin(...) is only supported by the postgres dialect"
|
|
4677
|
+
readonly __effect_qb_dialect__: Dialect
|
|
4678
|
+
readonly __effect_qb_hint__: "Use leftJoin/rightJoin with nullable handling or switch to postgres.Query.fullJoin(...)"
|
|
4679
|
+
}
|
|
4680
|
+
|
|
4681
|
+
type ReturningUnsupportedError<Dialect extends string> = {
|
|
4682
|
+
readonly __effect_qb_error__: "effect-qb: returning(...) is only supported by the postgres dialect"
|
|
4683
|
+
readonly __effect_qb_dialect__: Dialect
|
|
4684
|
+
readonly __effect_qb_hint__: "Use postgres.Query.returning(...) or run a follow-up select after MySQL mutations"
|
|
4685
|
+
}
|
|
4686
|
+
|
|
4687
|
+
type MysqlCteStatementError<PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>> =
|
|
4688
|
+
PlanValue & {
|
|
4689
|
+
readonly __effect_qb_error__: "effect-qb: mysql cte sources only accept select-like query plans"
|
|
4690
|
+
readonly __effect_qb_statement__: StatementOfPlan<PlanValue>
|
|
4691
|
+
readonly __effect_qb_hint__: "Use select(...) or a set operator before wrapping a MySQL plan in with(...)"
|
|
4692
|
+
}
|
|
4693
|
+
|
|
4694
|
+
type MysqlCteCompatiblePlan<
|
|
4695
|
+
PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>
|
|
4696
|
+
> = StatementOfPlan<PlanValue> extends "select" | "set"
|
|
4697
|
+
? DerivedSourceCompatiblePlan<PlanValue>
|
|
4698
|
+
: MysqlCteStatementError<PlanValue>
|
|
4699
|
+
|
|
4426
4700
|
type DistinctOnApi<Dialect extends string> = Dialect extends "postgres"
|
|
4427
|
-
? <Values extends readonly ExpressionInput[]>(
|
|
4701
|
+
? <Values extends readonly [ExpressionInput, ...ExpressionInput[]]>(
|
|
4428
4702
|
...values: Values
|
|
4429
4703
|
) => <PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
|
|
4430
4704
|
plan: PlanValue & RequireSelectStatement<PlanValue>
|
|
4431
4705
|
) => QueryPlan<
|
|
4432
4706
|
SelectionOfPlan<PlanValue>,
|
|
4433
|
-
RequiredOfPlan<PlanValue>,
|
|
4707
|
+
AddExpressionRequired<RequiredOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, Values[number]>,
|
|
4434
4708
|
AvailableOfPlan<PlanValue>,
|
|
4435
|
-
PlanDialectOf<PlanValue>,
|
|
4709
|
+
PlanDialectOf<PlanValue> | DialectOfDialectInput<Values[number], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
4436
4710
|
GroupedOfPlan<PlanValue>,
|
|
4437
4711
|
ScopedNamesOfPlan<PlanValue>,
|
|
4438
|
-
OutstandingOfPlan<PlanValue>,
|
|
4712
|
+
AddExpressionRequired<OutstandingOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, Values[number]>,
|
|
4439
4713
|
AssumptionsOfPlan<PlanValue>,
|
|
4440
4714
|
CapabilitiesOfPlan<PlanValue>,
|
|
4441
4715
|
StatementOfPlan<PlanValue>
|
|
@@ -4468,6 +4742,27 @@ type MysqlConflictWhereError<Values> = Values & {
|
|
|
4468
4742
|
readonly __effect_qb_hint__: "Move the condition into the update assignment expressions or use the Postgres dialect"
|
|
4469
4743
|
}
|
|
4470
4744
|
|
|
4745
|
+
type UpdateValuesNonEmptyError<Values> = Values & {
|
|
4746
|
+
readonly __effect_qb_error__: "effect-qb: update statements require at least one assignment"
|
|
4747
|
+
}
|
|
4748
|
+
|
|
4749
|
+
type UpdateValuesNonEmptyConstraint<Values> =
|
|
4750
|
+
[Extract<keyof Values, string>] extends [never]
|
|
4751
|
+
? UpdateValuesNonEmptyError<Values>
|
|
4752
|
+
: unknown
|
|
4753
|
+
|
|
4754
|
+
type NestedUpdateValuesNonEmptyConstraint<Values> =
|
|
4755
|
+
[Extract<keyof Values, string>] extends [never]
|
|
4756
|
+
? UpdateValuesNonEmptyError<Values>
|
|
4757
|
+
: true extends {
|
|
4758
|
+
[K in Extract<keyof Values, string>]:
|
|
4759
|
+
Values[K] extends Record<string, unknown>
|
|
4760
|
+
? [Extract<keyof Values[K], string>] extends [never] ? false : true
|
|
4761
|
+
: false
|
|
4762
|
+
}[Extract<keyof Values, string>]
|
|
4763
|
+
? unknown
|
|
4764
|
+
: UpdateValuesNonEmptyError<Values>
|
|
4765
|
+
|
|
4471
4766
|
type InsertShapeExtraKeys<TargetShape, SourceShape> = Exclude<Extract<keyof SourceShape, string>, Extract<keyof TargetShape, string>>
|
|
4472
4767
|
type InsertShapeMissingKeys<TargetShape, SourceShape> = Exclude<RequiredKeys<TargetShape>, Extract<keyof SourceShape, string>>
|
|
4473
4768
|
type InsertShapeMismatchedKeys<TargetShape, SourceShape> = Extract<{
|
|
@@ -4561,10 +4856,15 @@ type InsertSourceRequired<Source> =
|
|
|
4561
4856
|
Source extends QueryPlan<any, any, any, any, any, any, any, any, any, any> ? RequiredOfPlan<Source> :
|
|
4562
4857
|
never
|
|
4563
4858
|
|
|
4859
|
+
type InsertSourceDialect<Source> =
|
|
4860
|
+
Source extends QueryPlan<any, any, any, any, any, any, any, any, any, any> ? PlanDialectOf<Source> :
|
|
4861
|
+
Source extends SourceLike ? SourceDialectOf<Source> :
|
|
4862
|
+
never
|
|
4863
|
+
|
|
4564
4864
|
type ConflictColumnTarget<
|
|
4565
4865
|
Target extends MutationTargetLike,
|
|
4566
4866
|
Columns extends DdlColumnInput
|
|
4567
|
-
> =
|
|
4867
|
+
> = ValidateTargetColumnInput<Target, Columns>
|
|
4568
4868
|
|
|
4569
4869
|
type ConflictTargetInput<
|
|
4570
4870
|
Target extends MutationTargetLike,
|
|
@@ -4594,6 +4894,55 @@ type ConflictActionInput<
|
|
|
4594
4894
|
readonly where?: Dialect extends "postgres" ? PredicateInput : MysqlConflictWhereError<PredicateInput>
|
|
4595
4895
|
}
|
|
4596
4896
|
|
|
4897
|
+
type ConflictActionUpdateNonEmptyConstraint<Options> =
|
|
4898
|
+
Options extends { readonly update: infer Values }
|
|
4899
|
+
? UpdateValuesNonEmptyConstraint<Values>
|
|
4900
|
+
: unknown
|
|
4901
|
+
|
|
4902
|
+
type ConflictTargetPredicate<Target> =
|
|
4903
|
+
Target extends { readonly where?: infer Predicate } ? Extract<Predicate, PredicateInput> : never
|
|
4904
|
+
|
|
4905
|
+
type ConflictActionPredicate<Options> =
|
|
4906
|
+
Options extends { readonly where?: infer Predicate } ? Extract<Predicate, PredicateInput> : never
|
|
4907
|
+
|
|
4908
|
+
type MutationDialectFromValues<
|
|
4909
|
+
Values extends Record<string, unknown>,
|
|
4910
|
+
Dialect extends string,
|
|
4911
|
+
TextDb extends Expression.DbType.Any,
|
|
4912
|
+
NumericDb extends Expression.DbType.Any,
|
|
4913
|
+
BoolDb extends Expression.DbType.Any,
|
|
4914
|
+
TimestampDb extends Expression.DbType.Any,
|
|
4915
|
+
NullDb extends Expression.DbType.Any
|
|
4916
|
+
> = {
|
|
4917
|
+
[K in keyof Values]: Values[K] extends ExpressionInput
|
|
4918
|
+
? DialectOfDialectInput<Values[K], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
4919
|
+
: never
|
|
4920
|
+
}[keyof Values]
|
|
4921
|
+
|
|
4922
|
+
type ConflictRequired<
|
|
4923
|
+
UpdateValues extends MutationInputOf<any> | undefined,
|
|
4924
|
+
Options,
|
|
4925
|
+
ConflictTarget
|
|
4926
|
+
> =
|
|
4927
|
+
| MutationRequiredFromValues<Exclude<UpdateValues, undefined>>
|
|
4928
|
+
| RequiredFromInput<ConflictActionPredicate<Options>>
|
|
4929
|
+
| RequiredFromInput<ConflictTargetPredicate<ConflictTarget>>
|
|
4930
|
+
|
|
4931
|
+
type ConflictDialect<
|
|
4932
|
+
UpdateValues extends MutationInputOf<any> | undefined,
|
|
4933
|
+
Options,
|
|
4934
|
+
ConflictTarget,
|
|
4935
|
+
Dialect extends string,
|
|
4936
|
+
TextDb extends Expression.DbType.Any,
|
|
4937
|
+
NumericDb extends Expression.DbType.Any,
|
|
4938
|
+
BoolDb extends Expression.DbType.Any,
|
|
4939
|
+
TimestampDb extends Expression.DbType.Any,
|
|
4940
|
+
NullDb extends Expression.DbType.Any
|
|
4941
|
+
> =
|
|
4942
|
+
| MutationDialectFromValues<Exclude<UpdateValues, undefined>, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
4943
|
+
| DialectOfDialectInput<ConflictActionPredicate<Options>, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
4944
|
+
| DialectOfDialectInput<ConflictTargetPredicate<ConflictTarget>, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
4945
|
+
|
|
4597
4946
|
type MergeWhenMatchedDelete<
|
|
4598
4947
|
Predicate extends PredicateInput | undefined = undefined
|
|
4599
4948
|
> = {
|
|
@@ -4621,16 +4970,33 @@ type MergeWhenNotMatched<
|
|
|
4621
4970
|
readonly predicate?: Predicate
|
|
4622
4971
|
}
|
|
4623
4972
|
|
|
4973
|
+
type MergeMatchedOption<
|
|
4974
|
+
Target extends MutationTargetLike,
|
|
4975
|
+
MatchedValues extends MutationInputOf<Table.UpdateOf<Target>>,
|
|
4976
|
+
MatchedPredicate extends PredicateInput | undefined = undefined
|
|
4977
|
+
> = MergeWhenMatchedDelete<MatchedPredicate> | MergeWhenMatchedUpdate<Target, MatchedValues, MatchedPredicate>
|
|
4978
|
+
|
|
4979
|
+
type MergeNotMatchedOption<
|
|
4980
|
+
Target extends MutationTargetLike,
|
|
4981
|
+
InsertValues extends MutationInputOf<Table.InsertOf<Target>>,
|
|
4982
|
+
NotMatchedPredicate extends PredicateInput | undefined = undefined
|
|
4983
|
+
> = MergeWhenNotMatched<Target, InsertValues, NotMatchedPredicate>
|
|
4984
|
+
|
|
4624
4985
|
type MergeOptions<
|
|
4625
4986
|
Target extends MutationTargetLike,
|
|
4626
4987
|
MatchedValues extends MutationInputOf<Table.UpdateOf<Target>>,
|
|
4627
4988
|
InsertValues extends MutationInputOf<Table.InsertOf<Target>>,
|
|
4628
4989
|
MatchedPredicate extends PredicateInput | undefined = undefined,
|
|
4629
4990
|
NotMatchedPredicate extends PredicateInput | undefined = undefined
|
|
4630
|
-
> =
|
|
4631
|
-
|
|
4632
|
-
|
|
4633
|
-
|
|
4991
|
+
> =
|
|
4992
|
+
| {
|
|
4993
|
+
readonly whenMatched: MergeMatchedOption<Target, MatchedValues, MatchedPredicate>
|
|
4994
|
+
readonly whenNotMatched?: MergeNotMatchedOption<Target, InsertValues, NotMatchedPredicate>
|
|
4995
|
+
}
|
|
4996
|
+
| {
|
|
4997
|
+
readonly whenMatched?: MergeMatchedOption<Target, MatchedValues, MatchedPredicate>
|
|
4998
|
+
readonly whenNotMatched: MergeNotMatchedOption<Target, InsertValues, NotMatchedPredicate>
|
|
4999
|
+
}
|
|
4634
5000
|
|
|
4635
5001
|
type RequireSelectStatement<PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>> =
|
|
4636
5002
|
StatementOfPlan<PlanValue> extends "select" ? unknown : never
|
|
@@ -4662,6 +5028,38 @@ type MutationOrderLimitSupported<PlanValue extends QueryPlan<any, any, any, any,
|
|
|
4662
5028
|
? StatementOfPlan<PlanValue> extends "update" | "delete" ? unknown : never
|
|
4663
5029
|
: never
|
|
4664
5030
|
|
|
5031
|
+
type MutationTargetTupleDialectConstraint<
|
|
5032
|
+
Targets extends MutationTargetTuple,
|
|
5033
|
+
Dialect extends string
|
|
5034
|
+
> = Exclude<TableDialectOf<Targets[number]>, Dialect> extends never ? unknown : never
|
|
5035
|
+
|
|
5036
|
+
type DuplicateMutationTargetSourceName<
|
|
5037
|
+
Targets extends readonly MutationTargetLike[],
|
|
5038
|
+
Seen extends string = never
|
|
5039
|
+
> = Targets extends readonly [infer Head extends MutationTargetLike, ...infer Tail extends readonly MutationTargetLike[]]
|
|
5040
|
+
? SourceNameOf<Head> extends infer Name extends string
|
|
5041
|
+
? string extends Name
|
|
5042
|
+
? DuplicateMutationTargetSourceName<Tail, Seen>
|
|
5043
|
+
: Name extends Seen
|
|
5044
|
+
? Name
|
|
5045
|
+
: DuplicateMutationTargetSourceName<Tail, Seen | Name>
|
|
5046
|
+
: never
|
|
5047
|
+
: never
|
|
5048
|
+
|
|
5049
|
+
type MutationTargetTupleDuplicateNameError<Name extends string> = {
|
|
5050
|
+
readonly __effect_qb_error__: "effect-qb: mutation target source names must be unique"
|
|
5051
|
+
readonly __effect_qb_duplicate_source_name__: Name
|
|
5052
|
+
readonly __effect_qb_hint__: "Alias duplicate mutation targets with Table.alias(...)"
|
|
5053
|
+
}
|
|
5054
|
+
|
|
5055
|
+
type MutationTargetTupleUniqueNamesConstraint<
|
|
5056
|
+
Targets extends MutationTargetTuple
|
|
5057
|
+
> = DuplicateMutationTargetSourceName<Targets> extends infer Name extends string
|
|
5058
|
+
? [Name] extends [never]
|
|
5059
|
+
? unknown
|
|
5060
|
+
: MutationTargetTupleDuplicateNameError<Name>
|
|
5061
|
+
: unknown
|
|
5062
|
+
|
|
4665
5063
|
type MutationRequiredFromValues<Values extends Record<string, unknown>> = {
|
|
4666
5064
|
[K in keyof Values]: Values[K] extends Expression.Any ? RequiredFromDependencies<DependenciesOf<Values[K]>> : never
|
|
4667
5065
|
}[keyof Values]
|
|
@@ -4675,6 +5073,59 @@ type NestedMutationRequiredFromValues<Values> =
|
|
|
4675
5073
|
}[keyof Values]
|
|
4676
5074
|
: never
|
|
4677
5075
|
|
|
5076
|
+
type NestedMutationDialectFromValues<
|
|
5077
|
+
Values,
|
|
5078
|
+
Dialect extends string,
|
|
5079
|
+
TextDb extends Expression.DbType.Any,
|
|
5080
|
+
NumericDb extends Expression.DbType.Any,
|
|
5081
|
+
BoolDb extends Expression.DbType.Any,
|
|
5082
|
+
TimestampDb extends Expression.DbType.Any,
|
|
5083
|
+
NullDb extends Expression.DbType.Any
|
|
5084
|
+
> =
|
|
5085
|
+
Values extends ExpressionInput
|
|
5086
|
+
? DialectOfDialectInput<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
5087
|
+
: Values extends Record<string, unknown>
|
|
5088
|
+
? {
|
|
5089
|
+
[K in keyof Values]: NestedMutationDialectFromValues<Values[K], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
5090
|
+
}[keyof Values]
|
|
5091
|
+
: never
|
|
5092
|
+
|
|
5093
|
+
type KnownMutationDialectFromValues<
|
|
5094
|
+
Values,
|
|
5095
|
+
Dialect extends string,
|
|
5096
|
+
TextDb extends Expression.DbType.Any,
|
|
5097
|
+
NumericDb extends Expression.DbType.Any,
|
|
5098
|
+
BoolDb extends Expression.DbType.Any,
|
|
5099
|
+
TimestampDb extends Expression.DbType.Any,
|
|
5100
|
+
NullDb extends Expression.DbType.Any
|
|
5101
|
+
> = NestedMutationDialectFromValues<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> extends infer Current
|
|
5102
|
+
? Current extends string
|
|
5103
|
+
? string extends Current ? never : Current
|
|
5104
|
+
: never
|
|
5105
|
+
: never
|
|
5106
|
+
|
|
5107
|
+
type KnownIncompatibleMutationDialectFromValues<
|
|
5108
|
+
Values,
|
|
5109
|
+
Dialect extends string,
|
|
5110
|
+
TextDb extends Expression.DbType.Any,
|
|
5111
|
+
NumericDb extends Expression.DbType.Any,
|
|
5112
|
+
BoolDb extends Expression.DbType.Any,
|
|
5113
|
+
TimestampDb extends Expression.DbType.Any,
|
|
5114
|
+
NullDb extends Expression.DbType.Any
|
|
5115
|
+
> = Exclude<KnownMutationDialectFromValues<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>, Dialect>
|
|
5116
|
+
|
|
5117
|
+
type MutationValuesDialectConstraint<
|
|
5118
|
+
Values,
|
|
5119
|
+
Dialect extends string,
|
|
5120
|
+
TextDb extends Expression.DbType.Any,
|
|
5121
|
+
NumericDb extends Expression.DbType.Any,
|
|
5122
|
+
BoolDb extends Expression.DbType.Any,
|
|
5123
|
+
TimestampDb extends Expression.DbType.Any,
|
|
5124
|
+
NullDb extends Expression.DbType.Any
|
|
5125
|
+
> = KnownIncompatibleMutationDialectFromValues<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> extends never
|
|
5126
|
+
? unknown
|
|
5127
|
+
: never
|
|
5128
|
+
|
|
4678
5129
|
type MutationAssignments<Shape extends Record<string, unknown>> = {
|
|
4679
5130
|
readonly [K in keyof Shape]: QueryAst.AssignmentClause
|
|
4680
5131
|
}
|
|
@@ -4708,12 +5159,38 @@ type InsertDirectSource =
|
|
|
4708
5159
|
|
|
4709
5160
|
type FromInput = SourceLike | InsertDirectSource
|
|
4710
5161
|
|
|
5162
|
+
type SourceDialectConstraint<
|
|
5163
|
+
CurrentSource extends SourceLike,
|
|
5164
|
+
Dialect extends string
|
|
5165
|
+
> = [SourceDialectOf<CurrentSource>] extends [never]
|
|
5166
|
+
? unknown
|
|
5167
|
+
: Extract<SourceDialectOf<CurrentSource>, Dialect> extends never
|
|
5168
|
+
? never
|
|
5169
|
+
: unknown
|
|
5170
|
+
|
|
5171
|
+
type SourceRequirementConstraint<
|
|
5172
|
+
PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>,
|
|
5173
|
+
CurrentSource extends SourceLike
|
|
5174
|
+
> = [SourceRequiredOf<CurrentSource>] extends [never]
|
|
5175
|
+
? unknown
|
|
5176
|
+
: Exclude<SourceRequiredOf<CurrentSource>, ScopedNamesOfPlan<PlanValue>> extends never
|
|
5177
|
+
? unknown
|
|
5178
|
+
: SourceRequirementError<CurrentSource>
|
|
5179
|
+
|
|
4711
5180
|
type SelectFromConstraint<
|
|
4712
5181
|
PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>,
|
|
4713
5182
|
CurrentSource extends SourceLike
|
|
4714
5183
|
> =
|
|
4715
5184
|
RequireSelectStatement<PlanValue> &
|
|
4716
|
-
(
|
|
5185
|
+
(
|
|
5186
|
+
SourceNameOf<CurrentSource> extends OutstandingOfPlan<PlanValue>
|
|
5187
|
+
? unknown
|
|
5188
|
+
: [OutstandingOfPlan<PlanValue>] extends [never]
|
|
5189
|
+
? [ScopedNamesOfPlan<PlanValue>] extends [never]
|
|
5190
|
+
? unknown
|
|
5191
|
+
: never
|
|
5192
|
+
: never
|
|
5193
|
+
) &
|
|
4717
5194
|
(SourceRequiredOf<CurrentSource> extends never ? unknown : SourceRequirementError<CurrentSource>)
|
|
4718
5195
|
|
|
4719
5196
|
type UpdateFromConstraint<
|
|
@@ -4730,7 +5207,7 @@ type InsertFromConstraint<
|
|
|
4730
5207
|
Dialect extends string
|
|
4731
5208
|
> =
|
|
4732
5209
|
RequirePendingInsertStatement<PlanValue> &
|
|
4733
|
-
(InsertSourceOfPlanInput<PlanValue, CurrentSource, Dialect>
|
|
5210
|
+
(CurrentSource extends InsertSourceOfPlanInput<PlanValue, CurrentSource, Dialect>
|
|
4734
5211
|
? unknown
|
|
4735
5212
|
: InsertSourceOfPlanInput<PlanValue, CurrentSource, Dialect>)
|
|
4736
5213
|
|
|
@@ -4784,12 +5261,12 @@ type InsertFromResult<
|
|
|
4784
5261
|
Dialect extends string
|
|
4785
5262
|
> = QueryPlan<
|
|
4786
5263
|
SelectionOfPlan<PlanValue>,
|
|
4787
|
-
|
|
5264
|
+
InsertSourceRequired<CurrentSource>,
|
|
4788
5265
|
AvailableOfPlan<PlanValue>,
|
|
4789
|
-
PlanDialectOf<PlanValue>,
|
|
5266
|
+
PlanDialectOf<PlanValue> | InsertSourceDialect<CurrentSource>,
|
|
4790
5267
|
GroupedOfPlan<PlanValue>,
|
|
4791
5268
|
ScopedNamesOfPlan<PlanValue>,
|
|
4792
|
-
|
|
5269
|
+
InsertSourceRequired<CurrentSource>,
|
|
4793
5270
|
AssumptionsOfPlan<PlanValue>,
|
|
4794
5271
|
CurrentSource extends QueryPlan<any, any, any, any, any, any, any, any, any, any>
|
|
4795
5272
|
? MergeCapabilities<CapabilitiesOfPlan<PlanValue>, CapabilitiesOfPlan<CurrentSource>>
|
|
@@ -4806,15 +5283,17 @@ type FromPlanConstraint<
|
|
|
4806
5283
|
Dialect extends string
|
|
4807
5284
|
> =
|
|
4808
5285
|
CurrentSource extends SourceLike
|
|
4809
|
-
?
|
|
4810
|
-
|
|
4811
|
-
|
|
4812
|
-
|
|
4813
|
-
|
|
4814
|
-
|
|
4815
|
-
|
|
4816
|
-
|
|
4817
|
-
|
|
5286
|
+
? SourceDialectConstraint<CurrentSource, Dialect> & (
|
|
5287
|
+
StatementOfPlan<PlanValue> extends "select"
|
|
5288
|
+
? SelectFromConstraint<PlanValue, CurrentSource>
|
|
5289
|
+
: StatementOfPlan<PlanValue> extends "update"
|
|
5290
|
+
? UpdateFromConstraint<PlanValue, CurrentSource>
|
|
5291
|
+
: StatementOfPlan<PlanValue> extends "insert"
|
|
5292
|
+
? CurrentSource extends AnyValuesSource | AnyUnnestSource
|
|
5293
|
+
? InsertFromConstraint<PlanValue, CurrentSource, Dialect>
|
|
5294
|
+
: never
|
|
5295
|
+
: never
|
|
5296
|
+
)
|
|
4818
5297
|
: CurrentSource extends InsertDirectSource
|
|
4819
5298
|
? StatementOfPlan<PlanValue> extends "insert"
|
|
4820
5299
|
? InsertFromConstraint<PlanValue, CurrentSource, Dialect>
|
|
@@ -4869,7 +5348,10 @@ export type PublicStructuredFromResult<
|
|
|
4869
5348
|
Exclude<OutstandingOfPlan<PlanValue>, SourceNameOf<CurrentSource>>,
|
|
4870
5349
|
AssumptionsOfPlan<PlanValue>,
|
|
4871
5350
|
MergeCapabilities<CapabilitiesOfPlan<PlanValue>, SourceCapabilitiesOf<CurrentSource>>,
|
|
4872
|
-
StatementOfPlan<PlanValue
|
|
5351
|
+
StatementOfPlan<PlanValue>,
|
|
5352
|
+
MutationTargetOfPlan<PlanValue>,
|
|
5353
|
+
InsertSourceStateOfPlan<PlanValue>,
|
|
5354
|
+
FactsOfPlan<PlanValue>
|
|
4873
5355
|
>
|
|
4874
5356
|
: StatementOfPlan<PlanValue> extends "update"
|
|
4875
5357
|
? QueryPlan<
|
|
@@ -4882,7 +5364,10 @@ export type PublicStructuredFromResult<
|
|
|
4882
5364
|
Exclude<OutstandingOfPlan<PlanValue>, SourceNameOf<CurrentSource>>,
|
|
4883
5365
|
AssumptionsOfPlan<PlanValue>,
|
|
4884
5366
|
MergeCapabilities<CapabilitiesOfPlan<PlanValue>, SourceCapabilitiesOf<CurrentSource>>,
|
|
4885
|
-
StatementOfPlan<PlanValue
|
|
5367
|
+
StatementOfPlan<PlanValue>,
|
|
5368
|
+
MutationTargetOfPlan<PlanValue>,
|
|
5369
|
+
InsertSourceStateOfPlan<PlanValue>,
|
|
5370
|
+
FactsOfPlan<PlanValue>
|
|
4886
5371
|
>
|
|
4887
5372
|
: StatementOfPlan<PlanValue> extends "insert"
|
|
4888
5373
|
? CurrentSource extends AnyValuesSource | AnyUnnestSource
|
|
@@ -4890,7 +5375,7 @@ export type PublicStructuredFromResult<
|
|
|
4890
5375
|
SelectionOfPlan<PlanValue>,
|
|
4891
5376
|
never,
|
|
4892
5377
|
AvailableOfPlan<PlanValue>,
|
|
4893
|
-
PlanDialectOf<PlanValue>,
|
|
5378
|
+
PlanDialectOf<PlanValue> | SourceDialectOf<CurrentSource>,
|
|
4894
5379
|
GroupedOfPlan<PlanValue>,
|
|
4895
5380
|
ScopedNamesOfPlan<PlanValue>,
|
|
4896
5381
|
never,
|
|
@@ -4898,7 +5383,8 @@ export type PublicStructuredFromResult<
|
|
|
4898
5383
|
CapabilitiesOfPlan<PlanValue>,
|
|
4899
5384
|
StatementOfPlan<PlanValue>,
|
|
4900
5385
|
MutationTargetOfPlan<PlanValue>,
|
|
4901
|
-
"ready"
|
|
5386
|
+
"ready",
|
|
5387
|
+
FactsOfPlan<PlanValue>
|
|
4902
5388
|
>
|
|
4903
5389
|
: FromPlanResult<PlanValue, CurrentSource, Dialect>
|
|
4904
5390
|
: FromPlanResult<PlanValue, CurrentSource, Dialect>
|
|
@@ -4954,20 +5440,20 @@ type AsCurriedResult<
|
|
|
4954
5440
|
>(
|
|
4955
5441
|
value: Value,
|
|
4956
5442
|
alias: Alias
|
|
4957
|
-
): DialectAsExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
5443
|
+
): ProjectionAliasedExpression<DialectAsExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>, Alias>
|
|
4958
5444
|
function as<
|
|
4959
5445
|
Rows extends ValuesRowsInput,
|
|
4960
5446
|
Alias extends string
|
|
4961
5447
|
>(
|
|
4962
5448
|
value: ValuesInput<
|
|
4963
5449
|
Rows,
|
|
4964
|
-
ValuesOutputShape<Rows
|
|
5450
|
+
ValuesOutputShape<Rows, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
4965
5451
|
Dialect
|
|
4966
5452
|
>,
|
|
4967
5453
|
alias: Alias
|
|
4968
5454
|
): ValuesSource<
|
|
4969
5455
|
Rows,
|
|
4970
|
-
ValuesOutputShape<Rows
|
|
5456
|
+
ValuesOutputShape<Rows, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
4971
5457
|
Alias,
|
|
4972
5458
|
Dialect
|
|
4973
5459
|
>
|
|
@@ -4975,7 +5461,7 @@ type AsCurriedResult<
|
|
|
4975
5461
|
PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>,
|
|
4976
5462
|
Alias extends string
|
|
4977
5463
|
>(
|
|
4978
|
-
value:
|
|
5464
|
+
value: DerivedTableCompatiblePlan<PlanValue>,
|
|
4979
5465
|
alias: Alias
|
|
4980
5466
|
): DerivedSource<PlanValue, Alias>
|
|
4981
5467
|
function as(valueOrAlias: unknown, alias?: string): unknown {
|
|
@@ -5022,13 +5508,13 @@ type AsCurriedResult<
|
|
|
5022
5508
|
>(
|
|
5023
5509
|
alias: Alias
|
|
5024
5510
|
): <PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
|
|
5025
|
-
value:
|
|
5511
|
+
value: MysqlCteCompatiblePlan<PlanValue>
|
|
5026
5512
|
) => import("../../internal/query.js").CteSource<PlanValue, Alias>
|
|
5027
5513
|
function with_<
|
|
5028
5514
|
PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>,
|
|
5029
5515
|
Alias extends string
|
|
5030
5516
|
>(
|
|
5031
|
-
value:
|
|
5517
|
+
value: MysqlCteCompatiblePlan<PlanValue>,
|
|
5032
5518
|
alias: Alias
|
|
5033
5519
|
): import("../../internal/query.js").CteSource<PlanValue, Alias>
|
|
5034
5520
|
function with_(valueOrAlias: unknown, alias?: string): unknown {
|
|
@@ -5046,13 +5532,13 @@ type AsCurriedResult<
|
|
|
5046
5532
|
>(
|
|
5047
5533
|
alias: Alias
|
|
5048
5534
|
): <PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
|
|
5049
|
-
value:
|
|
5535
|
+
value: MysqlCteCompatiblePlan<PlanValue>
|
|
5050
5536
|
) => import("../../internal/query.js").CteSource<PlanValue, Alias>
|
|
5051
5537
|
function withRecursive_<
|
|
5052
5538
|
PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>,
|
|
5053
5539
|
Alias extends string
|
|
5054
5540
|
>(
|
|
5055
|
-
value:
|
|
5541
|
+
value: MysqlCteCompatiblePlan<PlanValue>,
|
|
5056
5542
|
alias: Alias
|
|
5057
5543
|
): import("../../internal/query.js").CteSource<PlanValue, Alias>
|
|
5058
5544
|
function withRecursive_(valueOrAlias: unknown, alias?: string): unknown {
|
|
@@ -5071,13 +5557,13 @@ type AsCurriedResult<
|
|
|
5071
5557
|
>(
|
|
5072
5558
|
alias: Alias
|
|
5073
5559
|
): <PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
|
|
5074
|
-
value: PlanValue
|
|
5560
|
+
value: LateralSourceCompatiblePlan<PlanValue>
|
|
5075
5561
|
) => import("../../internal/query.js").LateralSource<PlanValue, Alias>
|
|
5076
5562
|
function lateral<
|
|
5077
5563
|
PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>,
|
|
5078
5564
|
Alias extends string
|
|
5079
5565
|
>(
|
|
5080
|
-
value: PlanValue
|
|
5566
|
+
value: LateralSourceCompatiblePlan<PlanValue>,
|
|
5081
5567
|
alias: Alias
|
|
5082
5568
|
): import("../../internal/query.js").LateralSource<PlanValue, Alias>
|
|
5083
5569
|
function lateral(valueOrAlias: unknown, alias?: string): unknown {
|
|
@@ -5094,9 +5580,11 @@ type AsCurriedResult<
|
|
|
5094
5580
|
Rows extends ValuesRowsInput
|
|
5095
5581
|
>(
|
|
5096
5582
|
rows: Rows
|
|
5583
|
+
& ValuesRowsShapeInput<Rows>
|
|
5584
|
+
& ValuesRowsDialectInput<Rows, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
5097
5585
|
) => ValuesInput<
|
|
5098
5586
|
Rows,
|
|
5099
|
-
ValuesOutputShape<Rows
|
|
5587
|
+
ValuesOutputShape<Rows, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5100
5588
|
Dialect
|
|
5101
5589
|
>
|
|
5102
5590
|
|
|
@@ -5104,7 +5592,9 @@ type AsCurriedResult<
|
|
|
5104
5592
|
Columns extends UnnestColumnsInput,
|
|
5105
5593
|
Alias extends string
|
|
5106
5594
|
>(
|
|
5107
|
-
columns: Columns
|
|
5595
|
+
columns: Columns
|
|
5596
|
+
& UnnestColumnsShapeInput<Columns>
|
|
5597
|
+
& UnnestColumnsDialectInput<Columns, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5108
5598
|
alias: Alias
|
|
5109
5599
|
) => UnnestSource<
|
|
5110
5600
|
UnnestOutputShape<Columns, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
@@ -5118,9 +5608,9 @@ type AsCurriedResult<
|
|
|
5118
5608
|
Step extends NumericExpressionInput | undefined = undefined,
|
|
5119
5609
|
Alias extends string = "series"
|
|
5120
5610
|
>(
|
|
5121
|
-
start: Start,
|
|
5122
|
-
stop: Stop,
|
|
5123
|
-
step?: Step,
|
|
5611
|
+
start: Start & NumericExpressionDialectInput<Start, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5612
|
+
stop: Stop & NumericExpressionDialectInput<Stop, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5613
|
+
step?: Step & (Step extends NumericExpressionInput ? NumericExpressionDialectInput<Step, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> : unknown),
|
|
5124
5614
|
alias?: Alias
|
|
5125
5615
|
) => Dialect extends "postgres"
|
|
5126
5616
|
? TableFunctionSource<
|
|
@@ -5131,8 +5621,45 @@ type AsCurriedResult<
|
|
|
5131
5621
|
>
|
|
5132
5622
|
: GenerateSeriesUnsupportedError<Dialect>
|
|
5133
5623
|
|
|
5624
|
+
type SelectSelectionNonEmptyError<Selection> = Selection & {
|
|
5625
|
+
readonly __effect_qb_error__: "effect-qb: mysql select statements require at least one selected expression"
|
|
5626
|
+
}
|
|
5627
|
+
|
|
5628
|
+
type SelectionRootObjectError<Selection> = Selection & {
|
|
5629
|
+
readonly __effect_qb_error__: "effect-qb: selections must be projection objects"
|
|
5630
|
+
readonly __effect_qb_hint__: "Use select({ value: expression }) or returning({ value: expression })"
|
|
5631
|
+
}
|
|
5632
|
+
|
|
5633
|
+
type SelectionRootObjectConstraint<Selection> =
|
|
5634
|
+
Selection extends Expression.Any ? SelectionRootObjectError<Selection> : unknown
|
|
5635
|
+
|
|
5636
|
+
type SelectionNestedEmptyError<Selection> = Selection & {
|
|
5637
|
+
readonly __effect_qb_error__: "effect-qb: projection objects cannot contain empty nested selections"
|
|
5638
|
+
}
|
|
5639
|
+
|
|
5640
|
+
type SelectionHasEmptyNestedObject<Selection, IsRoot extends boolean> =
|
|
5641
|
+
Selection extends Expression.Any
|
|
5642
|
+
? false
|
|
5643
|
+
: Selection extends Record<string, any>
|
|
5644
|
+
? [Extract<keyof Selection, string>] extends [never]
|
|
5645
|
+
? IsRoot extends true ? false : true
|
|
5646
|
+
: true extends {
|
|
5647
|
+
[K in Extract<keyof Selection, string>]: SelectionHasEmptyNestedObject<Selection[K], false>
|
|
5648
|
+
}[Extract<keyof Selection, string>]
|
|
5649
|
+
? true
|
|
5650
|
+
: false
|
|
5651
|
+
: false
|
|
5652
|
+
|
|
5653
|
+
type SelectionNestedNonEmptyConstraint<Selection> =
|
|
5654
|
+
SelectionHasEmptyNestedObject<Selection, true> extends true ? SelectionNestedEmptyError<Selection> : unknown
|
|
5655
|
+
|
|
5656
|
+
type SelectSelectionNonEmptyConstraint<Selection> =
|
|
5657
|
+
[Extract<keyof Selection, string>] extends [never]
|
|
5658
|
+
? SelectSelectionNonEmptyError<Selection>
|
|
5659
|
+
: unknown
|
|
5660
|
+
|
|
5134
5661
|
export type SelectApi = <Selection extends SelectionShape>(
|
|
5135
|
-
selection: Selection
|
|
5662
|
+
selection: Selection & SelectionRootObjectConstraint<Selection> & SelectionNestedNonEmptyConstraint<Selection> & SelectSelectionNonEmptyConstraint<Selection>
|
|
5136
5663
|
) => QueryPlan<
|
|
5137
5664
|
Selection,
|
|
5138
5665
|
ExtractRequired<Selection>,
|
|
@@ -5169,7 +5696,7 @@ type AsCurriedResult<
|
|
|
5169
5696
|
getQueryState,
|
|
5170
5697
|
currentRequiredList,
|
|
5171
5698
|
dedupeGroupedExpressions
|
|
5172
|
-
}) as {
|
|
5699
|
+
}) as unknown as {
|
|
5173
5700
|
readonly values: ValuesApi
|
|
5174
5701
|
readonly unnest: UnnestApi
|
|
5175
5702
|
readonly generateSeries: GenerateSeriesApi
|
|
@@ -5191,7 +5718,10 @@ type AsCurriedResult<
|
|
|
5191
5718
|
never,
|
|
5192
5719
|
TrueFormula,
|
|
5193
5720
|
CapabilitiesOfPlan<LeftPlanValue> | CapabilitiesOfPlan<RightPlanValue>,
|
|
5194
|
-
"set"
|
|
5721
|
+
"set",
|
|
5722
|
+
any,
|
|
5723
|
+
"ready",
|
|
5724
|
+
CommonSetFacts<LeftPlanValue, RightPlanValue>
|
|
5195
5725
|
>
|
|
5196
5726
|
|
|
5197
5727
|
type SetOperationApi = <
|
|
@@ -5259,10 +5789,10 @@ type AsCurriedResult<
|
|
|
5259
5789
|
keyof AvailableOfPlan<PlanValue> extends never ? never : unknown
|
|
5260
5790
|
) & (
|
|
5261
5791
|
SourceNameOf<CurrentTable> extends ScopedNamesOfPlan<PlanValue> ? never : unknown
|
|
5262
|
-
)
|
|
5792
|
+
) & SourceRequirementConstraint<PlanValue, CurrentTable> & SourceDialectConstraint<CurrentTable, Dialect>
|
|
5263
5793
|
) => QueryPlan<
|
|
5264
5794
|
SelectionOfPlan<PlanValue>,
|
|
5265
|
-
AddJoinRequired<RequiredOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, never, "cross"
|
|
5795
|
+
AddJoinRequired<RequiredOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, never, "cross", SourceRequiredOf<CurrentTable>>,
|
|
5266
5796
|
AddAvailable<
|
|
5267
5797
|
AvailableOfPlan<PlanValue>,
|
|
5268
5798
|
SourceNameOf<CurrentTable>,
|
|
@@ -5273,10 +5803,13 @@ type AsCurriedResult<
|
|
|
5273
5803
|
PlanDialectOf<PlanValue> | SourceDialectOf<CurrentTable>,
|
|
5274
5804
|
GroupedOfPlan<PlanValue>,
|
|
5275
5805
|
ScopedNamesOfPlan<PlanValue> | SourceNameOf<CurrentTable>,
|
|
5276
|
-
AddJoinRequired<OutstandingOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, never, "cross"
|
|
5806
|
+
AddJoinRequired<OutstandingOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, never, "cross", SourceRequiredOf<CurrentTable>>,
|
|
5277
5807
|
AssumptionsOfPlan<PlanValue>,
|
|
5278
5808
|
MergeCapabilities<CapabilitiesOfPlan<PlanValue>, SourceCapabilitiesOf<CurrentTable>>,
|
|
5279
|
-
StatementOfPlan<PlanValue
|
|
5809
|
+
StatementOfPlan<PlanValue>,
|
|
5810
|
+
MutationTargetOfPlan<PlanValue>,
|
|
5811
|
+
InsertSourceStateOfPlan<PlanValue>,
|
|
5812
|
+
FactsOfPlan<PlanValue>
|
|
5280
5813
|
>
|
|
5281
5814
|
|
|
5282
5815
|
type JoinApi = <
|
|
@@ -5293,10 +5826,10 @@ type AsCurriedResult<
|
|
|
5293
5826
|
keyof AvailableOfPlan<PlanValue> extends never ? never : unknown
|
|
5294
5827
|
) & (
|
|
5295
5828
|
SourceNameOf<CurrentTable> extends ScopedNamesOfPlan<PlanValue> ? never : unknown
|
|
5296
|
-
)
|
|
5829
|
+
) & SourceRequirementConstraint<PlanValue, CurrentTable> & SourceDialectConstraint<CurrentTable, Dialect>
|
|
5297
5830
|
) => QueryPlan<
|
|
5298
5831
|
SelectionOfPlan<PlanValue>,
|
|
5299
|
-
AddJoinRequired<RequiredOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, Predicate, Kind
|
|
5832
|
+
AddJoinRequired<RequiredOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, Predicate, Kind, SourceRequiredOf<CurrentTable>>,
|
|
5300
5833
|
AvailableAfterJoin<
|
|
5301
5834
|
AvailableOfPlan<PlanValue>,
|
|
5302
5835
|
SourceNameOf<CurrentTable>,
|
|
@@ -5307,7 +5840,7 @@ type AsCurriedResult<
|
|
|
5307
5840
|
PlanDialectOf<PlanValue> | SourceDialectOf<CurrentTable> | DialectOfDialectInput<Predicate, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5308
5841
|
GroupedOfPlan<PlanValue>,
|
|
5309
5842
|
ScopedNamesOfPlan<PlanValue> | SourceNameOf<CurrentTable>,
|
|
5310
|
-
AddJoinRequired<OutstandingOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, Predicate, Kind
|
|
5843
|
+
AddJoinRequired<OutstandingOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, Predicate, Kind, SourceRequiredOf<CurrentTable>>,
|
|
5311
5844
|
PlanAssumptionsAfterJoin<PlanValue, Predicate, Kind, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5312
5845
|
MergeCapabilities<CapabilitiesOfPlan<PlanValue>, SourceCapabilitiesOf<CurrentTable>>,
|
|
5313
5846
|
StatementOfPlan<PlanValue>,
|
|
@@ -5328,10 +5861,10 @@ type AsCurriedResult<
|
|
|
5328
5861
|
keyof AvailableOfPlan<PlanValue> extends never ? never : unknown
|
|
5329
5862
|
) & (
|
|
5330
5863
|
SourceNameOf<CurrentTable> extends ScopedNamesOfPlan<PlanValue> ? never : unknown
|
|
5331
|
-
)
|
|
5864
|
+
) & SourceRequirementConstraint<PlanValue, CurrentTable> & SourceDialectConstraint<CurrentTable, Dialect>
|
|
5332
5865
|
) => QueryPlan<
|
|
5333
5866
|
SelectionOfPlan<PlanValue>,
|
|
5334
|
-
AddJoinRequired<RequiredOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, Predicate, Kind
|
|
5867
|
+
AddJoinRequired<RequiredOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, Predicate, Kind, SourceRequiredOf<CurrentTable>>,
|
|
5335
5868
|
AvailableAfterJoin<
|
|
5336
5869
|
AvailableOfPlan<PlanValue>,
|
|
5337
5870
|
SourceNameOf<CurrentTable>,
|
|
@@ -5342,7 +5875,7 @@ type AsCurriedResult<
|
|
|
5342
5875
|
PlanDialectOf<PlanValue> | SourceDialectOf<CurrentTable> | DialectOfDialectInput<Predicate, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5343
5876
|
GroupedOfPlan<PlanValue>,
|
|
5344
5877
|
ScopedNamesOfPlan<PlanValue> | SourceNameOf<CurrentTable>,
|
|
5345
|
-
AddJoinRequired<OutstandingOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, Predicate, Kind
|
|
5878
|
+
AddJoinRequired<OutstandingOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, Predicate, Kind, SourceRequiredOf<CurrentTable>>,
|
|
5346
5879
|
PlanAssumptionsAfterJoin<PlanValue, Predicate, Kind, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5347
5880
|
MergeCapabilities<CapabilitiesOfPlan<PlanValue>, SourceCapabilitiesOf<CurrentTable>>,
|
|
5348
5881
|
StatementOfPlan<PlanValue>,
|
|
@@ -5351,6 +5884,8 @@ type AsCurriedResult<
|
|
|
5351
5884
|
PlanFactsAfterJoin<PlanValue, Predicate, Kind, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
5352
5885
|
>
|
|
5353
5886
|
|
|
5887
|
+
type FullJoinApi = Dialect extends "postgres" ? BinaryJoinApi<"full"> : FullJoinUnsupportedError<Dialect>
|
|
5888
|
+
|
|
5354
5889
|
type OrderByApi = <Value extends ExpressionInput>(
|
|
5355
5890
|
value: Value,
|
|
5356
5891
|
direction?: OrderDirection
|
|
@@ -5548,7 +6083,7 @@ type AsCurriedResult<
|
|
|
5548
6083
|
|
|
5549
6084
|
const rightJoin = ((table, on) => (join as any)("right", table, on)) as BinaryJoinApi<"right">
|
|
5550
6085
|
|
|
5551
|
-
const fullJoin = ((table, on) => (join as any)("full", table, on)) as
|
|
6086
|
+
const fullJoin = ((table: any, on: any) => (join as any)("full", table, on)) as unknown as FullJoinApi
|
|
5552
6087
|
|
|
5553
6088
|
const distinctOn = {
|
|
5554
6089
|
__effect_qb_error__: "effect-qb: distinctOn(...) is only supported by the postgres dialect",
|
|
@@ -5577,26 +6112,39 @@ type AsCurriedResult<
|
|
|
5577
6112
|
FactsOfPlan<PlanValue>
|
|
5578
6113
|
>
|
|
5579
6114
|
|
|
5580
|
-
type
|
|
5581
|
-
|
|
5582
|
-
|
|
5583
|
-
|
|
5584
|
-
|
|
5585
|
-
|
|
5586
|
-
|
|
5587
|
-
|
|
5588
|
-
|
|
5589
|
-
|
|
5590
|
-
|
|
5591
|
-
|
|
5592
|
-
|
|
5593
|
-
|
|
5594
|
-
|
|
5595
|
-
|
|
5596
|
-
|
|
5597
|
-
|
|
5598
|
-
|
|
5599
|
-
|
|
6115
|
+
type ReturningSelectionNonEmptyError<Selection> = Selection & {
|
|
6116
|
+
readonly __effect_qb_error__: "effect-qb: returning(...) requires at least one selected expression"
|
|
6117
|
+
}
|
|
6118
|
+
|
|
6119
|
+
type ReturningSelectionNonEmptyConstraint<Selection> =
|
|
6120
|
+
Selection extends Expression.Any
|
|
6121
|
+
? unknown
|
|
6122
|
+
: [Extract<keyof Selection, string>] extends [never]
|
|
6123
|
+
? ReturningSelectionNonEmptyError<Selection>
|
|
6124
|
+
: unknown
|
|
6125
|
+
|
|
6126
|
+
type ReturningApi = Dialect extends "postgres"
|
|
6127
|
+
? <Selection extends SelectionShape>(
|
|
6128
|
+
selection: Selection & SelectionRootObjectConstraint<Selection> & SelectionNestedNonEmptyConstraint<Selection> & ReturningSelectionNonEmptyConstraint<Selection>
|
|
6129
|
+
) =>
|
|
6130
|
+
<PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
|
|
6131
|
+
plan: PlanValue & RequireMutationStatement<PlanValue>
|
|
6132
|
+
) => QueryPlan<
|
|
6133
|
+
Selection,
|
|
6134
|
+
Exclude<RequiredOfPlan<PlanValue> | ExtractRequired<Selection>, AvailableNames<AvailableOfPlan<PlanValue>>>,
|
|
6135
|
+
AvailableOfPlan<PlanValue>,
|
|
6136
|
+
PlanDialectOf<PlanValue> | ExtractDialect<Selection>,
|
|
6137
|
+
GroupedOfPlan<PlanValue>,
|
|
6138
|
+
ScopedNamesOfPlan<PlanValue>,
|
|
6139
|
+
Exclude<OutstandingOfPlan<PlanValue> | ExtractRequired<Selection>, AvailableNames<AvailableOfPlan<PlanValue>>>,
|
|
6140
|
+
AssumptionsOfPlan<PlanValue>,
|
|
6141
|
+
CapabilitiesOfPlan<PlanValue>,
|
|
6142
|
+
StatementOfPlan<PlanValue>,
|
|
6143
|
+
MutationTargetOfPlan<PlanValue>,
|
|
6144
|
+
InsertSourceStateOfPlan<PlanValue>,
|
|
6145
|
+
FactsOfPlan<PlanValue>
|
|
6146
|
+
>
|
|
6147
|
+
: ReturningUnsupportedError<Dialect>
|
|
5600
6148
|
|
|
5601
6149
|
export interface InsertApi {
|
|
5602
6150
|
<Target extends MutationTargetLike>(
|
|
@@ -5618,12 +6166,12 @@ type AsCurriedResult<
|
|
|
5618
6166
|
>
|
|
5619
6167
|
<Target extends MutationTargetLike, Values extends Record<string, unknown>>(
|
|
5620
6168
|
target: Target,
|
|
5621
|
-
values: MutationValuesInput<"insert", Target, Values>
|
|
6169
|
+
values: MutationValuesInput<"insert", Target, Values> & MutationValuesDialectConstraint<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
5622
6170
|
): QueryPlan<
|
|
5623
6171
|
{},
|
|
5624
6172
|
Exclude<MutationRequiredFromValues<Values>, SourceNameOf<Target>>,
|
|
5625
6173
|
AddAvailable<{}, SourceNameOf<Target>>,
|
|
5626
|
-
TableDialectOf<Target>,
|
|
6174
|
+
TableDialectOf<Target> | KnownMutationDialectFromValues<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5627
6175
|
never,
|
|
5628
6176
|
SourceNameOf<Target>,
|
|
5629
6177
|
Exclude<MutationRequiredFromValues<Values>, SourceNameOf<Target>>,
|
|
@@ -5645,21 +6193,22 @@ type AsCurriedResult<
|
|
|
5645
6193
|
Target extends MutationTargetLike,
|
|
5646
6194
|
const Columns extends DdlColumnInput,
|
|
5647
6195
|
UpdateValues extends MutationInputOf<Table.UpdateOf<Target>> | undefined = MutationInputOf<Table.UpdateOf<Target>> | undefined,
|
|
5648
|
-
Options extends ConflictActionInput<Target, Dialect, UpdateValues> = ConflictActionInput<Target, Dialect, UpdateValues
|
|
6196
|
+
Options extends ConflictActionInput<Target, Dialect, UpdateValues> = ConflictActionInput<Target, Dialect, UpdateValues>,
|
|
6197
|
+
ConflictTarget extends ConflictTargetInput<Target, Dialect, Columns> = ConflictTargetInput<Target, Dialect, Columns>
|
|
5649
6198
|
>(
|
|
5650
|
-
target:
|
|
5651
|
-
options?: Options
|
|
6199
|
+
target: ConflictTarget,
|
|
6200
|
+
options?: Options & ConflictActionUpdateNonEmptyConstraint<Options>
|
|
5652
6201
|
) =>
|
|
5653
6202
|
<PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
|
|
5654
6203
|
plan: PlanValue & RequireInsertStatement<PlanValue>
|
|
5655
6204
|
) => QueryPlan<
|
|
5656
6205
|
SelectionOfPlan<PlanValue>,
|
|
5657
|
-
Exclude<RequiredOfPlan<PlanValue> |
|
|
6206
|
+
Exclude<RequiredOfPlan<PlanValue> | ConflictRequired<UpdateValues, Options, ConflictTarget>, AvailableNames<AvailableOfPlan<PlanValue>>>,
|
|
5658
6207
|
AvailableOfPlan<PlanValue>,
|
|
5659
|
-
PlanDialectOf<PlanValue>,
|
|
6208
|
+
PlanDialectOf<PlanValue> | ConflictDialect<UpdateValues, Options, ConflictTarget, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5660
6209
|
GroupedOfPlan<PlanValue>,
|
|
5661
6210
|
ScopedNamesOfPlan<PlanValue>,
|
|
5662
|
-
Exclude<OutstandingOfPlan<PlanValue> |
|
|
6211
|
+
Exclude<OutstandingOfPlan<PlanValue> | ConflictRequired<UpdateValues, Options, ConflictTarget>, AvailableNames<AvailableOfPlan<PlanValue>>>,
|
|
5663
6212
|
AssumptionsOfPlan<PlanValue>,
|
|
5664
6213
|
CapabilitiesOfPlan<PlanValue>,
|
|
5665
6214
|
StatementOfPlan<PlanValue>,
|
|
@@ -5670,13 +6219,13 @@ type AsCurriedResult<
|
|
|
5670
6219
|
|
|
5671
6220
|
interface UpdateApi {
|
|
5672
6221
|
<Targets extends MutationTargetTuple, Values extends UpdateInputOfTarget<Targets>>(
|
|
5673
|
-
target: Dialect extends "mysql" ? Targets : never,
|
|
5674
|
-
values: Values
|
|
6222
|
+
target: Dialect extends "mysql" ? Targets & MutationTargetTupleDialectConstraint<Targets, Dialect> & MutationTargetTupleUniqueNamesConstraint<Targets> : never,
|
|
6223
|
+
values: Values & NestedUpdateValuesNonEmptyConstraint<Values> & MutationValuesDialectConstraint<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
5675
6224
|
): QueryPlan<
|
|
5676
6225
|
{},
|
|
5677
6226
|
Exclude<NestedMutationRequiredFromValues<Values>, MutationTargetNamesOf<Targets>>,
|
|
5678
6227
|
AddAvailableMany<{}, MutationTargetNamesOf<Targets>>,
|
|
5679
|
-
TableDialectOf<Targets[0]>,
|
|
6228
|
+
TableDialectOf<Targets[0]> | KnownMutationDialectFromValues<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5680
6229
|
never,
|
|
5681
6230
|
MutationTargetNamesOf<Targets>,
|
|
5682
6231
|
Exclude<NestedMutationRequiredFromValues<Values>, MutationTargetNamesOf<Targets>>,
|
|
@@ -5689,12 +6238,12 @@ type AsCurriedResult<
|
|
|
5689
6238
|
>
|
|
5690
6239
|
<Target extends MutationTargetLike, Values extends Record<string, unknown>>(
|
|
5691
6240
|
target: Target,
|
|
5692
|
-
values: MutationValuesInput<"update", Target, Values>
|
|
6241
|
+
values: MutationValuesInput<"update", Target, Values> & UpdateValuesNonEmptyConstraint<Values> & MutationValuesDialectConstraint<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
5693
6242
|
): QueryPlan<
|
|
5694
6243
|
{},
|
|
5695
6244
|
Exclude<MutationRequiredFromValues<Values>, SourceNameOf<Target>>,
|
|
5696
6245
|
AddAvailable<{}, SourceNameOf<Target>>,
|
|
5697
|
-
TableDialectOf<Target>,
|
|
6246
|
+
TableDialectOf<Target> | KnownMutationDialectFromValues<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5698
6247
|
never,
|
|
5699
6248
|
SourceNameOf<Target>,
|
|
5700
6249
|
Exclude<MutationRequiredFromValues<Values>, SourceNameOf<Target>>,
|
|
@@ -5711,20 +6260,22 @@ type AsCurriedResult<
|
|
|
5711
6260
|
Target extends MutationTargetLike,
|
|
5712
6261
|
Values extends MutationInputOf<Table.InsertOf<Target>>,
|
|
5713
6262
|
const Columns extends DdlColumnInput,
|
|
5714
|
-
UpdateValues extends MutationInputOf<Table.UpdateOf<Target>>
|
|
6263
|
+
UpdateValues extends MutationInputOf<Table.UpdateOf<Target>> | undefined = undefined
|
|
5715
6264
|
>(
|
|
5716
6265
|
target: Target,
|
|
5717
|
-
values: Values,
|
|
5718
|
-
conflictColumns:
|
|
5719
|
-
updateValues?: UpdateValues
|
|
6266
|
+
values: Values & MutationValuesDialectConstraint<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
6267
|
+
conflictColumns: ValidateTargetColumnInput<Target, Columns>,
|
|
6268
|
+
updateValues?: UpdateValues & UpdateValuesNonEmptyConstraint<Exclude<UpdateValues, undefined>> & MutationValuesDialectConstraint<Exclude<UpdateValues, undefined>, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
5720
6269
|
) => QueryPlan<
|
|
5721
6270
|
{},
|
|
5722
|
-
Exclude<MutationRequiredFromValues<Values> | MutationRequiredFromValues<UpdateValues
|
|
6271
|
+
Exclude<MutationRequiredFromValues<Values> | MutationRequiredFromValues<Exclude<UpdateValues, undefined>>, SourceNameOf<Target>>,
|
|
5723
6272
|
AddAvailable<{}, SourceNameOf<Target>>,
|
|
5724
|
-
TableDialectOf<Target
|
|
6273
|
+
| TableDialectOf<Target>
|
|
6274
|
+
| KnownMutationDialectFromValues<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
6275
|
+
| KnownMutationDialectFromValues<Exclude<UpdateValues, undefined>, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5725
6276
|
never,
|
|
5726
6277
|
SourceNameOf<Target>,
|
|
5727
|
-
Exclude<MutationRequiredFromValues<Values> | MutationRequiredFromValues<UpdateValues
|
|
6278
|
+
Exclude<MutationRequiredFromValues<Values> | MutationRequiredFromValues<Exclude<UpdateValues, undefined>>, SourceNameOf<Target>>,
|
|
5728
6279
|
TrueFormula,
|
|
5729
6280
|
"write",
|
|
5730
6281
|
"insert",
|
|
@@ -5752,7 +6303,7 @@ type AsCurriedResult<
|
|
|
5752
6303
|
EmptyFacts
|
|
5753
6304
|
>
|
|
5754
6305
|
<Targets extends MutationTargetTuple>(
|
|
5755
|
-
target: Dialect extends "mysql" ? Targets : never
|
|
6306
|
+
target: Dialect extends "mysql" ? Targets & MutationTargetTupleDialectConstraint<Targets, Dialect> & MutationTargetTupleUniqueNamesConstraint<Targets> : never
|
|
5756
6307
|
): QueryPlan<
|
|
5757
6308
|
{},
|
|
5758
6309
|
never,
|
|
@@ -5789,7 +6340,13 @@ type AsCurriedResult<
|
|
|
5789
6340
|
EmptyFacts
|
|
5790
6341
|
>
|
|
5791
6342
|
|
|
5792
|
-
type
|
|
6343
|
+
type MergeUnsupportedError<Dialect extends string> = {
|
|
6344
|
+
readonly __effect_qb_error__: "effect-qb: merge(...) is only supported by the postgres dialect"
|
|
6345
|
+
readonly __effect_qb_dialect__: Dialect
|
|
6346
|
+
readonly __effect_qb_hint__: "Use postgres.Query.merge(...) or dialect-specific insert/update/delete logic"
|
|
6347
|
+
}
|
|
6348
|
+
|
|
6349
|
+
type MergeSupportedApi = <
|
|
5793
6350
|
Target extends MutationTargetLike,
|
|
5794
6351
|
Source extends SourceLike,
|
|
5795
6352
|
On extends PredicateInput,
|
|
@@ -5803,7 +6360,7 @@ type AsCurriedResult<
|
|
|
5803
6360
|
SourceRequiredOf<Source> extends never ? unknown : SourceRequirementError<Source>
|
|
5804
6361
|
),
|
|
5805
6362
|
on: On,
|
|
5806
|
-
options
|
|
6363
|
+
options: MergeOptions<Target, MatchedValues, InsertValues, MatchedPredicate, NotMatchedPredicate>
|
|
5807
6364
|
) => QueryPlan<
|
|
5808
6365
|
{},
|
|
5809
6366
|
Exclude<
|
|
@@ -5846,7 +6403,10 @@ type AsCurriedResult<
|
|
|
5846
6403
|
EmptyFacts
|
|
5847
6404
|
>
|
|
5848
6405
|
|
|
6406
|
+
type MergeApi = Dialect extends "postgres" ? MergeSupportedApi : MergeUnsupportedError<Dialect>
|
|
6407
|
+
|
|
5849
6408
|
const mutationRuntime = makeDslMutationRuntime({
|
|
6409
|
+
profile,
|
|
5850
6410
|
makePlan,
|
|
5851
6411
|
getAst,
|
|
5852
6412
|
getQueryState,
|
|
@@ -5859,7 +6419,7 @@ type AsCurriedResult<
|
|
|
5859
6419
|
buildConflictTarget,
|
|
5860
6420
|
mutationTargetClauses,
|
|
5861
6421
|
mutationAvailableSources,
|
|
5862
|
-
|
|
6422
|
+
normalizeConflictColumns,
|
|
5863
6423
|
targetSourceDetails,
|
|
5864
6424
|
sourceDetails
|
|
5865
6425
|
})
|
|
@@ -5875,63 +6435,21 @@ type AsCurriedResult<
|
|
|
5875
6435
|
): QueryPlan<any, any, any, any, any, any, any, any, any, "insert", MutationTargetLike, "ready"> =>
|
|
5876
6436
|
mutationRuntime.attachInsertSource(plan, source)
|
|
5877
6437
|
|
|
5878
|
-
const onConflict:
|
|
5879
|
-
|
|
5880
|
-
|
|
5881
|
-
UpdateValues extends MutationInputOf<Table.UpdateOf<Target>> | undefined = MutationInputOf<Table.UpdateOf<Target>> | undefined,
|
|
5882
|
-
Options extends ConflictActionInput<Target, Dialect, UpdateValues> = ConflictActionInput<Target, Dialect, UpdateValues>
|
|
5883
|
-
>(
|
|
5884
|
-
target: ConflictTargetInput<Target, Dialect, Columns>,
|
|
5885
|
-
options: Options = {} as Options
|
|
5886
|
-
) =>
|
|
5887
|
-
<PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
|
|
5888
|
-
plan: PlanValue & RequireInsertStatement<PlanValue>
|
|
5889
|
-
): QueryPlan<
|
|
5890
|
-
SelectionOfPlan<PlanValue>,
|
|
5891
|
-
Exclude<RequiredOfPlan<PlanValue> | MutationRequiredFromValues<Exclude<UpdateValues, undefined>> | RequiredFromInput<Extract<Options["where"], PredicateInput>>, AvailableNames<AvailableOfPlan<PlanValue>>>,
|
|
5892
|
-
AvailableOfPlan<PlanValue>,
|
|
5893
|
-
PlanDialectOf<PlanValue>,
|
|
5894
|
-
GroupedOfPlan<PlanValue>,
|
|
5895
|
-
ScopedNamesOfPlan<PlanValue>,
|
|
5896
|
-
Exclude<OutstandingOfPlan<PlanValue> | MutationRequiredFromValues<Exclude<UpdateValues, undefined>> | RequiredFromInput<Extract<Options["where"], PredicateInput>>, AvailableNames<AvailableOfPlan<PlanValue>>>,
|
|
5897
|
-
AssumptionsOfPlan<PlanValue>,
|
|
5898
|
-
CapabilitiesOfPlan<PlanValue>,
|
|
5899
|
-
StatementOfPlan<PlanValue>,
|
|
5900
|
-
MutationTargetOfPlan<PlanValue>,
|
|
5901
|
-
InsertSourceStateOfPlan<PlanValue>,
|
|
5902
|
-
FactsOfPlan<PlanValue>
|
|
5903
|
-
> => mutationRuntime.onConflict(target, options)(plan)
|
|
6438
|
+
const onConflict = ((target: unknown, options: unknown = {}) =>
|
|
6439
|
+
(plan: QueryPlan<any, any, any, any, any, any, any, any, any, any>) =>
|
|
6440
|
+
mutationRuntime.onConflict(target, options)(plan)) as OnConflictApi
|
|
5904
6441
|
|
|
5905
6442
|
const update: UpdateApi = ((
|
|
5906
6443
|
target: MutationTargetInput,
|
|
5907
6444
|
values: Record<string, unknown>
|
|
5908
6445
|
) => mutationRuntime.update(target, values)) as UpdateApi
|
|
5909
6446
|
|
|
5910
|
-
const upsert
|
|
5911
|
-
|
|
5912
|
-
|
|
5913
|
-
|
|
5914
|
-
|
|
5915
|
-
|
|
5916
|
-
target: Target,
|
|
5917
|
-
values: Values,
|
|
5918
|
-
conflictColumns: ValidateTargetColumns<Target, NormalizeDdlColumns<Columns>>,
|
|
5919
|
-
updateValues?: UpdateValues
|
|
5920
|
-
): QueryPlan<
|
|
5921
|
-
{},
|
|
5922
|
-
Exclude<MutationRequiredFromValues<Values> | MutationRequiredFromValues<UpdateValues>, SourceNameOf<Target>>,
|
|
5923
|
-
AddAvailable<{}, SourceNameOf<Target>>,
|
|
5924
|
-
TableDialectOf<Target>,
|
|
5925
|
-
never,
|
|
5926
|
-
SourceNameOf<Target>,
|
|
5927
|
-
Exclude<MutationRequiredFromValues<Values> | MutationRequiredFromValues<UpdateValues>, SourceNameOf<Target>>,
|
|
5928
|
-
TrueFormula,
|
|
5929
|
-
"write",
|
|
5930
|
-
"insert",
|
|
5931
|
-
Target,
|
|
5932
|
-
"ready",
|
|
5933
|
-
EmptyFacts
|
|
5934
|
-
> => mutationRuntime.upsert(target, values, conflictColumns as string | readonly string[], updateValues)
|
|
6447
|
+
const upsert = ((
|
|
6448
|
+
target: MutationTargetLike,
|
|
6449
|
+
values: Record<string, unknown>,
|
|
6450
|
+
conflictColumns: DdlColumnInput,
|
|
6451
|
+
updateValues?: Record<string, unknown>
|
|
6452
|
+
) => mutationRuntime.upsert(target, values, conflictColumns as string | readonly string[], updateValues)) as UpsertApi
|
|
5935
6453
|
|
|
5936
6454
|
const delete_: DeleteApi = ((
|
|
5937
6455
|
target: MutationTargetInput
|
|
@@ -5958,7 +6476,7 @@ type AsCurriedResult<
|
|
|
5958
6476
|
EmptyFacts
|
|
5959
6477
|
> => mutationRuntime.truncate(target, options)
|
|
5960
6478
|
|
|
5961
|
-
const merge
|
|
6479
|
+
const merge = (<
|
|
5962
6480
|
Target extends MutationTargetLike,
|
|
5963
6481
|
Source extends SourceLike,
|
|
5964
6482
|
On extends PredicateInput,
|
|
@@ -5972,7 +6490,7 @@ type AsCurriedResult<
|
|
|
5972
6490
|
SourceRequiredOf<Source> extends never ? unknown : SourceRequirementError<Source>
|
|
5973
6491
|
),
|
|
5974
6492
|
on: On,
|
|
5975
|
-
options: MergeOptions<Target, MatchedValues, InsertValues, MatchedPredicate, NotMatchedPredicate>
|
|
6493
|
+
options: MergeOptions<Target, MatchedValues, InsertValues, MatchedPredicate, NotMatchedPredicate>
|
|
5976
6494
|
): QueryPlan<
|
|
5977
6495
|
{},
|
|
5978
6496
|
Exclude<
|
|
@@ -6013,7 +6531,7 @@ type AsCurriedResult<
|
|
|
6013
6531
|
any,
|
|
6014
6532
|
"ready",
|
|
6015
6533
|
EmptyFacts
|
|
6016
|
-
> => mutationRuntime.merge(target, source, on, options)
|
|
6534
|
+
> => mutationRuntime.merge(target, source, on, options)) as unknown as MergeApi
|
|
6017
6535
|
|
|
6018
6536
|
type TransactionApi = (options?: TransactionOptions) => QueryPlan<
|
|
6019
6537
|
{},
|
|
@@ -6127,7 +6645,7 @@ type AsCurriedResult<
|
|
|
6127
6645
|
|
|
6128
6646
|
type CreateIndexApi = <Target extends SchemaTableLike, const Columns extends DdlColumnInput>(
|
|
6129
6647
|
target: Target,
|
|
6130
|
-
columns: Columns &
|
|
6648
|
+
columns: Columns & ValidateDdlColumnInput<Target, Columns>,
|
|
6131
6649
|
options?: CreateIndexOptions
|
|
6132
6650
|
) => QueryPlan<
|
|
6133
6651
|
{},
|
|
@@ -6144,7 +6662,7 @@ type AsCurriedResult<
|
|
|
6144
6662
|
|
|
6145
6663
|
type DropIndexApi = <Target extends SchemaTableLike, const Columns extends DdlColumnInput>(
|
|
6146
6664
|
target: Target,
|
|
6147
|
-
columns: Columns &
|
|
6665
|
+
columns: Columns & ValidateDdlColumnInput<Target, Columns>,
|
|
6148
6666
|
options?: DropIndexOptions
|
|
6149
6667
|
) => QueryPlan<
|
|
6150
6668
|
{},
|