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,
|
|
@@ -1696,10 +1723,16 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
|
|
|
1696
1723
|
spec: WindowSpecInput<PartitionBy, OrderBy> | OrderedWindowSpecInput<PartitionBy, Extract<OrderBy, NonEmptyWindowOrderTerms>> | undefined
|
|
1697
1724
|
) => {
|
|
1698
1725
|
const partitionBy = [...(spec?.partitionBy ?? [])] as unknown as PartitionBy
|
|
1699
|
-
const orderBy = (spec?.orderBy ?? []).map((term) =>
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1726
|
+
const orderBy = (spec?.orderBy ?? []).map((term) => {
|
|
1727
|
+
const direction = term.direction ?? "asc"
|
|
1728
|
+
if (direction !== "asc" && direction !== "desc") {
|
|
1729
|
+
throw new Error("window order direction must be asc or desc")
|
|
1730
|
+
}
|
|
1731
|
+
return {
|
|
1732
|
+
value: term.value,
|
|
1733
|
+
direction
|
|
1734
|
+
}
|
|
1735
|
+
}) as {
|
|
1703
1736
|
readonly [K in keyof OrderBy]: OrderBy[K] extends WindowOrderTermInput<infer Value extends WindowOrderInput>
|
|
1704
1737
|
? { readonly value: Value; readonly direction: OrderDirection }
|
|
1705
1738
|
: never
|
|
@@ -2073,9 +2106,15 @@ type BinaryPredicateExpression<
|
|
|
2073
2106
|
})
|
|
2074
2107
|
}
|
|
2075
2108
|
|
|
2076
|
-
|
|
2109
|
+
type NormalizedCollation<Collation extends string | readonly [string, ...string[]]> =
|
|
2110
|
+
Collation extends string ? readonly [Collation] : Collation
|
|
2111
|
+
|
|
2112
|
+
const collate = <
|
|
2113
|
+
Value extends ExpressionInput,
|
|
2114
|
+
Collation extends string | readonly [string, ...string[]]
|
|
2115
|
+
>(
|
|
2077
2116
|
value: Value & TextInput<NoInfer<Value>, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "collate">,
|
|
2078
|
-
collation:
|
|
2117
|
+
collation: Collation
|
|
2079
2118
|
): AstBackedExpression<
|
|
2080
2119
|
Expression.RuntimeOf<DialectAsStringExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
|
|
2081
2120
|
Expression.DbTypeOf<DialectAsStringExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
|
|
@@ -2083,10 +2122,10 @@ type BinaryPredicateExpression<
|
|
|
2083
2122
|
DialectOfDialectStringInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
2084
2123
|
KindOf<DialectAsStringExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
|
|
2085
2124
|
DependenciesOfDialectStringInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
2086
|
-
ExpressionAst.CollateNode<DialectAsStringExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>
|
|
2125
|
+
ExpressionAst.CollateNode<DialectAsStringExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>, NormalizedCollation<Collation>>
|
|
2087
2126
|
> => {
|
|
2088
2127
|
const expression = toDialectStringExpression(value as any)
|
|
2089
|
-
const normalizedCollation
|
|
2128
|
+
const normalizedCollation = (typeof collation === "string" ? [collation] : collation) as NormalizedCollation<Collation>
|
|
2090
2129
|
return makeExpression({
|
|
2091
2130
|
runtime: expression[Expression.TypeId].runtime as Expression.RuntimeOf<DialectAsStringExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
|
|
2092
2131
|
dbType: expression[Expression.TypeId].dbType as Expression.DbTypeOf<DialectAsStringExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
|
|
@@ -2106,7 +2145,7 @@ type BinaryPredicateExpression<
|
|
|
2106
2145
|
DialectOfDialectStringInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
2107
2146
|
KindOf<DialectAsStringExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
|
|
2108
2147
|
DependenciesOfDialectStringInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
2109
|
-
ExpressionAst.CollateNode<DialectAsStringExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>
|
|
2148
|
+
ExpressionAst.CollateNode<DialectAsStringExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>, NormalizedCollation<Collation>>
|
|
2110
2149
|
>
|
|
2111
2150
|
}
|
|
2112
2151
|
|
|
@@ -2702,7 +2741,7 @@ type BinaryPredicateExpression<
|
|
|
2702
2741
|
Next extends JsonValueInput
|
|
2703
2742
|
>(
|
|
2704
2743
|
base: Base,
|
|
2705
|
-
target: Target & JsonSetGuard<Expression.RuntimeOf<Base>, Target, Next
|
|
2744
|
+
target: Target & JsonSetGuard<Expression.RuntimeOf<Base>, Target, NoInfer<Next>, "json.set">,
|
|
2706
2745
|
next: Next,
|
|
2707
2746
|
options: {
|
|
2708
2747
|
readonly createMissing?: boolean
|
|
@@ -2750,7 +2789,7 @@ type BinaryPredicateExpression<
|
|
|
2750
2789
|
InsertAfter extends boolean = false
|
|
2751
2790
|
>(
|
|
2752
2791
|
base: Base,
|
|
2753
|
-
target: Target & JsonInsertGuard<Expression.RuntimeOf<Base>, Target, Next
|
|
2792
|
+
target: Target & JsonInsertGuard<Expression.RuntimeOf<Base>, Target, NoInfer<Next>, NoInfer<InsertAfter>, "json.insert">,
|
|
2754
2793
|
next: Next,
|
|
2755
2794
|
options: {
|
|
2756
2795
|
readonly insertAfter?: InsertAfter
|
|
@@ -3964,7 +4003,9 @@ type BinaryPredicateExpression<
|
|
|
3964
4003
|
string,
|
|
3965
4004
|
"scalar",
|
|
3966
4005
|
Expression.BindingId
|
|
3967
|
-
>
|
|
4006
|
+
> & {
|
|
4007
|
+
readonly [ExpressionAst.TypeId]: ExpressionAst.ColumnNode<any, string>
|
|
4008
|
+
}
|
|
3968
4009
|
>(
|
|
3969
4010
|
value: Value
|
|
3970
4011
|
): AstBackedExpression<
|
|
@@ -4008,22 +4049,56 @@ type BinaryPredicateExpression<
|
|
|
4008
4049
|
value: Value,
|
|
4009
4050
|
column: Expression.Any
|
|
4010
4051
|
): Expression.Any => {
|
|
4052
|
+
const columnState = column[Expression.TypeId]
|
|
4053
|
+
const normalizeMutationValue = (candidate: unknown): unknown => {
|
|
4054
|
+
if (candidate === null && columnState.nullability !== "never") {
|
|
4055
|
+
return null
|
|
4056
|
+
}
|
|
4057
|
+
const runtimeSchemaAccepts = columnState.runtimeSchema !== undefined &&
|
|
4058
|
+
(Schema.is(columnState.runtimeSchema) as (input: unknown) => boolean)(candidate)
|
|
4059
|
+
if (runtimeSchemaAccepts) {
|
|
4060
|
+
return candidate
|
|
4061
|
+
}
|
|
4062
|
+
const normalized = normalizeDbValue(columnState.dbType, candidate)
|
|
4063
|
+
return columnState.runtimeSchema === undefined
|
|
4064
|
+
? normalized
|
|
4065
|
+
: (Schema.decodeUnknownSync as any)(columnState.runtimeSchema)(normalized)
|
|
4066
|
+
}
|
|
4011
4067
|
if (value !== null && typeof value === "object" && Expression.TypeId in value) {
|
|
4068
|
+
const expression = value as unknown as Expression.Any
|
|
4069
|
+
const ast = (expression as unknown as { readonly [ExpressionAst.TypeId]: ExpressionAst.Any })[ExpressionAst.TypeId]
|
|
4070
|
+
if (ast.kind === "literal") {
|
|
4071
|
+
const normalizedValue = normalizeMutationValue(ast.value)
|
|
4072
|
+
return makeExpression({
|
|
4073
|
+
runtime: normalizedValue,
|
|
4074
|
+
dbType: columnState.dbType,
|
|
4075
|
+
runtimeSchema: columnState.runtimeSchema,
|
|
4076
|
+
driverValueMapping: columnState.driverValueMapping,
|
|
4077
|
+
nullability: normalizedValue === null ? "always" : "never",
|
|
4078
|
+
dialect: columnState.dialect,
|
|
4079
|
+
kind: "scalar",
|
|
4080
|
+
dependencies: {}
|
|
4081
|
+
}, {
|
|
4082
|
+
kind: "literal",
|
|
4083
|
+
value: normalizedValue
|
|
4084
|
+
})
|
|
4085
|
+
}
|
|
4012
4086
|
return retargetLiteralExpression(value as unknown as Expression.Any, column)
|
|
4013
4087
|
}
|
|
4088
|
+
const normalizedValue = normalizeMutationValue(value)
|
|
4014
4089
|
return makeExpression({
|
|
4015
|
-
runtime:
|
|
4016
|
-
dbType:
|
|
4017
|
-
runtimeSchema:
|
|
4018
|
-
driverValueMapping:
|
|
4019
|
-
nullability:
|
|
4020
|
-
dialect:
|
|
4090
|
+
runtime: normalizedValue as Value,
|
|
4091
|
+
dbType: columnState.dbType,
|
|
4092
|
+
runtimeSchema: columnState.runtimeSchema,
|
|
4093
|
+
driverValueMapping: columnState.driverValueMapping,
|
|
4094
|
+
nullability: normalizedValue === null ? "always" : "never",
|
|
4095
|
+
dialect: columnState.dialect,
|
|
4021
4096
|
kind: "scalar",
|
|
4022
4097
|
|
|
4023
4098
|
dependencies: {}
|
|
4024
4099
|
}, {
|
|
4025
4100
|
kind: "literal",
|
|
4026
|
-
value
|
|
4101
|
+
value: normalizedValue
|
|
4027
4102
|
})
|
|
4028
4103
|
}
|
|
4029
4104
|
|
|
@@ -4111,16 +4186,16 @@ type BinaryPredicateExpression<
|
|
|
4111
4186
|
Alias extends string
|
|
4112
4187
|
>(
|
|
4113
4188
|
rows: readonly [Record<string, Expression.Any>, ...Record<string, Expression.Any>[]],
|
|
4114
|
-
selection: ValuesOutputShape<Rows
|
|
4189
|
+
selection: ValuesOutputShape<Rows, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
4115
4190
|
alias: Alias
|
|
4116
4191
|
): ValuesSource<
|
|
4117
4192
|
Rows,
|
|
4118
|
-
ValuesOutputShape<Rows
|
|
4193
|
+
ValuesOutputShape<Rows, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
4119
4194
|
Alias,
|
|
4120
4195
|
Dialect
|
|
4121
4196
|
> => {
|
|
4122
4197
|
const columns = makeColumnReferenceSelection(alias, selection as Record<string, Expression.Any>) as unknown as ValuesOutputShape<
|
|
4123
|
-
Rows
|
|
4198
|
+
Rows,
|
|
4124
4199
|
Dialect,
|
|
4125
4200
|
TextDb,
|
|
4126
4201
|
NumericDb,
|
|
@@ -4138,7 +4213,7 @@ type BinaryPredicateExpression<
|
|
|
4138
4213
|
}
|
|
4139
4214
|
return Object.assign(source, columns) as unknown as ValuesSource<
|
|
4140
4215
|
Rows,
|
|
4141
|
-
ValuesOutputShape<Rows
|
|
4216
|
+
ValuesOutputShape<Rows, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
4142
4217
|
Alias,
|
|
4143
4218
|
Dialect
|
|
4144
4219
|
>
|
|
@@ -4151,7 +4226,12 @@ type BinaryPredicateExpression<
|
|
|
4151
4226
|
|
|
4152
4227
|
const normalizeUnnestColumns = (columns: UnnestColumnsInput): Record<string, readonly Expression.Any[]> =>
|
|
4153
4228
|
Object.fromEntries(
|
|
4154
|
-
Object.entries(columns).map(([key, values]) =>
|
|
4229
|
+
Object.entries(columns).map(([key, values]) => {
|
|
4230
|
+
if (!Array.isArray(values)) {
|
|
4231
|
+
throw new Error("unnest(...) expects every value to be an array")
|
|
4232
|
+
}
|
|
4233
|
+
return [key, values.map((value) => toDialectExpression(value))]
|
|
4234
|
+
})
|
|
4155
4235
|
) as Record<string, readonly Expression.Any[]>
|
|
4156
4236
|
|
|
4157
4237
|
const normalizeMutationTargets = (
|
|
@@ -4194,6 +4274,17 @@ type BinaryPredicateExpression<
|
|
|
4194
4274
|
})
|
|
4195
4275
|
) as unknown as AddAvailableMany<{}, MutationTargetNamesOf<Target>, Mode>
|
|
4196
4276
|
|
|
4277
|
+
const getMutationColumn = (
|
|
4278
|
+
columns: Record<string, unknown>,
|
|
4279
|
+
columnName: string
|
|
4280
|
+
): Expression.Any => {
|
|
4281
|
+
const column = columns[columnName]
|
|
4282
|
+
if (column === undefined || column === null || typeof column !== "object" || !(Expression.TypeId in column)) {
|
|
4283
|
+
throw new Error("effect-qb: unknown mutation column")
|
|
4284
|
+
}
|
|
4285
|
+
return column as Expression.Any
|
|
4286
|
+
}
|
|
4287
|
+
|
|
4197
4288
|
const buildMutationAssignments = <Target extends MutationTargetInput, Values>(
|
|
4198
4289
|
target: Target,
|
|
4199
4290
|
values: Values
|
|
@@ -4203,7 +4294,7 @@ type BinaryPredicateExpression<
|
|
|
4203
4294
|
const columns = target as unknown as Record<string, Expression.Any>
|
|
4204
4295
|
return Object.entries(values as Record<string, unknown>).map(([columnName, value]) => ({
|
|
4205
4296
|
columnName,
|
|
4206
|
-
value: toMutationValueExpression(value, columns
|
|
4297
|
+
value: toMutationValueExpression(value, getMutationColumn(columns, columnName))
|
|
4207
4298
|
}))
|
|
4208
4299
|
}
|
|
4209
4300
|
const valueMap = values as Record<string, Record<string, unknown> | undefined>
|
|
@@ -4214,7 +4305,7 @@ type BinaryPredicateExpression<
|
|
|
4214
4305
|
return Object.entries(scopedValues).map(([columnName, value]) => ({
|
|
4215
4306
|
tableName: targetName,
|
|
4216
4307
|
columnName,
|
|
4217
|
-
value: toMutationValueExpression(value, columns
|
|
4308
|
+
value: toMutationValueExpression(value, getMutationColumn(columns, columnName))
|
|
4218
4309
|
}))
|
|
4219
4310
|
})
|
|
4220
4311
|
}
|
|
@@ -4301,14 +4392,26 @@ type BinaryPredicateExpression<
|
|
|
4301
4392
|
}
|
|
4302
4393
|
}
|
|
4303
4394
|
|
|
4395
|
+
const normalizeConflictColumns = <Target extends MutationTargetLike>(
|
|
4396
|
+
target: Target,
|
|
4397
|
+
columnsInput: string | readonly string[]
|
|
4398
|
+
): readonly [string, ...string[]] => {
|
|
4399
|
+
const columns = normalizeColumnList(columnsInput) as readonly [string, ...string[]]
|
|
4400
|
+
const knownColumns = new Set(Object.keys(target[Table.TypeId].fields))
|
|
4401
|
+
if (columns.some((columnName) => !knownColumns.has(columnName))) {
|
|
4402
|
+
throw new Error("effect-qb: unknown conflict target column")
|
|
4403
|
+
}
|
|
4404
|
+
return columns
|
|
4405
|
+
}
|
|
4406
|
+
|
|
4304
4407
|
const buildConflictTarget = <Target extends MutationTargetLike>(
|
|
4305
4408
|
target: Target,
|
|
4306
|
-
input: readonly string[] | { readonly columns: readonly string[]; readonly where?: PredicateInput } | { readonly constraint: string }
|
|
4409
|
+
input: string | readonly string[] | { readonly columns: string | readonly string[]; readonly where?: PredicateInput } | { readonly constraint: string }
|
|
4307
4410
|
): QueryAst.ConflictTargetClause => {
|
|
4308
|
-
if (Array.isArray(input)) {
|
|
4411
|
+
if (typeof input === "string" || Array.isArray(input)) {
|
|
4309
4412
|
return {
|
|
4310
4413
|
kind: "columns",
|
|
4311
|
-
columns:
|
|
4414
|
+
columns: normalizeConflictColumns(target, input)
|
|
4312
4415
|
}
|
|
4313
4416
|
}
|
|
4314
4417
|
if (!Array.isArray(input) && "constraint" in input) {
|
|
@@ -4318,12 +4421,12 @@ type BinaryPredicateExpression<
|
|
|
4318
4421
|
}
|
|
4319
4422
|
}
|
|
4320
4423
|
const columnTarget = input as {
|
|
4321
|
-
readonly columns: readonly string[]
|
|
4424
|
+
readonly columns: string | readonly string[]
|
|
4322
4425
|
readonly where?: PredicateInput
|
|
4323
4426
|
}
|
|
4324
4427
|
return {
|
|
4325
4428
|
kind: "columns",
|
|
4326
|
-
columns:
|
|
4429
|
+
columns: normalizeConflictColumns(target, columnTarget.columns),
|
|
4327
4430
|
where: columnTarget.where === undefined ? undefined : toDialectExpression(columnTarget.where)
|
|
4328
4431
|
}
|
|
4329
4432
|
}
|
|
@@ -4361,11 +4464,21 @@ type ValidateDdlColumns<
|
|
|
4361
4464
|
Columns extends readonly string[]
|
|
4362
4465
|
> = Exclude<Columns[number], SchemaColumnNames<Target>> extends never ? Columns : never
|
|
4363
4466
|
|
|
4467
|
+
type ValidateDdlColumnInput<
|
|
4468
|
+
Target extends SchemaTableLike,
|
|
4469
|
+
Columns extends DdlColumnInput
|
|
4470
|
+
> = ValidateDdlColumns<Target, NormalizeDdlColumns<Columns>> extends never ? never : Columns
|
|
4471
|
+
|
|
4364
4472
|
type ValidateTargetColumns<
|
|
4365
4473
|
Target extends MutationTargetLike,
|
|
4366
4474
|
Columns extends readonly string[]
|
|
4367
4475
|
> = Exclude<Columns[number], Extract<keyof Target[typeof Table.TypeId]["fields"], string>> extends never ? Columns : never
|
|
4368
4476
|
|
|
4477
|
+
type ValidateTargetColumnInput<
|
|
4478
|
+
Target extends MutationTargetLike,
|
|
4479
|
+
Columns extends DdlColumnInput
|
|
4480
|
+
> = ValidateTargetColumns<Target, NormalizeDdlColumns<Columns>> extends never ? never : Columns
|
|
4481
|
+
|
|
4369
4482
|
type CreateIndexOptions = {
|
|
4370
4483
|
readonly name?: string
|
|
4371
4484
|
readonly unique?: boolean
|
|
@@ -4395,10 +4508,15 @@ type TransactionOptions = {
|
|
|
4395
4508
|
readonly readOnly?: boolean
|
|
4396
4509
|
}
|
|
4397
4510
|
|
|
4398
|
-
type LockOptions =
|
|
4399
|
-
|
|
4400
|
-
|
|
4401
|
-
|
|
4511
|
+
type LockOptions =
|
|
4512
|
+
| {
|
|
4513
|
+
readonly nowait?: boolean
|
|
4514
|
+
readonly skipLocked?: false
|
|
4515
|
+
}
|
|
4516
|
+
| {
|
|
4517
|
+
readonly nowait?: false
|
|
4518
|
+
readonly skipLocked?: boolean
|
|
4519
|
+
}
|
|
4402
4520
|
|
|
4403
4521
|
type UpsertConflictOptions = {
|
|
4404
4522
|
readonly update?: Record<string, unknown>
|
|
@@ -4413,14 +4531,133 @@ type InsertRowInput<Target extends MutationTargetLike> = MutationInputOf<Table.I
|
|
|
4413
4531
|
type ValuesRowInput = Record<string, ExpressionInput>
|
|
4414
4532
|
type ValuesRowsInput = readonly [ValuesRowInput, ...ValuesRowInput[]]
|
|
4415
4533
|
|
|
4534
|
+
type ValuesColumnInput<Row, Key extends PropertyKey> =
|
|
4535
|
+
Row extends ValuesRowInput
|
|
4536
|
+
? Key extends keyof Row ? Row[Key] : never
|
|
4537
|
+
: never
|
|
4538
|
+
|
|
4539
|
+
type ValuesRowShapeMismatch<
|
|
4540
|
+
First extends ValuesRowInput,
|
|
4541
|
+
Row extends ValuesRowInput
|
|
4542
|
+
> =
|
|
4543
|
+
| Exclude<Extract<keyof Row, string>, Extract<keyof First, string>>
|
|
4544
|
+
| Exclude<Extract<keyof First, string>, Extract<keyof Row, string>>
|
|
4545
|
+
|
|
4546
|
+
type ValuesRowsShapeMismatchesFor<
|
|
4547
|
+
First extends ValuesRowInput,
|
|
4548
|
+
Row
|
|
4549
|
+
> = Row extends ValuesRowInput ? ValuesRowShapeMismatch<First, Row> : never
|
|
4550
|
+
|
|
4551
|
+
type ValuesRowsShapeMismatches<Rows extends ValuesRowsInput> =
|
|
4552
|
+
Rows extends readonly [infer First extends ValuesRowInput, ...infer Rest extends ValuesRowInput[]]
|
|
4553
|
+
? ValuesRowsShapeMismatchesFor<First, Rest[number]>
|
|
4554
|
+
: never
|
|
4555
|
+
|
|
4556
|
+
type ValuesRowsColumnKeys<Rows extends ValuesRowsInput> =
|
|
4557
|
+
Rows extends readonly [infer First extends ValuesRowInput, ...ValuesRowInput[]]
|
|
4558
|
+
? Extract<keyof First, string>
|
|
4559
|
+
: never
|
|
4560
|
+
|
|
4561
|
+
type ValuesRowsShapeInput<Rows extends ValuesRowsInput> =
|
|
4562
|
+
[ValuesRowsColumnKeys<Rows>] extends [never]
|
|
4563
|
+
? {
|
|
4564
|
+
readonly __effect_qb_error__: "effect-qb: values rows must project at least one column"
|
|
4565
|
+
}
|
|
4566
|
+
: [ValuesRowsShapeMismatches<Rows>] extends [never]
|
|
4567
|
+
? unknown
|
|
4568
|
+
: {
|
|
4569
|
+
readonly __effect_qb_error__: "effect-qb: values rows must project the same columns"
|
|
4570
|
+
readonly __effect_qb_mismatched_columns__: ValuesRowsShapeMismatches<Rows>
|
|
4571
|
+
}
|
|
4572
|
+
|
|
4573
|
+
type ValuesRowsDialect<
|
|
4574
|
+
Rows extends ValuesRowsInput,
|
|
4575
|
+
Dialect extends string,
|
|
4576
|
+
TextDb extends Expression.DbType.Any,
|
|
4577
|
+
NumericDb extends Expression.DbType.Any,
|
|
4578
|
+
BoolDb extends Expression.DbType.Any,
|
|
4579
|
+
TimestampDb extends Expression.DbType.Any,
|
|
4580
|
+
NullDb extends Expression.DbType.Any
|
|
4581
|
+
> = Rows[number][keyof Rows[number]] extends infer Value extends ExpressionInput
|
|
4582
|
+
? DialectOfDialectInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
4583
|
+
: never
|
|
4584
|
+
|
|
4585
|
+
type ValuesRowsDialectInput<
|
|
4586
|
+
Rows extends ValuesRowsInput,
|
|
4587
|
+
Dialect extends string,
|
|
4588
|
+
TextDb extends Expression.DbType.Any,
|
|
4589
|
+
NumericDb extends Expression.DbType.Any,
|
|
4590
|
+
BoolDb extends Expression.DbType.Any,
|
|
4591
|
+
TimestampDb extends Expression.DbType.Any,
|
|
4592
|
+
NullDb extends Expression.DbType.Any
|
|
4593
|
+
> = Exclude<ValuesRowsDialect<Rows, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>, Dialect> extends never
|
|
4594
|
+
? unknown
|
|
4595
|
+
: {
|
|
4596
|
+
readonly __effect_qb_error__: "effect-qb: values rows cannot mix dialects"
|
|
4597
|
+
readonly __effect_qb_dialect__: ValuesRowsDialect<Rows, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
4598
|
+
}
|
|
4599
|
+
|
|
4416
4600
|
type UnnestColumnsInput = Record<string, readonly [ExpressionInput, ...ExpressionInput[]]>
|
|
4417
4601
|
|
|
4602
|
+
type IsNever<Value> = [Value] extends [never] ? true : false
|
|
4603
|
+
|
|
4604
|
+
type IsUnion<Value, All = Value> = Value extends any
|
|
4605
|
+
? ([All] extends [Value] ? false : true)
|
|
4606
|
+
: never
|
|
4607
|
+
|
|
4608
|
+
type UnnestColumnKeys<Columns extends UnnestColumnsInput> =
|
|
4609
|
+
Extract<keyof Columns, string>
|
|
4610
|
+
|
|
4611
|
+
type UnnestColumnLengths<Columns extends UnnestColumnsInput> =
|
|
4612
|
+
Columns[UnnestColumnKeys<Columns>]["length"]
|
|
4613
|
+
|
|
4614
|
+
type UnnestColumnsShapeInput<Columns extends UnnestColumnsInput> =
|
|
4615
|
+
IsNever<UnnestColumnKeys<Columns>> extends true
|
|
4616
|
+
? {
|
|
4617
|
+
readonly __effect_qb_error__: "effect-qb: unnest requires at least one column array"
|
|
4618
|
+
}
|
|
4619
|
+
: number extends UnnestColumnLengths<Columns>
|
|
4620
|
+
? unknown
|
|
4621
|
+
: IsUnion<UnnestColumnLengths<Columns>> extends true
|
|
4622
|
+
? {
|
|
4623
|
+
readonly __effect_qb_error__: "effect-qb: unnest column arrays must have the same length"
|
|
4624
|
+
readonly __effect_qb_column_lengths__: UnnestColumnLengths<Columns>
|
|
4625
|
+
}
|
|
4626
|
+
: unknown
|
|
4627
|
+
|
|
4628
|
+
type UnnestColumnsDialect<
|
|
4629
|
+
Columns extends UnnestColumnsInput,
|
|
4630
|
+
Dialect extends string,
|
|
4631
|
+
TextDb extends Expression.DbType.Any,
|
|
4632
|
+
NumericDb extends Expression.DbType.Any,
|
|
4633
|
+
BoolDb extends Expression.DbType.Any,
|
|
4634
|
+
TimestampDb extends Expression.DbType.Any,
|
|
4635
|
+
NullDb extends Expression.DbType.Any
|
|
4636
|
+
> = Columns[UnnestColumnKeys<Columns>][number] extends infer Value extends ExpressionInput
|
|
4637
|
+
? DialectOfDialectInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
4638
|
+
: never
|
|
4639
|
+
|
|
4640
|
+
type UnnestColumnsDialectInput<
|
|
4641
|
+
Columns extends UnnestColumnsInput,
|
|
4642
|
+
Dialect extends string,
|
|
4643
|
+
TextDb extends Expression.DbType.Any,
|
|
4644
|
+
NumericDb extends Expression.DbType.Any,
|
|
4645
|
+
BoolDb extends Expression.DbType.Any,
|
|
4646
|
+
TimestampDb extends Expression.DbType.Any,
|
|
4647
|
+
NullDb extends Expression.DbType.Any
|
|
4648
|
+
> = Exclude<UnnestColumnsDialect<Columns, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>, Dialect> extends never
|
|
4649
|
+
? unknown
|
|
4650
|
+
: {
|
|
4651
|
+
readonly __effect_qb_error__: "effect-qb: unnest columns cannot mix dialects"
|
|
4652
|
+
readonly __effect_qb_dialect__: UnnestColumnsDialect<Columns, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
4653
|
+
}
|
|
4654
|
+
|
|
4418
4655
|
type UnnestRowShape<Shape extends Record<string, readonly unknown[]>> = {
|
|
4419
4656
|
readonly [K in keyof Shape]: Shape[K] extends readonly (infer Item)[] ? Item : never
|
|
4420
4657
|
}
|
|
4421
4658
|
|
|
4422
4659
|
type ValuesOutputShape<
|
|
4423
|
-
|
|
4660
|
+
Rows extends ValuesRowsInput,
|
|
4424
4661
|
Dialect extends string,
|
|
4425
4662
|
TextDb extends Expression.DbType.Any,
|
|
4426
4663
|
NumericDb extends Expression.DbType.Any,
|
|
@@ -4428,7 +4665,7 @@ type ValuesOutputShape<
|
|
|
4428
4665
|
TimestampDb extends Expression.DbType.Any,
|
|
4429
4666
|
NullDb extends Expression.DbType.Any
|
|
4430
4667
|
> = {
|
|
4431
|
-
readonly [K in keyof
|
|
4668
|
+
readonly [K in keyof Rows[0]]: DialectAsExpression<ValuesColumnInput<Rows[number], K>, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
4432
4669
|
}
|
|
4433
4670
|
|
|
4434
4671
|
type UnnestOutputShape<
|
|
@@ -4468,18 +4705,18 @@ type DistinctOnUnsupportedError<Dialect extends string> = {
|
|
|
4468
4705
|
}
|
|
4469
4706
|
|
|
4470
4707
|
type DistinctOnApi<Dialect extends string> = Dialect extends "postgres"
|
|
4471
|
-
? <Values extends readonly ExpressionInput[]>(
|
|
4708
|
+
? <Values extends readonly [ExpressionInput, ...ExpressionInput[]]>(
|
|
4472
4709
|
...values: Values
|
|
4473
4710
|
) => <PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
|
|
4474
4711
|
plan: PlanValue & RequireSelectStatement<PlanValue>
|
|
4475
4712
|
) => QueryPlan<
|
|
4476
4713
|
SelectionOfPlan<PlanValue>,
|
|
4477
|
-
RequiredOfPlan<PlanValue>,
|
|
4714
|
+
AddExpressionRequired<RequiredOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, Values[number]>,
|
|
4478
4715
|
AvailableOfPlan<PlanValue>,
|
|
4479
|
-
PlanDialectOf<PlanValue>,
|
|
4716
|
+
PlanDialectOf<PlanValue> | DialectOfDialectInput<Values[number], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
4480
4717
|
GroupedOfPlan<PlanValue>,
|
|
4481
4718
|
ScopedNamesOfPlan<PlanValue>,
|
|
4482
|
-
OutstandingOfPlan<PlanValue>,
|
|
4719
|
+
AddExpressionRequired<OutstandingOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, Values[number]>,
|
|
4483
4720
|
AssumptionsOfPlan<PlanValue>,
|
|
4484
4721
|
CapabilitiesOfPlan<PlanValue>,
|
|
4485
4722
|
StatementOfPlan<PlanValue>,
|
|
@@ -4515,6 +4752,44 @@ type MysqlConflictWhereError<Values> = Values & {
|
|
|
4515
4752
|
readonly __effect_qb_hint__: "Move the condition into the update assignment expressions or use the Postgres dialect"
|
|
4516
4753
|
}
|
|
4517
4754
|
|
|
4755
|
+
type ConflictActionWhereWithoutUpdateError<Values> = Values & {
|
|
4756
|
+
readonly __effect_qb_error__: "effect-qb: conflict action where(...) requires update assignments"
|
|
4757
|
+
readonly __effect_qb_hint__: "Add update assignments or move the predicate into the conflict target"
|
|
4758
|
+
}
|
|
4759
|
+
|
|
4760
|
+
type ConflictActionWhereInput<Dialect extends string> =
|
|
4761
|
+
Dialect extends "postgres" ? PredicateInput : MysqlConflictWhereError<PredicateInput>
|
|
4762
|
+
|
|
4763
|
+
type UpdateValuesNonEmptyError<Values> = Values & {
|
|
4764
|
+
readonly __effect_qb_error__: "effect-qb: update statements require at least one assignment"
|
|
4765
|
+
}
|
|
4766
|
+
|
|
4767
|
+
type UpdateValuesNonEmptyConstraint<Values> =
|
|
4768
|
+
[Extract<keyof Values, string>] extends [never]
|
|
4769
|
+
? UpdateValuesNonEmptyError<Values>
|
|
4770
|
+
: unknown
|
|
4771
|
+
|
|
4772
|
+
type NestedUpdateValuesNonEmptyConstraint<Values> =
|
|
4773
|
+
[Extract<keyof Values, string>] extends [never]
|
|
4774
|
+
? UpdateValuesNonEmptyError<Values>
|
|
4775
|
+
: true extends {
|
|
4776
|
+
[K in Extract<keyof Values, string>]:
|
|
4777
|
+
Values[K] extends Record<string, unknown>
|
|
4778
|
+
? [Extract<keyof Values[K], string>] extends [never] ? false : true
|
|
4779
|
+
: false
|
|
4780
|
+
}[Extract<keyof Values, string>]
|
|
4781
|
+
? unknown
|
|
4782
|
+
: UpdateValuesNonEmptyError<Values>
|
|
4783
|
+
|
|
4784
|
+
type MergeInsertValuesNonEmptyError<Values> = Values & {
|
|
4785
|
+
readonly __effect_qb_error__: "effect-qb: merge insert actions require at least one value"
|
|
4786
|
+
}
|
|
4787
|
+
|
|
4788
|
+
type MergeInsertValuesNonEmptyConstraint<Values> =
|
|
4789
|
+
[Extract<keyof Values, string>] extends [never]
|
|
4790
|
+
? MergeInsertValuesNonEmptyError<Values>
|
|
4791
|
+
: unknown
|
|
4792
|
+
|
|
4518
4793
|
type InsertShapeExtraKeys<TargetShape, SourceShape> = Exclude<Extract<keyof SourceShape, string>, Extract<keyof TargetShape, string>>
|
|
4519
4794
|
type InsertShapeMissingKeys<TargetShape, SourceShape> = Exclude<RequiredKeys<TargetShape>, Extract<keyof SourceShape, string>>
|
|
4520
4795
|
type InsertShapeMismatchedKeys<TargetShape, SourceShape> = Extract<{
|
|
@@ -4608,10 +4883,15 @@ type InsertSourceRequired<Source> =
|
|
|
4608
4883
|
Source extends QueryPlan<any, any, any, any, any, any, any, any, any, any> ? RequiredOfPlan<Source> :
|
|
4609
4884
|
never
|
|
4610
4885
|
|
|
4886
|
+
type InsertSourceDialect<Source> =
|
|
4887
|
+
Source extends QueryPlan<any, any, any, any, any, any, any, any, any, any> ? PlanDialectOf<Source> :
|
|
4888
|
+
Source extends SourceLike ? SourceDialectOf<Source> :
|
|
4889
|
+
never
|
|
4890
|
+
|
|
4611
4891
|
type ConflictColumnTarget<
|
|
4612
4892
|
Target extends MutationTargetLike,
|
|
4613
4893
|
Columns extends DdlColumnInput
|
|
4614
|
-
> =
|
|
4894
|
+
> = ValidateTargetColumnInput<Target, Columns>
|
|
4615
4895
|
|
|
4616
4896
|
type ConflictTargetInput<
|
|
4617
4897
|
Target extends MutationTargetLike,
|
|
@@ -4636,10 +4916,64 @@ type ConflictActionInput<
|
|
|
4636
4916
|
Target extends MutationTargetLike,
|
|
4637
4917
|
Dialect extends string,
|
|
4638
4918
|
UpdateValues extends MutationInputOf<Table.UpdateOf<Target>> | undefined = MutationInputOf<Table.UpdateOf<Target>> | undefined
|
|
4919
|
+
> =
|
|
4920
|
+
| {
|
|
4921
|
+
readonly update: Exclude<UpdateValues, undefined>
|
|
4922
|
+
readonly where?: ConflictActionWhereInput<Dialect>
|
|
4923
|
+
}
|
|
4924
|
+
| {
|
|
4925
|
+
readonly update?: undefined
|
|
4926
|
+
readonly where?: ConflictActionWhereWithoutUpdateError<PredicateInput>
|
|
4927
|
+
}
|
|
4928
|
+
|
|
4929
|
+
type ConflictActionUpdateNonEmptyConstraint<Options> =
|
|
4930
|
+
Options extends { readonly update: infer Values }
|
|
4931
|
+
? UpdateValuesNonEmptyConstraint<Values>
|
|
4932
|
+
: unknown
|
|
4933
|
+
|
|
4934
|
+
type ConflictTargetPredicate<Target> =
|
|
4935
|
+
Target extends { readonly where?: infer Predicate } ? Extract<Predicate, PredicateInput> : never
|
|
4936
|
+
|
|
4937
|
+
type ConflictActionPredicate<Options> =
|
|
4938
|
+
Options extends { readonly where?: infer Predicate } ? Extract<Predicate, PredicateInput> : never
|
|
4939
|
+
|
|
4940
|
+
type MutationDialectFromValues<
|
|
4941
|
+
Values extends Record<string, unknown>,
|
|
4942
|
+
Dialect extends string,
|
|
4943
|
+
TextDb extends Expression.DbType.Any,
|
|
4944
|
+
NumericDb extends Expression.DbType.Any,
|
|
4945
|
+
BoolDb extends Expression.DbType.Any,
|
|
4946
|
+
TimestampDb extends Expression.DbType.Any,
|
|
4947
|
+
NullDb extends Expression.DbType.Any
|
|
4639
4948
|
> = {
|
|
4640
|
-
|
|
4641
|
-
|
|
4642
|
-
|
|
4949
|
+
[K in keyof Values]: Values[K] extends ExpressionInput
|
|
4950
|
+
? DialectOfDialectInput<Values[K], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
4951
|
+
: never
|
|
4952
|
+
}[keyof Values]
|
|
4953
|
+
|
|
4954
|
+
type ConflictRequired<
|
|
4955
|
+
UpdateValues extends MutationInputOf<any> | undefined,
|
|
4956
|
+
Options,
|
|
4957
|
+
ConflictTarget
|
|
4958
|
+
> =
|
|
4959
|
+
| MutationRequiredFromValues<Exclude<UpdateValues, undefined>>
|
|
4960
|
+
| RequiredFromInput<ConflictActionPredicate<Options>>
|
|
4961
|
+
| RequiredFromInput<ConflictTargetPredicate<ConflictTarget>>
|
|
4962
|
+
|
|
4963
|
+
type ConflictDialect<
|
|
4964
|
+
UpdateValues extends MutationInputOf<any> | undefined,
|
|
4965
|
+
Options,
|
|
4966
|
+
ConflictTarget,
|
|
4967
|
+
Dialect extends string,
|
|
4968
|
+
TextDb extends Expression.DbType.Any,
|
|
4969
|
+
NumericDb extends Expression.DbType.Any,
|
|
4970
|
+
BoolDb extends Expression.DbType.Any,
|
|
4971
|
+
TimestampDb extends Expression.DbType.Any,
|
|
4972
|
+
NullDb extends Expression.DbType.Any
|
|
4973
|
+
> =
|
|
4974
|
+
| MutationDialectFromValues<Exclude<UpdateValues, undefined>, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
4975
|
+
| DialectOfDialectInput<ConflictActionPredicate<Options>, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
4976
|
+
| DialectOfDialectInput<ConflictTargetPredicate<ConflictTarget>, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
4643
4977
|
|
|
4644
4978
|
type MergeWhenMatchedDelete<
|
|
4645
4979
|
Predicate extends PredicateInput | undefined = undefined
|
|
@@ -4654,7 +4988,7 @@ type MergeWhenMatchedUpdate<
|
|
|
4654
4988
|
Values extends MutationInputOf<Table.UpdateOf<Target>>,
|
|
4655
4989
|
Predicate extends PredicateInput | undefined = undefined
|
|
4656
4990
|
> = {
|
|
4657
|
-
readonly update: Values
|
|
4991
|
+
readonly update: Values & UpdateValuesNonEmptyConstraint<Values>
|
|
4658
4992
|
readonly predicate?: Predicate
|
|
4659
4993
|
readonly delete?: never
|
|
4660
4994
|
}
|
|
@@ -4664,20 +4998,37 @@ type MergeWhenNotMatched<
|
|
|
4664
4998
|
Values extends MutationInputOf<Table.InsertOf<Target>>,
|
|
4665
4999
|
Predicate extends PredicateInput | undefined = undefined
|
|
4666
5000
|
> = {
|
|
4667
|
-
readonly values: Values
|
|
5001
|
+
readonly values: Values & MergeInsertValuesNonEmptyConstraint<Values>
|
|
4668
5002
|
readonly predicate?: Predicate
|
|
4669
5003
|
}
|
|
4670
5004
|
|
|
5005
|
+
type MergeMatchedOption<
|
|
5006
|
+
Target extends MutationTargetLike,
|
|
5007
|
+
MatchedValues extends MutationInputOf<Table.UpdateOf<Target>>,
|
|
5008
|
+
MatchedPredicate extends PredicateInput | undefined = undefined
|
|
5009
|
+
> = MergeWhenMatchedDelete<MatchedPredicate> | MergeWhenMatchedUpdate<Target, MatchedValues, MatchedPredicate>
|
|
5010
|
+
|
|
5011
|
+
type MergeNotMatchedOption<
|
|
5012
|
+
Target extends MutationTargetLike,
|
|
5013
|
+
InsertValues extends MutationInputOf<Table.InsertOf<Target>>,
|
|
5014
|
+
NotMatchedPredicate extends PredicateInput | undefined = undefined
|
|
5015
|
+
> = MergeWhenNotMatched<Target, InsertValues, NotMatchedPredicate>
|
|
5016
|
+
|
|
4671
5017
|
type MergeOptions<
|
|
4672
5018
|
Target extends MutationTargetLike,
|
|
4673
5019
|
MatchedValues extends MutationInputOf<Table.UpdateOf<Target>>,
|
|
4674
5020
|
InsertValues extends MutationInputOf<Table.InsertOf<Target>>,
|
|
4675
5021
|
MatchedPredicate extends PredicateInput | undefined = undefined,
|
|
4676
5022
|
NotMatchedPredicate extends PredicateInput | undefined = undefined
|
|
4677
|
-
> =
|
|
4678
|
-
|
|
4679
|
-
|
|
4680
|
-
|
|
5023
|
+
> =
|
|
5024
|
+
| {
|
|
5025
|
+
readonly whenMatched: MergeMatchedOption<Target, MatchedValues, MatchedPredicate>
|
|
5026
|
+
readonly whenNotMatched?: MergeNotMatchedOption<Target, InsertValues, NotMatchedPredicate>
|
|
5027
|
+
}
|
|
5028
|
+
| {
|
|
5029
|
+
readonly whenMatched?: MergeMatchedOption<Target, MatchedValues, MatchedPredicate>
|
|
5030
|
+
readonly whenNotMatched: MergeNotMatchedOption<Target, InsertValues, NotMatchedPredicate>
|
|
5031
|
+
}
|
|
4681
5032
|
|
|
4682
5033
|
type RequireSelectStatement<PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>> =
|
|
4683
5034
|
StatementOfPlan<PlanValue> extends "select" ? unknown : never
|
|
@@ -4709,6 +5060,11 @@ type MutationOrderLimitSupported<PlanValue extends QueryPlan<any, any, any, any,
|
|
|
4709
5060
|
? StatementOfPlan<PlanValue> extends "update" | "delete" ? unknown : never
|
|
4710
5061
|
: never
|
|
4711
5062
|
|
|
5063
|
+
type MutationTargetTupleDialectConstraint<
|
|
5064
|
+
Targets extends MutationTargetTuple,
|
|
5065
|
+
Dialect extends string
|
|
5066
|
+
> = Exclude<TableDialectOf<Targets[number]>, Dialect> extends never ? unknown : never
|
|
5067
|
+
|
|
4712
5068
|
type MutationRequiredFromValues<Values extends Record<string, unknown>> = {
|
|
4713
5069
|
[K in keyof Values]: Values[K] extends Expression.Any ? RequiredFromDependencies<DependenciesOf<Values[K]>> : never
|
|
4714
5070
|
}[keyof Values]
|
|
@@ -4722,6 +5078,59 @@ type NestedMutationRequiredFromValues<Values> =
|
|
|
4722
5078
|
}[keyof Values]
|
|
4723
5079
|
: never
|
|
4724
5080
|
|
|
5081
|
+
type NestedMutationDialectFromValues<
|
|
5082
|
+
Values,
|
|
5083
|
+
Dialect extends string,
|
|
5084
|
+
TextDb extends Expression.DbType.Any,
|
|
5085
|
+
NumericDb extends Expression.DbType.Any,
|
|
5086
|
+
BoolDb extends Expression.DbType.Any,
|
|
5087
|
+
TimestampDb extends Expression.DbType.Any,
|
|
5088
|
+
NullDb extends Expression.DbType.Any
|
|
5089
|
+
> =
|
|
5090
|
+
Values extends ExpressionInput
|
|
5091
|
+
? DialectOfDialectInput<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
5092
|
+
: Values extends Record<string, unknown>
|
|
5093
|
+
? {
|
|
5094
|
+
[K in keyof Values]: NestedMutationDialectFromValues<Values[K], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
5095
|
+
}[keyof Values]
|
|
5096
|
+
: never
|
|
5097
|
+
|
|
5098
|
+
type KnownMutationDialectFromValues<
|
|
5099
|
+
Values,
|
|
5100
|
+
Dialect extends string,
|
|
5101
|
+
TextDb extends Expression.DbType.Any,
|
|
5102
|
+
NumericDb extends Expression.DbType.Any,
|
|
5103
|
+
BoolDb extends Expression.DbType.Any,
|
|
5104
|
+
TimestampDb extends Expression.DbType.Any,
|
|
5105
|
+
NullDb extends Expression.DbType.Any
|
|
5106
|
+
> = NestedMutationDialectFromValues<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> extends infer Current
|
|
5107
|
+
? Current extends string
|
|
5108
|
+
? string extends Current ? never : Current
|
|
5109
|
+
: never
|
|
5110
|
+
: never
|
|
5111
|
+
|
|
5112
|
+
type KnownIncompatibleMutationDialectFromValues<
|
|
5113
|
+
Values,
|
|
5114
|
+
Dialect extends string,
|
|
5115
|
+
TextDb extends Expression.DbType.Any,
|
|
5116
|
+
NumericDb extends Expression.DbType.Any,
|
|
5117
|
+
BoolDb extends Expression.DbType.Any,
|
|
5118
|
+
TimestampDb extends Expression.DbType.Any,
|
|
5119
|
+
NullDb extends Expression.DbType.Any
|
|
5120
|
+
> = Exclude<KnownMutationDialectFromValues<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>, Dialect>
|
|
5121
|
+
|
|
5122
|
+
type MutationValuesDialectConstraint<
|
|
5123
|
+
Values,
|
|
5124
|
+
Dialect extends string,
|
|
5125
|
+
TextDb extends Expression.DbType.Any,
|
|
5126
|
+
NumericDb extends Expression.DbType.Any,
|
|
5127
|
+
BoolDb extends Expression.DbType.Any,
|
|
5128
|
+
TimestampDb extends Expression.DbType.Any,
|
|
5129
|
+
NullDb extends Expression.DbType.Any
|
|
5130
|
+
> = KnownIncompatibleMutationDialectFromValues<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> extends never
|
|
5131
|
+
? unknown
|
|
5132
|
+
: never
|
|
5133
|
+
|
|
4725
5134
|
type MutationAssignments<Shape extends Record<string, unknown>> = {
|
|
4726
5135
|
readonly [K in keyof Shape]: QueryAst.AssignmentClause
|
|
4727
5136
|
}
|
|
@@ -4755,12 +5164,38 @@ type InsertDirectSource =
|
|
|
4755
5164
|
|
|
4756
5165
|
type FromInput = SourceLike | InsertDirectSource
|
|
4757
5166
|
|
|
5167
|
+
type SourceDialectConstraint<
|
|
5168
|
+
CurrentSource extends SourceLike,
|
|
5169
|
+
Dialect extends string
|
|
5170
|
+
> = [SourceDialectOf<CurrentSource>] extends [never]
|
|
5171
|
+
? unknown
|
|
5172
|
+
: Extract<SourceDialectOf<CurrentSource>, Dialect> extends never
|
|
5173
|
+
? never
|
|
5174
|
+
: unknown
|
|
5175
|
+
|
|
5176
|
+
type SourceRequirementConstraint<
|
|
5177
|
+
PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>,
|
|
5178
|
+
CurrentSource extends SourceLike
|
|
5179
|
+
> = [SourceRequiredOf<CurrentSource>] extends [never]
|
|
5180
|
+
? unknown
|
|
5181
|
+
: Exclude<SourceRequiredOf<CurrentSource>, ScopedNamesOfPlan<PlanValue>> extends never
|
|
5182
|
+
? unknown
|
|
5183
|
+
: SourceRequirementError<CurrentSource>
|
|
5184
|
+
|
|
4758
5185
|
type SelectFromConstraint<
|
|
4759
5186
|
PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>,
|
|
4760
5187
|
CurrentSource extends SourceLike
|
|
4761
5188
|
> =
|
|
4762
5189
|
RequireSelectStatement<PlanValue> &
|
|
4763
|
-
(
|
|
5190
|
+
(
|
|
5191
|
+
SourceNameOf<CurrentSource> extends OutstandingOfPlan<PlanValue>
|
|
5192
|
+
? unknown
|
|
5193
|
+
: [OutstandingOfPlan<PlanValue>] extends [never]
|
|
5194
|
+
? [ScopedNamesOfPlan<PlanValue>] extends [never]
|
|
5195
|
+
? unknown
|
|
5196
|
+
: never
|
|
5197
|
+
: never
|
|
5198
|
+
) &
|
|
4764
5199
|
(SourceRequiredOf<CurrentSource> extends never ? unknown : SourceRequirementError<CurrentSource>)
|
|
4765
5200
|
|
|
4766
5201
|
type UpdateFromConstraint<
|
|
@@ -4777,7 +5212,7 @@ type InsertFromConstraint<
|
|
|
4777
5212
|
Dialect extends string
|
|
4778
5213
|
> =
|
|
4779
5214
|
RequirePendingInsertStatement<PlanValue> &
|
|
4780
|
-
(InsertSourceOfPlanInput<PlanValue, CurrentSource, Dialect>
|
|
5215
|
+
(CurrentSource extends InsertSourceOfPlanInput<PlanValue, CurrentSource, Dialect>
|
|
4781
5216
|
? unknown
|
|
4782
5217
|
: InsertSourceOfPlanInput<PlanValue, CurrentSource, Dialect>)
|
|
4783
5218
|
|
|
@@ -4831,12 +5266,12 @@ type InsertFromResult<
|
|
|
4831
5266
|
Dialect extends string
|
|
4832
5267
|
> = QueryPlan<
|
|
4833
5268
|
SelectionOfPlan<PlanValue>,
|
|
4834
|
-
|
|
5269
|
+
InsertSourceRequired<CurrentSource>,
|
|
4835
5270
|
AvailableOfPlan<PlanValue>,
|
|
4836
|
-
PlanDialectOf<PlanValue>,
|
|
5271
|
+
PlanDialectOf<PlanValue> | InsertSourceDialect<CurrentSource>,
|
|
4837
5272
|
GroupedOfPlan<PlanValue>,
|
|
4838
5273
|
ScopedNamesOfPlan<PlanValue>,
|
|
4839
|
-
|
|
5274
|
+
InsertSourceRequired<CurrentSource>,
|
|
4840
5275
|
AssumptionsOfPlan<PlanValue>,
|
|
4841
5276
|
CurrentSource extends QueryPlan<any, any, any, any, any, any, any, any, any, any>
|
|
4842
5277
|
? MergeCapabilities<CapabilitiesOfPlan<PlanValue>, CapabilitiesOfPlan<CurrentSource>>
|
|
@@ -4853,15 +5288,17 @@ type FromPlanConstraint<
|
|
|
4853
5288
|
Dialect extends string
|
|
4854
5289
|
> =
|
|
4855
5290
|
CurrentSource extends SourceLike
|
|
4856
|
-
?
|
|
4857
|
-
|
|
4858
|
-
|
|
4859
|
-
|
|
4860
|
-
|
|
4861
|
-
|
|
4862
|
-
|
|
4863
|
-
|
|
4864
|
-
|
|
5291
|
+
? SourceDialectConstraint<CurrentSource, Dialect> & (
|
|
5292
|
+
StatementOfPlan<PlanValue> extends "select"
|
|
5293
|
+
? SelectFromConstraint<PlanValue, CurrentSource>
|
|
5294
|
+
: StatementOfPlan<PlanValue> extends "update"
|
|
5295
|
+
? UpdateFromConstraint<PlanValue, CurrentSource>
|
|
5296
|
+
: StatementOfPlan<PlanValue> extends "insert"
|
|
5297
|
+
? CurrentSource extends AnyValuesSource | AnyUnnestSource
|
|
5298
|
+
? InsertFromConstraint<PlanValue, CurrentSource, Dialect>
|
|
5299
|
+
: never
|
|
5300
|
+
: never
|
|
5301
|
+
)
|
|
4865
5302
|
: CurrentSource extends InsertDirectSource
|
|
4866
5303
|
? StatementOfPlan<PlanValue> extends "insert"
|
|
4867
5304
|
? InsertFromConstraint<PlanValue, CurrentSource, Dialect>
|
|
@@ -4916,7 +5353,10 @@ export type PublicStructuredFromResult<
|
|
|
4916
5353
|
Exclude<OutstandingOfPlan<PlanValue>, SourceNameOf<CurrentSource>>,
|
|
4917
5354
|
AssumptionsOfPlan<PlanValue>,
|
|
4918
5355
|
MergeCapabilities<CapabilitiesOfPlan<PlanValue>, SourceCapabilitiesOf<CurrentSource>>,
|
|
4919
|
-
StatementOfPlan<PlanValue
|
|
5356
|
+
StatementOfPlan<PlanValue>,
|
|
5357
|
+
MutationTargetOfPlan<PlanValue>,
|
|
5358
|
+
InsertSourceStateOfPlan<PlanValue>,
|
|
5359
|
+
FactsOfPlan<PlanValue>
|
|
4920
5360
|
>
|
|
4921
5361
|
: StatementOfPlan<PlanValue> extends "update"
|
|
4922
5362
|
? QueryPlan<
|
|
@@ -4929,7 +5369,10 @@ export type PublicStructuredFromResult<
|
|
|
4929
5369
|
Exclude<OutstandingOfPlan<PlanValue>, SourceNameOf<CurrentSource>>,
|
|
4930
5370
|
AssumptionsOfPlan<PlanValue>,
|
|
4931
5371
|
MergeCapabilities<CapabilitiesOfPlan<PlanValue>, SourceCapabilitiesOf<CurrentSource>>,
|
|
4932
|
-
StatementOfPlan<PlanValue
|
|
5372
|
+
StatementOfPlan<PlanValue>,
|
|
5373
|
+
MutationTargetOfPlan<PlanValue>,
|
|
5374
|
+
InsertSourceStateOfPlan<PlanValue>,
|
|
5375
|
+
FactsOfPlan<PlanValue>
|
|
4933
5376
|
>
|
|
4934
5377
|
: StatementOfPlan<PlanValue> extends "insert"
|
|
4935
5378
|
? CurrentSource extends AnyValuesSource | AnyUnnestSource
|
|
@@ -4937,7 +5380,7 @@ export type PublicStructuredFromResult<
|
|
|
4937
5380
|
SelectionOfPlan<PlanValue>,
|
|
4938
5381
|
never,
|
|
4939
5382
|
AvailableOfPlan<PlanValue>,
|
|
4940
|
-
PlanDialectOf<PlanValue>,
|
|
5383
|
+
PlanDialectOf<PlanValue> | SourceDialectOf<CurrentSource>,
|
|
4941
5384
|
GroupedOfPlan<PlanValue>,
|
|
4942
5385
|
ScopedNamesOfPlan<PlanValue>,
|
|
4943
5386
|
never,
|
|
@@ -4945,7 +5388,8 @@ export type PublicStructuredFromResult<
|
|
|
4945
5388
|
CapabilitiesOfPlan<PlanValue>,
|
|
4946
5389
|
StatementOfPlan<PlanValue>,
|
|
4947
5390
|
MutationTargetOfPlan<PlanValue>,
|
|
4948
|
-
"ready"
|
|
5391
|
+
"ready",
|
|
5392
|
+
FactsOfPlan<PlanValue>
|
|
4949
5393
|
>
|
|
4950
5394
|
: FromPlanResult<PlanValue, CurrentSource, Dialect>
|
|
4951
5395
|
: FromPlanResult<PlanValue, CurrentSource, Dialect>
|
|
@@ -4962,6 +5406,36 @@ type MergeRequiredFromPredicate<
|
|
|
4962
5406
|
Available extends Record<string, Plan.AnySource>
|
|
4963
5407
|
> = Predicate extends PredicateInput ? AddExpressionRequired<never, Available, Predicate> : never
|
|
4964
5408
|
|
|
5409
|
+
type BroadString<Value extends string> = string extends Value ? true : false
|
|
5410
|
+
|
|
5411
|
+
type SameSourceName<
|
|
5412
|
+
Left extends string,
|
|
5413
|
+
Right extends string
|
|
5414
|
+
> = [Left] extends [Right] ? [Right] extends [Left] ? true : false : false
|
|
5415
|
+
|
|
5416
|
+
type MergeSourceNameConflictError<
|
|
5417
|
+
TargetName extends string,
|
|
5418
|
+
SourceName extends string
|
|
5419
|
+
> = {
|
|
5420
|
+
readonly __effect_qb_error__: "effect-qb: merge source name must differ from target source name"
|
|
5421
|
+
readonly __effect_qb_target_source_name__: TargetName
|
|
5422
|
+
readonly __effect_qb_using_source_name__: SourceName
|
|
5423
|
+
readonly __effect_qb_hint__: "Alias the merge source with Table.alias(...), Query.as(...), or Query.with(...)"
|
|
5424
|
+
}
|
|
5425
|
+
|
|
5426
|
+
type MergeSourceNameConstraint<
|
|
5427
|
+
Target extends MutationTargetLike,
|
|
5428
|
+
Source extends SourceLike,
|
|
5429
|
+
TargetName extends string = SourceNameOf<Target>,
|
|
5430
|
+
SourceName extends string = SourceNameOf<Source>
|
|
5431
|
+
> = BroadString<TargetName> extends true
|
|
5432
|
+
? unknown
|
|
5433
|
+
: BroadString<SourceName> extends true
|
|
5434
|
+
? unknown
|
|
5435
|
+
: SameSourceName<TargetName, SourceName> extends true
|
|
5436
|
+
? MergeSourceNameConflictError<TargetName, SourceName>
|
|
5437
|
+
: unknown
|
|
5438
|
+
|
|
4965
5439
|
type AsCurriedInput<Dialect extends string> =
|
|
4966
5440
|
| ExpressionInput
|
|
4967
5441
|
| ValuesInput<any, any, Dialect>
|
|
@@ -5001,20 +5475,20 @@ type AsCurriedResult<
|
|
|
5001
5475
|
>(
|
|
5002
5476
|
value: Value,
|
|
5003
5477
|
alias: Alias
|
|
5004
|
-
): DialectAsExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
5478
|
+
): ProjectionAliasedExpression<DialectAsExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>, Alias>
|
|
5005
5479
|
function as<
|
|
5006
5480
|
Rows extends ValuesRowsInput,
|
|
5007
5481
|
Alias extends string
|
|
5008
5482
|
>(
|
|
5009
5483
|
value: ValuesInput<
|
|
5010
5484
|
Rows,
|
|
5011
|
-
ValuesOutputShape<Rows
|
|
5485
|
+
ValuesOutputShape<Rows, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5012
5486
|
Dialect
|
|
5013
5487
|
>,
|
|
5014
5488
|
alias: Alias
|
|
5015
5489
|
): ValuesSource<
|
|
5016
5490
|
Rows,
|
|
5017
|
-
ValuesOutputShape<Rows
|
|
5491
|
+
ValuesOutputShape<Rows, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5018
5492
|
Alias,
|
|
5019
5493
|
Dialect
|
|
5020
5494
|
>
|
|
@@ -5022,7 +5496,7 @@ type AsCurriedResult<
|
|
|
5022
5496
|
PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>,
|
|
5023
5497
|
Alias extends string
|
|
5024
5498
|
>(
|
|
5025
|
-
value:
|
|
5499
|
+
value: DerivedTableCompatiblePlan<PlanValue>,
|
|
5026
5500
|
alias: Alias
|
|
5027
5501
|
): DerivedSource<PlanValue, Alias>
|
|
5028
5502
|
function as(valueOrAlias: unknown, alias?: string): unknown {
|
|
@@ -5069,13 +5543,13 @@ type AsCurriedResult<
|
|
|
5069
5543
|
>(
|
|
5070
5544
|
alias: Alias
|
|
5071
5545
|
): <PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
|
|
5072
|
-
value:
|
|
5546
|
+
value: DerivedSourceCompatiblePlan<PlanValue>
|
|
5073
5547
|
) => import("../../internal/query.js").CteSource<PlanValue, Alias>
|
|
5074
5548
|
function with_<
|
|
5075
5549
|
PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>,
|
|
5076
5550
|
Alias extends string
|
|
5077
5551
|
>(
|
|
5078
|
-
value:
|
|
5552
|
+
value: DerivedSourceCompatiblePlan<PlanValue>,
|
|
5079
5553
|
alias: Alias
|
|
5080
5554
|
): import("../../internal/query.js").CteSource<PlanValue, Alias>
|
|
5081
5555
|
function with_(valueOrAlias: unknown, alias?: string): unknown {
|
|
@@ -5093,13 +5567,13 @@ type AsCurriedResult<
|
|
|
5093
5567
|
>(
|
|
5094
5568
|
alias: Alias
|
|
5095
5569
|
): <PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
|
|
5096
|
-
value:
|
|
5570
|
+
value: DerivedSourceCompatiblePlan<PlanValue>
|
|
5097
5571
|
) => import("../../internal/query.js").CteSource<PlanValue, Alias>
|
|
5098
5572
|
function withRecursive_<
|
|
5099
5573
|
PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>,
|
|
5100
5574
|
Alias extends string
|
|
5101
5575
|
>(
|
|
5102
|
-
value:
|
|
5576
|
+
value: DerivedSourceCompatiblePlan<PlanValue>,
|
|
5103
5577
|
alias: Alias
|
|
5104
5578
|
): import("../../internal/query.js").CteSource<PlanValue, Alias>
|
|
5105
5579
|
function withRecursive_(valueOrAlias: unknown, alias?: string): unknown {
|
|
@@ -5118,13 +5592,13 @@ type AsCurriedResult<
|
|
|
5118
5592
|
>(
|
|
5119
5593
|
alias: Alias
|
|
5120
5594
|
): <PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
|
|
5121
|
-
value: PlanValue
|
|
5595
|
+
value: LateralSourceCompatiblePlan<PlanValue>
|
|
5122
5596
|
) => import("../../internal/query.js").LateralSource<PlanValue, Alias>
|
|
5123
5597
|
function lateral<
|
|
5124
5598
|
PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>,
|
|
5125
5599
|
Alias extends string
|
|
5126
5600
|
>(
|
|
5127
|
-
value: PlanValue
|
|
5601
|
+
value: LateralSourceCompatiblePlan<PlanValue>,
|
|
5128
5602
|
alias: Alias
|
|
5129
5603
|
): import("../../internal/query.js").LateralSource<PlanValue, Alias>
|
|
5130
5604
|
function lateral(valueOrAlias: unknown, alias?: string): unknown {
|
|
@@ -5141,9 +5615,11 @@ type AsCurriedResult<
|
|
|
5141
5615
|
Rows extends ValuesRowsInput
|
|
5142
5616
|
>(
|
|
5143
5617
|
rows: Rows
|
|
5618
|
+
& ValuesRowsShapeInput<Rows>
|
|
5619
|
+
& ValuesRowsDialectInput<Rows, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
5144
5620
|
) => ValuesInput<
|
|
5145
5621
|
Rows,
|
|
5146
|
-
ValuesOutputShape<Rows
|
|
5622
|
+
ValuesOutputShape<Rows, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5147
5623
|
Dialect
|
|
5148
5624
|
>
|
|
5149
5625
|
|
|
@@ -5151,7 +5627,9 @@ type AsCurriedResult<
|
|
|
5151
5627
|
Columns extends UnnestColumnsInput,
|
|
5152
5628
|
Alias extends string
|
|
5153
5629
|
>(
|
|
5154
|
-
columns: Columns
|
|
5630
|
+
columns: Columns
|
|
5631
|
+
& UnnestColumnsShapeInput<Columns>
|
|
5632
|
+
& UnnestColumnsDialectInput<Columns, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5155
5633
|
alias: Alias
|
|
5156
5634
|
) => UnnestSource<
|
|
5157
5635
|
UnnestOutputShape<Columns, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
@@ -5165,9 +5643,9 @@ type AsCurriedResult<
|
|
|
5165
5643
|
Step extends NumericExpressionInput | undefined = undefined,
|
|
5166
5644
|
Alias extends string = "series"
|
|
5167
5645
|
>(
|
|
5168
|
-
start: Start,
|
|
5169
|
-
stop: Stop,
|
|
5170
|
-
step?: Step,
|
|
5646
|
+
start: Start & NumericExpressionDialectInput<Start, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5647
|
+
stop: Stop & NumericExpressionDialectInput<Stop, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5648
|
+
step?: Step & (Step extends NumericExpressionInput ? NumericExpressionDialectInput<Step, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> : unknown),
|
|
5171
5649
|
alias?: Alias
|
|
5172
5650
|
) => Dialect extends "postgres"
|
|
5173
5651
|
? TableFunctionSource<
|
|
@@ -5179,11 +5657,14 @@ type AsCurriedResult<
|
|
|
5179
5657
|
: GenerateSeriesUnsupportedError<Dialect>
|
|
5180
5658
|
|
|
5181
5659
|
export type PublicGenerateSeriesApi = <
|
|
5660
|
+
Start extends NumericExpressionInput,
|
|
5661
|
+
Stop extends NumericExpressionInput,
|
|
5662
|
+
Step extends NumericExpressionInput | undefined = undefined,
|
|
5182
5663
|
Alias extends string = "series"
|
|
5183
5664
|
>(
|
|
5184
|
-
start:
|
|
5185
|
-
stop:
|
|
5186
|
-
step?: NumericExpressionInput,
|
|
5665
|
+
start: Start & NumericExpressionDialectInput<Start, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5666
|
+
stop: Stop & NumericExpressionDialectInput<Stop, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5667
|
+
step?: Step & (Step extends NumericExpressionInput ? NumericExpressionDialectInput<Step, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> : unknown),
|
|
5187
5668
|
alias?: Alias
|
|
5188
5669
|
) => TableFunctionSource<
|
|
5189
5670
|
{
|
|
@@ -5194,8 +5675,36 @@ type AsCurriedResult<
|
|
|
5194
5675
|
"generate_series"
|
|
5195
5676
|
>
|
|
5196
5677
|
|
|
5197
|
-
|
|
5198
|
-
|
|
5678
|
+
type SelectionRootObjectError<Selection> = Selection & {
|
|
5679
|
+
readonly __effect_qb_error__: "effect-qb: selections must be projection objects"
|
|
5680
|
+
readonly __effect_qb_hint__: "Use select({ value: expression }) or returning({ value: expression })"
|
|
5681
|
+
}
|
|
5682
|
+
|
|
5683
|
+
type SelectionRootObjectConstraint<Selection> =
|
|
5684
|
+
Selection extends Expression.Any ? SelectionRootObjectError<Selection> : unknown
|
|
5685
|
+
|
|
5686
|
+
type SelectionNestedEmptyError<Selection> = Selection & {
|
|
5687
|
+
readonly __effect_qb_error__: "effect-qb: projection objects cannot contain empty nested selections"
|
|
5688
|
+
}
|
|
5689
|
+
|
|
5690
|
+
type SelectionHasEmptyNestedObject<Selection, IsRoot extends boolean> =
|
|
5691
|
+
Selection extends Expression.Any
|
|
5692
|
+
? false
|
|
5693
|
+
: Selection extends Record<string, any>
|
|
5694
|
+
? [Extract<keyof Selection, string>] extends [never]
|
|
5695
|
+
? IsRoot extends true ? false : true
|
|
5696
|
+
: true extends {
|
|
5697
|
+
[K in Extract<keyof Selection, string>]: SelectionHasEmptyNestedObject<Selection[K], false>
|
|
5698
|
+
}[Extract<keyof Selection, string>]
|
|
5699
|
+
? true
|
|
5700
|
+
: false
|
|
5701
|
+
: false
|
|
5702
|
+
|
|
5703
|
+
type SelectionNestedNonEmptyConstraint<Selection> =
|
|
5704
|
+
SelectionHasEmptyNestedObject<Selection, true> extends true ? SelectionNestedEmptyError<Selection> : unknown
|
|
5705
|
+
|
|
5706
|
+
export type SelectApi = <Selection extends SelectionShape = {}>(
|
|
5707
|
+
selection?: Selection & SelectionRootObjectConstraint<Selection> & SelectionNestedNonEmptyConstraint<Selection>
|
|
5199
5708
|
) => QueryPlan<
|
|
5200
5709
|
Selection,
|
|
5201
5710
|
ExtractRequired<Selection>,
|
|
@@ -5254,7 +5763,10 @@ type AsCurriedResult<
|
|
|
5254
5763
|
never,
|
|
5255
5764
|
TrueFormula,
|
|
5256
5765
|
CapabilitiesOfPlan<LeftPlanValue> | CapabilitiesOfPlan<RightPlanValue>,
|
|
5257
|
-
"set"
|
|
5766
|
+
"set",
|
|
5767
|
+
any,
|
|
5768
|
+
"ready",
|
|
5769
|
+
CommonSetFacts<LeftPlanValue, RightPlanValue>
|
|
5258
5770
|
>
|
|
5259
5771
|
|
|
5260
5772
|
type SetOperationApi = <
|
|
@@ -5322,10 +5834,10 @@ type AsCurriedResult<
|
|
|
5322
5834
|
keyof AvailableOfPlan<PlanValue> extends never ? never : unknown
|
|
5323
5835
|
) & (
|
|
5324
5836
|
SourceNameOf<CurrentTable> extends ScopedNamesOfPlan<PlanValue> ? never : unknown
|
|
5325
|
-
)
|
|
5837
|
+
) & SourceRequirementConstraint<PlanValue, CurrentTable> & SourceDialectConstraint<CurrentTable, Dialect>
|
|
5326
5838
|
) => QueryPlan<
|
|
5327
5839
|
SelectionOfPlan<PlanValue>,
|
|
5328
|
-
AddJoinRequired<RequiredOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, never, "cross"
|
|
5840
|
+
AddJoinRequired<RequiredOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, never, "cross", SourceRequiredOf<CurrentTable>>,
|
|
5329
5841
|
AddAvailable<
|
|
5330
5842
|
AvailableOfPlan<PlanValue>,
|
|
5331
5843
|
SourceNameOf<CurrentTable>,
|
|
@@ -5336,10 +5848,13 @@ type AsCurriedResult<
|
|
|
5336
5848
|
PlanDialectOf<PlanValue> | SourceDialectOf<CurrentTable>,
|
|
5337
5849
|
GroupedOfPlan<PlanValue>,
|
|
5338
5850
|
ScopedNamesOfPlan<PlanValue> | SourceNameOf<CurrentTable>,
|
|
5339
|
-
AddJoinRequired<OutstandingOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, never, "cross"
|
|
5851
|
+
AddJoinRequired<OutstandingOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, never, "cross", SourceRequiredOf<CurrentTable>>,
|
|
5340
5852
|
AssumptionsOfPlan<PlanValue>,
|
|
5341
5853
|
MergeCapabilities<CapabilitiesOfPlan<PlanValue>, SourceCapabilitiesOf<CurrentTable>>,
|
|
5342
|
-
StatementOfPlan<PlanValue
|
|
5854
|
+
StatementOfPlan<PlanValue>,
|
|
5855
|
+
MutationTargetOfPlan<PlanValue>,
|
|
5856
|
+
InsertSourceStateOfPlan<PlanValue>,
|
|
5857
|
+
FactsOfPlan<PlanValue>
|
|
5343
5858
|
>
|
|
5344
5859
|
|
|
5345
5860
|
type JoinApi = <
|
|
@@ -5356,10 +5871,10 @@ type AsCurriedResult<
|
|
|
5356
5871
|
keyof AvailableOfPlan<PlanValue> extends never ? never : unknown
|
|
5357
5872
|
) & (
|
|
5358
5873
|
SourceNameOf<CurrentTable> extends ScopedNamesOfPlan<PlanValue> ? never : unknown
|
|
5359
|
-
)
|
|
5874
|
+
) & SourceRequirementConstraint<PlanValue, CurrentTable> & SourceDialectConstraint<CurrentTable, Dialect>
|
|
5360
5875
|
) => QueryPlan<
|
|
5361
5876
|
SelectionOfPlan<PlanValue>,
|
|
5362
|
-
AddJoinRequired<RequiredOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, Predicate, Kind
|
|
5877
|
+
AddJoinRequired<RequiredOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, Predicate, Kind, SourceRequiredOf<CurrentTable>>,
|
|
5363
5878
|
AvailableAfterJoin<
|
|
5364
5879
|
AvailableOfPlan<PlanValue>,
|
|
5365
5880
|
SourceNameOf<CurrentTable>,
|
|
@@ -5370,7 +5885,7 @@ type AsCurriedResult<
|
|
|
5370
5885
|
PlanDialectOf<PlanValue> | SourceDialectOf<CurrentTable> | DialectOfDialectInput<Predicate, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5371
5886
|
GroupedOfPlan<PlanValue>,
|
|
5372
5887
|
ScopedNamesOfPlan<PlanValue> | SourceNameOf<CurrentTable>,
|
|
5373
|
-
AddJoinRequired<OutstandingOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, Predicate, Kind
|
|
5888
|
+
AddJoinRequired<OutstandingOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, Predicate, Kind, SourceRequiredOf<CurrentTable>>,
|
|
5374
5889
|
PlanAssumptionsAfterJoin<PlanValue, Predicate, Kind, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5375
5890
|
MergeCapabilities<CapabilitiesOfPlan<PlanValue>, SourceCapabilitiesOf<CurrentTable>>,
|
|
5376
5891
|
StatementOfPlan<PlanValue>,
|
|
@@ -5391,10 +5906,10 @@ type AsCurriedResult<
|
|
|
5391
5906
|
keyof AvailableOfPlan<PlanValue> extends never ? never : unknown
|
|
5392
5907
|
) & (
|
|
5393
5908
|
SourceNameOf<CurrentTable> extends ScopedNamesOfPlan<PlanValue> ? never : unknown
|
|
5394
|
-
)
|
|
5909
|
+
) & SourceRequirementConstraint<PlanValue, CurrentTable> & SourceDialectConstraint<CurrentTable, Dialect>
|
|
5395
5910
|
) => QueryPlan<
|
|
5396
5911
|
SelectionOfPlan<PlanValue>,
|
|
5397
|
-
AddJoinRequired<RequiredOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, Predicate, Kind
|
|
5912
|
+
AddJoinRequired<RequiredOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, Predicate, Kind, SourceRequiredOf<CurrentTable>>,
|
|
5398
5913
|
AvailableAfterJoin<
|
|
5399
5914
|
AvailableOfPlan<PlanValue>,
|
|
5400
5915
|
SourceNameOf<CurrentTable>,
|
|
@@ -5405,7 +5920,7 @@ type AsCurriedResult<
|
|
|
5405
5920
|
PlanDialectOf<PlanValue> | SourceDialectOf<CurrentTable> | DialectOfDialectInput<Predicate, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5406
5921
|
GroupedOfPlan<PlanValue>,
|
|
5407
5922
|
ScopedNamesOfPlan<PlanValue> | SourceNameOf<CurrentTable>,
|
|
5408
|
-
AddJoinRequired<OutstandingOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, Predicate, Kind
|
|
5923
|
+
AddJoinRequired<OutstandingOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, Predicate, Kind, SourceRequiredOf<CurrentTable>>,
|
|
5409
5924
|
PlanAssumptionsAfterJoin<PlanValue, Predicate, Kind, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5410
5925
|
MergeCapabilities<CapabilitiesOfPlan<PlanValue>, SourceCapabilitiesOf<CurrentTable>>,
|
|
5411
5926
|
StatementOfPlan<PlanValue>,
|
|
@@ -5613,18 +6128,21 @@ type AsCurriedResult<
|
|
|
5613
6128
|
|
|
5614
6129
|
const fullJoin = ((table, on) => (join as any)("full", table, on)) as BinaryJoinApi<"full">
|
|
5615
6130
|
|
|
5616
|
-
const distinctOn = (
|
|
6131
|
+
const distinctOn = (<Values extends readonly [ExpressionInput, ...ExpressionInput[]]>(...values: Values) => {
|
|
6132
|
+
if (values.length === 0) {
|
|
6133
|
+
throw new Error("distinctOn(...) requires at least one expression")
|
|
6134
|
+
}
|
|
5617
6135
|
const expressions = values.map((value) => toDialectExpression(value)) as Expression.Any[]
|
|
5618
6136
|
return <PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
|
|
5619
6137
|
plan: PlanValue & RequireSelectStatement<PlanValue>
|
|
5620
6138
|
): QueryPlan<
|
|
5621
6139
|
SelectionOfPlan<PlanValue>,
|
|
5622
|
-
RequiredOfPlan<PlanValue>,
|
|
6140
|
+
AddExpressionRequired<RequiredOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, Values[number]>,
|
|
5623
6141
|
AvailableOfPlan<PlanValue>,
|
|
5624
|
-
PlanDialectOf<PlanValue>,
|
|
6142
|
+
PlanDialectOf<PlanValue> | DialectOfDialectInput<Values[number], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5625
6143
|
GroupedOfPlan<PlanValue>,
|
|
5626
6144
|
ScopedNamesOfPlan<PlanValue>,
|
|
5627
|
-
OutstandingOfPlan<PlanValue>,
|
|
6145
|
+
AddExpressionRequired<OutstandingOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, Values[number]>,
|
|
5628
6146
|
AssumptionsOfPlan<PlanValue>,
|
|
5629
6147
|
CapabilitiesOfPlan<PlanValue>,
|
|
5630
6148
|
StatementOfPlan<PlanValue>
|
|
@@ -5632,11 +6150,13 @@ type AsCurriedResult<
|
|
|
5632
6150
|
const current = plan[Plan.TypeId]
|
|
5633
6151
|
const currentAst = getAst(plan)
|
|
5634
6152
|
const currentQuery = getQueryState(plan)
|
|
6153
|
+
const required = values.flatMap((value) => extractRequiredFromDialectInputRuntime(value))
|
|
5635
6154
|
return makePlan({
|
|
5636
6155
|
selection: current.selection,
|
|
5637
|
-
required: current.required
|
|
6156
|
+
required: [...currentRequiredList(current.required), ...required].filter((name, index, list) =>
|
|
6157
|
+
!(name in current.available) && list.indexOf(name) === index) as AddExpressionRequired<RequiredOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, Values[number]>,
|
|
5638
6158
|
available: current.available,
|
|
5639
|
-
dialect: current.dialect as PlanDialectOf<PlanValue>
|
|
6159
|
+
dialect: current.dialect as PlanDialectOf<PlanValue> | DialectOfDialectInput<Values[number], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
5640
6160
|
}, {
|
|
5641
6161
|
...currentAst,
|
|
5642
6162
|
distinct: true,
|
|
@@ -5666,8 +6186,19 @@ type AsCurriedResult<
|
|
|
5666
6186
|
FactsOfPlan<PlanValue>
|
|
5667
6187
|
>
|
|
5668
6188
|
|
|
6189
|
+
type ReturningSelectionNonEmptyError<Selection> = Selection & {
|
|
6190
|
+
readonly __effect_qb_error__: "effect-qb: returning(...) requires at least one selected expression"
|
|
6191
|
+
}
|
|
6192
|
+
|
|
6193
|
+
type ReturningSelectionNonEmptyConstraint<Selection> =
|
|
6194
|
+
Selection extends Expression.Any
|
|
6195
|
+
? unknown
|
|
6196
|
+
: [Extract<keyof Selection, string>] extends [never]
|
|
6197
|
+
? ReturningSelectionNonEmptyError<Selection>
|
|
6198
|
+
: unknown
|
|
6199
|
+
|
|
5669
6200
|
type ReturningApi = <Selection extends SelectionShape>(
|
|
5670
|
-
selection: Selection
|
|
6201
|
+
selection: Selection & SelectionRootObjectConstraint<Selection> & SelectionNestedNonEmptyConstraint<Selection> & ReturningSelectionNonEmptyConstraint<Selection>
|
|
5671
6202
|
) =>
|
|
5672
6203
|
<PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
|
|
5673
6204
|
plan: PlanValue & RequireMutationStatement<PlanValue>
|
|
@@ -5707,12 +6238,12 @@ type AsCurriedResult<
|
|
|
5707
6238
|
>
|
|
5708
6239
|
<Target extends MutationTargetLike, Values extends Record<string, unknown>>(
|
|
5709
6240
|
target: Target,
|
|
5710
|
-
values: MutationValuesInput<"insert", Target, Values>
|
|
6241
|
+
values: MutationValuesInput<"insert", Target, Values> & MutationValuesDialectConstraint<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
5711
6242
|
): QueryPlan<
|
|
5712
6243
|
{},
|
|
5713
6244
|
Exclude<MutationRequiredFromValues<Values>, SourceNameOf<Target>>,
|
|
5714
6245
|
AddAvailable<{}, SourceNameOf<Target>>,
|
|
5715
|
-
TableDialectOf<Target>,
|
|
6246
|
+
TableDialectOf<Target> | KnownMutationDialectFromValues<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5716
6247
|
never,
|
|
5717
6248
|
SourceNameOf<Target>,
|
|
5718
6249
|
Exclude<MutationRequiredFromValues<Values>, SourceNameOf<Target>>,
|
|
@@ -5734,21 +6265,22 @@ type AsCurriedResult<
|
|
|
5734
6265
|
Target extends MutationTargetLike,
|
|
5735
6266
|
const Columns extends DdlColumnInput,
|
|
5736
6267
|
UpdateValues extends MutationInputOf<Table.UpdateOf<Target>> | undefined = MutationInputOf<Table.UpdateOf<Target>> | undefined,
|
|
5737
|
-
Options extends ConflictActionInput<Target, Dialect, UpdateValues> = ConflictActionInput<Target, Dialect, UpdateValues
|
|
6268
|
+
Options extends ConflictActionInput<Target, Dialect, UpdateValues> = ConflictActionInput<Target, Dialect, UpdateValues>,
|
|
6269
|
+
ConflictTarget extends ConflictTargetInput<Target, Dialect, Columns> = ConflictTargetInput<Target, Dialect, Columns>
|
|
5738
6270
|
>(
|
|
5739
|
-
target:
|
|
5740
|
-
options?: Options
|
|
6271
|
+
target: ConflictTarget,
|
|
6272
|
+
options?: Options & ConflictActionUpdateNonEmptyConstraint<Options>
|
|
5741
6273
|
) =>
|
|
5742
6274
|
<PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
|
|
5743
6275
|
plan: PlanValue & RequireInsertStatement<PlanValue>
|
|
5744
6276
|
) => QueryPlan<
|
|
5745
6277
|
SelectionOfPlan<PlanValue>,
|
|
5746
|
-
Exclude<RequiredOfPlan<PlanValue> |
|
|
6278
|
+
Exclude<RequiredOfPlan<PlanValue> | ConflictRequired<UpdateValues, Options, ConflictTarget>, AvailableNames<AvailableOfPlan<PlanValue>>>,
|
|
5747
6279
|
AvailableOfPlan<PlanValue>,
|
|
5748
|
-
PlanDialectOf<PlanValue>,
|
|
6280
|
+
PlanDialectOf<PlanValue> | ConflictDialect<UpdateValues, Options, ConflictTarget, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5749
6281
|
GroupedOfPlan<PlanValue>,
|
|
5750
6282
|
ScopedNamesOfPlan<PlanValue>,
|
|
5751
|
-
Exclude<OutstandingOfPlan<PlanValue> |
|
|
6283
|
+
Exclude<OutstandingOfPlan<PlanValue> | ConflictRequired<UpdateValues, Options, ConflictTarget>, AvailableNames<AvailableOfPlan<PlanValue>>>,
|
|
5752
6284
|
AssumptionsOfPlan<PlanValue>,
|
|
5753
6285
|
CapabilitiesOfPlan<PlanValue>,
|
|
5754
6286
|
StatementOfPlan<PlanValue>,
|
|
@@ -5759,13 +6291,13 @@ type AsCurriedResult<
|
|
|
5759
6291
|
|
|
5760
6292
|
interface UpdateApi {
|
|
5761
6293
|
<Targets extends MutationTargetTuple, Values extends UpdateInputOfTarget<Targets>>(
|
|
5762
|
-
target: Dialect extends "mysql" ? Targets : never,
|
|
5763
|
-
values: Values
|
|
6294
|
+
target: Dialect extends "mysql" ? Targets & MutationTargetTupleDialectConstraint<Targets, Dialect> : never,
|
|
6295
|
+
values: Values & NestedUpdateValuesNonEmptyConstraint<Values> & MutationValuesDialectConstraint<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
5764
6296
|
): QueryPlan<
|
|
5765
6297
|
{},
|
|
5766
6298
|
Exclude<NestedMutationRequiredFromValues<Values>, MutationTargetNamesOf<Targets>>,
|
|
5767
6299
|
AddAvailableMany<{}, MutationTargetNamesOf<Targets>>,
|
|
5768
|
-
TableDialectOf<Targets[0]>,
|
|
6300
|
+
TableDialectOf<Targets[0]> | KnownMutationDialectFromValues<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5769
6301
|
never,
|
|
5770
6302
|
MutationTargetNamesOf<Targets>,
|
|
5771
6303
|
Exclude<NestedMutationRequiredFromValues<Values>, MutationTargetNamesOf<Targets>>,
|
|
@@ -5778,12 +6310,12 @@ type AsCurriedResult<
|
|
|
5778
6310
|
>
|
|
5779
6311
|
<Target extends MutationTargetLike, Values extends Record<string, unknown>>(
|
|
5780
6312
|
target: Target,
|
|
5781
|
-
values: MutationValuesInput<"update", Target, Values>
|
|
6313
|
+
values: MutationValuesInput<"update", Target, Values> & UpdateValuesNonEmptyConstraint<Values> & MutationValuesDialectConstraint<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
5782
6314
|
): QueryPlan<
|
|
5783
6315
|
{},
|
|
5784
6316
|
Exclude<MutationRequiredFromValues<Values>, SourceNameOf<Target>>,
|
|
5785
6317
|
AddAvailable<{}, SourceNameOf<Target>>,
|
|
5786
|
-
TableDialectOf<Target>,
|
|
6318
|
+
TableDialectOf<Target> | KnownMutationDialectFromValues<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5787
6319
|
never,
|
|
5788
6320
|
SourceNameOf<Target>,
|
|
5789
6321
|
Exclude<MutationRequiredFromValues<Values>, SourceNameOf<Target>>,
|
|
@@ -5800,20 +6332,22 @@ type AsCurriedResult<
|
|
|
5800
6332
|
Target extends MutationTargetLike,
|
|
5801
6333
|
Values extends MutationInputOf<Table.InsertOf<Target>>,
|
|
5802
6334
|
const Columns extends DdlColumnInput,
|
|
5803
|
-
UpdateValues extends MutationInputOf<Table.UpdateOf<Target>>
|
|
6335
|
+
UpdateValues extends MutationInputOf<Table.UpdateOf<Target>> | undefined = undefined
|
|
5804
6336
|
>(
|
|
5805
6337
|
target: Target,
|
|
5806
|
-
values: Values,
|
|
5807
|
-
conflictColumns:
|
|
5808
|
-
updateValues?: UpdateValues
|
|
6338
|
+
values: Values & MutationValuesDialectConstraint<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
6339
|
+
conflictColumns: ValidateTargetColumnInput<Target, Columns>,
|
|
6340
|
+
updateValues?: UpdateValues & UpdateValuesNonEmptyConstraint<Exclude<UpdateValues, undefined>> & MutationValuesDialectConstraint<Exclude<UpdateValues, undefined>, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
5809
6341
|
) => QueryPlan<
|
|
5810
6342
|
{},
|
|
5811
|
-
Exclude<MutationRequiredFromValues<Values> | MutationRequiredFromValues<UpdateValues
|
|
6343
|
+
Exclude<MutationRequiredFromValues<Values> | MutationRequiredFromValues<Exclude<UpdateValues, undefined>>, SourceNameOf<Target>>,
|
|
5812
6344
|
AddAvailable<{}, SourceNameOf<Target>>,
|
|
5813
|
-
TableDialectOf<Target
|
|
6345
|
+
| TableDialectOf<Target>
|
|
6346
|
+
| KnownMutationDialectFromValues<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
6347
|
+
| KnownMutationDialectFromValues<Exclude<UpdateValues, undefined>, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5814
6348
|
never,
|
|
5815
6349
|
SourceNameOf<Target>,
|
|
5816
|
-
Exclude<MutationRequiredFromValues<Values> | MutationRequiredFromValues<UpdateValues
|
|
6350
|
+
Exclude<MutationRequiredFromValues<Values> | MutationRequiredFromValues<Exclude<UpdateValues, undefined>>, SourceNameOf<Target>>,
|
|
5817
6351
|
TrueFormula,
|
|
5818
6352
|
"write",
|
|
5819
6353
|
"insert",
|
|
@@ -5841,7 +6375,7 @@ type AsCurriedResult<
|
|
|
5841
6375
|
EmptyFacts
|
|
5842
6376
|
>
|
|
5843
6377
|
<Targets extends MutationTargetTuple>(
|
|
5844
|
-
target: Dialect extends "mysql" ? Targets : never
|
|
6378
|
+
target: Dialect extends "mysql" ? Targets & MutationTargetTupleDialectConstraint<Targets, Dialect> : never
|
|
5845
6379
|
): QueryPlan<
|
|
5846
6380
|
{},
|
|
5847
6381
|
never,
|
|
@@ -5890,9 +6424,9 @@ type AsCurriedResult<
|
|
|
5890
6424
|
target: Target,
|
|
5891
6425
|
source: Source & (
|
|
5892
6426
|
SourceRequiredOf<Source> extends never ? unknown : SourceRequirementError<Source>
|
|
5893
|
-
),
|
|
6427
|
+
) & MergeSourceNameConstraint<Target, Source>,
|
|
5894
6428
|
on: On,
|
|
5895
|
-
options
|
|
6429
|
+
options: MergeOptions<Target, MatchedValues, InsertValues, MatchedPredicate, NotMatchedPredicate>
|
|
5896
6430
|
) => QueryPlan<
|
|
5897
6431
|
{},
|
|
5898
6432
|
Exclude<
|
|
@@ -5936,6 +6470,7 @@ type AsCurriedResult<
|
|
|
5936
6470
|
>
|
|
5937
6471
|
|
|
5938
6472
|
const mutationRuntime = makeDslMutationRuntime({
|
|
6473
|
+
profile,
|
|
5939
6474
|
makePlan,
|
|
5940
6475
|
getAst,
|
|
5941
6476
|
getQueryState,
|
|
@@ -5948,7 +6483,7 @@ type AsCurriedResult<
|
|
|
5948
6483
|
buildConflictTarget,
|
|
5949
6484
|
mutationTargetClauses,
|
|
5950
6485
|
mutationAvailableSources,
|
|
5951
|
-
|
|
6486
|
+
normalizeConflictColumns,
|
|
5952
6487
|
targetSourceDetails,
|
|
5953
6488
|
sourceDetails
|
|
5954
6489
|
})
|
|
@@ -5964,63 +6499,21 @@ type AsCurriedResult<
|
|
|
5964
6499
|
): QueryPlan<any, any, any, any, any, any, any, any, any, "insert", MutationTargetLike, "ready"> =>
|
|
5965
6500
|
mutationRuntime.attachInsertSource(plan, source)
|
|
5966
6501
|
|
|
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)
|
|
6502
|
+
const onConflict = ((target: unknown, options: unknown = {}) =>
|
|
6503
|
+
(plan: QueryPlan<any, any, any, any, any, any, any, any, any, any>) =>
|
|
6504
|
+
mutationRuntime.onConflict(target, options)(plan)) as OnConflictApi
|
|
5993
6505
|
|
|
5994
6506
|
const update: UpdateApi = ((
|
|
5995
6507
|
target: MutationTargetInput,
|
|
5996
6508
|
values: Record<string, unknown>
|
|
5997
6509
|
) => mutationRuntime.update(target, values)) as UpdateApi
|
|
5998
6510
|
|
|
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)
|
|
6511
|
+
const upsert = ((
|
|
6512
|
+
target: MutationTargetLike,
|
|
6513
|
+
values: Record<string, unknown>,
|
|
6514
|
+
conflictColumns: DdlColumnInput,
|
|
6515
|
+
updateValues?: Record<string, unknown>
|
|
6516
|
+
) => mutationRuntime.upsert(target, values, conflictColumns as string | readonly string[], updateValues)) as UpsertApi
|
|
6024
6517
|
|
|
6025
6518
|
const delete_: DeleteApi = ((
|
|
6026
6519
|
target: MutationTargetInput
|
|
@@ -6047,62 +6540,12 @@ type AsCurriedResult<
|
|
|
6047
6540
|
EmptyFacts
|
|
6048
6541
|
> => mutationRuntime.truncate(target, options)
|
|
6049
6542
|
|
|
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)
|
|
6543
|
+
const merge = ((
|
|
6544
|
+
target: MutationTargetLike,
|
|
6545
|
+
source: SourceLike,
|
|
6546
|
+
on: PredicateInput,
|
|
6547
|
+
options: Record<string, unknown>
|
|
6548
|
+
) => mutationRuntime.merge(target, source, on, options)) as MergeApi
|
|
6106
6549
|
|
|
6107
6550
|
type TransactionApi = (options?: TransactionOptions) => QueryPlan<
|
|
6108
6551
|
{},
|
|
@@ -6216,7 +6659,7 @@ type AsCurriedResult<
|
|
|
6216
6659
|
|
|
6217
6660
|
type CreateIndexApi = <Target extends SchemaTableLike, const Columns extends DdlColumnInput>(
|
|
6218
6661
|
target: Target,
|
|
6219
|
-
columns: Columns &
|
|
6662
|
+
columns: Columns & ValidateDdlColumnInput<Target, Columns>,
|
|
6220
6663
|
options?: CreateIndexOptions
|
|
6221
6664
|
) => QueryPlan<
|
|
6222
6665
|
{},
|
|
@@ -6233,7 +6676,7 @@ type AsCurriedResult<
|
|
|
6233
6676
|
|
|
6234
6677
|
type DropIndexApi = <Target extends SchemaTableLike, const Columns extends DdlColumnInput>(
|
|
6235
6678
|
target: Target,
|
|
6236
|
-
columns: Columns &
|
|
6679
|
+
columns: Columns & ValidateDdlColumnInput<Target, Columns>,
|
|
6237
6680
|
options?: DropIndexOptions
|
|
6238
6681
|
) => QueryPlan<
|
|
6239
6682
|
{},
|