effect-qb 0.15.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 +1957 -595
- package/dist/postgres/metadata.js +2507 -182
- package/dist/postgres.js +9587 -8201
- package/dist/sqlite.js +8360 -0
- package/package.json +7 -2
- package/src/internal/column-state.ts +7 -0
- package/src/internal/column.ts +22 -0
- package/src/internal/derived-table.ts +29 -3
- package/src/internal/dialect.ts +14 -1
- 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 +62 -13
- 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/analysis.ts +103 -1
- package/src/internal/predicate/atom.ts +7 -0
- package/src/internal/predicate/context.ts +170 -17
- package/src/internal/predicate/key.ts +64 -2
- package/src/internal/predicate/normalize.ts +115 -34
- package/src/internal/predicate/runtime.ts +144 -13
- package/src/internal/query.ts +563 -103
- package/src/internal/renderer.ts +39 -2
- package/src/internal/runtime/driver-value-mapping.ts +244 -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/scalar.ts +11 -0
- package/src/internal/table-options.ts +108 -1
- package/src/internal/table.ts +87 -29
- package/src/mysql/column.ts +19 -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/executor.ts +20 -5
- package/src/mysql/internal/dialect.ts +12 -6
- package/src/mysql/internal/dsl.ts +995 -263
- package/src/mysql/internal/renderer.ts +13 -3
- package/src/mysql/internal/sql-expression-renderer.ts +530 -128
- package/src/mysql/query.ts +9 -2
- package/src/mysql/renderer.ts +7 -2
- package/src/mysql/table.ts +38 -12
- package/src/postgres/cast.ts +22 -7
- package/src/postgres/column.ts +5 -2
- package/src/postgres/errors/normalize.ts +2 -2
- package/src/postgres/executor.ts +68 -10
- package/src/postgres/function/core.ts +19 -1
- package/src/postgres/internal/dialect.ts +12 -6
- package/src/postgres/internal/dsl.ts +958 -288
- package/src/postgres/internal/renderer.ts +13 -3
- 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 +477 -96
- package/src/postgres/json.ts +57 -17
- package/src/postgres/query.ts +9 -2
- package/src/postgres/renderer.ts +7 -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/postgres/type.ts +4 -0
- 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,16 +31,21 @@ 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,
|
|
41
46
|
type ExtractDialect,
|
|
42
47
|
type ExtractRequired,
|
|
48
|
+
type FactsOfPlan,
|
|
43
49
|
type GroupByInput,
|
|
44
50
|
type GroupedOfPlan,
|
|
45
51
|
type GroupedKeysFromValues,
|
|
@@ -55,6 +61,7 @@ import {
|
|
|
55
61
|
type PlanDialectOf,
|
|
56
62
|
type PresenceWitnessKeysOfSource,
|
|
57
63
|
type PredicateInput,
|
|
64
|
+
type PredicateStateOfPlan,
|
|
58
65
|
type KindOf,
|
|
59
66
|
type QueryPlan,
|
|
60
67
|
type OutputOfSelection,
|
|
@@ -117,7 +124,7 @@ import type {
|
|
|
117
124
|
JsonValueAtPath,
|
|
118
125
|
NormalizeJsonLiteral
|
|
119
126
|
} from "../../internal/json/types.js"
|
|
120
|
-
import type {
|
|
127
|
+
import type { AssumePredicateStateTrue, EmptyFacts, PredicateStateFacts, PredicateStateFormula } from "../../internal/predicate/analysis.js"
|
|
121
128
|
import type { FormulaOfPredicate } from "../../internal/predicate/normalize.js"
|
|
122
129
|
import type { TrueFormula } from "../../internal/predicate/formula.js"
|
|
123
130
|
import { assumeFormulaTrue, formulaOfExpression as formulaOfExpressionRuntime, trueFormula } from "../../internal/predicate/runtime.js"
|
|
@@ -215,6 +222,13 @@ type DialectAsExpression<
|
|
|
215
222
|
? Value
|
|
216
223
|
: DialectLiteralExpression<Extract<Value, LiteralValue>, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
217
224
|
|
|
225
|
+
type ProjectionAliasedExpression<
|
|
226
|
+
Value extends Expression.Any,
|
|
227
|
+
Alias extends string
|
|
228
|
+
> = Value & {
|
|
229
|
+
readonly [ProjectionAlias.TypeId]: ProjectionAlias.State<Alias>
|
|
230
|
+
}
|
|
231
|
+
|
|
218
232
|
/** Normalizes a generic string-capable input into the expression form used internally. */
|
|
219
233
|
type DialectAsStringExpression<
|
|
220
234
|
Value extends ExpressionInput,
|
|
@@ -688,6 +702,21 @@ type DialectOfDialectNumericInput<
|
|
|
688
702
|
NullDb extends Expression.DbType.Any
|
|
689
703
|
> = DialectOf<DialectAsNumericExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>
|
|
690
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
|
+
|
|
691
720
|
/** Dependency map carried by a numeric-clause input after coercion. */
|
|
692
721
|
type DependenciesOfDialectNumericInput<
|
|
693
722
|
Value extends NumericExpressionInput,
|
|
@@ -762,6 +791,18 @@ type DialectExpressionTuple<
|
|
|
762
791
|
readonly [K in keyof Values]: DialectAsExpression<Values[K], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
763
792
|
}
|
|
764
793
|
|
|
794
|
+
type DialectExpressionArray<
|
|
795
|
+
Values extends readonly ExpressionInput[],
|
|
796
|
+
Dialect extends string,
|
|
797
|
+
TextDb extends Expression.DbType.Any,
|
|
798
|
+
NumericDb extends Expression.DbType.Any,
|
|
799
|
+
BoolDb extends Expression.DbType.Any,
|
|
800
|
+
TimestampDb extends Expression.DbType.Any,
|
|
801
|
+
NullDb extends Expression.DbType.Any
|
|
802
|
+
> = DialectExpressionTuple<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> extends infer Tuple extends readonly Expression.Any[]
|
|
803
|
+
? Tuple
|
|
804
|
+
: never
|
|
805
|
+
|
|
765
806
|
/** Normalized expression tuple for generic string operator inputs. */
|
|
766
807
|
type DialectStringExpressionTuple<
|
|
767
808
|
Values extends readonly ExpressionInput[],
|
|
@@ -778,7 +819,7 @@ type DialectStringExpressionTuple<
|
|
|
778
819
|
/** Names of sources already available to a plan. */
|
|
779
820
|
type AvailableNames<Available extends Record<string, Plan.AnySource>> = Extract<keyof Available, string>
|
|
780
821
|
|
|
781
|
-
type
|
|
822
|
+
type PlanPredicateStateAfterWhere<
|
|
782
823
|
PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>,
|
|
783
824
|
Predicate extends PredicateInput,
|
|
784
825
|
Dialect extends string,
|
|
@@ -787,12 +828,34 @@ type PlanAssumptionsAfterWhere<
|
|
|
787
828
|
BoolDb extends Expression.DbType.Any,
|
|
788
829
|
TimestampDb extends Expression.DbType.Any,
|
|
789
830
|
NullDb extends Expression.DbType.Any
|
|
790
|
-
> =
|
|
791
|
-
|
|
831
|
+
> = AssumePredicateStateTrue<
|
|
832
|
+
PredicateStateOfPlan<PlanValue>,
|
|
792
833
|
DialectAsExpression<Predicate, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
793
834
|
>
|
|
794
835
|
|
|
795
|
-
type
|
|
836
|
+
type PlanAssumptionsAfterWhere<
|
|
837
|
+
PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>,
|
|
838
|
+
Predicate extends PredicateInput,
|
|
839
|
+
Dialect extends string,
|
|
840
|
+
TextDb extends Expression.DbType.Any,
|
|
841
|
+
NumericDb extends Expression.DbType.Any,
|
|
842
|
+
BoolDb extends Expression.DbType.Any,
|
|
843
|
+
TimestampDb extends Expression.DbType.Any,
|
|
844
|
+
NullDb extends Expression.DbType.Any
|
|
845
|
+
> = PredicateStateFormula<PlanPredicateStateAfterWhere<PlanValue, Predicate, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>
|
|
846
|
+
|
|
847
|
+
type PlanFactsAfterWhere<
|
|
848
|
+
PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>,
|
|
849
|
+
Predicate extends PredicateInput,
|
|
850
|
+
Dialect extends string,
|
|
851
|
+
TextDb extends Expression.DbType.Any,
|
|
852
|
+
NumericDb extends Expression.DbType.Any,
|
|
853
|
+
BoolDb extends Expression.DbType.Any,
|
|
854
|
+
TimestampDb extends Expression.DbType.Any,
|
|
855
|
+
NullDb extends Expression.DbType.Any
|
|
856
|
+
> = PredicateStateFacts<PlanPredicateStateAfterWhere<PlanValue, Predicate, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>
|
|
857
|
+
|
|
858
|
+
type PlanPredicateStateAfterHaving<
|
|
796
859
|
PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>,
|
|
797
860
|
Predicate extends HavingPredicateInput,
|
|
798
861
|
Dialect extends string,
|
|
@@ -801,12 +864,34 @@ type PlanAssumptionsAfterHaving<
|
|
|
801
864
|
BoolDb extends Expression.DbType.Any,
|
|
802
865
|
TimestampDb extends Expression.DbType.Any,
|
|
803
866
|
NullDb extends Expression.DbType.Any
|
|
804
|
-
> =
|
|
805
|
-
|
|
867
|
+
> = AssumePredicateStateTrue<
|
|
868
|
+
PredicateStateOfPlan<PlanValue>,
|
|
806
869
|
DialectAsExpression<Predicate, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
807
870
|
>
|
|
808
871
|
|
|
809
|
-
type
|
|
872
|
+
type PlanAssumptionsAfterHaving<
|
|
873
|
+
PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>,
|
|
874
|
+
Predicate extends HavingPredicateInput,
|
|
875
|
+
Dialect extends string,
|
|
876
|
+
TextDb extends Expression.DbType.Any,
|
|
877
|
+
NumericDb extends Expression.DbType.Any,
|
|
878
|
+
BoolDb extends Expression.DbType.Any,
|
|
879
|
+
TimestampDb extends Expression.DbType.Any,
|
|
880
|
+
NullDb extends Expression.DbType.Any
|
|
881
|
+
> = PredicateStateFormula<PlanPredicateStateAfterHaving<PlanValue, Predicate, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>
|
|
882
|
+
|
|
883
|
+
type PlanFactsAfterHaving<
|
|
884
|
+
PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>,
|
|
885
|
+
Predicate extends HavingPredicateInput,
|
|
886
|
+
Dialect extends string,
|
|
887
|
+
TextDb extends Expression.DbType.Any,
|
|
888
|
+
NumericDb extends Expression.DbType.Any,
|
|
889
|
+
BoolDb extends Expression.DbType.Any,
|
|
890
|
+
TimestampDb extends Expression.DbType.Any,
|
|
891
|
+
NullDb extends Expression.DbType.Any
|
|
892
|
+
> = PredicateStateFacts<PlanPredicateStateAfterHaving<PlanValue, Predicate, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>
|
|
893
|
+
|
|
894
|
+
type PlanPredicateStateAfterJoin<
|
|
810
895
|
PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>,
|
|
811
896
|
Predicate extends PredicateInput,
|
|
812
897
|
Kind extends QueryAst.JoinKind,
|
|
@@ -817,11 +902,35 @@ type PlanAssumptionsAfterJoin<
|
|
|
817
902
|
TimestampDb extends Expression.DbType.Any,
|
|
818
903
|
NullDb extends Expression.DbType.Any
|
|
819
904
|
> = Kind extends "inner"
|
|
820
|
-
?
|
|
821
|
-
|
|
905
|
+
? AssumePredicateStateTrue<
|
|
906
|
+
PredicateStateOfPlan<PlanValue>,
|
|
822
907
|
DialectAsExpression<Predicate, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
823
908
|
>
|
|
824
|
-
:
|
|
909
|
+
: PredicateStateOfPlan<PlanValue>
|
|
910
|
+
|
|
911
|
+
type PlanAssumptionsAfterJoin<
|
|
912
|
+
PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>,
|
|
913
|
+
Predicate extends PredicateInput,
|
|
914
|
+
Kind extends QueryAst.JoinKind,
|
|
915
|
+
Dialect extends string,
|
|
916
|
+
TextDb extends Expression.DbType.Any,
|
|
917
|
+
NumericDb extends Expression.DbType.Any,
|
|
918
|
+
BoolDb extends Expression.DbType.Any,
|
|
919
|
+
TimestampDb extends Expression.DbType.Any,
|
|
920
|
+
NullDb extends Expression.DbType.Any
|
|
921
|
+
> = PredicateStateFormula<PlanPredicateStateAfterJoin<PlanValue, Predicate, Kind, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>
|
|
922
|
+
|
|
923
|
+
type PlanFactsAfterJoin<
|
|
924
|
+
PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>,
|
|
925
|
+
Predicate extends PredicateInput,
|
|
926
|
+
Kind extends QueryAst.JoinKind,
|
|
927
|
+
Dialect extends string,
|
|
928
|
+
TextDb extends Expression.DbType.Any,
|
|
929
|
+
NumericDb extends Expression.DbType.Any,
|
|
930
|
+
BoolDb extends Expression.DbType.Any,
|
|
931
|
+
TimestampDb extends Expression.DbType.Any,
|
|
932
|
+
NullDb extends Expression.DbType.Any
|
|
933
|
+
> = PredicateStateFacts<PlanPredicateStateAfterJoin<PlanValue, Predicate, Kind, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>
|
|
825
934
|
|
|
826
935
|
type ScalarSubqueryInput<
|
|
827
936
|
PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>,
|
|
@@ -960,6 +1069,16 @@ type JsonPathInput = JsonPath.Path<any> | JsonPath.CanonicalSegment
|
|
|
960
1069
|
|
|
961
1070
|
type JsonQueryInput = JsonPath.Path<any> | StringExpressionInput
|
|
962
1071
|
|
|
1072
|
+
type JsonPathSegmentsOf<Target extends JsonPathInput> =
|
|
1073
|
+
Target extends JsonPath.Path<any>
|
|
1074
|
+
? JsonPath.SegmentsOf<Target>
|
|
1075
|
+
: readonly [Target]
|
|
1076
|
+
|
|
1077
|
+
type JsonTextAccessKind<Target extends JsonPathInput> =
|
|
1078
|
+
Target extends JsonPath.Path<any>
|
|
1079
|
+
? JsonPath.IsExactPath<Target> extends true ? "jsonPathText" : "jsonTraverseText"
|
|
1080
|
+
: Target extends JsonPath.ExactSegment ? "jsonGetText" : "jsonAccessText"
|
|
1081
|
+
|
|
963
1082
|
type JsonPathOutputOf<
|
|
964
1083
|
Root,
|
|
965
1084
|
Target extends JsonPathInput,
|
|
@@ -1480,6 +1599,42 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
|
|
|
1480
1599
|
>
|
|
1481
1600
|
}
|
|
1482
1601
|
|
|
1602
|
+
const retargetLiteralExpression = (
|
|
1603
|
+
value: Expression.Any,
|
|
1604
|
+
target: Expression.Any
|
|
1605
|
+
): Expression.Any => {
|
|
1606
|
+
const ast = (value as unknown as { readonly [ExpressionAst.TypeId]: ExpressionAst.Any })[ExpressionAst.TypeId]
|
|
1607
|
+
if (ast.kind !== "literal") {
|
|
1608
|
+
return value
|
|
1609
|
+
}
|
|
1610
|
+
const targetState = target[Expression.TypeId]
|
|
1611
|
+
return makeExpression({
|
|
1612
|
+
runtime: value[Expression.TypeId].runtime,
|
|
1613
|
+
dbType: targetState.dbType,
|
|
1614
|
+
runtimeSchema: targetState.runtimeSchema,
|
|
1615
|
+
driverValueMapping: targetState.driverValueMapping,
|
|
1616
|
+
nullability: value[Expression.TypeId].nullability,
|
|
1617
|
+
dialect: targetState.dialect,
|
|
1618
|
+
kind: "scalar",
|
|
1619
|
+
dependencies: {}
|
|
1620
|
+
}, ast)
|
|
1621
|
+
}
|
|
1622
|
+
|
|
1623
|
+
const alignBinaryPredicateExpressions = (
|
|
1624
|
+
left: Expression.Any,
|
|
1625
|
+
right: Expression.Any
|
|
1626
|
+
): readonly [Expression.Any, Expression.Any] => {
|
|
1627
|
+
const leftAst = (left as unknown as { readonly [ExpressionAst.TypeId]: ExpressionAst.Any })[ExpressionAst.TypeId]
|
|
1628
|
+
const rightAst = (right as unknown as { readonly [ExpressionAst.TypeId]: ExpressionAst.Any })[ExpressionAst.TypeId]
|
|
1629
|
+
if (leftAst.kind === "literal" && rightAst.kind !== "literal") {
|
|
1630
|
+
return [retargetLiteralExpression(left, right), right]
|
|
1631
|
+
}
|
|
1632
|
+
if (rightAst.kind === "literal" && leftAst.kind !== "literal") {
|
|
1633
|
+
return [left, retargetLiteralExpression(right, left)]
|
|
1634
|
+
}
|
|
1635
|
+
return [left, right]
|
|
1636
|
+
}
|
|
1637
|
+
|
|
1483
1638
|
const toDialectStringExpression = <Value extends StringExpressionInput>(
|
|
1484
1639
|
value: Value
|
|
1485
1640
|
): DialectAsStringExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> =>
|
|
@@ -1568,10 +1723,16 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
|
|
|
1568
1723
|
spec: WindowSpecInput<PartitionBy, OrderBy> | OrderedWindowSpecInput<PartitionBy, Extract<OrderBy, NonEmptyWindowOrderTerms>> | undefined
|
|
1569
1724
|
) => {
|
|
1570
1725
|
const partitionBy = [...(spec?.partitionBy ?? [])] as unknown as PartitionBy
|
|
1571
|
-
const orderBy = (spec?.orderBy ?? []).map((term) =>
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
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 {
|
|
1575
1736
|
readonly [K in keyof OrderBy]: OrderBy[K] extends WindowOrderTermInput<infer Value extends WindowOrderInput>
|
|
1576
1737
|
? { readonly value: Value; readonly direction: OrderDirection }
|
|
1577
1738
|
: never
|
|
@@ -1657,8 +1818,10 @@ type BinaryPredicateExpression<
|
|
|
1657
1818
|
kind: Kind,
|
|
1658
1819
|
nullability: Nullability = "maybe" as Nullability,
|
|
1659
1820
|
): any => {
|
|
1660
|
-
const leftExpression =
|
|
1661
|
-
|
|
1821
|
+
const [leftExpression, rightExpression] = alignBinaryPredicateExpressions(
|
|
1822
|
+
toDialectExpression(left),
|
|
1823
|
+
toDialectExpression(right)
|
|
1824
|
+
)
|
|
1662
1825
|
return (makeExpression as any)({
|
|
1663
1826
|
runtime: true as boolean,
|
|
1664
1827
|
dbType: profile.boolDb as BoolDb,
|
|
@@ -1681,17 +1844,21 @@ type BinaryPredicateExpression<
|
|
|
1681
1844
|
kind: ExpressionAst.VariadicKind
|
|
1682
1845
|
): Expression.Any => {
|
|
1683
1846
|
const expressions = values.map((value) => toDialectExpression(value as any)) as readonly Expression.Any[]
|
|
1847
|
+
const [head, ...tail] = expressions
|
|
1848
|
+
const alignedExpressions = (head !== undefined && (kind === "in" || kind === "notIn" || kind === "between"))
|
|
1849
|
+
? [head, ...tail.map((value) => retargetLiteralExpression(value, head))]
|
|
1850
|
+
: expressions
|
|
1684
1851
|
return makeExpression({
|
|
1685
1852
|
runtime: true as boolean,
|
|
1686
1853
|
dbType: profile.boolDb as BoolDb,
|
|
1687
1854
|
nullability: "maybe",
|
|
1688
|
-
dialect: (
|
|
1855
|
+
dialect: (alignedExpressions.find((value) => value[Expression.TypeId].dialect !== undefined)?.[Expression.TypeId].dialect ?? profile.dialect) as Dialect,
|
|
1689
1856
|
kind: "scalar",
|
|
1690
1857
|
|
|
1691
|
-
dependencies: mergeManyDependencies(
|
|
1858
|
+
dependencies: mergeManyDependencies(alignedExpressions)
|
|
1692
1859
|
}, {
|
|
1693
1860
|
kind,
|
|
1694
|
-
values:
|
|
1861
|
+
values: alignedExpressions
|
|
1695
1862
|
})
|
|
1696
1863
|
}
|
|
1697
1864
|
|
|
@@ -1939,9 +2106,15 @@ type BinaryPredicateExpression<
|
|
|
1939
2106
|
})
|
|
1940
2107
|
}
|
|
1941
2108
|
|
|
1942
|
-
|
|
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
|
+
>(
|
|
1943
2116
|
value: Value & TextInput<NoInfer<Value>, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "collate">,
|
|
1944
|
-
collation:
|
|
2117
|
+
collation: Collation
|
|
1945
2118
|
): AstBackedExpression<
|
|
1946
2119
|
Expression.RuntimeOf<DialectAsStringExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
|
|
1947
2120
|
Expression.DbTypeOf<DialectAsStringExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
|
|
@@ -1949,10 +2122,10 @@ type BinaryPredicateExpression<
|
|
|
1949
2122
|
DialectOfDialectStringInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
1950
2123
|
KindOf<DialectAsStringExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
|
|
1951
2124
|
DependenciesOfDialectStringInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
1952
|
-
ExpressionAst.CollateNode<DialectAsStringExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>
|
|
2125
|
+
ExpressionAst.CollateNode<DialectAsStringExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>, NormalizedCollation<Collation>>
|
|
1953
2126
|
> => {
|
|
1954
2127
|
const expression = toDialectStringExpression(value as any)
|
|
1955
|
-
const normalizedCollation
|
|
2128
|
+
const normalizedCollation = (typeof collation === "string" ? [collation] : collation) as NormalizedCollation<Collation>
|
|
1956
2129
|
return makeExpression({
|
|
1957
2130
|
runtime: expression[Expression.TypeId].runtime as Expression.RuntimeOf<DialectAsStringExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
|
|
1958
2131
|
dbType: expression[Expression.TypeId].dbType as Expression.DbTypeOf<DialectAsStringExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
|
|
@@ -1972,7 +2145,7 @@ type BinaryPredicateExpression<
|
|
|
1972
2145
|
DialectOfDialectStringInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
1973
2146
|
KindOf<DialectAsStringExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
|
|
1974
2147
|
DependenciesOfDialectStringInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
1975
|
-
ExpressionAst.CollateNode<DialectAsStringExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>
|
|
2148
|
+
ExpressionAst.CollateNode<DialectAsStringExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>, NormalizedCollation<Collation>>
|
|
1976
2149
|
>
|
|
1977
2150
|
}
|
|
1978
2151
|
|
|
@@ -1997,6 +2170,7 @@ type BinaryPredicateExpression<
|
|
|
1997
2170
|
runtime: undefined as unknown as RuntimeOfDbType<Target>,
|
|
1998
2171
|
dbType: target as Target,
|
|
1999
2172
|
runtimeSchema: undefined,
|
|
2173
|
+
driverValueMapping: (target as Expression.DbType.Any).driverValueMapping,
|
|
2000
2174
|
nullability: expression[Expression.TypeId].nullability,
|
|
2001
2175
|
dialect: expression[Expression.TypeId].dialect,
|
|
2002
2176
|
kind: expression[Expression.TypeId].kind,
|
|
@@ -2076,6 +2250,14 @@ type BinaryPredicateExpression<
|
|
|
2076
2250
|
kind
|
|
2077
2251
|
})
|
|
2078
2252
|
|
|
2253
|
+
const driverValueMapping = <Db extends Expression.DbType.Any>(
|
|
2254
|
+
dbType: Db,
|
|
2255
|
+
mapping: Expression.DriverValueMapping
|
|
2256
|
+
): Db => ({
|
|
2257
|
+
...dbType,
|
|
2258
|
+
driverValueMapping: mapping
|
|
2259
|
+
})
|
|
2260
|
+
|
|
2079
2261
|
const type = {
|
|
2080
2262
|
...profile.type,
|
|
2081
2263
|
array,
|
|
@@ -2085,7 +2267,8 @@ type BinaryPredicateExpression<
|
|
|
2085
2267
|
domain,
|
|
2086
2268
|
enum: enum_,
|
|
2087
2269
|
set,
|
|
2088
|
-
custom
|
|
2270
|
+
custom,
|
|
2271
|
+
driverValueMapping
|
|
2089
2272
|
}
|
|
2090
2273
|
|
|
2091
2274
|
const makeJsonDb = <Kind extends string>(
|
|
@@ -2273,7 +2456,7 @@ type BinaryPredicateExpression<
|
|
|
2273
2456
|
DialectOf<Base>,
|
|
2274
2457
|
KindOf<Base>,
|
|
2275
2458
|
DependenciesOf<Base>,
|
|
2276
|
-
|
|
2459
|
+
ExpressionAst.JsonAccessNode<JsonTextAccessKind<Target>, Base, JsonPathSegmentsOf<Target>>
|
|
2277
2460
|
> => {
|
|
2278
2461
|
const segments = normalizeJsonPathInput(target)
|
|
2279
2462
|
const kind = isJsonPathValue(target)
|
|
@@ -2300,7 +2483,7 @@ type BinaryPredicateExpression<
|
|
|
2300
2483
|
DialectOf<Base>,
|
|
2301
2484
|
KindOf<Base>,
|
|
2302
2485
|
DependenciesOf<Base>,
|
|
2303
|
-
|
|
2486
|
+
ExpressionAst.JsonAccessNode<JsonTextAccessKind<Target>, Base, JsonPathSegmentsOf<Target>>
|
|
2304
2487
|
>
|
|
2305
2488
|
}
|
|
2306
2489
|
|
|
@@ -2558,7 +2741,7 @@ type BinaryPredicateExpression<
|
|
|
2558
2741
|
Next extends JsonValueInput
|
|
2559
2742
|
>(
|
|
2560
2743
|
base: Base,
|
|
2561
|
-
target: Target & JsonSetGuard<Expression.RuntimeOf<Base>, Target, Next
|
|
2744
|
+
target: Target & JsonSetGuard<Expression.RuntimeOf<Base>, Target, NoInfer<Next>, "json.set">,
|
|
2562
2745
|
next: Next,
|
|
2563
2746
|
options: {
|
|
2564
2747
|
readonly createMissing?: boolean
|
|
@@ -2606,7 +2789,7 @@ type BinaryPredicateExpression<
|
|
|
2606
2789
|
InsertAfter extends boolean = false
|
|
2607
2790
|
>(
|
|
2608
2791
|
base: Base,
|
|
2609
|
-
target: Target & JsonInsertGuard<Expression.RuntimeOf<Base>, Target, Next
|
|
2792
|
+
target: Target & JsonInsertGuard<Expression.RuntimeOf<Base>, Target, NoInfer<Next>, NoInfer<InsertAfter>, "json.insert">,
|
|
2610
2793
|
next: Next,
|
|
2611
2794
|
options: {
|
|
2612
2795
|
readonly insertAfter?: InsertAfter
|
|
@@ -3027,12 +3210,12 @@ type BinaryPredicateExpression<
|
|
|
3027
3210
|
}
|
|
3028
3211
|
|
|
3029
3212
|
const and = <
|
|
3030
|
-
Values extends readonly [ExpressionInput, ...ExpressionInput[]]
|
|
3213
|
+
const Values extends readonly [ExpressionInput, ...ExpressionInput[]]
|
|
3031
3214
|
>(
|
|
3032
3215
|
...values: Values
|
|
3033
3216
|
): VariadicBooleanExpression<
|
|
3034
3217
|
"and",
|
|
3035
|
-
|
|
3218
|
+
DialectExpressionArray<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
3036
3219
|
Dialect,
|
|
3037
3220
|
TextDb,
|
|
3038
3221
|
NumericDb,
|
|
@@ -3042,16 +3225,16 @@ type BinaryPredicateExpression<
|
|
|
3042
3225
|
> =>
|
|
3043
3226
|
makeVariadicBooleanExpression(
|
|
3044
3227
|
"and",
|
|
3045
|
-
values.map((value) => toDialectExpression(value)) as
|
|
3228
|
+
values.map((value) => toDialectExpression(value)) as unknown as DialectExpressionArray<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
3046
3229
|
)
|
|
3047
3230
|
|
|
3048
3231
|
const or = <
|
|
3049
|
-
Values extends readonly [ExpressionInput, ...ExpressionInput[]]
|
|
3232
|
+
const Values extends readonly [ExpressionInput, ...ExpressionInput[]]
|
|
3050
3233
|
>(
|
|
3051
3234
|
...values: Values
|
|
3052
3235
|
): VariadicBooleanExpression<
|
|
3053
3236
|
"or",
|
|
3054
|
-
|
|
3237
|
+
DialectExpressionArray<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
3055
3238
|
Dialect,
|
|
3056
3239
|
TextDb,
|
|
3057
3240
|
NumericDb,
|
|
@@ -3061,7 +3244,7 @@ type BinaryPredicateExpression<
|
|
|
3061
3244
|
> =>
|
|
3062
3245
|
makeVariadicBooleanExpression(
|
|
3063
3246
|
"or",
|
|
3064
|
-
values.map((value) => toDialectExpression(value)) as
|
|
3247
|
+
values.map((value) => toDialectExpression(value)) as unknown as DialectExpressionArray<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
3065
3248
|
)
|
|
3066
3249
|
|
|
3067
3250
|
const not = <Value extends ExpressionInput>(
|
|
@@ -3295,6 +3478,8 @@ type BinaryPredicateExpression<
|
|
|
3295
3478
|
return makeExpression({
|
|
3296
3479
|
runtime: undefined as Expression.RuntimeOf<ScalarOutputOfPlan<PlanValue>> | null,
|
|
3297
3480
|
dbType: expression[Expression.TypeId].dbType as Expression.DbTypeOf<ScalarOutputOfPlan<PlanValue>>,
|
|
3481
|
+
runtimeSchema: expression[Expression.TypeId].runtimeSchema,
|
|
3482
|
+
driverValueMapping: expression[Expression.TypeId].driverValueMapping,
|
|
3298
3483
|
nullability: "maybe",
|
|
3299
3484
|
dialect: profile.dialect as Dialect,
|
|
3300
3485
|
kind: "scalar",
|
|
@@ -3818,7 +4003,9 @@ type BinaryPredicateExpression<
|
|
|
3818
4003
|
string,
|
|
3819
4004
|
"scalar",
|
|
3820
4005
|
Expression.BindingId
|
|
3821
|
-
>
|
|
4006
|
+
> & {
|
|
4007
|
+
readonly [ExpressionAst.TypeId]: ExpressionAst.ColumnNode<any, string>
|
|
4008
|
+
}
|
|
3822
4009
|
>(
|
|
3823
4010
|
value: Value
|
|
3824
4011
|
): AstBackedExpression<
|
|
@@ -3838,6 +4025,7 @@ type BinaryPredicateExpression<
|
|
|
3838
4025
|
runtime: undefined as Expression.RuntimeOf<Value>,
|
|
3839
4026
|
dbType: value[Expression.TypeId].dbType as Expression.DbTypeOf<Value>,
|
|
3840
4027
|
runtimeSchema: value[Expression.TypeId].runtimeSchema,
|
|
4028
|
+
driverValueMapping: value[Expression.TypeId].driverValueMapping,
|
|
3841
4029
|
nullability: value[Expression.TypeId].nullability as Expression.NullabilityOf<Value>,
|
|
3842
4030
|
dialect: profile.dialect as Dialect,
|
|
3843
4031
|
kind: "scalar",
|
|
@@ -3861,20 +4049,56 @@ type BinaryPredicateExpression<
|
|
|
3861
4049
|
value: Value,
|
|
3862
4050
|
column: Expression.Any
|
|
3863
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
|
+
}
|
|
3864
4067
|
if (value !== null && typeof value === "object" && Expression.TypeId in value) {
|
|
3865
|
-
|
|
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
|
+
}
|
|
4086
|
+
return retargetLiteralExpression(value as unknown as Expression.Any, column)
|
|
3866
4087
|
}
|
|
4088
|
+
const normalizedValue = normalizeMutationValue(value)
|
|
3867
4089
|
return makeExpression({
|
|
3868
|
-
runtime:
|
|
3869
|
-
dbType:
|
|
3870
|
-
|
|
3871
|
-
|
|
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,
|
|
3872
4096
|
kind: "scalar",
|
|
3873
4097
|
|
|
3874
4098
|
dependencies: {}
|
|
3875
4099
|
}, {
|
|
3876
4100
|
kind: "literal",
|
|
3877
|
-
value
|
|
4101
|
+
value: normalizedValue
|
|
3878
4102
|
})
|
|
3879
4103
|
}
|
|
3880
4104
|
|
|
@@ -3941,6 +4165,7 @@ type BinaryPredicateExpression<
|
|
|
3941
4165
|
runtime: undefined as never,
|
|
3942
4166
|
dbType: state.dbType,
|
|
3943
4167
|
runtimeSchema: state.runtimeSchema,
|
|
4168
|
+
driverValueMapping: state.driverValueMapping,
|
|
3944
4169
|
nullability: state.nullability,
|
|
3945
4170
|
dialect: state.dialect,
|
|
3946
4171
|
kind: "scalar",
|
|
@@ -3961,16 +4186,16 @@ type BinaryPredicateExpression<
|
|
|
3961
4186
|
Alias extends string
|
|
3962
4187
|
>(
|
|
3963
4188
|
rows: readonly [Record<string, Expression.Any>, ...Record<string, Expression.Any>[]],
|
|
3964
|
-
selection: ValuesOutputShape<Rows
|
|
4189
|
+
selection: ValuesOutputShape<Rows, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
3965
4190
|
alias: Alias
|
|
3966
4191
|
): ValuesSource<
|
|
3967
4192
|
Rows,
|
|
3968
|
-
ValuesOutputShape<Rows
|
|
4193
|
+
ValuesOutputShape<Rows, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
3969
4194
|
Alias,
|
|
3970
4195
|
Dialect
|
|
3971
4196
|
> => {
|
|
3972
4197
|
const columns = makeColumnReferenceSelection(alias, selection as Record<string, Expression.Any>) as unknown as ValuesOutputShape<
|
|
3973
|
-
Rows
|
|
4198
|
+
Rows,
|
|
3974
4199
|
Dialect,
|
|
3975
4200
|
TextDb,
|
|
3976
4201
|
NumericDb,
|
|
@@ -3988,7 +4213,7 @@ type BinaryPredicateExpression<
|
|
|
3988
4213
|
}
|
|
3989
4214
|
return Object.assign(source, columns) as unknown as ValuesSource<
|
|
3990
4215
|
Rows,
|
|
3991
|
-
ValuesOutputShape<Rows
|
|
4216
|
+
ValuesOutputShape<Rows, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
3992
4217
|
Alias,
|
|
3993
4218
|
Dialect
|
|
3994
4219
|
>
|
|
@@ -4001,7 +4226,12 @@ type BinaryPredicateExpression<
|
|
|
4001
4226
|
|
|
4002
4227
|
const normalizeUnnestColumns = (columns: UnnestColumnsInput): Record<string, readonly Expression.Any[]> =>
|
|
4003
4228
|
Object.fromEntries(
|
|
4004
|
-
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
|
+
})
|
|
4005
4235
|
) as Record<string, readonly Expression.Any[]>
|
|
4006
4236
|
|
|
4007
4237
|
const normalizeMutationTargets = (
|
|
@@ -4044,6 +4274,17 @@ type BinaryPredicateExpression<
|
|
|
4044
4274
|
})
|
|
4045
4275
|
) as unknown as AddAvailableMany<{}, MutationTargetNamesOf<Target>, Mode>
|
|
4046
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
|
+
|
|
4047
4288
|
const buildMutationAssignments = <Target extends MutationTargetInput, Values>(
|
|
4048
4289
|
target: Target,
|
|
4049
4290
|
values: Values
|
|
@@ -4053,7 +4294,7 @@ type BinaryPredicateExpression<
|
|
|
4053
4294
|
const columns = target as unknown as Record<string, Expression.Any>
|
|
4054
4295
|
return Object.entries(values as Record<string, unknown>).map(([columnName, value]) => ({
|
|
4055
4296
|
columnName,
|
|
4056
|
-
value: toMutationValueExpression(value, columns
|
|
4297
|
+
value: toMutationValueExpression(value, getMutationColumn(columns, columnName))
|
|
4057
4298
|
}))
|
|
4058
4299
|
}
|
|
4059
4300
|
const valueMap = values as Record<string, Record<string, unknown> | undefined>
|
|
@@ -4064,7 +4305,7 @@ type BinaryPredicateExpression<
|
|
|
4064
4305
|
return Object.entries(scopedValues).map(([columnName, value]) => ({
|
|
4065
4306
|
tableName: targetName,
|
|
4066
4307
|
columnName,
|
|
4067
|
-
value: toMutationValueExpression(value, columns
|
|
4308
|
+
value: toMutationValueExpression(value, getMutationColumn(columns, columnName))
|
|
4068
4309
|
}))
|
|
4069
4310
|
})
|
|
4070
4311
|
}
|
|
@@ -4151,14 +4392,26 @@ type BinaryPredicateExpression<
|
|
|
4151
4392
|
}
|
|
4152
4393
|
}
|
|
4153
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
|
+
|
|
4154
4407
|
const buildConflictTarget = <Target extends MutationTargetLike>(
|
|
4155
4408
|
target: Target,
|
|
4156
|
-
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 }
|
|
4157
4410
|
): QueryAst.ConflictTargetClause => {
|
|
4158
|
-
if (Array.isArray(input)) {
|
|
4411
|
+
if (typeof input === "string" || Array.isArray(input)) {
|
|
4159
4412
|
return {
|
|
4160
4413
|
kind: "columns",
|
|
4161
|
-
columns:
|
|
4414
|
+
columns: normalizeConflictColumns(target, input)
|
|
4162
4415
|
}
|
|
4163
4416
|
}
|
|
4164
4417
|
if (!Array.isArray(input) && "constraint" in input) {
|
|
@@ -4168,12 +4421,12 @@ type BinaryPredicateExpression<
|
|
|
4168
4421
|
}
|
|
4169
4422
|
}
|
|
4170
4423
|
const columnTarget = input as {
|
|
4171
|
-
readonly columns: readonly string[]
|
|
4424
|
+
readonly columns: string | readonly string[]
|
|
4172
4425
|
readonly where?: PredicateInput
|
|
4173
4426
|
}
|
|
4174
4427
|
return {
|
|
4175
4428
|
kind: "columns",
|
|
4176
|
-
columns:
|
|
4429
|
+
columns: normalizeConflictColumns(target, columnTarget.columns),
|
|
4177
4430
|
where: columnTarget.where === undefined ? undefined : toDialectExpression(columnTarget.where)
|
|
4178
4431
|
}
|
|
4179
4432
|
}
|
|
@@ -4211,11 +4464,21 @@ type ValidateDdlColumns<
|
|
|
4211
4464
|
Columns extends readonly string[]
|
|
4212
4465
|
> = Exclude<Columns[number], SchemaColumnNames<Target>> extends never ? Columns : never
|
|
4213
4466
|
|
|
4467
|
+
type ValidateDdlColumnInput<
|
|
4468
|
+
Target extends SchemaTableLike,
|
|
4469
|
+
Columns extends DdlColumnInput
|
|
4470
|
+
> = ValidateDdlColumns<Target, NormalizeDdlColumns<Columns>> extends never ? never : Columns
|
|
4471
|
+
|
|
4214
4472
|
type ValidateTargetColumns<
|
|
4215
4473
|
Target extends MutationTargetLike,
|
|
4216
4474
|
Columns extends readonly string[]
|
|
4217
4475
|
> = Exclude<Columns[number], Extract<keyof Target[typeof Table.TypeId]["fields"], string>> extends never ? Columns : never
|
|
4218
4476
|
|
|
4477
|
+
type ValidateTargetColumnInput<
|
|
4478
|
+
Target extends MutationTargetLike,
|
|
4479
|
+
Columns extends DdlColumnInput
|
|
4480
|
+
> = ValidateTargetColumns<Target, NormalizeDdlColumns<Columns>> extends never ? never : Columns
|
|
4481
|
+
|
|
4219
4482
|
type CreateIndexOptions = {
|
|
4220
4483
|
readonly name?: string
|
|
4221
4484
|
readonly unique?: boolean
|
|
@@ -4245,10 +4508,15 @@ type TransactionOptions = {
|
|
|
4245
4508
|
readonly readOnly?: boolean
|
|
4246
4509
|
}
|
|
4247
4510
|
|
|
4248
|
-
type LockOptions =
|
|
4249
|
-
|
|
4250
|
-
|
|
4251
|
-
|
|
4511
|
+
type LockOptions =
|
|
4512
|
+
| {
|
|
4513
|
+
readonly nowait?: boolean
|
|
4514
|
+
readonly skipLocked?: false
|
|
4515
|
+
}
|
|
4516
|
+
| {
|
|
4517
|
+
readonly nowait?: false
|
|
4518
|
+
readonly skipLocked?: boolean
|
|
4519
|
+
}
|
|
4252
4520
|
|
|
4253
4521
|
type UpsertConflictOptions = {
|
|
4254
4522
|
readonly update?: Record<string, unknown>
|
|
@@ -4263,14 +4531,133 @@ type InsertRowInput<Target extends MutationTargetLike> = MutationInputOf<Table.I
|
|
|
4263
4531
|
type ValuesRowInput = Record<string, ExpressionInput>
|
|
4264
4532
|
type ValuesRowsInput = readonly [ValuesRowInput, ...ValuesRowInput[]]
|
|
4265
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
|
+
|
|
4266
4600
|
type UnnestColumnsInput = Record<string, readonly [ExpressionInput, ...ExpressionInput[]]>
|
|
4267
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
|
+
|
|
4268
4655
|
type UnnestRowShape<Shape extends Record<string, readonly unknown[]>> = {
|
|
4269
4656
|
readonly [K in keyof Shape]: Shape[K] extends readonly (infer Item)[] ? Item : never
|
|
4270
4657
|
}
|
|
4271
4658
|
|
|
4272
4659
|
type ValuesOutputShape<
|
|
4273
|
-
|
|
4660
|
+
Rows extends ValuesRowsInput,
|
|
4274
4661
|
Dialect extends string,
|
|
4275
4662
|
TextDb extends Expression.DbType.Any,
|
|
4276
4663
|
NumericDb extends Expression.DbType.Any,
|
|
@@ -4278,7 +4665,7 @@ type ValuesOutputShape<
|
|
|
4278
4665
|
TimestampDb extends Expression.DbType.Any,
|
|
4279
4666
|
NullDb extends Expression.DbType.Any
|
|
4280
4667
|
> = {
|
|
4281
|
-
readonly [K in keyof
|
|
4668
|
+
readonly [K in keyof Rows[0]]: DialectAsExpression<ValuesColumnInput<Rows[number], K>, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
4282
4669
|
}
|
|
4283
4670
|
|
|
4284
4671
|
type UnnestOutputShape<
|
|
@@ -4318,21 +4705,24 @@ type DistinctOnUnsupportedError<Dialect extends string> = {
|
|
|
4318
4705
|
}
|
|
4319
4706
|
|
|
4320
4707
|
type DistinctOnApi<Dialect extends string> = Dialect extends "postgres"
|
|
4321
|
-
? <Values extends readonly ExpressionInput[]>(
|
|
4708
|
+
? <Values extends readonly [ExpressionInput, ...ExpressionInput[]]>(
|
|
4322
4709
|
...values: Values
|
|
4323
4710
|
) => <PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
|
|
4324
4711
|
plan: PlanValue & RequireSelectStatement<PlanValue>
|
|
4325
4712
|
) => QueryPlan<
|
|
4326
4713
|
SelectionOfPlan<PlanValue>,
|
|
4327
|
-
RequiredOfPlan<PlanValue>,
|
|
4714
|
+
AddExpressionRequired<RequiredOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, Values[number]>,
|
|
4328
4715
|
AvailableOfPlan<PlanValue>,
|
|
4329
|
-
PlanDialectOf<PlanValue>,
|
|
4716
|
+
PlanDialectOf<PlanValue> | DialectOfDialectInput<Values[number], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
4330
4717
|
GroupedOfPlan<PlanValue>,
|
|
4331
4718
|
ScopedNamesOfPlan<PlanValue>,
|
|
4332
|
-
OutstandingOfPlan<PlanValue>,
|
|
4719
|
+
AddExpressionRequired<OutstandingOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, Values[number]>,
|
|
4333
4720
|
AssumptionsOfPlan<PlanValue>,
|
|
4334
4721
|
CapabilitiesOfPlan<PlanValue>,
|
|
4335
|
-
StatementOfPlan<PlanValue
|
|
4722
|
+
StatementOfPlan<PlanValue>,
|
|
4723
|
+
MutationTargetOfPlan<PlanValue>,
|
|
4724
|
+
InsertSourceStateOfPlan<PlanValue>,
|
|
4725
|
+
FactsOfPlan<PlanValue>
|
|
4336
4726
|
>
|
|
4337
4727
|
: DistinctOnUnsupportedError<Dialect>
|
|
4338
4728
|
|
|
@@ -4362,6 +4752,44 @@ type MysqlConflictWhereError<Values> = Values & {
|
|
|
4362
4752
|
readonly __effect_qb_hint__: "Move the condition into the update assignment expressions or use the Postgres dialect"
|
|
4363
4753
|
}
|
|
4364
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
|
+
|
|
4365
4793
|
type InsertShapeExtraKeys<TargetShape, SourceShape> = Exclude<Extract<keyof SourceShape, string>, Extract<keyof TargetShape, string>>
|
|
4366
4794
|
type InsertShapeMissingKeys<TargetShape, SourceShape> = Exclude<RequiredKeys<TargetShape>, Extract<keyof SourceShape, string>>
|
|
4367
4795
|
type InsertShapeMismatchedKeys<TargetShape, SourceShape> = Extract<{
|
|
@@ -4455,10 +4883,15 @@ type InsertSourceRequired<Source> =
|
|
|
4455
4883
|
Source extends QueryPlan<any, any, any, any, any, any, any, any, any, any> ? RequiredOfPlan<Source> :
|
|
4456
4884
|
never
|
|
4457
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
|
+
|
|
4458
4891
|
type ConflictColumnTarget<
|
|
4459
4892
|
Target extends MutationTargetLike,
|
|
4460
4893
|
Columns extends DdlColumnInput
|
|
4461
|
-
> =
|
|
4894
|
+
> = ValidateTargetColumnInput<Target, Columns>
|
|
4462
4895
|
|
|
4463
4896
|
type ConflictTargetInput<
|
|
4464
4897
|
Target extends MutationTargetLike,
|
|
@@ -4483,10 +4916,64 @@ type ConflictActionInput<
|
|
|
4483
4916
|
Target extends MutationTargetLike,
|
|
4484
4917
|
Dialect extends string,
|
|
4485
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
|
|
4486
4948
|
> = {
|
|
4487
|
-
|
|
4488
|
-
|
|
4489
|
-
|
|
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>
|
|
4490
4977
|
|
|
4491
4978
|
type MergeWhenMatchedDelete<
|
|
4492
4979
|
Predicate extends PredicateInput | undefined = undefined
|
|
@@ -4501,7 +4988,7 @@ type MergeWhenMatchedUpdate<
|
|
|
4501
4988
|
Values extends MutationInputOf<Table.UpdateOf<Target>>,
|
|
4502
4989
|
Predicate extends PredicateInput | undefined = undefined
|
|
4503
4990
|
> = {
|
|
4504
|
-
readonly update: Values
|
|
4991
|
+
readonly update: Values & UpdateValuesNonEmptyConstraint<Values>
|
|
4505
4992
|
readonly predicate?: Predicate
|
|
4506
4993
|
readonly delete?: never
|
|
4507
4994
|
}
|
|
@@ -4511,20 +4998,37 @@ type MergeWhenNotMatched<
|
|
|
4511
4998
|
Values extends MutationInputOf<Table.InsertOf<Target>>,
|
|
4512
4999
|
Predicate extends PredicateInput | undefined = undefined
|
|
4513
5000
|
> = {
|
|
4514
|
-
readonly values: Values
|
|
5001
|
+
readonly values: Values & MergeInsertValuesNonEmptyConstraint<Values>
|
|
4515
5002
|
readonly predicate?: Predicate
|
|
4516
5003
|
}
|
|
4517
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
|
+
|
|
4518
5017
|
type MergeOptions<
|
|
4519
5018
|
Target extends MutationTargetLike,
|
|
4520
5019
|
MatchedValues extends MutationInputOf<Table.UpdateOf<Target>>,
|
|
4521
5020
|
InsertValues extends MutationInputOf<Table.InsertOf<Target>>,
|
|
4522
5021
|
MatchedPredicate extends PredicateInput | undefined = undefined,
|
|
4523
5022
|
NotMatchedPredicate extends PredicateInput | undefined = undefined
|
|
4524
|
-
> =
|
|
4525
|
-
|
|
4526
|
-
|
|
4527
|
-
|
|
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
|
+
}
|
|
4528
5032
|
|
|
4529
5033
|
type RequireSelectStatement<PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>> =
|
|
4530
5034
|
StatementOfPlan<PlanValue> extends "select" ? unknown : never
|
|
@@ -4556,6 +5060,11 @@ type MutationOrderLimitSupported<PlanValue extends QueryPlan<any, any, any, any,
|
|
|
4556
5060
|
? StatementOfPlan<PlanValue> extends "update" | "delete" ? unknown : never
|
|
4557
5061
|
: never
|
|
4558
5062
|
|
|
5063
|
+
type MutationTargetTupleDialectConstraint<
|
|
5064
|
+
Targets extends MutationTargetTuple,
|
|
5065
|
+
Dialect extends string
|
|
5066
|
+
> = Exclude<TableDialectOf<Targets[number]>, Dialect> extends never ? unknown : never
|
|
5067
|
+
|
|
4559
5068
|
type MutationRequiredFromValues<Values extends Record<string, unknown>> = {
|
|
4560
5069
|
[K in keyof Values]: Values[K] extends Expression.Any ? RequiredFromDependencies<DependenciesOf<Values[K]>> : never
|
|
4561
5070
|
}[keyof Values]
|
|
@@ -4569,6 +5078,59 @@ type NestedMutationRequiredFromValues<Values> =
|
|
|
4569
5078
|
}[keyof Values]
|
|
4570
5079
|
: never
|
|
4571
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
|
+
|
|
4572
5134
|
type MutationAssignments<Shape extends Record<string, unknown>> = {
|
|
4573
5135
|
readonly [K in keyof Shape]: QueryAst.AssignmentClause
|
|
4574
5136
|
}
|
|
@@ -4602,12 +5164,38 @@ type InsertDirectSource =
|
|
|
4602
5164
|
|
|
4603
5165
|
type FromInput = SourceLike | InsertDirectSource
|
|
4604
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
|
+
|
|
4605
5185
|
type SelectFromConstraint<
|
|
4606
5186
|
PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>,
|
|
4607
5187
|
CurrentSource extends SourceLike
|
|
4608
5188
|
> =
|
|
4609
5189
|
RequireSelectStatement<PlanValue> &
|
|
4610
|
-
(
|
|
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
|
+
) &
|
|
4611
5199
|
(SourceRequiredOf<CurrentSource> extends never ? unknown : SourceRequirementError<CurrentSource>)
|
|
4612
5200
|
|
|
4613
5201
|
type UpdateFromConstraint<
|
|
@@ -4624,7 +5212,7 @@ type InsertFromConstraint<
|
|
|
4624
5212
|
Dialect extends string
|
|
4625
5213
|
> =
|
|
4626
5214
|
RequirePendingInsertStatement<PlanValue> &
|
|
4627
|
-
(InsertSourceOfPlanInput<PlanValue, CurrentSource, Dialect>
|
|
5215
|
+
(CurrentSource extends InsertSourceOfPlanInput<PlanValue, CurrentSource, Dialect>
|
|
4628
5216
|
? unknown
|
|
4629
5217
|
: InsertSourceOfPlanInput<PlanValue, CurrentSource, Dialect>)
|
|
4630
5218
|
|
|
@@ -4641,7 +5229,10 @@ type SelectFromResult<
|
|
|
4641
5229
|
Exclude<OutstandingOfPlan<PlanValue>, SourceNameOf<CurrentSource>>,
|
|
4642
5230
|
AssumptionsOfPlan<PlanValue>,
|
|
4643
5231
|
MergeCapabilities<CapabilitiesOfPlan<PlanValue>, SourceCapabilitiesOf<CurrentSource>>,
|
|
4644
|
-
StatementOfPlan<PlanValue
|
|
5232
|
+
StatementOfPlan<PlanValue>,
|
|
5233
|
+
MutationTargetOfPlan<PlanValue>,
|
|
5234
|
+
InsertSourceStateOfPlan<PlanValue>,
|
|
5235
|
+
FactsOfPlan<PlanValue>
|
|
4645
5236
|
>
|
|
4646
5237
|
|
|
4647
5238
|
type UpdateFromResult<
|
|
@@ -4663,7 +5254,10 @@ type UpdateFromResult<
|
|
|
4663
5254
|
Exclude<OutstandingOfPlan<PlanValue>, SourceNameOf<CurrentSource>>,
|
|
4664
5255
|
AssumptionsOfPlan<PlanValue>,
|
|
4665
5256
|
MergeCapabilities<CapabilitiesOfPlan<PlanValue>, SourceCapabilitiesOf<CurrentSource>>,
|
|
4666
|
-
StatementOfPlan<PlanValue
|
|
5257
|
+
StatementOfPlan<PlanValue>,
|
|
5258
|
+
MutationTargetOfPlan<PlanValue>,
|
|
5259
|
+
InsertSourceStateOfPlan<PlanValue>,
|
|
5260
|
+
FactsOfPlan<PlanValue>
|
|
4667
5261
|
>
|
|
4668
5262
|
|
|
4669
5263
|
type InsertFromResult<
|
|
@@ -4672,19 +5266,20 @@ type InsertFromResult<
|
|
|
4672
5266
|
Dialect extends string
|
|
4673
5267
|
> = QueryPlan<
|
|
4674
5268
|
SelectionOfPlan<PlanValue>,
|
|
4675
|
-
|
|
5269
|
+
InsertSourceRequired<CurrentSource>,
|
|
4676
5270
|
AvailableOfPlan<PlanValue>,
|
|
4677
|
-
PlanDialectOf<PlanValue>,
|
|
5271
|
+
PlanDialectOf<PlanValue> | InsertSourceDialect<CurrentSource>,
|
|
4678
5272
|
GroupedOfPlan<PlanValue>,
|
|
4679
5273
|
ScopedNamesOfPlan<PlanValue>,
|
|
4680
|
-
|
|
5274
|
+
InsertSourceRequired<CurrentSource>,
|
|
4681
5275
|
AssumptionsOfPlan<PlanValue>,
|
|
4682
5276
|
CurrentSource extends QueryPlan<any, any, any, any, any, any, any, any, any, any>
|
|
4683
5277
|
? MergeCapabilities<CapabilitiesOfPlan<PlanValue>, CapabilitiesOfPlan<CurrentSource>>
|
|
4684
5278
|
: CapabilitiesOfPlan<PlanValue>,
|
|
4685
5279
|
StatementOfPlan<PlanValue>,
|
|
4686
5280
|
MutationTargetOfPlan<PlanValue>,
|
|
4687
|
-
"ready"
|
|
5281
|
+
"ready",
|
|
5282
|
+
FactsOfPlan<PlanValue>
|
|
4688
5283
|
>
|
|
4689
5284
|
|
|
4690
5285
|
type FromPlanConstraint<
|
|
@@ -4693,15 +5288,17 @@ type FromPlanConstraint<
|
|
|
4693
5288
|
Dialect extends string
|
|
4694
5289
|
> =
|
|
4695
5290
|
CurrentSource extends SourceLike
|
|
4696
|
-
?
|
|
4697
|
-
|
|
4698
|
-
|
|
4699
|
-
|
|
4700
|
-
|
|
4701
|
-
|
|
4702
|
-
|
|
4703
|
-
|
|
4704
|
-
|
|
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
|
+
)
|
|
4705
5302
|
: CurrentSource extends InsertDirectSource
|
|
4706
5303
|
? StatementOfPlan<PlanValue> extends "insert"
|
|
4707
5304
|
? InsertFromConstraint<PlanValue, CurrentSource, Dialect>
|
|
@@ -4756,7 +5353,10 @@ export type PublicStructuredFromResult<
|
|
|
4756
5353
|
Exclude<OutstandingOfPlan<PlanValue>, SourceNameOf<CurrentSource>>,
|
|
4757
5354
|
AssumptionsOfPlan<PlanValue>,
|
|
4758
5355
|
MergeCapabilities<CapabilitiesOfPlan<PlanValue>, SourceCapabilitiesOf<CurrentSource>>,
|
|
4759
|
-
StatementOfPlan<PlanValue
|
|
5356
|
+
StatementOfPlan<PlanValue>,
|
|
5357
|
+
MutationTargetOfPlan<PlanValue>,
|
|
5358
|
+
InsertSourceStateOfPlan<PlanValue>,
|
|
5359
|
+
FactsOfPlan<PlanValue>
|
|
4760
5360
|
>
|
|
4761
5361
|
: StatementOfPlan<PlanValue> extends "update"
|
|
4762
5362
|
? QueryPlan<
|
|
@@ -4769,7 +5369,10 @@ export type PublicStructuredFromResult<
|
|
|
4769
5369
|
Exclude<OutstandingOfPlan<PlanValue>, SourceNameOf<CurrentSource>>,
|
|
4770
5370
|
AssumptionsOfPlan<PlanValue>,
|
|
4771
5371
|
MergeCapabilities<CapabilitiesOfPlan<PlanValue>, SourceCapabilitiesOf<CurrentSource>>,
|
|
4772
|
-
StatementOfPlan<PlanValue
|
|
5372
|
+
StatementOfPlan<PlanValue>,
|
|
5373
|
+
MutationTargetOfPlan<PlanValue>,
|
|
5374
|
+
InsertSourceStateOfPlan<PlanValue>,
|
|
5375
|
+
FactsOfPlan<PlanValue>
|
|
4773
5376
|
>
|
|
4774
5377
|
: StatementOfPlan<PlanValue> extends "insert"
|
|
4775
5378
|
? CurrentSource extends AnyValuesSource | AnyUnnestSource
|
|
@@ -4777,7 +5380,7 @@ export type PublicStructuredFromResult<
|
|
|
4777
5380
|
SelectionOfPlan<PlanValue>,
|
|
4778
5381
|
never,
|
|
4779
5382
|
AvailableOfPlan<PlanValue>,
|
|
4780
|
-
PlanDialectOf<PlanValue>,
|
|
5383
|
+
PlanDialectOf<PlanValue> | SourceDialectOf<CurrentSource>,
|
|
4781
5384
|
GroupedOfPlan<PlanValue>,
|
|
4782
5385
|
ScopedNamesOfPlan<PlanValue>,
|
|
4783
5386
|
never,
|
|
@@ -4785,7 +5388,8 @@ export type PublicStructuredFromResult<
|
|
|
4785
5388
|
CapabilitiesOfPlan<PlanValue>,
|
|
4786
5389
|
StatementOfPlan<PlanValue>,
|
|
4787
5390
|
MutationTargetOfPlan<PlanValue>,
|
|
4788
|
-
"ready"
|
|
5391
|
+
"ready",
|
|
5392
|
+
FactsOfPlan<PlanValue>
|
|
4789
5393
|
>
|
|
4790
5394
|
: FromPlanResult<PlanValue, CurrentSource, Dialect>
|
|
4791
5395
|
: FromPlanResult<PlanValue, CurrentSource, Dialect>
|
|
@@ -4802,6 +5406,36 @@ type MergeRequiredFromPredicate<
|
|
|
4802
5406
|
Available extends Record<string, Plan.AnySource>
|
|
4803
5407
|
> = Predicate extends PredicateInput ? AddExpressionRequired<never, Available, Predicate> : never
|
|
4804
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
|
+
|
|
4805
5439
|
type AsCurriedInput<Dialect extends string> =
|
|
4806
5440
|
| ExpressionInput
|
|
4807
5441
|
| ValuesInput<any, any, Dialect>
|
|
@@ -4841,20 +5475,20 @@ type AsCurriedResult<
|
|
|
4841
5475
|
>(
|
|
4842
5476
|
value: Value,
|
|
4843
5477
|
alias: Alias
|
|
4844
|
-
): DialectAsExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
5478
|
+
): ProjectionAliasedExpression<DialectAsExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>, Alias>
|
|
4845
5479
|
function as<
|
|
4846
5480
|
Rows extends ValuesRowsInput,
|
|
4847
5481
|
Alias extends string
|
|
4848
5482
|
>(
|
|
4849
5483
|
value: ValuesInput<
|
|
4850
5484
|
Rows,
|
|
4851
|
-
ValuesOutputShape<Rows
|
|
5485
|
+
ValuesOutputShape<Rows, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
4852
5486
|
Dialect
|
|
4853
5487
|
>,
|
|
4854
5488
|
alias: Alias
|
|
4855
5489
|
): ValuesSource<
|
|
4856
5490
|
Rows,
|
|
4857
|
-
ValuesOutputShape<Rows
|
|
5491
|
+
ValuesOutputShape<Rows, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
4858
5492
|
Alias,
|
|
4859
5493
|
Dialect
|
|
4860
5494
|
>
|
|
@@ -4862,7 +5496,7 @@ type AsCurriedResult<
|
|
|
4862
5496
|
PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>,
|
|
4863
5497
|
Alias extends string
|
|
4864
5498
|
>(
|
|
4865
|
-
value:
|
|
5499
|
+
value: DerivedTableCompatiblePlan<PlanValue>,
|
|
4866
5500
|
alias: Alias
|
|
4867
5501
|
): DerivedSource<PlanValue, Alias>
|
|
4868
5502
|
function as(valueOrAlias: unknown, alias?: string): unknown {
|
|
@@ -4909,13 +5543,13 @@ type AsCurriedResult<
|
|
|
4909
5543
|
>(
|
|
4910
5544
|
alias: Alias
|
|
4911
5545
|
): <PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
|
|
4912
|
-
value:
|
|
5546
|
+
value: DerivedSourceCompatiblePlan<PlanValue>
|
|
4913
5547
|
) => import("../../internal/query.js").CteSource<PlanValue, Alias>
|
|
4914
5548
|
function with_<
|
|
4915
5549
|
PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>,
|
|
4916
5550
|
Alias extends string
|
|
4917
5551
|
>(
|
|
4918
|
-
value:
|
|
5552
|
+
value: DerivedSourceCompatiblePlan<PlanValue>,
|
|
4919
5553
|
alias: Alias
|
|
4920
5554
|
): import("../../internal/query.js").CteSource<PlanValue, Alias>
|
|
4921
5555
|
function with_(valueOrAlias: unknown, alias?: string): unknown {
|
|
@@ -4933,13 +5567,13 @@ type AsCurriedResult<
|
|
|
4933
5567
|
>(
|
|
4934
5568
|
alias: Alias
|
|
4935
5569
|
): <PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
|
|
4936
|
-
value:
|
|
5570
|
+
value: DerivedSourceCompatiblePlan<PlanValue>
|
|
4937
5571
|
) => import("../../internal/query.js").CteSource<PlanValue, Alias>
|
|
4938
5572
|
function withRecursive_<
|
|
4939
5573
|
PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>,
|
|
4940
5574
|
Alias extends string
|
|
4941
5575
|
>(
|
|
4942
|
-
value:
|
|
5576
|
+
value: DerivedSourceCompatiblePlan<PlanValue>,
|
|
4943
5577
|
alias: Alias
|
|
4944
5578
|
): import("../../internal/query.js").CteSource<PlanValue, Alias>
|
|
4945
5579
|
function withRecursive_(valueOrAlias: unknown, alias?: string): unknown {
|
|
@@ -4958,13 +5592,13 @@ type AsCurriedResult<
|
|
|
4958
5592
|
>(
|
|
4959
5593
|
alias: Alias
|
|
4960
5594
|
): <PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
|
|
4961
|
-
value: PlanValue
|
|
5595
|
+
value: LateralSourceCompatiblePlan<PlanValue>
|
|
4962
5596
|
) => import("../../internal/query.js").LateralSource<PlanValue, Alias>
|
|
4963
5597
|
function lateral<
|
|
4964
5598
|
PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>,
|
|
4965
5599
|
Alias extends string
|
|
4966
5600
|
>(
|
|
4967
|
-
value: PlanValue
|
|
5601
|
+
value: LateralSourceCompatiblePlan<PlanValue>,
|
|
4968
5602
|
alias: Alias
|
|
4969
5603
|
): import("../../internal/query.js").LateralSource<PlanValue, Alias>
|
|
4970
5604
|
function lateral(valueOrAlias: unknown, alias?: string): unknown {
|
|
@@ -4981,9 +5615,11 @@ type AsCurriedResult<
|
|
|
4981
5615
|
Rows extends ValuesRowsInput
|
|
4982
5616
|
>(
|
|
4983
5617
|
rows: Rows
|
|
5618
|
+
& ValuesRowsShapeInput<Rows>
|
|
5619
|
+
& ValuesRowsDialectInput<Rows, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
4984
5620
|
) => ValuesInput<
|
|
4985
5621
|
Rows,
|
|
4986
|
-
ValuesOutputShape<Rows
|
|
5622
|
+
ValuesOutputShape<Rows, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
4987
5623
|
Dialect
|
|
4988
5624
|
>
|
|
4989
5625
|
|
|
@@ -4991,7 +5627,9 @@ type AsCurriedResult<
|
|
|
4991
5627
|
Columns extends UnnestColumnsInput,
|
|
4992
5628
|
Alias extends string
|
|
4993
5629
|
>(
|
|
4994
|
-
columns: Columns
|
|
5630
|
+
columns: Columns
|
|
5631
|
+
& UnnestColumnsShapeInput<Columns>
|
|
5632
|
+
& UnnestColumnsDialectInput<Columns, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
4995
5633
|
alias: Alias
|
|
4996
5634
|
) => UnnestSource<
|
|
4997
5635
|
UnnestOutputShape<Columns, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
@@ -5005,9 +5643,9 @@ type AsCurriedResult<
|
|
|
5005
5643
|
Step extends NumericExpressionInput | undefined = undefined,
|
|
5006
5644
|
Alias extends string = "series"
|
|
5007
5645
|
>(
|
|
5008
|
-
start: Start,
|
|
5009
|
-
stop: Stop,
|
|
5010
|
-
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),
|
|
5011
5649
|
alias?: Alias
|
|
5012
5650
|
) => Dialect extends "postgres"
|
|
5013
5651
|
? TableFunctionSource<
|
|
@@ -5019,11 +5657,14 @@ type AsCurriedResult<
|
|
|
5019
5657
|
: GenerateSeriesUnsupportedError<Dialect>
|
|
5020
5658
|
|
|
5021
5659
|
export type PublicGenerateSeriesApi = <
|
|
5660
|
+
Start extends NumericExpressionInput,
|
|
5661
|
+
Stop extends NumericExpressionInput,
|
|
5662
|
+
Step extends NumericExpressionInput | undefined = undefined,
|
|
5022
5663
|
Alias extends string = "series"
|
|
5023
5664
|
>(
|
|
5024
|
-
start:
|
|
5025
|
-
stop:
|
|
5026
|
-
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),
|
|
5027
5668
|
alias?: Alias
|
|
5028
5669
|
) => TableFunctionSource<
|
|
5029
5670
|
{
|
|
@@ -5034,8 +5675,36 @@ type AsCurriedResult<
|
|
|
5034
5675
|
"generate_series"
|
|
5035
5676
|
>
|
|
5036
5677
|
|
|
5037
|
-
|
|
5038
|
-
|
|
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>
|
|
5039
5708
|
) => QueryPlan<
|
|
5040
5709
|
Selection,
|
|
5041
5710
|
ExtractRequired<Selection>,
|
|
@@ -5046,7 +5715,10 @@ type AsCurriedResult<
|
|
|
5046
5715
|
ExtractRequired<Selection>,
|
|
5047
5716
|
TrueFormula,
|
|
5048
5717
|
"read",
|
|
5049
|
-
"select"
|
|
5718
|
+
"select",
|
|
5719
|
+
any,
|
|
5720
|
+
"ready",
|
|
5721
|
+
EmptyFacts
|
|
5050
5722
|
>
|
|
5051
5723
|
|
|
5052
5724
|
const {
|
|
@@ -5091,7 +5763,10 @@ type AsCurriedResult<
|
|
|
5091
5763
|
never,
|
|
5092
5764
|
TrueFormula,
|
|
5093
5765
|
CapabilitiesOfPlan<LeftPlanValue> | CapabilitiesOfPlan<RightPlanValue>,
|
|
5094
|
-
"set"
|
|
5766
|
+
"set",
|
|
5767
|
+
any,
|
|
5768
|
+
"ready",
|
|
5769
|
+
CommonSetFacts<LeftPlanValue, RightPlanValue>
|
|
5095
5770
|
>
|
|
5096
5771
|
|
|
5097
5772
|
type SetOperationApi = <
|
|
@@ -5117,7 +5792,10 @@ type AsCurriedResult<
|
|
|
5117
5792
|
AddExpressionRequired<OutstandingOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, Predicate>,
|
|
5118
5793
|
PlanAssumptionsAfterWhere<PlanValue, Predicate, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5119
5794
|
CapabilitiesOfPlan<PlanValue>,
|
|
5120
|
-
StatementOfPlan<PlanValue
|
|
5795
|
+
StatementOfPlan<PlanValue>,
|
|
5796
|
+
MutationTargetOfPlan<PlanValue>,
|
|
5797
|
+
InsertSourceStateOfPlan<PlanValue>,
|
|
5798
|
+
PlanFactsAfterWhere<PlanValue, Predicate, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
5121
5799
|
>
|
|
5122
5800
|
|
|
5123
5801
|
export type FromApi = <CurrentSource extends FromInput>(
|
|
@@ -5142,7 +5820,10 @@ type AsCurriedResult<
|
|
|
5142
5820
|
AddExpressionRequired<OutstandingOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, Predicate>,
|
|
5143
5821
|
PlanAssumptionsAfterHaving<PlanValue, Predicate, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5144
5822
|
CapabilitiesOfPlan<PlanValue>,
|
|
5145
|
-
StatementOfPlan<PlanValue
|
|
5823
|
+
StatementOfPlan<PlanValue>,
|
|
5824
|
+
MutationTargetOfPlan<PlanValue>,
|
|
5825
|
+
InsertSourceStateOfPlan<PlanValue>,
|
|
5826
|
+
PlanFactsAfterHaving<PlanValue, Predicate, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
5146
5827
|
>
|
|
5147
5828
|
|
|
5148
5829
|
type CrossJoinApi = <CurrentTable extends SourceLike>(
|
|
@@ -5153,10 +5834,10 @@ type AsCurriedResult<
|
|
|
5153
5834
|
keyof AvailableOfPlan<PlanValue> extends never ? never : unknown
|
|
5154
5835
|
) & (
|
|
5155
5836
|
SourceNameOf<CurrentTable> extends ScopedNamesOfPlan<PlanValue> ? never : unknown
|
|
5156
|
-
)
|
|
5837
|
+
) & SourceRequirementConstraint<PlanValue, CurrentTable> & SourceDialectConstraint<CurrentTable, Dialect>
|
|
5157
5838
|
) => QueryPlan<
|
|
5158
5839
|
SelectionOfPlan<PlanValue>,
|
|
5159
|
-
AddJoinRequired<RequiredOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, never, "cross"
|
|
5840
|
+
AddJoinRequired<RequiredOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, never, "cross", SourceRequiredOf<CurrentTable>>,
|
|
5160
5841
|
AddAvailable<
|
|
5161
5842
|
AvailableOfPlan<PlanValue>,
|
|
5162
5843
|
SourceNameOf<CurrentTable>,
|
|
@@ -5167,10 +5848,13 @@ type AsCurriedResult<
|
|
|
5167
5848
|
PlanDialectOf<PlanValue> | SourceDialectOf<CurrentTable>,
|
|
5168
5849
|
GroupedOfPlan<PlanValue>,
|
|
5169
5850
|
ScopedNamesOfPlan<PlanValue> | SourceNameOf<CurrentTable>,
|
|
5170
|
-
AddJoinRequired<OutstandingOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, never, "cross"
|
|
5851
|
+
AddJoinRequired<OutstandingOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, never, "cross", SourceRequiredOf<CurrentTable>>,
|
|
5171
5852
|
AssumptionsOfPlan<PlanValue>,
|
|
5172
5853
|
MergeCapabilities<CapabilitiesOfPlan<PlanValue>, SourceCapabilitiesOf<CurrentTable>>,
|
|
5173
|
-
StatementOfPlan<PlanValue
|
|
5854
|
+
StatementOfPlan<PlanValue>,
|
|
5855
|
+
MutationTargetOfPlan<PlanValue>,
|
|
5856
|
+
InsertSourceStateOfPlan<PlanValue>,
|
|
5857
|
+
FactsOfPlan<PlanValue>
|
|
5174
5858
|
>
|
|
5175
5859
|
|
|
5176
5860
|
type JoinApi = <
|
|
@@ -5187,10 +5871,10 @@ type AsCurriedResult<
|
|
|
5187
5871
|
keyof AvailableOfPlan<PlanValue> extends never ? never : unknown
|
|
5188
5872
|
) & (
|
|
5189
5873
|
SourceNameOf<CurrentTable> extends ScopedNamesOfPlan<PlanValue> ? never : unknown
|
|
5190
|
-
)
|
|
5874
|
+
) & SourceRequirementConstraint<PlanValue, CurrentTable> & SourceDialectConstraint<CurrentTable, Dialect>
|
|
5191
5875
|
) => QueryPlan<
|
|
5192
5876
|
SelectionOfPlan<PlanValue>,
|
|
5193
|
-
AddJoinRequired<RequiredOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, Predicate, Kind
|
|
5877
|
+
AddJoinRequired<RequiredOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, Predicate, Kind, SourceRequiredOf<CurrentTable>>,
|
|
5194
5878
|
AvailableAfterJoin<
|
|
5195
5879
|
AvailableOfPlan<PlanValue>,
|
|
5196
5880
|
SourceNameOf<CurrentTable>,
|
|
@@ -5201,10 +5885,13 @@ type AsCurriedResult<
|
|
|
5201
5885
|
PlanDialectOf<PlanValue> | SourceDialectOf<CurrentTable> | DialectOfDialectInput<Predicate, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5202
5886
|
GroupedOfPlan<PlanValue>,
|
|
5203
5887
|
ScopedNamesOfPlan<PlanValue> | SourceNameOf<CurrentTable>,
|
|
5204
|
-
AddJoinRequired<OutstandingOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, Predicate, Kind
|
|
5888
|
+
AddJoinRequired<OutstandingOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, Predicate, Kind, SourceRequiredOf<CurrentTable>>,
|
|
5205
5889
|
PlanAssumptionsAfterJoin<PlanValue, Predicate, Kind, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5206
5890
|
MergeCapabilities<CapabilitiesOfPlan<PlanValue>, SourceCapabilitiesOf<CurrentTable>>,
|
|
5207
|
-
StatementOfPlan<PlanValue
|
|
5891
|
+
StatementOfPlan<PlanValue>,
|
|
5892
|
+
MutationTargetOfPlan<PlanValue>,
|
|
5893
|
+
InsertSourceStateOfPlan<PlanValue>,
|
|
5894
|
+
PlanFactsAfterJoin<PlanValue, Predicate, Kind, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
5208
5895
|
>
|
|
5209
5896
|
|
|
5210
5897
|
type BinaryJoinApi<Kind extends QueryAst.JoinKind> = <
|
|
@@ -5219,10 +5906,10 @@ type AsCurriedResult<
|
|
|
5219
5906
|
keyof AvailableOfPlan<PlanValue> extends never ? never : unknown
|
|
5220
5907
|
) & (
|
|
5221
5908
|
SourceNameOf<CurrentTable> extends ScopedNamesOfPlan<PlanValue> ? never : unknown
|
|
5222
|
-
)
|
|
5909
|
+
) & SourceRequirementConstraint<PlanValue, CurrentTable> & SourceDialectConstraint<CurrentTable, Dialect>
|
|
5223
5910
|
) => QueryPlan<
|
|
5224
5911
|
SelectionOfPlan<PlanValue>,
|
|
5225
|
-
AddJoinRequired<RequiredOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, Predicate, Kind
|
|
5912
|
+
AddJoinRequired<RequiredOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, Predicate, Kind, SourceRequiredOf<CurrentTable>>,
|
|
5226
5913
|
AvailableAfterJoin<
|
|
5227
5914
|
AvailableOfPlan<PlanValue>,
|
|
5228
5915
|
SourceNameOf<CurrentTable>,
|
|
@@ -5233,10 +5920,13 @@ type AsCurriedResult<
|
|
|
5233
5920
|
PlanDialectOf<PlanValue> | SourceDialectOf<CurrentTable> | DialectOfDialectInput<Predicate, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5234
5921
|
GroupedOfPlan<PlanValue>,
|
|
5235
5922
|
ScopedNamesOfPlan<PlanValue> | SourceNameOf<CurrentTable>,
|
|
5236
|
-
AddJoinRequired<OutstandingOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, Predicate, Kind
|
|
5923
|
+
AddJoinRequired<OutstandingOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, Predicate, Kind, SourceRequiredOf<CurrentTable>>,
|
|
5237
5924
|
PlanAssumptionsAfterJoin<PlanValue, Predicate, Kind, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5238
5925
|
MergeCapabilities<CapabilitiesOfPlan<PlanValue>, SourceCapabilitiesOf<CurrentTable>>,
|
|
5239
|
-
StatementOfPlan<PlanValue
|
|
5926
|
+
StatementOfPlan<PlanValue>,
|
|
5927
|
+
MutationTargetOfPlan<PlanValue>,
|
|
5928
|
+
InsertSourceStateOfPlan<PlanValue>,
|
|
5929
|
+
PlanFactsAfterJoin<PlanValue, Predicate, Kind, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
5240
5930
|
>
|
|
5241
5931
|
|
|
5242
5932
|
type OrderByApi = <Value extends ExpressionInput>(
|
|
@@ -5255,7 +5945,10 @@ type AsCurriedResult<
|
|
|
5255
5945
|
AddExpressionRequired<OutstandingOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, Value>,
|
|
5256
5946
|
AssumptionsOfPlan<PlanValue>,
|
|
5257
5947
|
CapabilitiesOfPlan<PlanValue>,
|
|
5258
|
-
StatementOfPlan<PlanValue
|
|
5948
|
+
StatementOfPlan<PlanValue>,
|
|
5949
|
+
MutationTargetOfPlan<PlanValue>,
|
|
5950
|
+
InsertSourceStateOfPlan<PlanValue>,
|
|
5951
|
+
FactsOfPlan<PlanValue>
|
|
5259
5952
|
>
|
|
5260
5953
|
|
|
5261
5954
|
interface LockApi {
|
|
@@ -5271,7 +5964,10 @@ type AsCurriedResult<
|
|
|
5271
5964
|
OutstandingOfPlan<PlanValue>,
|
|
5272
5965
|
AssumptionsOfPlan<PlanValue>,
|
|
5273
5966
|
MergeCapabilities<CapabilitiesOfPlan<PlanValue>, "transaction">,
|
|
5274
|
-
StatementOfPlan<PlanValue
|
|
5967
|
+
StatementOfPlan<PlanValue>,
|
|
5968
|
+
MutationTargetOfPlan<PlanValue>,
|
|
5969
|
+
InsertSourceStateOfPlan<PlanValue>,
|
|
5970
|
+
FactsOfPlan<PlanValue>
|
|
5275
5971
|
>
|
|
5276
5972
|
<Mode extends Dialect extends "mysql" ? "lowPriority" | "ignore" | "quick" : never>(
|
|
5277
5973
|
mode: Mode,
|
|
@@ -5296,7 +5992,10 @@ type AsCurriedResult<
|
|
|
5296
5992
|
OutstandingOfPlan<PlanValue>,
|
|
5297
5993
|
AssumptionsOfPlan<PlanValue>,
|
|
5298
5994
|
MergeCapabilities<CapabilitiesOfPlan<PlanValue>, "transaction">,
|
|
5299
|
-
StatementOfPlan<PlanValue
|
|
5995
|
+
StatementOfPlan<PlanValue>,
|
|
5996
|
+
MutationTargetOfPlan<PlanValue>,
|
|
5997
|
+
InsertSourceStateOfPlan<PlanValue>,
|
|
5998
|
+
FactsOfPlan<PlanValue>
|
|
5300
5999
|
>
|
|
5301
6000
|
}
|
|
5302
6001
|
|
|
@@ -5313,7 +6012,10 @@ type AsCurriedResult<
|
|
|
5313
6012
|
OutstandingOfPlan<PlanValue>,
|
|
5314
6013
|
AssumptionsOfPlan<PlanValue>,
|
|
5315
6014
|
CapabilitiesOfPlan<PlanValue>,
|
|
5316
|
-
StatementOfPlan<PlanValue
|
|
6015
|
+
StatementOfPlan<PlanValue>,
|
|
6016
|
+
MutationTargetOfPlan<PlanValue>,
|
|
6017
|
+
InsertSourceStateOfPlan<PlanValue>,
|
|
6018
|
+
FactsOfPlan<PlanValue>
|
|
5317
6019
|
>
|
|
5318
6020
|
|
|
5319
6021
|
type LimitApi = <Value extends NumericExpressionInput>(
|
|
@@ -5331,7 +6033,10 @@ type AsCurriedResult<
|
|
|
5331
6033
|
AddExpressionRequired<OutstandingOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, DialectAsNumericExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
|
|
5332
6034
|
AssumptionsOfPlan<PlanValue>,
|
|
5333
6035
|
CapabilitiesOfPlan<PlanValue>,
|
|
5334
|
-
StatementOfPlan<PlanValue
|
|
6036
|
+
StatementOfPlan<PlanValue>,
|
|
6037
|
+
MutationTargetOfPlan<PlanValue>,
|
|
6038
|
+
InsertSourceStateOfPlan<PlanValue>,
|
|
6039
|
+
FactsOfPlan<PlanValue>
|
|
5335
6040
|
>
|
|
5336
6041
|
|
|
5337
6042
|
type OffsetApi = <Value extends NumericExpressionInput>(
|
|
@@ -5349,7 +6054,10 @@ type AsCurriedResult<
|
|
|
5349
6054
|
AddExpressionRequired<OutstandingOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, DialectAsNumericExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
|
|
5350
6055
|
AssumptionsOfPlan<PlanValue>,
|
|
5351
6056
|
CapabilitiesOfPlan<PlanValue>,
|
|
5352
|
-
StatementOfPlan<PlanValue
|
|
6057
|
+
StatementOfPlan<PlanValue>,
|
|
6058
|
+
MutationTargetOfPlan<PlanValue>,
|
|
6059
|
+
InsertSourceStateOfPlan<PlanValue>,
|
|
6060
|
+
FactsOfPlan<PlanValue>
|
|
5353
6061
|
>
|
|
5354
6062
|
|
|
5355
6063
|
const {
|
|
@@ -5420,18 +6128,21 @@ type AsCurriedResult<
|
|
|
5420
6128
|
|
|
5421
6129
|
const fullJoin = ((table, on) => (join as any)("full", table, on)) as BinaryJoinApi<"full">
|
|
5422
6130
|
|
|
5423
|
-
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
|
+
}
|
|
5424
6135
|
const expressions = values.map((value) => toDialectExpression(value)) as Expression.Any[]
|
|
5425
6136
|
return <PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
|
|
5426
6137
|
plan: PlanValue & RequireSelectStatement<PlanValue>
|
|
5427
6138
|
): QueryPlan<
|
|
5428
6139
|
SelectionOfPlan<PlanValue>,
|
|
5429
|
-
RequiredOfPlan<PlanValue>,
|
|
6140
|
+
AddExpressionRequired<RequiredOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, Values[number]>,
|
|
5430
6141
|
AvailableOfPlan<PlanValue>,
|
|
5431
|
-
PlanDialectOf<PlanValue>,
|
|
6142
|
+
PlanDialectOf<PlanValue> | DialectOfDialectInput<Values[number], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5432
6143
|
GroupedOfPlan<PlanValue>,
|
|
5433
6144
|
ScopedNamesOfPlan<PlanValue>,
|
|
5434
|
-
OutstandingOfPlan<PlanValue>,
|
|
6145
|
+
AddExpressionRequired<OutstandingOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, Values[number]>,
|
|
5435
6146
|
AssumptionsOfPlan<PlanValue>,
|
|
5436
6147
|
CapabilitiesOfPlan<PlanValue>,
|
|
5437
6148
|
StatementOfPlan<PlanValue>
|
|
@@ -5439,16 +6150,18 @@ type AsCurriedResult<
|
|
|
5439
6150
|
const current = plan[Plan.TypeId]
|
|
5440
6151
|
const currentAst = getAst(plan)
|
|
5441
6152
|
const currentQuery = getQueryState(plan)
|
|
6153
|
+
const required = values.flatMap((value) => extractRequiredFromDialectInputRuntime(value))
|
|
5442
6154
|
return makePlan({
|
|
5443
6155
|
selection: current.selection,
|
|
5444
|
-
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]>,
|
|
5445
6158
|
available: current.available,
|
|
5446
|
-
dialect: current.dialect as PlanDialectOf<PlanValue>
|
|
6159
|
+
dialect: current.dialect as PlanDialectOf<PlanValue> | DialectOfDialectInput<Values[number], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
5447
6160
|
}, {
|
|
5448
6161
|
...currentAst,
|
|
5449
6162
|
distinct: true,
|
|
5450
6163
|
distinctOn: expressions
|
|
5451
|
-
}, currentQuery.assumptions, currentQuery.capabilities, currentQuery.statement as StatementOfPlan<PlanValue
|
|
6164
|
+
}, currentQuery.assumptions, currentQuery.capabilities, currentQuery.statement as StatementOfPlan<PlanValue>, currentQuery.target, currentQuery.insertSource, currentQuery.facts)
|
|
5452
6165
|
}
|
|
5453
6166
|
}) as DistinctOnApi<Dialect>
|
|
5454
6167
|
|
|
@@ -5467,11 +6180,25 @@ type AsCurriedResult<
|
|
|
5467
6180
|
Exclude<OutstandingOfPlan<PlanValue> | RequiredFromDependencies<TupleDependencies<Values>>, AvailableNames<AvailableOfPlan<PlanValue>>>,
|
|
5468
6181
|
AssumptionsOfPlan<PlanValue>,
|
|
5469
6182
|
CapabilitiesOfPlan<PlanValue>,
|
|
5470
|
-
StatementOfPlan<PlanValue
|
|
6183
|
+
StatementOfPlan<PlanValue>,
|
|
6184
|
+
MutationTargetOfPlan<PlanValue>,
|
|
6185
|
+
InsertSourceStateOfPlan<PlanValue>,
|
|
6186
|
+
FactsOfPlan<PlanValue>
|
|
5471
6187
|
>
|
|
5472
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
|
+
|
|
5473
6200
|
type ReturningApi = <Selection extends SelectionShape>(
|
|
5474
|
-
selection: Selection
|
|
6201
|
+
selection: Selection & SelectionRootObjectConstraint<Selection> & SelectionNestedNonEmptyConstraint<Selection> & ReturningSelectionNonEmptyConstraint<Selection>
|
|
5475
6202
|
) =>
|
|
5476
6203
|
<PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
|
|
5477
6204
|
plan: PlanValue & RequireMutationStatement<PlanValue>
|
|
@@ -5487,7 +6214,8 @@ type AsCurriedResult<
|
|
|
5487
6214
|
CapabilitiesOfPlan<PlanValue>,
|
|
5488
6215
|
StatementOfPlan<PlanValue>,
|
|
5489
6216
|
MutationTargetOfPlan<PlanValue>,
|
|
5490
|
-
InsertSourceStateOfPlan<PlanValue
|
|
6217
|
+
InsertSourceStateOfPlan<PlanValue>,
|
|
6218
|
+
FactsOfPlan<PlanValue>
|
|
5491
6219
|
>
|
|
5492
6220
|
|
|
5493
6221
|
export interface InsertApi {
|
|
@@ -5505,16 +6233,17 @@ type AsCurriedResult<
|
|
|
5505
6233
|
"write",
|
|
5506
6234
|
"insert",
|
|
5507
6235
|
Target,
|
|
5508
|
-
"missing"
|
|
6236
|
+
"missing",
|
|
6237
|
+
EmptyFacts
|
|
5509
6238
|
>
|
|
5510
6239
|
<Target extends MutationTargetLike, Values extends Record<string, unknown>>(
|
|
5511
6240
|
target: Target,
|
|
5512
|
-
values: MutationValuesInput<"insert", Target, Values>
|
|
6241
|
+
values: MutationValuesInput<"insert", Target, Values> & MutationValuesDialectConstraint<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
5513
6242
|
): QueryPlan<
|
|
5514
6243
|
{},
|
|
5515
6244
|
Exclude<MutationRequiredFromValues<Values>, SourceNameOf<Target>>,
|
|
5516
6245
|
AddAvailable<{}, SourceNameOf<Target>>,
|
|
5517
|
-
TableDialectOf<Target>,
|
|
6246
|
+
TableDialectOf<Target> | KnownMutationDialectFromValues<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5518
6247
|
never,
|
|
5519
6248
|
SourceNameOf<Target>,
|
|
5520
6249
|
Exclude<MutationRequiredFromValues<Values>, SourceNameOf<Target>>,
|
|
@@ -5522,7 +6251,8 @@ type AsCurriedResult<
|
|
|
5522
6251
|
"write",
|
|
5523
6252
|
"insert",
|
|
5524
6253
|
Target,
|
|
5525
|
-
"ready"
|
|
6254
|
+
"ready",
|
|
6255
|
+
EmptyFacts
|
|
5526
6256
|
>
|
|
5527
6257
|
}
|
|
5528
6258
|
|
|
@@ -5535,58 +6265,66 @@ type AsCurriedResult<
|
|
|
5535
6265
|
Target extends MutationTargetLike,
|
|
5536
6266
|
const Columns extends DdlColumnInput,
|
|
5537
6267
|
UpdateValues extends MutationInputOf<Table.UpdateOf<Target>> | undefined = MutationInputOf<Table.UpdateOf<Target>> | undefined,
|
|
5538
|
-
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>
|
|
5539
6270
|
>(
|
|
5540
|
-
target:
|
|
5541
|
-
options?: Options
|
|
6271
|
+
target: ConflictTarget,
|
|
6272
|
+
options?: Options & ConflictActionUpdateNonEmptyConstraint<Options>
|
|
5542
6273
|
) =>
|
|
5543
6274
|
<PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
|
|
5544
6275
|
plan: PlanValue & RequireInsertStatement<PlanValue>
|
|
5545
6276
|
) => QueryPlan<
|
|
5546
6277
|
SelectionOfPlan<PlanValue>,
|
|
5547
|
-
Exclude<RequiredOfPlan<PlanValue> |
|
|
6278
|
+
Exclude<RequiredOfPlan<PlanValue> | ConflictRequired<UpdateValues, Options, ConflictTarget>, AvailableNames<AvailableOfPlan<PlanValue>>>,
|
|
5548
6279
|
AvailableOfPlan<PlanValue>,
|
|
5549
|
-
PlanDialectOf<PlanValue>,
|
|
6280
|
+
PlanDialectOf<PlanValue> | ConflictDialect<UpdateValues, Options, ConflictTarget, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5550
6281
|
GroupedOfPlan<PlanValue>,
|
|
5551
6282
|
ScopedNamesOfPlan<PlanValue>,
|
|
5552
|
-
Exclude<OutstandingOfPlan<PlanValue> |
|
|
6283
|
+
Exclude<OutstandingOfPlan<PlanValue> | ConflictRequired<UpdateValues, Options, ConflictTarget>, AvailableNames<AvailableOfPlan<PlanValue>>>,
|
|
5553
6284
|
AssumptionsOfPlan<PlanValue>,
|
|
5554
6285
|
CapabilitiesOfPlan<PlanValue>,
|
|
5555
6286
|
StatementOfPlan<PlanValue>,
|
|
5556
6287
|
MutationTargetOfPlan<PlanValue>,
|
|
5557
|
-
InsertSourceStateOfPlan<PlanValue
|
|
6288
|
+
InsertSourceStateOfPlan<PlanValue>,
|
|
6289
|
+
FactsOfPlan<PlanValue>
|
|
5558
6290
|
>
|
|
5559
6291
|
|
|
5560
6292
|
interface UpdateApi {
|
|
5561
6293
|
<Targets extends MutationTargetTuple, Values extends UpdateInputOfTarget<Targets>>(
|
|
5562
|
-
target: Dialect extends "mysql" ? Targets : never,
|
|
5563
|
-
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>
|
|
5564
6296
|
): QueryPlan<
|
|
5565
6297
|
{},
|
|
5566
6298
|
Exclude<NestedMutationRequiredFromValues<Values>, MutationTargetNamesOf<Targets>>,
|
|
5567
6299
|
AddAvailableMany<{}, MutationTargetNamesOf<Targets>>,
|
|
5568
|
-
TableDialectOf<Targets[0]>,
|
|
6300
|
+
TableDialectOf<Targets[0]> | KnownMutationDialectFromValues<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5569
6301
|
never,
|
|
5570
6302
|
MutationTargetNamesOf<Targets>,
|
|
5571
6303
|
Exclude<NestedMutationRequiredFromValues<Values>, MutationTargetNamesOf<Targets>>,
|
|
5572
6304
|
TrueFormula,
|
|
5573
6305
|
"write",
|
|
5574
|
-
"update"
|
|
6306
|
+
"update",
|
|
6307
|
+
any,
|
|
6308
|
+
"ready",
|
|
6309
|
+
EmptyFacts
|
|
5575
6310
|
>
|
|
5576
6311
|
<Target extends MutationTargetLike, Values extends Record<string, unknown>>(
|
|
5577
6312
|
target: Target,
|
|
5578
|
-
values: MutationValuesInput<"update", Target, Values>
|
|
6313
|
+
values: MutationValuesInput<"update", Target, Values> & UpdateValuesNonEmptyConstraint<Values> & MutationValuesDialectConstraint<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
5579
6314
|
): QueryPlan<
|
|
5580
6315
|
{},
|
|
5581
6316
|
Exclude<MutationRequiredFromValues<Values>, SourceNameOf<Target>>,
|
|
5582
6317
|
AddAvailable<{}, SourceNameOf<Target>>,
|
|
5583
|
-
TableDialectOf<Target>,
|
|
6318
|
+
TableDialectOf<Target> | KnownMutationDialectFromValues<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5584
6319
|
never,
|
|
5585
6320
|
SourceNameOf<Target>,
|
|
5586
6321
|
Exclude<MutationRequiredFromValues<Values>, SourceNameOf<Target>>,
|
|
5587
6322
|
TrueFormula,
|
|
5588
6323
|
"write",
|
|
5589
|
-
"update"
|
|
6324
|
+
"update",
|
|
6325
|
+
any,
|
|
6326
|
+
"ready",
|
|
6327
|
+
EmptyFacts
|
|
5590
6328
|
>
|
|
5591
6329
|
}
|
|
5592
6330
|
|
|
@@ -5594,25 +6332,28 @@ type AsCurriedResult<
|
|
|
5594
6332
|
Target extends MutationTargetLike,
|
|
5595
6333
|
Values extends MutationInputOf<Table.InsertOf<Target>>,
|
|
5596
6334
|
const Columns extends DdlColumnInput,
|
|
5597
|
-
UpdateValues extends MutationInputOf<Table.UpdateOf<Target>>
|
|
6335
|
+
UpdateValues extends MutationInputOf<Table.UpdateOf<Target>> | undefined = undefined
|
|
5598
6336
|
>(
|
|
5599
6337
|
target: Target,
|
|
5600
|
-
values: Values,
|
|
5601
|
-
conflictColumns:
|
|
5602
|
-
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>
|
|
5603
6341
|
) => QueryPlan<
|
|
5604
6342
|
{},
|
|
5605
|
-
Exclude<MutationRequiredFromValues<Values> | MutationRequiredFromValues<UpdateValues
|
|
6343
|
+
Exclude<MutationRequiredFromValues<Values> | MutationRequiredFromValues<Exclude<UpdateValues, undefined>>, SourceNameOf<Target>>,
|
|
5606
6344
|
AddAvailable<{}, SourceNameOf<Target>>,
|
|
5607
|
-
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>,
|
|
5608
6348
|
never,
|
|
5609
6349
|
SourceNameOf<Target>,
|
|
5610
|
-
Exclude<MutationRequiredFromValues<Values> | MutationRequiredFromValues<UpdateValues
|
|
6350
|
+
Exclude<MutationRequiredFromValues<Values> | MutationRequiredFromValues<Exclude<UpdateValues, undefined>>, SourceNameOf<Target>>,
|
|
5611
6351
|
TrueFormula,
|
|
5612
6352
|
"write",
|
|
5613
6353
|
"insert",
|
|
5614
6354
|
Target,
|
|
5615
|
-
"ready"
|
|
6355
|
+
"ready",
|
|
6356
|
+
EmptyFacts
|
|
5616
6357
|
>
|
|
5617
6358
|
|
|
5618
6359
|
interface DeleteApi {
|
|
@@ -5628,10 +6369,13 @@ type AsCurriedResult<
|
|
|
5628
6369
|
never,
|
|
5629
6370
|
TrueFormula,
|
|
5630
6371
|
"write",
|
|
5631
|
-
"delete"
|
|
6372
|
+
"delete",
|
|
6373
|
+
any,
|
|
6374
|
+
"ready",
|
|
6375
|
+
EmptyFacts
|
|
5632
6376
|
>
|
|
5633
6377
|
<Targets extends MutationTargetTuple>(
|
|
5634
|
-
target: Dialect extends "mysql" ? Targets : never
|
|
6378
|
+
target: Dialect extends "mysql" ? Targets & MutationTargetTupleDialectConstraint<Targets, Dialect> : never
|
|
5635
6379
|
): QueryPlan<
|
|
5636
6380
|
{},
|
|
5637
6381
|
never,
|
|
@@ -5642,7 +6386,10 @@ type AsCurriedResult<
|
|
|
5642
6386
|
never,
|
|
5643
6387
|
TrueFormula,
|
|
5644
6388
|
"write",
|
|
5645
|
-
"delete"
|
|
6389
|
+
"delete",
|
|
6390
|
+
any,
|
|
6391
|
+
"ready",
|
|
6392
|
+
EmptyFacts
|
|
5646
6393
|
>
|
|
5647
6394
|
}
|
|
5648
6395
|
|
|
@@ -5659,7 +6406,10 @@ type AsCurriedResult<
|
|
|
5659
6406
|
never,
|
|
5660
6407
|
TrueFormula,
|
|
5661
6408
|
"write",
|
|
5662
|
-
"truncate"
|
|
6409
|
+
"truncate",
|
|
6410
|
+
any,
|
|
6411
|
+
"ready",
|
|
6412
|
+
EmptyFacts
|
|
5663
6413
|
>
|
|
5664
6414
|
|
|
5665
6415
|
type MergeApi = <
|
|
@@ -5674,9 +6424,9 @@ type AsCurriedResult<
|
|
|
5674
6424
|
target: Target,
|
|
5675
6425
|
source: Source & (
|
|
5676
6426
|
SourceRequiredOf<Source> extends never ? unknown : SourceRequirementError<Source>
|
|
5677
|
-
),
|
|
6427
|
+
) & MergeSourceNameConstraint<Target, Source>,
|
|
5678
6428
|
on: On,
|
|
5679
|
-
options
|
|
6429
|
+
options: MergeOptions<Target, MatchedValues, InsertValues, MatchedPredicate, NotMatchedPredicate>
|
|
5680
6430
|
) => QueryPlan<
|
|
5681
6431
|
{},
|
|
5682
6432
|
Exclude<
|
|
@@ -5713,10 +6463,14 @@ type AsCurriedResult<
|
|
|
5713
6463
|
>,
|
|
5714
6464
|
TrueFormula,
|
|
5715
6465
|
MergeCapabilities<"write", SourceCapabilitiesOf<Source>>,
|
|
5716
|
-
"merge"
|
|
6466
|
+
"merge",
|
|
6467
|
+
any,
|
|
6468
|
+
"ready",
|
|
6469
|
+
EmptyFacts
|
|
5717
6470
|
>
|
|
5718
6471
|
|
|
5719
6472
|
const mutationRuntime = makeDslMutationRuntime({
|
|
6473
|
+
profile,
|
|
5720
6474
|
makePlan,
|
|
5721
6475
|
getAst,
|
|
5722
6476
|
getQueryState,
|
|
@@ -5729,7 +6483,7 @@ type AsCurriedResult<
|
|
|
5729
6483
|
buildConflictTarget,
|
|
5730
6484
|
mutationTargetClauses,
|
|
5731
6485
|
mutationAvailableSources,
|
|
5732
|
-
|
|
6486
|
+
normalizeConflictColumns,
|
|
5733
6487
|
targetSourceDetails,
|
|
5734
6488
|
sourceDetails
|
|
5735
6489
|
})
|
|
@@ -5745,61 +6499,21 @@ type AsCurriedResult<
|
|
|
5745
6499
|
): QueryPlan<any, any, any, any, any, any, any, any, any, "insert", MutationTargetLike, "ready"> =>
|
|
5746
6500
|
mutationRuntime.attachInsertSource(plan, source)
|
|
5747
6501
|
|
|
5748
|
-
const onConflict:
|
|
5749
|
-
|
|
5750
|
-
|
|
5751
|
-
UpdateValues extends MutationInputOf<Table.UpdateOf<Target>> | undefined = MutationInputOf<Table.UpdateOf<Target>> | undefined,
|
|
5752
|
-
Options extends ConflictActionInput<Target, Dialect, UpdateValues> = ConflictActionInput<Target, Dialect, UpdateValues>
|
|
5753
|
-
>(
|
|
5754
|
-
target: ConflictTargetInput<Target, Dialect, Columns>,
|
|
5755
|
-
options: Options = {} as Options
|
|
5756
|
-
) =>
|
|
5757
|
-
<PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
|
|
5758
|
-
plan: PlanValue & RequireInsertStatement<PlanValue>
|
|
5759
|
-
): QueryPlan<
|
|
5760
|
-
SelectionOfPlan<PlanValue>,
|
|
5761
|
-
Exclude<RequiredOfPlan<PlanValue> | MutationRequiredFromValues<Exclude<UpdateValues, undefined>> | RequiredFromInput<Extract<Options["where"], PredicateInput>>, AvailableNames<AvailableOfPlan<PlanValue>>>,
|
|
5762
|
-
AvailableOfPlan<PlanValue>,
|
|
5763
|
-
PlanDialectOf<PlanValue>,
|
|
5764
|
-
GroupedOfPlan<PlanValue>,
|
|
5765
|
-
ScopedNamesOfPlan<PlanValue>,
|
|
5766
|
-
Exclude<OutstandingOfPlan<PlanValue> | MutationRequiredFromValues<Exclude<UpdateValues, undefined>> | RequiredFromInput<Extract<Options["where"], PredicateInput>>, AvailableNames<AvailableOfPlan<PlanValue>>>,
|
|
5767
|
-
AssumptionsOfPlan<PlanValue>,
|
|
5768
|
-
CapabilitiesOfPlan<PlanValue>,
|
|
5769
|
-
StatementOfPlan<PlanValue>,
|
|
5770
|
-
MutationTargetOfPlan<PlanValue>,
|
|
5771
|
-
InsertSourceStateOfPlan<PlanValue>
|
|
5772
|
-
> => 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
|
|
5773
6505
|
|
|
5774
6506
|
const update: UpdateApi = ((
|
|
5775
6507
|
target: MutationTargetInput,
|
|
5776
6508
|
values: Record<string, unknown>
|
|
5777
6509
|
) => mutationRuntime.update(target, values)) as UpdateApi
|
|
5778
6510
|
|
|
5779
|
-
const upsert
|
|
5780
|
-
|
|
5781
|
-
|
|
5782
|
-
|
|
5783
|
-
|
|
5784
|
-
|
|
5785
|
-
target: Target,
|
|
5786
|
-
values: Values,
|
|
5787
|
-
conflictColumns: ValidateTargetColumns<Target, NormalizeDdlColumns<Columns>>,
|
|
5788
|
-
updateValues?: UpdateValues
|
|
5789
|
-
): QueryPlan<
|
|
5790
|
-
{},
|
|
5791
|
-
Exclude<MutationRequiredFromValues<Values> | MutationRequiredFromValues<UpdateValues>, SourceNameOf<Target>>,
|
|
5792
|
-
AddAvailable<{}, SourceNameOf<Target>>,
|
|
5793
|
-
TableDialectOf<Target>,
|
|
5794
|
-
never,
|
|
5795
|
-
SourceNameOf<Target>,
|
|
5796
|
-
Exclude<MutationRequiredFromValues<Values> | MutationRequiredFromValues<UpdateValues>, SourceNameOf<Target>>,
|
|
5797
|
-
TrueFormula,
|
|
5798
|
-
"write",
|
|
5799
|
-
"insert",
|
|
5800
|
-
Target,
|
|
5801
|
-
"ready"
|
|
5802
|
-
> => 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
|
|
5803
6517
|
|
|
5804
6518
|
const delete_: DeleteApi = ((
|
|
5805
6519
|
target: MutationTargetInput
|
|
@@ -5820,62 +6534,18 @@ type AsCurriedResult<
|
|
|
5820
6534
|
never,
|
|
5821
6535
|
TrueFormula,
|
|
5822
6536
|
"write",
|
|
5823
|
-
"truncate"
|
|
6537
|
+
"truncate",
|
|
6538
|
+
any,
|
|
6539
|
+
"ready",
|
|
6540
|
+
EmptyFacts
|
|
5824
6541
|
> => mutationRuntime.truncate(target, options)
|
|
5825
6542
|
|
|
5826
|
-
const merge
|
|
5827
|
-
|
|
5828
|
-
|
|
5829
|
-
|
|
5830
|
-
|
|
5831
|
-
|
|
5832
|
-
MatchedPredicate extends PredicateInput | undefined = undefined,
|
|
5833
|
-
NotMatchedPredicate extends PredicateInput | undefined = undefined
|
|
5834
|
-
>(
|
|
5835
|
-
target: Target,
|
|
5836
|
-
source: Source & (
|
|
5837
|
-
SourceRequiredOf<Source> extends never ? unknown : SourceRequirementError<Source>
|
|
5838
|
-
),
|
|
5839
|
-
on: On,
|
|
5840
|
-
options: MergeOptions<Target, MatchedValues, InsertValues, MatchedPredicate, NotMatchedPredicate> = {}
|
|
5841
|
-
): QueryPlan<
|
|
5842
|
-
{},
|
|
5843
|
-
Exclude<
|
|
5844
|
-
AddExpressionRequired<
|
|
5845
|
-
MergeRequiredFromPredicate<
|
|
5846
|
-
MatchedPredicate,
|
|
5847
|
-
AddAvailable<AddAvailable<{}, SourceNameOf<Target>>, SourceNameOf<Source>>
|
|
5848
|
-
> | MergeRequiredFromPredicate<
|
|
5849
|
-
NotMatchedPredicate,
|
|
5850
|
-
AddAvailable<AddAvailable<{}, SourceNameOf<Target>>, SourceNameOf<Source>>
|
|
5851
|
-
> | MutationRequiredFromValues<MatchedValues> | MutationRequiredFromValues<InsertValues>,
|
|
5852
|
-
AddAvailable<AddAvailable<{}, SourceNameOf<Target>>, SourceNameOf<Source>>,
|
|
5853
|
-
On
|
|
5854
|
-
>,
|
|
5855
|
-
SourceNameOf<Target> | SourceNameOf<Source>
|
|
5856
|
-
>,
|
|
5857
|
-
AddAvailable<AddAvailable<{}, SourceNameOf<Target>>, SourceNameOf<Source>>,
|
|
5858
|
-
TableDialectOf<Target> | SourceDialectOf<Source>,
|
|
5859
|
-
never,
|
|
5860
|
-
SourceNameOf<Target> | SourceNameOf<Source>,
|
|
5861
|
-
Exclude<
|
|
5862
|
-
AddExpressionRequired<
|
|
5863
|
-
MergeRequiredFromPredicate<
|
|
5864
|
-
MatchedPredicate,
|
|
5865
|
-
AddAvailable<AddAvailable<{}, SourceNameOf<Target>>, SourceNameOf<Source>>
|
|
5866
|
-
> | MergeRequiredFromPredicate<
|
|
5867
|
-
NotMatchedPredicate,
|
|
5868
|
-
AddAvailable<AddAvailable<{}, SourceNameOf<Target>>, SourceNameOf<Source>>
|
|
5869
|
-
> | MutationRequiredFromValues<MatchedValues> | MutationRequiredFromValues<InsertValues>,
|
|
5870
|
-
AddAvailable<AddAvailable<{}, SourceNameOf<Target>>, SourceNameOf<Source>>,
|
|
5871
|
-
On
|
|
5872
|
-
>,
|
|
5873
|
-
SourceNameOf<Target> | SourceNameOf<Source>
|
|
5874
|
-
>,
|
|
5875
|
-
TrueFormula,
|
|
5876
|
-
MergeCapabilities<"write", SourceCapabilitiesOf<Source>>,
|
|
5877
|
-
"merge"
|
|
5878
|
-
> => 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
|
|
5879
6549
|
|
|
5880
6550
|
type TransactionApi = (options?: TransactionOptions) => QueryPlan<
|
|
5881
6551
|
{},
|
|
@@ -5989,7 +6659,7 @@ type AsCurriedResult<
|
|
|
5989
6659
|
|
|
5990
6660
|
type CreateIndexApi = <Target extends SchemaTableLike, const Columns extends DdlColumnInput>(
|
|
5991
6661
|
target: Target,
|
|
5992
|
-
columns: Columns &
|
|
6662
|
+
columns: Columns & ValidateDdlColumnInput<Target, Columns>,
|
|
5993
6663
|
options?: CreateIndexOptions
|
|
5994
6664
|
) => QueryPlan<
|
|
5995
6665
|
{},
|
|
@@ -6006,7 +6676,7 @@ type AsCurriedResult<
|
|
|
6006
6676
|
|
|
6007
6677
|
type DropIndexApi = <Target extends SchemaTableLike, const Columns extends DdlColumnInput>(
|
|
6008
6678
|
target: Target,
|
|
6009
|
-
columns: Columns &
|
|
6679
|
+
columns: Columns & ValidateDdlColumnInput<Target, Columns>,
|
|
6010
6680
|
options?: DropIndexOptions
|
|
6011
6681
|
) => QueryPlan<
|
|
6012
6682
|
{},
|