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>,
|
|
@@ -991,6 +1100,16 @@ type JsonSetOutputOf<
|
|
|
991
1100
|
? JsonSetAtPath<Root, JsonPath.Path<[Target]>, Next, Operation>
|
|
992
1101
|
: never
|
|
993
1102
|
|
|
1103
|
+
type JsonSetOutputWithCreateMissing<
|
|
1104
|
+
Root,
|
|
1105
|
+
Target extends JsonPathInput,
|
|
1106
|
+
Next,
|
|
1107
|
+
Operation extends string,
|
|
1108
|
+
CreateMissing extends boolean
|
|
1109
|
+
> = false extends CreateMissing
|
|
1110
|
+
? Root | JsonSetOutputOf<Root, Target, Next, Operation>
|
|
1111
|
+
: JsonSetOutputOf<Root, Target, Next, Operation>
|
|
1112
|
+
|
|
994
1113
|
type JsonInsertOutputOf<
|
|
995
1114
|
Root,
|
|
996
1115
|
Target extends JsonPathInput,
|
|
@@ -1003,6 +1122,27 @@ type JsonInsertOutputOf<
|
|
|
1003
1122
|
? JsonInsertAtPath<Root, JsonPath.Path<[Target]>, Next, InsertAfter, Operation>
|
|
1004
1123
|
: never
|
|
1005
1124
|
|
|
1125
|
+
type MySqlJsonLengthResult<Value> =
|
|
1126
|
+
JsonLengthResult<Value> extends null ? number : JsonLengthResult<Value>
|
|
1127
|
+
|
|
1128
|
+
type MySqlJsonTypeName<Value> =
|
|
1129
|
+
JsonTypeName<Value> extends "object" ? "OBJECT" :
|
|
1130
|
+
JsonTypeName<Value> extends "array" ? "ARRAY" :
|
|
1131
|
+
JsonTypeName<Value> extends "string" ? "STRING" :
|
|
1132
|
+
JsonTypeName<Value> extends "number" ? "INTEGER" | "DOUBLE" | "DECIMAL" :
|
|
1133
|
+
JsonTypeName<Value> extends "boolean" ? "BOOLEAN" :
|
|
1134
|
+
JsonTypeName<Value> extends "null" ? "NULL" :
|
|
1135
|
+
JsonTypeName<Value>
|
|
1136
|
+
|
|
1137
|
+
type MySqlUnsupportedJsonFeatureUsageError<Feature extends string> = {
|
|
1138
|
+
readonly __effect_qb_error__: "effect-qb: unsupported mysql json feature"
|
|
1139
|
+
readonly __effect_qb_json_feature__: Feature
|
|
1140
|
+
}
|
|
1141
|
+
|
|
1142
|
+
type MySqlUnsupportedJsonFeature<Feature extends string> = (
|
|
1143
|
+
feature: MySqlUnsupportedJsonFeatureUsageError<Feature>
|
|
1144
|
+
) => never
|
|
1145
|
+
|
|
1006
1146
|
type JsonPathGuard<
|
|
1007
1147
|
Root,
|
|
1008
1148
|
Target extends JsonPathInput,
|
|
@@ -1480,6 +1620,42 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
|
|
|
1480
1620
|
>
|
|
1481
1621
|
}
|
|
1482
1622
|
|
|
1623
|
+
const retargetLiteralExpression = (
|
|
1624
|
+
value: Expression.Any,
|
|
1625
|
+
target: Expression.Any
|
|
1626
|
+
): Expression.Any => {
|
|
1627
|
+
const ast = (value as unknown as { readonly [ExpressionAst.TypeId]: ExpressionAst.Any })[ExpressionAst.TypeId]
|
|
1628
|
+
if (ast.kind !== "literal") {
|
|
1629
|
+
return value
|
|
1630
|
+
}
|
|
1631
|
+
const targetState = target[Expression.TypeId]
|
|
1632
|
+
return makeExpression({
|
|
1633
|
+
runtime: value[Expression.TypeId].runtime,
|
|
1634
|
+
dbType: targetState.dbType,
|
|
1635
|
+
runtimeSchema: targetState.runtimeSchema,
|
|
1636
|
+
driverValueMapping: targetState.driverValueMapping,
|
|
1637
|
+
nullability: value[Expression.TypeId].nullability,
|
|
1638
|
+
dialect: targetState.dialect,
|
|
1639
|
+
kind: "scalar",
|
|
1640
|
+
dependencies: {}
|
|
1641
|
+
}, ast)
|
|
1642
|
+
}
|
|
1643
|
+
|
|
1644
|
+
const alignBinaryPredicateExpressions = (
|
|
1645
|
+
left: Expression.Any,
|
|
1646
|
+
right: Expression.Any
|
|
1647
|
+
): readonly [Expression.Any, Expression.Any] => {
|
|
1648
|
+
const leftAst = (left as unknown as { readonly [ExpressionAst.TypeId]: ExpressionAst.Any })[ExpressionAst.TypeId]
|
|
1649
|
+
const rightAst = (right as unknown as { readonly [ExpressionAst.TypeId]: ExpressionAst.Any })[ExpressionAst.TypeId]
|
|
1650
|
+
if (leftAst.kind === "literal" && rightAst.kind !== "literal") {
|
|
1651
|
+
return [retargetLiteralExpression(left, right), right]
|
|
1652
|
+
}
|
|
1653
|
+
if (rightAst.kind === "literal" && leftAst.kind !== "literal") {
|
|
1654
|
+
return [left, retargetLiteralExpression(right, left)]
|
|
1655
|
+
}
|
|
1656
|
+
return [left, right]
|
|
1657
|
+
}
|
|
1658
|
+
|
|
1483
1659
|
const toDialectStringExpression = <Value extends StringExpressionInput>(
|
|
1484
1660
|
value: Value
|
|
1485
1661
|
): DialectAsStringExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> =>
|
|
@@ -1568,10 +1744,16 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
|
|
|
1568
1744
|
spec: WindowSpecInput<PartitionBy, OrderBy> | OrderedWindowSpecInput<PartitionBy, Extract<OrderBy, NonEmptyWindowOrderTerms>> | undefined
|
|
1569
1745
|
) => {
|
|
1570
1746
|
const partitionBy = [...(spec?.partitionBy ?? [])] as unknown as PartitionBy
|
|
1571
|
-
const orderBy = (spec?.orderBy ?? []).map((term) =>
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1747
|
+
const orderBy = (spec?.orderBy ?? []).map((term) => {
|
|
1748
|
+
const direction = term.direction ?? "asc"
|
|
1749
|
+
if (direction !== "asc" && direction !== "desc") {
|
|
1750
|
+
throw new Error("window order direction must be asc or desc")
|
|
1751
|
+
}
|
|
1752
|
+
return {
|
|
1753
|
+
value: term.value,
|
|
1754
|
+
direction
|
|
1755
|
+
}
|
|
1756
|
+
}) as {
|
|
1575
1757
|
readonly [K in keyof OrderBy]: OrderBy[K] extends WindowOrderTermInput<infer Value extends WindowOrderInput>
|
|
1576
1758
|
? { readonly value: Value; readonly direction: OrderDirection }
|
|
1577
1759
|
: never
|
|
@@ -1657,8 +1839,10 @@ type BinaryPredicateExpression<
|
|
|
1657
1839
|
kind: Kind,
|
|
1658
1840
|
nullability: Nullability = "maybe" as Nullability,
|
|
1659
1841
|
): any => {
|
|
1660
|
-
const leftExpression =
|
|
1661
|
-
|
|
1842
|
+
const [leftExpression, rightExpression] = alignBinaryPredicateExpressions(
|
|
1843
|
+
toDialectExpression(left),
|
|
1844
|
+
toDialectExpression(right)
|
|
1845
|
+
)
|
|
1662
1846
|
return (makeExpression as any)({
|
|
1663
1847
|
runtime: true as boolean,
|
|
1664
1848
|
dbType: profile.boolDb as BoolDb,
|
|
@@ -1681,17 +1865,21 @@ type BinaryPredicateExpression<
|
|
|
1681
1865
|
kind: ExpressionAst.VariadicKind
|
|
1682
1866
|
): Expression.Any => {
|
|
1683
1867
|
const expressions = values.map((value) => toDialectExpression(value as any)) as readonly Expression.Any[]
|
|
1868
|
+
const [head, ...tail] = expressions
|
|
1869
|
+
const alignedExpressions = (head !== undefined && (kind === "in" || kind === "notIn" || kind === "between"))
|
|
1870
|
+
? [head, ...tail.map((value) => retargetLiteralExpression(value, head))]
|
|
1871
|
+
: expressions
|
|
1684
1872
|
return makeExpression({
|
|
1685
1873
|
runtime: true as boolean,
|
|
1686
1874
|
dbType: profile.boolDb as BoolDb,
|
|
1687
1875
|
nullability: "maybe",
|
|
1688
|
-
dialect: (
|
|
1876
|
+
dialect: (alignedExpressions.find((value) => value[Expression.TypeId].dialect !== undefined)?.[Expression.TypeId].dialect ?? profile.dialect) as Dialect,
|
|
1689
1877
|
kind: "scalar",
|
|
1690
1878
|
|
|
1691
|
-
dependencies: mergeManyDependencies(
|
|
1879
|
+
dependencies: mergeManyDependencies(alignedExpressions)
|
|
1692
1880
|
}, {
|
|
1693
1881
|
kind,
|
|
1694
|
-
values:
|
|
1882
|
+
values: alignedExpressions
|
|
1695
1883
|
})
|
|
1696
1884
|
}
|
|
1697
1885
|
|
|
@@ -1960,6 +2148,7 @@ type BinaryPredicateExpression<
|
|
|
1960
2148
|
runtime: undefined as unknown as RuntimeOfDbType<Target>,
|
|
1961
2149
|
dbType: target as Target,
|
|
1962
2150
|
runtimeSchema: undefined,
|
|
2151
|
+
driverValueMapping: (target as Expression.DbType.Any).driverValueMapping,
|
|
1963
2152
|
nullability: expression[Expression.TypeId].nullability,
|
|
1964
2153
|
dialect: expression[Expression.TypeId].dialect,
|
|
1965
2154
|
kind: expression[Expression.TypeId].kind,
|
|
@@ -2039,6 +2228,14 @@ type BinaryPredicateExpression<
|
|
|
2039
2228
|
kind
|
|
2040
2229
|
})
|
|
2041
2230
|
|
|
2231
|
+
const driverValueMapping = <Db extends Expression.DbType.Any>(
|
|
2232
|
+
dbType: Db,
|
|
2233
|
+
mapping: Expression.DriverValueMapping
|
|
2234
|
+
): Db => ({
|
|
2235
|
+
...dbType,
|
|
2236
|
+
driverValueMapping: mapping
|
|
2237
|
+
})
|
|
2238
|
+
|
|
2042
2239
|
const type = {
|
|
2043
2240
|
...profile.type,
|
|
2044
2241
|
array,
|
|
@@ -2048,7 +2245,8 @@ type BinaryPredicateExpression<
|
|
|
2048
2245
|
domain,
|
|
2049
2246
|
enum: enum_,
|
|
2050
2247
|
set,
|
|
2051
|
-
custom
|
|
2248
|
+
custom,
|
|
2249
|
+
driverValueMapping
|
|
2052
2250
|
}
|
|
2053
2251
|
|
|
2054
2252
|
const makeJsonDb = <Kind extends string>(
|
|
@@ -2521,18 +2719,19 @@ type BinaryPredicateExpression<
|
|
|
2521
2719
|
const jsonSet = <
|
|
2522
2720
|
Base extends JsonExpressionLike<any>,
|
|
2523
2721
|
Target extends JsonPathInput,
|
|
2524
|
-
Next extends JsonValueInput
|
|
2722
|
+
Next extends JsonValueInput,
|
|
2723
|
+
CreateMissing extends boolean = true
|
|
2525
2724
|
>(
|
|
2526
2725
|
base: Base,
|
|
2527
|
-
target: Target & JsonSetGuard<Expression.RuntimeOf<Base>, Target, Next
|
|
2726
|
+
target: Target & JsonSetGuard<Expression.RuntimeOf<Base>, Target, NoInfer<Next>, "json.set">,
|
|
2528
2727
|
next: Next,
|
|
2529
2728
|
options: {
|
|
2530
|
-
readonly createMissing?:
|
|
2729
|
+
readonly createMissing?: CreateMissing
|
|
2531
2730
|
} = {}
|
|
2532
2731
|
): JsonExpression<
|
|
2533
|
-
|
|
2732
|
+
JsonSetOutputWithCreateMissing<Expression.RuntimeOf<Base>, Target, Next, "json.set", CreateMissing>,
|
|
2534
2733
|
JsonDbOfExpression<Base>,
|
|
2535
|
-
JsonNullabilityOf<
|
|
2734
|
+
JsonNullabilityOf<JsonSetOutputWithCreateMissing<Expression.RuntimeOf<Base>, Target, Next, "json.set", CreateMissing>>,
|
|
2536
2735
|
DialectOf<Base>,
|
|
2537
2736
|
KindOf<Base>,
|
|
2538
2737
|
DependenciesOf<Base>,
|
|
@@ -2543,9 +2742,9 @@ type BinaryPredicateExpression<
|
|
|
2543
2742
|
return buildJsonNodeExpression(
|
|
2544
2743
|
[base, newValue],
|
|
2545
2744
|
{
|
|
2546
|
-
runtime: undefined as unknown as
|
|
2745
|
+
runtime: undefined as unknown as JsonSetOutputWithCreateMissing<Expression.RuntimeOf<Base>, Target, Next, "json.set", CreateMissing>,
|
|
2547
2746
|
dbType: jsonDbTypeOf(base),
|
|
2548
|
-
nullability: undefined as unknown as JsonNullabilityOf<
|
|
2747
|
+
nullability: undefined as unknown as JsonNullabilityOf<JsonSetOutputWithCreateMissing<Expression.RuntimeOf<Base>, Target, Next, "json.set", CreateMissing>>
|
|
2549
2748
|
},
|
|
2550
2749
|
{
|
|
2551
2750
|
kind: "jsonSet",
|
|
@@ -2555,9 +2754,9 @@ type BinaryPredicateExpression<
|
|
|
2555
2754
|
createMissing: options.createMissing ?? true
|
|
2556
2755
|
}
|
|
2557
2756
|
) as JsonExpression<
|
|
2558
|
-
|
|
2757
|
+
JsonSetOutputWithCreateMissing<Expression.RuntimeOf<Base>, Target, Next, "json.set", CreateMissing>,
|
|
2559
2758
|
JsonDbOfExpression<Base>,
|
|
2560
|
-
JsonNullabilityOf<
|
|
2759
|
+
JsonNullabilityOf<JsonSetOutputWithCreateMissing<Expression.RuntimeOf<Base>, Target, Next, "json.set", CreateMissing>>,
|
|
2561
2760
|
DialectOf<Base>,
|
|
2562
2761
|
KindOf<Base>,
|
|
2563
2762
|
DependenciesOf<Base>,
|
|
@@ -2572,7 +2771,7 @@ type BinaryPredicateExpression<
|
|
|
2572
2771
|
InsertAfter extends boolean = false
|
|
2573
2772
|
>(
|
|
2574
2773
|
base: Base,
|
|
2575
|
-
target: Target & JsonInsertGuard<Expression.RuntimeOf<Base>, Target, Next
|
|
2774
|
+
target: Target & JsonInsertGuard<Expression.RuntimeOf<Base>, Target, NoInfer<Next>, NoInfer<InsertAfter>, "json.insert">,
|
|
2576
2775
|
next: Next,
|
|
2577
2776
|
options: {
|
|
2578
2777
|
readonly insertAfter?: InsertAfter
|
|
@@ -2794,7 +2993,7 @@ type BinaryPredicateExpression<
|
|
|
2794
2993
|
) => buildJsonNodeExpression(
|
|
2795
2994
|
[base],
|
|
2796
2995
|
{
|
|
2797
|
-
runtime: undefined as unknown as
|
|
2996
|
+
runtime: undefined as unknown as MySqlJsonTypeName<Expression.RuntimeOf<Base>>,
|
|
2798
2997
|
dbType: profile.textDb as TextDb,
|
|
2799
2998
|
nullability: base[Expression.TypeId].nullability
|
|
2800
2999
|
},
|
|
@@ -2809,9 +3008,9 @@ type BinaryPredicateExpression<
|
|
|
2809
3008
|
) => buildJsonNodeExpression(
|
|
2810
3009
|
[base],
|
|
2811
3010
|
{
|
|
2812
|
-
runtime: undefined as unknown as
|
|
3011
|
+
runtime: undefined as unknown as MySqlJsonLengthResult<Expression.RuntimeOf<Base>>,
|
|
2813
3012
|
dbType: profile.numericDb as NumericDb,
|
|
2814
|
-
nullability: undefined as unknown as JsonNullabilityOf<
|
|
3013
|
+
nullability: undefined as unknown as JsonNullabilityOf<MySqlJsonLengthResult<Expression.RuntimeOf<Base>>>
|
|
2815
3014
|
},
|
|
2816
3015
|
{
|
|
2817
3016
|
kind: "jsonLength",
|
|
@@ -2951,9 +3150,9 @@ type BinaryPredicateExpression<
|
|
|
2951
3150
|
typeOf: jsonTypeOf,
|
|
2952
3151
|
length: jsonLength,
|
|
2953
3152
|
keys: jsonKeys,
|
|
2954
|
-
stripNulls: jsonStripNulls
|
|
3153
|
+
stripNulls: jsonStripNulls as unknown as MySqlUnsupportedJsonFeature<"json.stripNulls">,
|
|
2955
3154
|
pathExists: jsonPathExists,
|
|
2956
|
-
pathMatch: jsonPathMatch
|
|
3155
|
+
pathMatch: jsonPathMatch as unknown as MySqlUnsupportedJsonFeature<"json.pathMatch">
|
|
2957
3156
|
}
|
|
2958
3157
|
|
|
2959
3158
|
const jsonb = {
|
|
@@ -2993,12 +3192,12 @@ type BinaryPredicateExpression<
|
|
|
2993
3192
|
}
|
|
2994
3193
|
|
|
2995
3194
|
const and = <
|
|
2996
|
-
Values extends readonly [ExpressionInput, ...ExpressionInput[]]
|
|
3195
|
+
const Values extends readonly [ExpressionInput, ...ExpressionInput[]]
|
|
2997
3196
|
>(
|
|
2998
3197
|
...values: Values
|
|
2999
3198
|
): VariadicBooleanExpression<
|
|
3000
3199
|
"and",
|
|
3001
|
-
|
|
3200
|
+
DialectExpressionArray<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
3002
3201
|
Dialect,
|
|
3003
3202
|
TextDb,
|
|
3004
3203
|
NumericDb,
|
|
@@ -3008,16 +3207,16 @@ type BinaryPredicateExpression<
|
|
|
3008
3207
|
> =>
|
|
3009
3208
|
makeVariadicBooleanExpression(
|
|
3010
3209
|
"and",
|
|
3011
|
-
values.map((value) => toDialectExpression(value)) as
|
|
3210
|
+
values.map((value) => toDialectExpression(value)) as unknown as DialectExpressionArray<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
3012
3211
|
)
|
|
3013
3212
|
|
|
3014
3213
|
const or = <
|
|
3015
|
-
Values extends readonly [ExpressionInput, ...ExpressionInput[]]
|
|
3214
|
+
const Values extends readonly [ExpressionInput, ...ExpressionInput[]]
|
|
3016
3215
|
>(
|
|
3017
3216
|
...values: Values
|
|
3018
3217
|
): VariadicBooleanExpression<
|
|
3019
3218
|
"or",
|
|
3020
|
-
|
|
3219
|
+
DialectExpressionArray<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
3021
3220
|
Dialect,
|
|
3022
3221
|
TextDb,
|
|
3023
3222
|
NumericDb,
|
|
@@ -3027,7 +3226,7 @@ type BinaryPredicateExpression<
|
|
|
3027
3226
|
> =>
|
|
3028
3227
|
makeVariadicBooleanExpression(
|
|
3029
3228
|
"or",
|
|
3030
|
-
values.map((value) => toDialectExpression(value)) as
|
|
3229
|
+
values.map((value) => toDialectExpression(value)) as unknown as DialectExpressionArray<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
3031
3230
|
)
|
|
3032
3231
|
|
|
3033
3232
|
const not = <Value extends ExpressionInput>(
|
|
@@ -3261,6 +3460,8 @@ type BinaryPredicateExpression<
|
|
|
3261
3460
|
return makeExpression({
|
|
3262
3461
|
runtime: undefined as Expression.RuntimeOf<ScalarOutputOfPlan<PlanValue>> | null,
|
|
3263
3462
|
dbType: expression[Expression.TypeId].dbType as Expression.DbTypeOf<ScalarOutputOfPlan<PlanValue>>,
|
|
3463
|
+
runtimeSchema: expression[Expression.TypeId].runtimeSchema,
|
|
3464
|
+
driverValueMapping: expression[Expression.TypeId].driverValueMapping,
|
|
3264
3465
|
nullability: "maybe",
|
|
3265
3466
|
dialect: profile.dialect as Dialect,
|
|
3266
3467
|
kind: "scalar",
|
|
@@ -3784,7 +3985,9 @@ type BinaryPredicateExpression<
|
|
|
3784
3985
|
string,
|
|
3785
3986
|
"scalar",
|
|
3786
3987
|
Expression.BindingId
|
|
3787
|
-
>
|
|
3988
|
+
> & {
|
|
3989
|
+
readonly [ExpressionAst.TypeId]: ExpressionAst.ColumnNode<any, string>
|
|
3990
|
+
}
|
|
3788
3991
|
>(
|
|
3789
3992
|
value: Value
|
|
3790
3993
|
): AstBackedExpression<
|
|
@@ -3804,6 +4007,7 @@ type BinaryPredicateExpression<
|
|
|
3804
4007
|
runtime: undefined as Expression.RuntimeOf<Value>,
|
|
3805
4008
|
dbType: value[Expression.TypeId].dbType as Expression.DbTypeOf<Value>,
|
|
3806
4009
|
runtimeSchema: value[Expression.TypeId].runtimeSchema,
|
|
4010
|
+
driverValueMapping: value[Expression.TypeId].driverValueMapping,
|
|
3807
4011
|
nullability: value[Expression.TypeId].nullability as Expression.NullabilityOf<Value>,
|
|
3808
4012
|
dialect: profile.dialect as Dialect,
|
|
3809
4013
|
kind: "scalar",
|
|
@@ -3827,20 +4031,56 @@ type BinaryPredicateExpression<
|
|
|
3827
4031
|
value: Value,
|
|
3828
4032
|
column: Expression.Any
|
|
3829
4033
|
): Expression.Any => {
|
|
4034
|
+
const columnState = column[Expression.TypeId]
|
|
4035
|
+
const normalizeMutationValue = (candidate: unknown): unknown => {
|
|
4036
|
+
if (candidate === null && columnState.nullability !== "never") {
|
|
4037
|
+
return null
|
|
4038
|
+
}
|
|
4039
|
+
const runtimeSchemaAccepts = columnState.runtimeSchema !== undefined &&
|
|
4040
|
+
(Schema.is(columnState.runtimeSchema) as (input: unknown) => boolean)(candidate)
|
|
4041
|
+
if (runtimeSchemaAccepts) {
|
|
4042
|
+
return candidate
|
|
4043
|
+
}
|
|
4044
|
+
const normalized = normalizeDbValue(columnState.dbType, candidate)
|
|
4045
|
+
return columnState.runtimeSchema === undefined
|
|
4046
|
+
? normalized
|
|
4047
|
+
: (Schema.decodeUnknownSync as any)(columnState.runtimeSchema)(normalized)
|
|
4048
|
+
}
|
|
3830
4049
|
if (value !== null && typeof value === "object" && Expression.TypeId in value) {
|
|
3831
|
-
|
|
4050
|
+
const expression = value as unknown as Expression.Any
|
|
4051
|
+
const ast = (expression as unknown as { readonly [ExpressionAst.TypeId]: ExpressionAst.Any })[ExpressionAst.TypeId]
|
|
4052
|
+
if (ast.kind === "literal") {
|
|
4053
|
+
const normalizedValue = normalizeMutationValue(ast.value)
|
|
4054
|
+
return makeExpression({
|
|
4055
|
+
runtime: normalizedValue,
|
|
4056
|
+
dbType: columnState.dbType,
|
|
4057
|
+
runtimeSchema: columnState.runtimeSchema,
|
|
4058
|
+
driverValueMapping: columnState.driverValueMapping,
|
|
4059
|
+
nullability: normalizedValue === null ? "always" : "never",
|
|
4060
|
+
dialect: columnState.dialect,
|
|
4061
|
+
kind: "scalar",
|
|
4062
|
+
dependencies: {}
|
|
4063
|
+
}, {
|
|
4064
|
+
kind: "literal",
|
|
4065
|
+
value: normalizedValue
|
|
4066
|
+
})
|
|
4067
|
+
}
|
|
4068
|
+
return retargetLiteralExpression(value as unknown as Expression.Any, column)
|
|
3832
4069
|
}
|
|
4070
|
+
const normalizedValue = normalizeMutationValue(value)
|
|
3833
4071
|
return makeExpression({
|
|
3834
|
-
runtime:
|
|
3835
|
-
dbType:
|
|
3836
|
-
|
|
3837
|
-
|
|
4072
|
+
runtime: normalizedValue as Value,
|
|
4073
|
+
dbType: columnState.dbType,
|
|
4074
|
+
runtimeSchema: columnState.runtimeSchema,
|
|
4075
|
+
driverValueMapping: columnState.driverValueMapping,
|
|
4076
|
+
nullability: normalizedValue === null ? "always" : "never",
|
|
4077
|
+
dialect: columnState.dialect,
|
|
3838
4078
|
kind: "scalar",
|
|
3839
4079
|
|
|
3840
4080
|
dependencies: {}
|
|
3841
4081
|
}, {
|
|
3842
4082
|
kind: "literal",
|
|
3843
|
-
value
|
|
4083
|
+
value: normalizedValue
|
|
3844
4084
|
})
|
|
3845
4085
|
}
|
|
3846
4086
|
|
|
@@ -3907,6 +4147,7 @@ type BinaryPredicateExpression<
|
|
|
3907
4147
|
runtime: undefined as never,
|
|
3908
4148
|
dbType: state.dbType,
|
|
3909
4149
|
runtimeSchema: state.runtimeSchema,
|
|
4150
|
+
driverValueMapping: state.driverValueMapping,
|
|
3910
4151
|
nullability: state.nullability,
|
|
3911
4152
|
dialect: state.dialect,
|
|
3912
4153
|
kind: "scalar",
|
|
@@ -3927,16 +4168,16 @@ type BinaryPredicateExpression<
|
|
|
3927
4168
|
Alias extends string
|
|
3928
4169
|
>(
|
|
3929
4170
|
rows: readonly [Record<string, Expression.Any>, ...Record<string, Expression.Any>[]],
|
|
3930
|
-
selection: ValuesOutputShape<Rows
|
|
4171
|
+
selection: ValuesOutputShape<Rows, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
3931
4172
|
alias: Alias
|
|
3932
4173
|
): ValuesSource<
|
|
3933
4174
|
Rows,
|
|
3934
|
-
ValuesOutputShape<Rows
|
|
4175
|
+
ValuesOutputShape<Rows, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
3935
4176
|
Alias,
|
|
3936
4177
|
Dialect
|
|
3937
4178
|
> => {
|
|
3938
4179
|
const columns = makeColumnReferenceSelection(alias, selection as Record<string, Expression.Any>) as unknown as ValuesOutputShape<
|
|
3939
|
-
Rows
|
|
4180
|
+
Rows,
|
|
3940
4181
|
Dialect,
|
|
3941
4182
|
TextDb,
|
|
3942
4183
|
NumericDb,
|
|
@@ -3954,7 +4195,7 @@ type BinaryPredicateExpression<
|
|
|
3954
4195
|
}
|
|
3955
4196
|
return Object.assign(source, columns) as unknown as ValuesSource<
|
|
3956
4197
|
Rows,
|
|
3957
|
-
ValuesOutputShape<Rows
|
|
4198
|
+
ValuesOutputShape<Rows, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
3958
4199
|
Alias,
|
|
3959
4200
|
Dialect
|
|
3960
4201
|
>
|
|
@@ -3967,7 +4208,12 @@ type BinaryPredicateExpression<
|
|
|
3967
4208
|
|
|
3968
4209
|
const normalizeUnnestColumns = (columns: UnnestColumnsInput): Record<string, readonly Expression.Any[]> =>
|
|
3969
4210
|
Object.fromEntries(
|
|
3970
|
-
Object.entries(columns).map(([key, values]) =>
|
|
4211
|
+
Object.entries(columns).map(([key, values]) => {
|
|
4212
|
+
if (!Array.isArray(values)) {
|
|
4213
|
+
throw new Error("unnest(...) expects every value to be an array")
|
|
4214
|
+
}
|
|
4215
|
+
return [key, values.map((value) => toDialectExpression(value))]
|
|
4216
|
+
})
|
|
3971
4217
|
) as Record<string, readonly Expression.Any[]>
|
|
3972
4218
|
|
|
3973
4219
|
const normalizeMutationTargets = (
|
|
@@ -4010,6 +4256,17 @@ type BinaryPredicateExpression<
|
|
|
4010
4256
|
})
|
|
4011
4257
|
) as unknown as AddAvailableMany<{}, MutationTargetNamesOf<Target>, Mode>
|
|
4012
4258
|
|
|
4259
|
+
const getMutationColumn = (
|
|
4260
|
+
columns: Record<string, unknown>,
|
|
4261
|
+
columnName: string
|
|
4262
|
+
): Expression.Any => {
|
|
4263
|
+
const column = columns[columnName]
|
|
4264
|
+
if (column === undefined || column === null || typeof column !== "object" || !(Expression.TypeId in column)) {
|
|
4265
|
+
throw new Error("effect-qb: unknown mutation column")
|
|
4266
|
+
}
|
|
4267
|
+
return column as Expression.Any
|
|
4268
|
+
}
|
|
4269
|
+
|
|
4013
4270
|
const buildMutationAssignments = <Target extends MutationTargetInput, Values>(
|
|
4014
4271
|
target: Target,
|
|
4015
4272
|
values: Values
|
|
@@ -4019,7 +4276,7 @@ type BinaryPredicateExpression<
|
|
|
4019
4276
|
const columns = target as unknown as Record<string, Expression.Any>
|
|
4020
4277
|
return Object.entries(values as Record<string, unknown>).map(([columnName, value]) => ({
|
|
4021
4278
|
columnName,
|
|
4022
|
-
value: toMutationValueExpression(value, columns
|
|
4279
|
+
value: toMutationValueExpression(value, getMutationColumn(columns, columnName))
|
|
4023
4280
|
}))
|
|
4024
4281
|
}
|
|
4025
4282
|
const valueMap = values as Record<string, Record<string, unknown> | undefined>
|
|
@@ -4030,7 +4287,7 @@ type BinaryPredicateExpression<
|
|
|
4030
4287
|
return Object.entries(scopedValues).map(([columnName, value]) => ({
|
|
4031
4288
|
tableName: targetName,
|
|
4032
4289
|
columnName,
|
|
4033
|
-
value: toMutationValueExpression(value, columns
|
|
4290
|
+
value: toMutationValueExpression(value, getMutationColumn(columns, columnName))
|
|
4034
4291
|
}))
|
|
4035
4292
|
})
|
|
4036
4293
|
}
|
|
@@ -4117,31 +4374,29 @@ type BinaryPredicateExpression<
|
|
|
4117
4374
|
}
|
|
4118
4375
|
}
|
|
4119
4376
|
|
|
4377
|
+
const normalizeConflictColumns = <Target extends MutationTargetLike>(
|
|
4378
|
+
target: Target,
|
|
4379
|
+
columnsInput: string | readonly string[]
|
|
4380
|
+
): readonly [string, ...string[]] => {
|
|
4381
|
+
const columns = normalizeColumnList(columnsInput) as readonly [string, ...string[]]
|
|
4382
|
+
const knownColumns = new Set(Object.keys(target[Table.TypeId].fields))
|
|
4383
|
+
if (columns.some((columnName) => !knownColumns.has(columnName))) {
|
|
4384
|
+
throw new Error("effect-qb: unknown conflict target column")
|
|
4385
|
+
}
|
|
4386
|
+
return columns
|
|
4387
|
+
}
|
|
4388
|
+
|
|
4120
4389
|
const buildConflictTarget = <Target extends MutationTargetLike>(
|
|
4121
4390
|
target: Target,
|
|
4122
|
-
input: readonly string[] | { readonly columns: readonly string[]; readonly where?: PredicateInput } | { readonly constraint: string }
|
|
4391
|
+
input: string | readonly string[] | { readonly columns: string | readonly string[]; readonly where?: PredicateInput } | { readonly constraint: string }
|
|
4123
4392
|
): QueryAst.ConflictTargetClause => {
|
|
4124
|
-
if (Array.isArray(input)) {
|
|
4393
|
+
if (typeof input === "string" || Array.isArray(input)) {
|
|
4125
4394
|
return {
|
|
4126
4395
|
kind: "columns",
|
|
4127
|
-
columns:
|
|
4396
|
+
columns: normalizeConflictColumns(target, input)
|
|
4128
4397
|
}
|
|
4129
4398
|
}
|
|
4130
|
-
|
|
4131
|
-
return {
|
|
4132
|
-
kind: "constraint",
|
|
4133
|
-
name: input.constraint
|
|
4134
|
-
}
|
|
4135
|
-
}
|
|
4136
|
-
const columnTarget = input as {
|
|
4137
|
-
readonly columns: readonly string[]
|
|
4138
|
-
readonly where?: PredicateInput
|
|
4139
|
-
}
|
|
4140
|
-
return {
|
|
4141
|
-
kind: "columns",
|
|
4142
|
-
columns: normalizeColumnList(columnTarget.columns) as readonly [string, ...string[]],
|
|
4143
|
-
where: columnTarget.where === undefined ? undefined : toDialectExpression(columnTarget.where)
|
|
4144
|
-
}
|
|
4399
|
+
throw new Error("Unsupported mysql conflict target")
|
|
4145
4400
|
}
|
|
4146
4401
|
|
|
4147
4402
|
const defaultIndexName = (
|
|
@@ -4177,20 +4432,30 @@ type ValidateDdlColumns<
|
|
|
4177
4432
|
Columns extends readonly string[]
|
|
4178
4433
|
> = Exclude<Columns[number], SchemaColumnNames<Target>> extends never ? Columns : never
|
|
4179
4434
|
|
|
4435
|
+
type ValidateDdlColumnInput<
|
|
4436
|
+
Target extends SchemaTableLike,
|
|
4437
|
+
Columns extends DdlColumnInput
|
|
4438
|
+
> = ValidateDdlColumns<Target, NormalizeDdlColumns<Columns>> extends never ? never : Columns
|
|
4439
|
+
|
|
4180
4440
|
type ValidateTargetColumns<
|
|
4181
4441
|
Target extends MutationTargetLike,
|
|
4182
4442
|
Columns extends readonly string[]
|
|
4183
4443
|
> = Exclude<Columns[number], Extract<keyof Target[typeof Table.TypeId]["fields"], string>> extends never ? Columns : never
|
|
4184
4444
|
|
|
4445
|
+
type ValidateTargetColumnInput<
|
|
4446
|
+
Target extends MutationTargetLike,
|
|
4447
|
+
Columns extends DdlColumnInput
|
|
4448
|
+
> = ValidateTargetColumns<Target, NormalizeDdlColumns<Columns>> extends never ? never : Columns
|
|
4449
|
+
|
|
4185
4450
|
type CreateIndexOptions = {
|
|
4186
4451
|
readonly name?: string
|
|
4187
4452
|
readonly unique?: boolean
|
|
4188
|
-
readonly ifNotExists?:
|
|
4453
|
+
readonly ifNotExists?: never
|
|
4189
4454
|
}
|
|
4190
4455
|
|
|
4191
4456
|
type DropIndexOptions = {
|
|
4192
4457
|
readonly name?: string
|
|
4193
|
-
readonly ifExists?:
|
|
4458
|
+
readonly ifExists?: never
|
|
4194
4459
|
}
|
|
4195
4460
|
|
|
4196
4461
|
type CreateTableOptions = {
|
|
@@ -4202,8 +4467,8 @@ type DropTableOptions = {
|
|
|
4202
4467
|
}
|
|
4203
4468
|
|
|
4204
4469
|
type TruncateOptions = {
|
|
4205
|
-
readonly restartIdentity?:
|
|
4206
|
-
readonly cascade?:
|
|
4470
|
+
readonly restartIdentity?: never
|
|
4471
|
+
readonly cascade?: never
|
|
4207
4472
|
}
|
|
4208
4473
|
|
|
4209
4474
|
type TransactionOptions = {
|
|
@@ -4211,10 +4476,15 @@ type TransactionOptions = {
|
|
|
4211
4476
|
readonly readOnly?: boolean
|
|
4212
4477
|
}
|
|
4213
4478
|
|
|
4214
|
-
type LockOptions =
|
|
4215
|
-
|
|
4216
|
-
|
|
4217
|
-
|
|
4479
|
+
type LockOptions =
|
|
4480
|
+
| {
|
|
4481
|
+
readonly nowait?: boolean
|
|
4482
|
+
readonly skipLocked?: false
|
|
4483
|
+
}
|
|
4484
|
+
| {
|
|
4485
|
+
readonly nowait?: false
|
|
4486
|
+
readonly skipLocked?: boolean
|
|
4487
|
+
}
|
|
4218
4488
|
|
|
4219
4489
|
type UpsertConflictOptions = {
|
|
4220
4490
|
readonly update?: Record<string, unknown>
|
|
@@ -4229,14 +4499,133 @@ type InsertRowInput<Target extends MutationTargetLike> = MutationInputOf<Table.I
|
|
|
4229
4499
|
type ValuesRowInput = Record<string, ExpressionInput>
|
|
4230
4500
|
type ValuesRowsInput = readonly [ValuesRowInput, ...ValuesRowInput[]]
|
|
4231
4501
|
|
|
4502
|
+
type ValuesColumnInput<Row, Key extends PropertyKey> =
|
|
4503
|
+
Row extends ValuesRowInput
|
|
4504
|
+
? Key extends keyof Row ? Row[Key] : never
|
|
4505
|
+
: never
|
|
4506
|
+
|
|
4507
|
+
type ValuesRowShapeMismatch<
|
|
4508
|
+
First extends ValuesRowInput,
|
|
4509
|
+
Row extends ValuesRowInput
|
|
4510
|
+
> =
|
|
4511
|
+
| Exclude<Extract<keyof Row, string>, Extract<keyof First, string>>
|
|
4512
|
+
| Exclude<Extract<keyof First, string>, Extract<keyof Row, string>>
|
|
4513
|
+
|
|
4514
|
+
type ValuesRowsShapeMismatchesFor<
|
|
4515
|
+
First extends ValuesRowInput,
|
|
4516
|
+
Row
|
|
4517
|
+
> = Row extends ValuesRowInput ? ValuesRowShapeMismatch<First, Row> : never
|
|
4518
|
+
|
|
4519
|
+
type ValuesRowsShapeMismatches<Rows extends ValuesRowsInput> =
|
|
4520
|
+
Rows extends readonly [infer First extends ValuesRowInput, ...infer Rest extends ValuesRowInput[]]
|
|
4521
|
+
? ValuesRowsShapeMismatchesFor<First, Rest[number]>
|
|
4522
|
+
: never
|
|
4523
|
+
|
|
4524
|
+
type ValuesRowsColumnKeys<Rows extends ValuesRowsInput> =
|
|
4525
|
+
Rows extends readonly [infer First extends ValuesRowInput, ...ValuesRowInput[]]
|
|
4526
|
+
? Extract<keyof First, string>
|
|
4527
|
+
: never
|
|
4528
|
+
|
|
4529
|
+
type ValuesRowsShapeInput<Rows extends ValuesRowsInput> =
|
|
4530
|
+
[ValuesRowsColumnKeys<Rows>] extends [never]
|
|
4531
|
+
? {
|
|
4532
|
+
readonly __effect_qb_error__: "effect-qb: values rows must project at least one column"
|
|
4533
|
+
}
|
|
4534
|
+
: [ValuesRowsShapeMismatches<Rows>] extends [never]
|
|
4535
|
+
? unknown
|
|
4536
|
+
: {
|
|
4537
|
+
readonly __effect_qb_error__: "effect-qb: values rows must project the same columns"
|
|
4538
|
+
readonly __effect_qb_mismatched_columns__: ValuesRowsShapeMismatches<Rows>
|
|
4539
|
+
}
|
|
4540
|
+
|
|
4541
|
+
type ValuesRowsDialect<
|
|
4542
|
+
Rows extends ValuesRowsInput,
|
|
4543
|
+
Dialect extends string,
|
|
4544
|
+
TextDb extends Expression.DbType.Any,
|
|
4545
|
+
NumericDb extends Expression.DbType.Any,
|
|
4546
|
+
BoolDb extends Expression.DbType.Any,
|
|
4547
|
+
TimestampDb extends Expression.DbType.Any,
|
|
4548
|
+
NullDb extends Expression.DbType.Any
|
|
4549
|
+
> = Rows[number][keyof Rows[number]] extends infer Value extends ExpressionInput
|
|
4550
|
+
? DialectOfDialectInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
4551
|
+
: never
|
|
4552
|
+
|
|
4553
|
+
type ValuesRowsDialectInput<
|
|
4554
|
+
Rows extends ValuesRowsInput,
|
|
4555
|
+
Dialect extends string,
|
|
4556
|
+
TextDb extends Expression.DbType.Any,
|
|
4557
|
+
NumericDb extends Expression.DbType.Any,
|
|
4558
|
+
BoolDb extends Expression.DbType.Any,
|
|
4559
|
+
TimestampDb extends Expression.DbType.Any,
|
|
4560
|
+
NullDb extends Expression.DbType.Any
|
|
4561
|
+
> = Exclude<ValuesRowsDialect<Rows, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>, Dialect> extends never
|
|
4562
|
+
? unknown
|
|
4563
|
+
: {
|
|
4564
|
+
readonly __effect_qb_error__: "effect-qb: values rows cannot mix dialects"
|
|
4565
|
+
readonly __effect_qb_dialect__: ValuesRowsDialect<Rows, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
4566
|
+
}
|
|
4567
|
+
|
|
4232
4568
|
type UnnestColumnsInput = Record<string, readonly [ExpressionInput, ...ExpressionInput[]]>
|
|
4233
4569
|
|
|
4570
|
+
type IsNever<Value> = [Value] extends [never] ? true : false
|
|
4571
|
+
|
|
4572
|
+
type IsUnion<Value, All = Value> = Value extends any
|
|
4573
|
+
? ([All] extends [Value] ? false : true)
|
|
4574
|
+
: never
|
|
4575
|
+
|
|
4576
|
+
type UnnestColumnKeys<Columns extends UnnestColumnsInput> =
|
|
4577
|
+
Extract<keyof Columns, string>
|
|
4578
|
+
|
|
4579
|
+
type UnnestColumnLengths<Columns extends UnnestColumnsInput> =
|
|
4580
|
+
Columns[UnnestColumnKeys<Columns>]["length"]
|
|
4581
|
+
|
|
4582
|
+
type UnnestColumnsShapeInput<Columns extends UnnestColumnsInput> =
|
|
4583
|
+
IsNever<UnnestColumnKeys<Columns>> extends true
|
|
4584
|
+
? {
|
|
4585
|
+
readonly __effect_qb_error__: "effect-qb: unnest requires at least one column array"
|
|
4586
|
+
}
|
|
4587
|
+
: number extends UnnestColumnLengths<Columns>
|
|
4588
|
+
? unknown
|
|
4589
|
+
: IsUnion<UnnestColumnLengths<Columns>> extends true
|
|
4590
|
+
? {
|
|
4591
|
+
readonly __effect_qb_error__: "effect-qb: unnest column arrays must have the same length"
|
|
4592
|
+
readonly __effect_qb_column_lengths__: UnnestColumnLengths<Columns>
|
|
4593
|
+
}
|
|
4594
|
+
: unknown
|
|
4595
|
+
|
|
4596
|
+
type UnnestColumnsDialect<
|
|
4597
|
+
Columns extends UnnestColumnsInput,
|
|
4598
|
+
Dialect extends string,
|
|
4599
|
+
TextDb extends Expression.DbType.Any,
|
|
4600
|
+
NumericDb extends Expression.DbType.Any,
|
|
4601
|
+
BoolDb extends Expression.DbType.Any,
|
|
4602
|
+
TimestampDb extends Expression.DbType.Any,
|
|
4603
|
+
NullDb extends Expression.DbType.Any
|
|
4604
|
+
> = Columns[UnnestColumnKeys<Columns>][number] extends infer Value extends ExpressionInput
|
|
4605
|
+
? DialectOfDialectInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
4606
|
+
: never
|
|
4607
|
+
|
|
4608
|
+
type UnnestColumnsDialectInput<
|
|
4609
|
+
Columns extends UnnestColumnsInput,
|
|
4610
|
+
Dialect extends string,
|
|
4611
|
+
TextDb extends Expression.DbType.Any,
|
|
4612
|
+
NumericDb extends Expression.DbType.Any,
|
|
4613
|
+
BoolDb extends Expression.DbType.Any,
|
|
4614
|
+
TimestampDb extends Expression.DbType.Any,
|
|
4615
|
+
NullDb extends Expression.DbType.Any
|
|
4616
|
+
> = Exclude<UnnestColumnsDialect<Columns, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>, Dialect> extends never
|
|
4617
|
+
? unknown
|
|
4618
|
+
: {
|
|
4619
|
+
readonly __effect_qb_error__: "effect-qb: unnest columns cannot mix dialects"
|
|
4620
|
+
readonly __effect_qb_dialect__: UnnestColumnsDialect<Columns, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
4621
|
+
}
|
|
4622
|
+
|
|
4234
4623
|
type UnnestRowShape<Shape extends Record<string, readonly unknown[]>> = {
|
|
4235
4624
|
readonly [K in keyof Shape]: Shape[K] extends readonly (infer Item)[] ? Item : never
|
|
4236
4625
|
}
|
|
4237
4626
|
|
|
4238
4627
|
type ValuesOutputShape<
|
|
4239
|
-
|
|
4628
|
+
Rows extends ValuesRowsInput,
|
|
4240
4629
|
Dialect extends string,
|
|
4241
4630
|
TextDb extends Expression.DbType.Any,
|
|
4242
4631
|
NumericDb extends Expression.DbType.Any,
|
|
@@ -4244,7 +4633,7 @@ type ValuesOutputShape<
|
|
|
4244
4633
|
TimestampDb extends Expression.DbType.Any,
|
|
4245
4634
|
NullDb extends Expression.DbType.Any
|
|
4246
4635
|
> = {
|
|
4247
|
-
readonly [K in keyof
|
|
4636
|
+
readonly [K in keyof Rows[0]]: DialectAsExpression<ValuesColumnInput<Rows[number], K>, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
4248
4637
|
}
|
|
4249
4638
|
|
|
4250
4639
|
type UnnestOutputShape<
|
|
@@ -4283,19 +4672,44 @@ type DistinctOnUnsupportedError<Dialect extends string> = {
|
|
|
4283
4672
|
readonly __effect_qb_hint__: "Use postgres.Query.distinctOn(...) or regular distinct()/grouping logic"
|
|
4284
4673
|
}
|
|
4285
4674
|
|
|
4675
|
+
type FullJoinUnsupportedError<Dialect extends string> = {
|
|
4676
|
+
readonly __effect_qb_error__: "effect-qb: fullJoin(...) is only supported by the postgres dialect"
|
|
4677
|
+
readonly __effect_qb_dialect__: Dialect
|
|
4678
|
+
readonly __effect_qb_hint__: "Use leftJoin/rightJoin with nullable handling or switch to postgres.Query.fullJoin(...)"
|
|
4679
|
+
}
|
|
4680
|
+
|
|
4681
|
+
type ReturningUnsupportedError<Dialect extends string> = {
|
|
4682
|
+
readonly __effect_qb_error__: "effect-qb: returning(...) is only supported by the postgres dialect"
|
|
4683
|
+
readonly __effect_qb_dialect__: Dialect
|
|
4684
|
+
readonly __effect_qb_hint__: "Use postgres.Query.returning(...) or run a follow-up select after MySQL mutations"
|
|
4685
|
+
}
|
|
4686
|
+
|
|
4687
|
+
type MysqlCteStatementError<PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>> =
|
|
4688
|
+
PlanValue & {
|
|
4689
|
+
readonly __effect_qb_error__: "effect-qb: mysql cte sources only accept select-like query plans"
|
|
4690
|
+
readonly __effect_qb_statement__: StatementOfPlan<PlanValue>
|
|
4691
|
+
readonly __effect_qb_hint__: "Use select(...) or a set operator before wrapping a MySQL plan in with(...)"
|
|
4692
|
+
}
|
|
4693
|
+
|
|
4694
|
+
type MysqlCteCompatiblePlan<
|
|
4695
|
+
PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>
|
|
4696
|
+
> = StatementOfPlan<PlanValue> extends "select" | "set"
|
|
4697
|
+
? DerivedSourceCompatiblePlan<PlanValue>
|
|
4698
|
+
: MysqlCteStatementError<PlanValue>
|
|
4699
|
+
|
|
4286
4700
|
type DistinctOnApi<Dialect extends string> = Dialect extends "postgres"
|
|
4287
|
-
? <Values extends readonly ExpressionInput[]>(
|
|
4701
|
+
? <Values extends readonly [ExpressionInput, ...ExpressionInput[]]>(
|
|
4288
4702
|
...values: Values
|
|
4289
4703
|
) => <PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
|
|
4290
4704
|
plan: PlanValue & RequireSelectStatement<PlanValue>
|
|
4291
4705
|
) => QueryPlan<
|
|
4292
4706
|
SelectionOfPlan<PlanValue>,
|
|
4293
|
-
RequiredOfPlan<PlanValue>,
|
|
4707
|
+
AddExpressionRequired<RequiredOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, Values[number]>,
|
|
4294
4708
|
AvailableOfPlan<PlanValue>,
|
|
4295
|
-
PlanDialectOf<PlanValue>,
|
|
4709
|
+
PlanDialectOf<PlanValue> | DialectOfDialectInput<Values[number], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
4296
4710
|
GroupedOfPlan<PlanValue>,
|
|
4297
4711
|
ScopedNamesOfPlan<PlanValue>,
|
|
4298
|
-
OutstandingOfPlan<PlanValue>,
|
|
4712
|
+
AddExpressionRequired<OutstandingOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, Values[number]>,
|
|
4299
4713
|
AssumptionsOfPlan<PlanValue>,
|
|
4300
4714
|
CapabilitiesOfPlan<PlanValue>,
|
|
4301
4715
|
StatementOfPlan<PlanValue>
|
|
@@ -4328,6 +4742,27 @@ type MysqlConflictWhereError<Values> = Values & {
|
|
|
4328
4742
|
readonly __effect_qb_hint__: "Move the condition into the update assignment expressions or use the Postgres dialect"
|
|
4329
4743
|
}
|
|
4330
4744
|
|
|
4745
|
+
type UpdateValuesNonEmptyError<Values> = Values & {
|
|
4746
|
+
readonly __effect_qb_error__: "effect-qb: update statements require at least one assignment"
|
|
4747
|
+
}
|
|
4748
|
+
|
|
4749
|
+
type UpdateValuesNonEmptyConstraint<Values> =
|
|
4750
|
+
[Extract<keyof Values, string>] extends [never]
|
|
4751
|
+
? UpdateValuesNonEmptyError<Values>
|
|
4752
|
+
: unknown
|
|
4753
|
+
|
|
4754
|
+
type NestedUpdateValuesNonEmptyConstraint<Values> =
|
|
4755
|
+
[Extract<keyof Values, string>] extends [never]
|
|
4756
|
+
? UpdateValuesNonEmptyError<Values>
|
|
4757
|
+
: true extends {
|
|
4758
|
+
[K in Extract<keyof Values, string>]:
|
|
4759
|
+
Values[K] extends Record<string, unknown>
|
|
4760
|
+
? [Extract<keyof Values[K], string>] extends [never] ? false : true
|
|
4761
|
+
: false
|
|
4762
|
+
}[Extract<keyof Values, string>]
|
|
4763
|
+
? unknown
|
|
4764
|
+
: UpdateValuesNonEmptyError<Values>
|
|
4765
|
+
|
|
4331
4766
|
type InsertShapeExtraKeys<TargetShape, SourceShape> = Exclude<Extract<keyof SourceShape, string>, Extract<keyof TargetShape, string>>
|
|
4332
4767
|
type InsertShapeMissingKeys<TargetShape, SourceShape> = Exclude<RequiredKeys<TargetShape>, Extract<keyof SourceShape, string>>
|
|
4333
4768
|
type InsertShapeMismatchedKeys<TargetShape, SourceShape> = Extract<{
|
|
@@ -4421,10 +4856,15 @@ type InsertSourceRequired<Source> =
|
|
|
4421
4856
|
Source extends QueryPlan<any, any, any, any, any, any, any, any, any, any> ? RequiredOfPlan<Source> :
|
|
4422
4857
|
never
|
|
4423
4858
|
|
|
4859
|
+
type InsertSourceDialect<Source> =
|
|
4860
|
+
Source extends QueryPlan<any, any, any, any, any, any, any, any, any, any> ? PlanDialectOf<Source> :
|
|
4861
|
+
Source extends SourceLike ? SourceDialectOf<Source> :
|
|
4862
|
+
never
|
|
4863
|
+
|
|
4424
4864
|
type ConflictColumnTarget<
|
|
4425
4865
|
Target extends MutationTargetLike,
|
|
4426
4866
|
Columns extends DdlColumnInput
|
|
4427
|
-
> =
|
|
4867
|
+
> = ValidateTargetColumnInput<Target, Columns>
|
|
4428
4868
|
|
|
4429
4869
|
type ConflictTargetInput<
|
|
4430
4870
|
Target extends MutationTargetLike,
|
|
@@ -4454,6 +4894,55 @@ type ConflictActionInput<
|
|
|
4454
4894
|
readonly where?: Dialect extends "postgres" ? PredicateInput : MysqlConflictWhereError<PredicateInput>
|
|
4455
4895
|
}
|
|
4456
4896
|
|
|
4897
|
+
type ConflictActionUpdateNonEmptyConstraint<Options> =
|
|
4898
|
+
Options extends { readonly update: infer Values }
|
|
4899
|
+
? UpdateValuesNonEmptyConstraint<Values>
|
|
4900
|
+
: unknown
|
|
4901
|
+
|
|
4902
|
+
type ConflictTargetPredicate<Target> =
|
|
4903
|
+
Target extends { readonly where?: infer Predicate } ? Extract<Predicate, PredicateInput> : never
|
|
4904
|
+
|
|
4905
|
+
type ConflictActionPredicate<Options> =
|
|
4906
|
+
Options extends { readonly where?: infer Predicate } ? Extract<Predicate, PredicateInput> : never
|
|
4907
|
+
|
|
4908
|
+
type MutationDialectFromValues<
|
|
4909
|
+
Values extends Record<string, unknown>,
|
|
4910
|
+
Dialect extends string,
|
|
4911
|
+
TextDb extends Expression.DbType.Any,
|
|
4912
|
+
NumericDb extends Expression.DbType.Any,
|
|
4913
|
+
BoolDb extends Expression.DbType.Any,
|
|
4914
|
+
TimestampDb extends Expression.DbType.Any,
|
|
4915
|
+
NullDb extends Expression.DbType.Any
|
|
4916
|
+
> = {
|
|
4917
|
+
[K in keyof Values]: Values[K] extends ExpressionInput
|
|
4918
|
+
? DialectOfDialectInput<Values[K], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
4919
|
+
: never
|
|
4920
|
+
}[keyof Values]
|
|
4921
|
+
|
|
4922
|
+
type ConflictRequired<
|
|
4923
|
+
UpdateValues extends MutationInputOf<any> | undefined,
|
|
4924
|
+
Options,
|
|
4925
|
+
ConflictTarget
|
|
4926
|
+
> =
|
|
4927
|
+
| MutationRequiredFromValues<Exclude<UpdateValues, undefined>>
|
|
4928
|
+
| RequiredFromInput<ConflictActionPredicate<Options>>
|
|
4929
|
+
| RequiredFromInput<ConflictTargetPredicate<ConflictTarget>>
|
|
4930
|
+
|
|
4931
|
+
type ConflictDialect<
|
|
4932
|
+
UpdateValues extends MutationInputOf<any> | undefined,
|
|
4933
|
+
Options,
|
|
4934
|
+
ConflictTarget,
|
|
4935
|
+
Dialect extends string,
|
|
4936
|
+
TextDb extends Expression.DbType.Any,
|
|
4937
|
+
NumericDb extends Expression.DbType.Any,
|
|
4938
|
+
BoolDb extends Expression.DbType.Any,
|
|
4939
|
+
TimestampDb extends Expression.DbType.Any,
|
|
4940
|
+
NullDb extends Expression.DbType.Any
|
|
4941
|
+
> =
|
|
4942
|
+
| MutationDialectFromValues<Exclude<UpdateValues, undefined>, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
4943
|
+
| DialectOfDialectInput<ConflictActionPredicate<Options>, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
4944
|
+
| DialectOfDialectInput<ConflictTargetPredicate<ConflictTarget>, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
4945
|
+
|
|
4457
4946
|
type MergeWhenMatchedDelete<
|
|
4458
4947
|
Predicate extends PredicateInput | undefined = undefined
|
|
4459
4948
|
> = {
|
|
@@ -4481,16 +4970,33 @@ type MergeWhenNotMatched<
|
|
|
4481
4970
|
readonly predicate?: Predicate
|
|
4482
4971
|
}
|
|
4483
4972
|
|
|
4973
|
+
type MergeMatchedOption<
|
|
4974
|
+
Target extends MutationTargetLike,
|
|
4975
|
+
MatchedValues extends MutationInputOf<Table.UpdateOf<Target>>,
|
|
4976
|
+
MatchedPredicate extends PredicateInput | undefined = undefined
|
|
4977
|
+
> = MergeWhenMatchedDelete<MatchedPredicate> | MergeWhenMatchedUpdate<Target, MatchedValues, MatchedPredicate>
|
|
4978
|
+
|
|
4979
|
+
type MergeNotMatchedOption<
|
|
4980
|
+
Target extends MutationTargetLike,
|
|
4981
|
+
InsertValues extends MutationInputOf<Table.InsertOf<Target>>,
|
|
4982
|
+
NotMatchedPredicate extends PredicateInput | undefined = undefined
|
|
4983
|
+
> = MergeWhenNotMatched<Target, InsertValues, NotMatchedPredicate>
|
|
4984
|
+
|
|
4484
4985
|
type MergeOptions<
|
|
4485
4986
|
Target extends MutationTargetLike,
|
|
4486
4987
|
MatchedValues extends MutationInputOf<Table.UpdateOf<Target>>,
|
|
4487
4988
|
InsertValues extends MutationInputOf<Table.InsertOf<Target>>,
|
|
4488
4989
|
MatchedPredicate extends PredicateInput | undefined = undefined,
|
|
4489
4990
|
NotMatchedPredicate extends PredicateInput | undefined = undefined
|
|
4490
|
-
> =
|
|
4491
|
-
|
|
4492
|
-
|
|
4493
|
-
|
|
4991
|
+
> =
|
|
4992
|
+
| {
|
|
4993
|
+
readonly whenMatched: MergeMatchedOption<Target, MatchedValues, MatchedPredicate>
|
|
4994
|
+
readonly whenNotMatched?: MergeNotMatchedOption<Target, InsertValues, NotMatchedPredicate>
|
|
4995
|
+
}
|
|
4996
|
+
| {
|
|
4997
|
+
readonly whenMatched?: MergeMatchedOption<Target, MatchedValues, MatchedPredicate>
|
|
4998
|
+
readonly whenNotMatched: MergeNotMatchedOption<Target, InsertValues, NotMatchedPredicate>
|
|
4999
|
+
}
|
|
4494
5000
|
|
|
4495
5001
|
type RequireSelectStatement<PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>> =
|
|
4496
5002
|
StatementOfPlan<PlanValue> extends "select" ? unknown : never
|
|
@@ -4522,6 +5028,38 @@ type MutationOrderLimitSupported<PlanValue extends QueryPlan<any, any, any, any,
|
|
|
4522
5028
|
? StatementOfPlan<PlanValue> extends "update" | "delete" ? unknown : never
|
|
4523
5029
|
: never
|
|
4524
5030
|
|
|
5031
|
+
type MutationTargetTupleDialectConstraint<
|
|
5032
|
+
Targets extends MutationTargetTuple,
|
|
5033
|
+
Dialect extends string
|
|
5034
|
+
> = Exclude<TableDialectOf<Targets[number]>, Dialect> extends never ? unknown : never
|
|
5035
|
+
|
|
5036
|
+
type DuplicateMutationTargetSourceName<
|
|
5037
|
+
Targets extends readonly MutationTargetLike[],
|
|
5038
|
+
Seen extends string = never
|
|
5039
|
+
> = Targets extends readonly [infer Head extends MutationTargetLike, ...infer Tail extends readonly MutationTargetLike[]]
|
|
5040
|
+
? SourceNameOf<Head> extends infer Name extends string
|
|
5041
|
+
? string extends Name
|
|
5042
|
+
? DuplicateMutationTargetSourceName<Tail, Seen>
|
|
5043
|
+
: Name extends Seen
|
|
5044
|
+
? Name
|
|
5045
|
+
: DuplicateMutationTargetSourceName<Tail, Seen | Name>
|
|
5046
|
+
: never
|
|
5047
|
+
: never
|
|
5048
|
+
|
|
5049
|
+
type MutationTargetTupleDuplicateNameError<Name extends string> = {
|
|
5050
|
+
readonly __effect_qb_error__: "effect-qb: mutation target source names must be unique"
|
|
5051
|
+
readonly __effect_qb_duplicate_source_name__: Name
|
|
5052
|
+
readonly __effect_qb_hint__: "Alias duplicate mutation targets with Table.alias(...)"
|
|
5053
|
+
}
|
|
5054
|
+
|
|
5055
|
+
type MutationTargetTupleUniqueNamesConstraint<
|
|
5056
|
+
Targets extends MutationTargetTuple
|
|
5057
|
+
> = DuplicateMutationTargetSourceName<Targets> extends infer Name extends string
|
|
5058
|
+
? [Name] extends [never]
|
|
5059
|
+
? unknown
|
|
5060
|
+
: MutationTargetTupleDuplicateNameError<Name>
|
|
5061
|
+
: unknown
|
|
5062
|
+
|
|
4525
5063
|
type MutationRequiredFromValues<Values extends Record<string, unknown>> = {
|
|
4526
5064
|
[K in keyof Values]: Values[K] extends Expression.Any ? RequiredFromDependencies<DependenciesOf<Values[K]>> : never
|
|
4527
5065
|
}[keyof Values]
|
|
@@ -4535,6 +5073,59 @@ type NestedMutationRequiredFromValues<Values> =
|
|
|
4535
5073
|
}[keyof Values]
|
|
4536
5074
|
: never
|
|
4537
5075
|
|
|
5076
|
+
type NestedMutationDialectFromValues<
|
|
5077
|
+
Values,
|
|
5078
|
+
Dialect extends string,
|
|
5079
|
+
TextDb extends Expression.DbType.Any,
|
|
5080
|
+
NumericDb extends Expression.DbType.Any,
|
|
5081
|
+
BoolDb extends Expression.DbType.Any,
|
|
5082
|
+
TimestampDb extends Expression.DbType.Any,
|
|
5083
|
+
NullDb extends Expression.DbType.Any
|
|
5084
|
+
> =
|
|
5085
|
+
Values extends ExpressionInput
|
|
5086
|
+
? DialectOfDialectInput<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
5087
|
+
: Values extends Record<string, unknown>
|
|
5088
|
+
? {
|
|
5089
|
+
[K in keyof Values]: NestedMutationDialectFromValues<Values[K], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
5090
|
+
}[keyof Values]
|
|
5091
|
+
: never
|
|
5092
|
+
|
|
5093
|
+
type KnownMutationDialectFromValues<
|
|
5094
|
+
Values,
|
|
5095
|
+
Dialect extends string,
|
|
5096
|
+
TextDb extends Expression.DbType.Any,
|
|
5097
|
+
NumericDb extends Expression.DbType.Any,
|
|
5098
|
+
BoolDb extends Expression.DbType.Any,
|
|
5099
|
+
TimestampDb extends Expression.DbType.Any,
|
|
5100
|
+
NullDb extends Expression.DbType.Any
|
|
5101
|
+
> = NestedMutationDialectFromValues<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> extends infer Current
|
|
5102
|
+
? Current extends string
|
|
5103
|
+
? string extends Current ? never : Current
|
|
5104
|
+
: never
|
|
5105
|
+
: never
|
|
5106
|
+
|
|
5107
|
+
type KnownIncompatibleMutationDialectFromValues<
|
|
5108
|
+
Values,
|
|
5109
|
+
Dialect extends string,
|
|
5110
|
+
TextDb extends Expression.DbType.Any,
|
|
5111
|
+
NumericDb extends Expression.DbType.Any,
|
|
5112
|
+
BoolDb extends Expression.DbType.Any,
|
|
5113
|
+
TimestampDb extends Expression.DbType.Any,
|
|
5114
|
+
NullDb extends Expression.DbType.Any
|
|
5115
|
+
> = Exclude<KnownMutationDialectFromValues<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>, Dialect>
|
|
5116
|
+
|
|
5117
|
+
type MutationValuesDialectConstraint<
|
|
5118
|
+
Values,
|
|
5119
|
+
Dialect extends string,
|
|
5120
|
+
TextDb extends Expression.DbType.Any,
|
|
5121
|
+
NumericDb extends Expression.DbType.Any,
|
|
5122
|
+
BoolDb extends Expression.DbType.Any,
|
|
5123
|
+
TimestampDb extends Expression.DbType.Any,
|
|
5124
|
+
NullDb extends Expression.DbType.Any
|
|
5125
|
+
> = KnownIncompatibleMutationDialectFromValues<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> extends never
|
|
5126
|
+
? unknown
|
|
5127
|
+
: never
|
|
5128
|
+
|
|
4538
5129
|
type MutationAssignments<Shape extends Record<string, unknown>> = {
|
|
4539
5130
|
readonly [K in keyof Shape]: QueryAst.AssignmentClause
|
|
4540
5131
|
}
|
|
@@ -4568,12 +5159,38 @@ type InsertDirectSource =
|
|
|
4568
5159
|
|
|
4569
5160
|
type FromInput = SourceLike | InsertDirectSource
|
|
4570
5161
|
|
|
5162
|
+
type SourceDialectConstraint<
|
|
5163
|
+
CurrentSource extends SourceLike,
|
|
5164
|
+
Dialect extends string
|
|
5165
|
+
> = [SourceDialectOf<CurrentSource>] extends [never]
|
|
5166
|
+
? unknown
|
|
5167
|
+
: Extract<SourceDialectOf<CurrentSource>, Dialect> extends never
|
|
5168
|
+
? never
|
|
5169
|
+
: unknown
|
|
5170
|
+
|
|
5171
|
+
type SourceRequirementConstraint<
|
|
5172
|
+
PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>,
|
|
5173
|
+
CurrentSource extends SourceLike
|
|
5174
|
+
> = [SourceRequiredOf<CurrentSource>] extends [never]
|
|
5175
|
+
? unknown
|
|
5176
|
+
: Exclude<SourceRequiredOf<CurrentSource>, ScopedNamesOfPlan<PlanValue>> extends never
|
|
5177
|
+
? unknown
|
|
5178
|
+
: SourceRequirementError<CurrentSource>
|
|
5179
|
+
|
|
4571
5180
|
type SelectFromConstraint<
|
|
4572
5181
|
PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>,
|
|
4573
5182
|
CurrentSource extends SourceLike
|
|
4574
5183
|
> =
|
|
4575
5184
|
RequireSelectStatement<PlanValue> &
|
|
4576
|
-
(
|
|
5185
|
+
(
|
|
5186
|
+
SourceNameOf<CurrentSource> extends OutstandingOfPlan<PlanValue>
|
|
5187
|
+
? unknown
|
|
5188
|
+
: [OutstandingOfPlan<PlanValue>] extends [never]
|
|
5189
|
+
? [ScopedNamesOfPlan<PlanValue>] extends [never]
|
|
5190
|
+
? unknown
|
|
5191
|
+
: never
|
|
5192
|
+
: never
|
|
5193
|
+
) &
|
|
4577
5194
|
(SourceRequiredOf<CurrentSource> extends never ? unknown : SourceRequirementError<CurrentSource>)
|
|
4578
5195
|
|
|
4579
5196
|
type UpdateFromConstraint<
|
|
@@ -4590,7 +5207,7 @@ type InsertFromConstraint<
|
|
|
4590
5207
|
Dialect extends string
|
|
4591
5208
|
> =
|
|
4592
5209
|
RequirePendingInsertStatement<PlanValue> &
|
|
4593
|
-
(InsertSourceOfPlanInput<PlanValue, CurrentSource, Dialect>
|
|
5210
|
+
(CurrentSource extends InsertSourceOfPlanInput<PlanValue, CurrentSource, Dialect>
|
|
4594
5211
|
? unknown
|
|
4595
5212
|
: InsertSourceOfPlanInput<PlanValue, CurrentSource, Dialect>)
|
|
4596
5213
|
|
|
@@ -4607,7 +5224,10 @@ type SelectFromResult<
|
|
|
4607
5224
|
Exclude<OutstandingOfPlan<PlanValue>, SourceNameOf<CurrentSource>>,
|
|
4608
5225
|
AssumptionsOfPlan<PlanValue>,
|
|
4609
5226
|
MergeCapabilities<CapabilitiesOfPlan<PlanValue>, SourceCapabilitiesOf<CurrentSource>>,
|
|
4610
|
-
StatementOfPlan<PlanValue
|
|
5227
|
+
StatementOfPlan<PlanValue>,
|
|
5228
|
+
MutationTargetOfPlan<PlanValue>,
|
|
5229
|
+
InsertSourceStateOfPlan<PlanValue>,
|
|
5230
|
+
FactsOfPlan<PlanValue>
|
|
4611
5231
|
>
|
|
4612
5232
|
|
|
4613
5233
|
type UpdateFromResult<
|
|
@@ -4629,7 +5249,10 @@ type UpdateFromResult<
|
|
|
4629
5249
|
Exclude<OutstandingOfPlan<PlanValue>, SourceNameOf<CurrentSource>>,
|
|
4630
5250
|
AssumptionsOfPlan<PlanValue>,
|
|
4631
5251
|
MergeCapabilities<CapabilitiesOfPlan<PlanValue>, SourceCapabilitiesOf<CurrentSource>>,
|
|
4632
|
-
StatementOfPlan<PlanValue
|
|
5252
|
+
StatementOfPlan<PlanValue>,
|
|
5253
|
+
MutationTargetOfPlan<PlanValue>,
|
|
5254
|
+
InsertSourceStateOfPlan<PlanValue>,
|
|
5255
|
+
FactsOfPlan<PlanValue>
|
|
4633
5256
|
>
|
|
4634
5257
|
|
|
4635
5258
|
type InsertFromResult<
|
|
@@ -4638,19 +5261,20 @@ type InsertFromResult<
|
|
|
4638
5261
|
Dialect extends string
|
|
4639
5262
|
> = QueryPlan<
|
|
4640
5263
|
SelectionOfPlan<PlanValue>,
|
|
4641
|
-
|
|
5264
|
+
InsertSourceRequired<CurrentSource>,
|
|
4642
5265
|
AvailableOfPlan<PlanValue>,
|
|
4643
|
-
PlanDialectOf<PlanValue>,
|
|
5266
|
+
PlanDialectOf<PlanValue> | InsertSourceDialect<CurrentSource>,
|
|
4644
5267
|
GroupedOfPlan<PlanValue>,
|
|
4645
5268
|
ScopedNamesOfPlan<PlanValue>,
|
|
4646
|
-
|
|
5269
|
+
InsertSourceRequired<CurrentSource>,
|
|
4647
5270
|
AssumptionsOfPlan<PlanValue>,
|
|
4648
5271
|
CurrentSource extends QueryPlan<any, any, any, any, any, any, any, any, any, any>
|
|
4649
5272
|
? MergeCapabilities<CapabilitiesOfPlan<PlanValue>, CapabilitiesOfPlan<CurrentSource>>
|
|
4650
5273
|
: CapabilitiesOfPlan<PlanValue>,
|
|
4651
5274
|
StatementOfPlan<PlanValue>,
|
|
4652
5275
|
MutationTargetOfPlan<PlanValue>,
|
|
4653
|
-
"ready"
|
|
5276
|
+
"ready",
|
|
5277
|
+
FactsOfPlan<PlanValue>
|
|
4654
5278
|
>
|
|
4655
5279
|
|
|
4656
5280
|
type FromPlanConstraint<
|
|
@@ -4659,15 +5283,17 @@ type FromPlanConstraint<
|
|
|
4659
5283
|
Dialect extends string
|
|
4660
5284
|
> =
|
|
4661
5285
|
CurrentSource extends SourceLike
|
|
4662
|
-
?
|
|
4663
|
-
|
|
4664
|
-
|
|
4665
|
-
|
|
4666
|
-
|
|
4667
|
-
|
|
4668
|
-
|
|
4669
|
-
|
|
4670
|
-
|
|
5286
|
+
? SourceDialectConstraint<CurrentSource, Dialect> & (
|
|
5287
|
+
StatementOfPlan<PlanValue> extends "select"
|
|
5288
|
+
? SelectFromConstraint<PlanValue, CurrentSource>
|
|
5289
|
+
: StatementOfPlan<PlanValue> extends "update"
|
|
5290
|
+
? UpdateFromConstraint<PlanValue, CurrentSource>
|
|
5291
|
+
: StatementOfPlan<PlanValue> extends "insert"
|
|
5292
|
+
? CurrentSource extends AnyValuesSource | AnyUnnestSource
|
|
5293
|
+
? InsertFromConstraint<PlanValue, CurrentSource, Dialect>
|
|
5294
|
+
: never
|
|
5295
|
+
: never
|
|
5296
|
+
)
|
|
4671
5297
|
: CurrentSource extends InsertDirectSource
|
|
4672
5298
|
? StatementOfPlan<PlanValue> extends "insert"
|
|
4673
5299
|
? InsertFromConstraint<PlanValue, CurrentSource, Dialect>
|
|
@@ -4722,7 +5348,10 @@ export type PublicStructuredFromResult<
|
|
|
4722
5348
|
Exclude<OutstandingOfPlan<PlanValue>, SourceNameOf<CurrentSource>>,
|
|
4723
5349
|
AssumptionsOfPlan<PlanValue>,
|
|
4724
5350
|
MergeCapabilities<CapabilitiesOfPlan<PlanValue>, SourceCapabilitiesOf<CurrentSource>>,
|
|
4725
|
-
StatementOfPlan<PlanValue
|
|
5351
|
+
StatementOfPlan<PlanValue>,
|
|
5352
|
+
MutationTargetOfPlan<PlanValue>,
|
|
5353
|
+
InsertSourceStateOfPlan<PlanValue>,
|
|
5354
|
+
FactsOfPlan<PlanValue>
|
|
4726
5355
|
>
|
|
4727
5356
|
: StatementOfPlan<PlanValue> extends "update"
|
|
4728
5357
|
? QueryPlan<
|
|
@@ -4735,7 +5364,10 @@ export type PublicStructuredFromResult<
|
|
|
4735
5364
|
Exclude<OutstandingOfPlan<PlanValue>, SourceNameOf<CurrentSource>>,
|
|
4736
5365
|
AssumptionsOfPlan<PlanValue>,
|
|
4737
5366
|
MergeCapabilities<CapabilitiesOfPlan<PlanValue>, SourceCapabilitiesOf<CurrentSource>>,
|
|
4738
|
-
StatementOfPlan<PlanValue
|
|
5367
|
+
StatementOfPlan<PlanValue>,
|
|
5368
|
+
MutationTargetOfPlan<PlanValue>,
|
|
5369
|
+
InsertSourceStateOfPlan<PlanValue>,
|
|
5370
|
+
FactsOfPlan<PlanValue>
|
|
4739
5371
|
>
|
|
4740
5372
|
: StatementOfPlan<PlanValue> extends "insert"
|
|
4741
5373
|
? CurrentSource extends AnyValuesSource | AnyUnnestSource
|
|
@@ -4743,7 +5375,7 @@ export type PublicStructuredFromResult<
|
|
|
4743
5375
|
SelectionOfPlan<PlanValue>,
|
|
4744
5376
|
never,
|
|
4745
5377
|
AvailableOfPlan<PlanValue>,
|
|
4746
|
-
PlanDialectOf<PlanValue>,
|
|
5378
|
+
PlanDialectOf<PlanValue> | SourceDialectOf<CurrentSource>,
|
|
4747
5379
|
GroupedOfPlan<PlanValue>,
|
|
4748
5380
|
ScopedNamesOfPlan<PlanValue>,
|
|
4749
5381
|
never,
|
|
@@ -4751,7 +5383,8 @@ export type PublicStructuredFromResult<
|
|
|
4751
5383
|
CapabilitiesOfPlan<PlanValue>,
|
|
4752
5384
|
StatementOfPlan<PlanValue>,
|
|
4753
5385
|
MutationTargetOfPlan<PlanValue>,
|
|
4754
|
-
"ready"
|
|
5386
|
+
"ready",
|
|
5387
|
+
FactsOfPlan<PlanValue>
|
|
4755
5388
|
>
|
|
4756
5389
|
: FromPlanResult<PlanValue, CurrentSource, Dialect>
|
|
4757
5390
|
: FromPlanResult<PlanValue, CurrentSource, Dialect>
|
|
@@ -4807,20 +5440,20 @@ type AsCurriedResult<
|
|
|
4807
5440
|
>(
|
|
4808
5441
|
value: Value,
|
|
4809
5442
|
alias: Alias
|
|
4810
|
-
): DialectAsExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
5443
|
+
): ProjectionAliasedExpression<DialectAsExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>, Alias>
|
|
4811
5444
|
function as<
|
|
4812
5445
|
Rows extends ValuesRowsInput,
|
|
4813
5446
|
Alias extends string
|
|
4814
5447
|
>(
|
|
4815
5448
|
value: ValuesInput<
|
|
4816
5449
|
Rows,
|
|
4817
|
-
ValuesOutputShape<Rows
|
|
5450
|
+
ValuesOutputShape<Rows, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
4818
5451
|
Dialect
|
|
4819
5452
|
>,
|
|
4820
5453
|
alias: Alias
|
|
4821
5454
|
): ValuesSource<
|
|
4822
5455
|
Rows,
|
|
4823
|
-
ValuesOutputShape<Rows
|
|
5456
|
+
ValuesOutputShape<Rows, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
4824
5457
|
Alias,
|
|
4825
5458
|
Dialect
|
|
4826
5459
|
>
|
|
@@ -4828,7 +5461,7 @@ type AsCurriedResult<
|
|
|
4828
5461
|
PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>,
|
|
4829
5462
|
Alias extends string
|
|
4830
5463
|
>(
|
|
4831
|
-
value:
|
|
5464
|
+
value: DerivedTableCompatiblePlan<PlanValue>,
|
|
4832
5465
|
alias: Alias
|
|
4833
5466
|
): DerivedSource<PlanValue, Alias>
|
|
4834
5467
|
function as(valueOrAlias: unknown, alias?: string): unknown {
|
|
@@ -4875,13 +5508,13 @@ type AsCurriedResult<
|
|
|
4875
5508
|
>(
|
|
4876
5509
|
alias: Alias
|
|
4877
5510
|
): <PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
|
|
4878
|
-
value:
|
|
5511
|
+
value: MysqlCteCompatiblePlan<PlanValue>
|
|
4879
5512
|
) => import("../../internal/query.js").CteSource<PlanValue, Alias>
|
|
4880
5513
|
function with_<
|
|
4881
5514
|
PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>,
|
|
4882
5515
|
Alias extends string
|
|
4883
5516
|
>(
|
|
4884
|
-
value:
|
|
5517
|
+
value: MysqlCteCompatiblePlan<PlanValue>,
|
|
4885
5518
|
alias: Alias
|
|
4886
5519
|
): import("../../internal/query.js").CteSource<PlanValue, Alias>
|
|
4887
5520
|
function with_(valueOrAlias: unknown, alias?: string): unknown {
|
|
@@ -4899,13 +5532,13 @@ type AsCurriedResult<
|
|
|
4899
5532
|
>(
|
|
4900
5533
|
alias: Alias
|
|
4901
5534
|
): <PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
|
|
4902
|
-
value:
|
|
5535
|
+
value: MysqlCteCompatiblePlan<PlanValue>
|
|
4903
5536
|
) => import("../../internal/query.js").CteSource<PlanValue, Alias>
|
|
4904
5537
|
function withRecursive_<
|
|
4905
5538
|
PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>,
|
|
4906
5539
|
Alias extends string
|
|
4907
5540
|
>(
|
|
4908
|
-
value:
|
|
5541
|
+
value: MysqlCteCompatiblePlan<PlanValue>,
|
|
4909
5542
|
alias: Alias
|
|
4910
5543
|
): import("../../internal/query.js").CteSource<PlanValue, Alias>
|
|
4911
5544
|
function withRecursive_(valueOrAlias: unknown, alias?: string): unknown {
|
|
@@ -4924,13 +5557,13 @@ type AsCurriedResult<
|
|
|
4924
5557
|
>(
|
|
4925
5558
|
alias: Alias
|
|
4926
5559
|
): <PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
|
|
4927
|
-
value: PlanValue
|
|
5560
|
+
value: LateralSourceCompatiblePlan<PlanValue>
|
|
4928
5561
|
) => import("../../internal/query.js").LateralSource<PlanValue, Alias>
|
|
4929
5562
|
function lateral<
|
|
4930
5563
|
PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>,
|
|
4931
5564
|
Alias extends string
|
|
4932
5565
|
>(
|
|
4933
|
-
value: PlanValue
|
|
5566
|
+
value: LateralSourceCompatiblePlan<PlanValue>,
|
|
4934
5567
|
alias: Alias
|
|
4935
5568
|
): import("../../internal/query.js").LateralSource<PlanValue, Alias>
|
|
4936
5569
|
function lateral(valueOrAlias: unknown, alias?: string): unknown {
|
|
@@ -4947,9 +5580,11 @@ type AsCurriedResult<
|
|
|
4947
5580
|
Rows extends ValuesRowsInput
|
|
4948
5581
|
>(
|
|
4949
5582
|
rows: Rows
|
|
5583
|
+
& ValuesRowsShapeInput<Rows>
|
|
5584
|
+
& ValuesRowsDialectInput<Rows, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
4950
5585
|
) => ValuesInput<
|
|
4951
5586
|
Rows,
|
|
4952
|
-
ValuesOutputShape<Rows
|
|
5587
|
+
ValuesOutputShape<Rows, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
4953
5588
|
Dialect
|
|
4954
5589
|
>
|
|
4955
5590
|
|
|
@@ -4957,7 +5592,9 @@ type AsCurriedResult<
|
|
|
4957
5592
|
Columns extends UnnestColumnsInput,
|
|
4958
5593
|
Alias extends string
|
|
4959
5594
|
>(
|
|
4960
|
-
columns: Columns
|
|
5595
|
+
columns: Columns
|
|
5596
|
+
& UnnestColumnsShapeInput<Columns>
|
|
5597
|
+
& UnnestColumnsDialectInput<Columns, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
4961
5598
|
alias: Alias
|
|
4962
5599
|
) => UnnestSource<
|
|
4963
5600
|
UnnestOutputShape<Columns, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
@@ -4971,9 +5608,9 @@ type AsCurriedResult<
|
|
|
4971
5608
|
Step extends NumericExpressionInput | undefined = undefined,
|
|
4972
5609
|
Alias extends string = "series"
|
|
4973
5610
|
>(
|
|
4974
|
-
start: Start,
|
|
4975
|
-
stop: Stop,
|
|
4976
|
-
step?: Step,
|
|
5611
|
+
start: Start & NumericExpressionDialectInput<Start, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5612
|
+
stop: Stop & NumericExpressionDialectInput<Stop, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5613
|
+
step?: Step & (Step extends NumericExpressionInput ? NumericExpressionDialectInput<Step, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> : unknown),
|
|
4977
5614
|
alias?: Alias
|
|
4978
5615
|
) => Dialect extends "postgres"
|
|
4979
5616
|
? TableFunctionSource<
|
|
@@ -4984,8 +5621,45 @@ type AsCurriedResult<
|
|
|
4984
5621
|
>
|
|
4985
5622
|
: GenerateSeriesUnsupportedError<Dialect>
|
|
4986
5623
|
|
|
5624
|
+
type SelectSelectionNonEmptyError<Selection> = Selection & {
|
|
5625
|
+
readonly __effect_qb_error__: "effect-qb: mysql select statements require at least one selected expression"
|
|
5626
|
+
}
|
|
5627
|
+
|
|
5628
|
+
type SelectionRootObjectError<Selection> = Selection & {
|
|
5629
|
+
readonly __effect_qb_error__: "effect-qb: selections must be projection objects"
|
|
5630
|
+
readonly __effect_qb_hint__: "Use select({ value: expression }) or returning({ value: expression })"
|
|
5631
|
+
}
|
|
5632
|
+
|
|
5633
|
+
type SelectionRootObjectConstraint<Selection> =
|
|
5634
|
+
Selection extends Expression.Any ? SelectionRootObjectError<Selection> : unknown
|
|
5635
|
+
|
|
5636
|
+
type SelectionNestedEmptyError<Selection> = Selection & {
|
|
5637
|
+
readonly __effect_qb_error__: "effect-qb: projection objects cannot contain empty nested selections"
|
|
5638
|
+
}
|
|
5639
|
+
|
|
5640
|
+
type SelectionHasEmptyNestedObject<Selection, IsRoot extends boolean> =
|
|
5641
|
+
Selection extends Expression.Any
|
|
5642
|
+
? false
|
|
5643
|
+
: Selection extends Record<string, any>
|
|
5644
|
+
? [Extract<keyof Selection, string>] extends [never]
|
|
5645
|
+
? IsRoot extends true ? false : true
|
|
5646
|
+
: true extends {
|
|
5647
|
+
[K in Extract<keyof Selection, string>]: SelectionHasEmptyNestedObject<Selection[K], false>
|
|
5648
|
+
}[Extract<keyof Selection, string>]
|
|
5649
|
+
? true
|
|
5650
|
+
: false
|
|
5651
|
+
: false
|
|
5652
|
+
|
|
5653
|
+
type SelectionNestedNonEmptyConstraint<Selection> =
|
|
5654
|
+
SelectionHasEmptyNestedObject<Selection, true> extends true ? SelectionNestedEmptyError<Selection> : unknown
|
|
5655
|
+
|
|
5656
|
+
type SelectSelectionNonEmptyConstraint<Selection> =
|
|
5657
|
+
[Extract<keyof Selection, string>] extends [never]
|
|
5658
|
+
? SelectSelectionNonEmptyError<Selection>
|
|
5659
|
+
: unknown
|
|
5660
|
+
|
|
4987
5661
|
export type SelectApi = <Selection extends SelectionShape>(
|
|
4988
|
-
selection: Selection
|
|
5662
|
+
selection: Selection & SelectionRootObjectConstraint<Selection> & SelectionNestedNonEmptyConstraint<Selection> & SelectSelectionNonEmptyConstraint<Selection>
|
|
4989
5663
|
) => QueryPlan<
|
|
4990
5664
|
Selection,
|
|
4991
5665
|
ExtractRequired<Selection>,
|
|
@@ -4996,7 +5670,10 @@ type AsCurriedResult<
|
|
|
4996
5670
|
ExtractRequired<Selection>,
|
|
4997
5671
|
TrueFormula,
|
|
4998
5672
|
"read",
|
|
4999
|
-
"select"
|
|
5673
|
+
"select",
|
|
5674
|
+
any,
|
|
5675
|
+
"ready",
|
|
5676
|
+
EmptyFacts
|
|
5000
5677
|
>
|
|
5001
5678
|
|
|
5002
5679
|
const {
|
|
@@ -5019,7 +5696,7 @@ type AsCurriedResult<
|
|
|
5019
5696
|
getQueryState,
|
|
5020
5697
|
currentRequiredList,
|
|
5021
5698
|
dedupeGroupedExpressions
|
|
5022
|
-
}) as {
|
|
5699
|
+
}) as unknown as {
|
|
5023
5700
|
readonly values: ValuesApi
|
|
5024
5701
|
readonly unnest: UnnestApi
|
|
5025
5702
|
readonly generateSeries: GenerateSeriesApi
|
|
@@ -5041,7 +5718,10 @@ type AsCurriedResult<
|
|
|
5041
5718
|
never,
|
|
5042
5719
|
TrueFormula,
|
|
5043
5720
|
CapabilitiesOfPlan<LeftPlanValue> | CapabilitiesOfPlan<RightPlanValue>,
|
|
5044
|
-
"set"
|
|
5721
|
+
"set",
|
|
5722
|
+
any,
|
|
5723
|
+
"ready",
|
|
5724
|
+
CommonSetFacts<LeftPlanValue, RightPlanValue>
|
|
5045
5725
|
>
|
|
5046
5726
|
|
|
5047
5727
|
type SetOperationApi = <
|
|
@@ -5067,7 +5747,10 @@ type AsCurriedResult<
|
|
|
5067
5747
|
AddExpressionRequired<OutstandingOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, Predicate>,
|
|
5068
5748
|
PlanAssumptionsAfterWhere<PlanValue, Predicate, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5069
5749
|
CapabilitiesOfPlan<PlanValue>,
|
|
5070
|
-
StatementOfPlan<PlanValue
|
|
5750
|
+
StatementOfPlan<PlanValue>,
|
|
5751
|
+
MutationTargetOfPlan<PlanValue>,
|
|
5752
|
+
InsertSourceStateOfPlan<PlanValue>,
|
|
5753
|
+
PlanFactsAfterWhere<PlanValue, Predicate, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
5071
5754
|
>
|
|
5072
5755
|
|
|
5073
5756
|
export type FromApi = <CurrentSource extends FromInput>(
|
|
@@ -5092,7 +5775,10 @@ type AsCurriedResult<
|
|
|
5092
5775
|
AddExpressionRequired<OutstandingOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, Predicate>,
|
|
5093
5776
|
PlanAssumptionsAfterHaving<PlanValue, Predicate, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5094
5777
|
CapabilitiesOfPlan<PlanValue>,
|
|
5095
|
-
StatementOfPlan<PlanValue
|
|
5778
|
+
StatementOfPlan<PlanValue>,
|
|
5779
|
+
MutationTargetOfPlan<PlanValue>,
|
|
5780
|
+
InsertSourceStateOfPlan<PlanValue>,
|
|
5781
|
+
PlanFactsAfterHaving<PlanValue, Predicate, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
5096
5782
|
>
|
|
5097
5783
|
|
|
5098
5784
|
type CrossJoinApi = <CurrentTable extends SourceLike>(
|
|
@@ -5103,10 +5789,10 @@ type AsCurriedResult<
|
|
|
5103
5789
|
keyof AvailableOfPlan<PlanValue> extends never ? never : unknown
|
|
5104
5790
|
) & (
|
|
5105
5791
|
SourceNameOf<CurrentTable> extends ScopedNamesOfPlan<PlanValue> ? never : unknown
|
|
5106
|
-
)
|
|
5792
|
+
) & SourceRequirementConstraint<PlanValue, CurrentTable> & SourceDialectConstraint<CurrentTable, Dialect>
|
|
5107
5793
|
) => QueryPlan<
|
|
5108
5794
|
SelectionOfPlan<PlanValue>,
|
|
5109
|
-
AddJoinRequired<RequiredOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, never, "cross"
|
|
5795
|
+
AddJoinRequired<RequiredOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, never, "cross", SourceRequiredOf<CurrentTable>>,
|
|
5110
5796
|
AddAvailable<
|
|
5111
5797
|
AvailableOfPlan<PlanValue>,
|
|
5112
5798
|
SourceNameOf<CurrentTable>,
|
|
@@ -5117,10 +5803,13 @@ type AsCurriedResult<
|
|
|
5117
5803
|
PlanDialectOf<PlanValue> | SourceDialectOf<CurrentTable>,
|
|
5118
5804
|
GroupedOfPlan<PlanValue>,
|
|
5119
5805
|
ScopedNamesOfPlan<PlanValue> | SourceNameOf<CurrentTable>,
|
|
5120
|
-
AddJoinRequired<OutstandingOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, never, "cross"
|
|
5806
|
+
AddJoinRequired<OutstandingOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, never, "cross", SourceRequiredOf<CurrentTable>>,
|
|
5121
5807
|
AssumptionsOfPlan<PlanValue>,
|
|
5122
5808
|
MergeCapabilities<CapabilitiesOfPlan<PlanValue>, SourceCapabilitiesOf<CurrentTable>>,
|
|
5123
|
-
StatementOfPlan<PlanValue
|
|
5809
|
+
StatementOfPlan<PlanValue>,
|
|
5810
|
+
MutationTargetOfPlan<PlanValue>,
|
|
5811
|
+
InsertSourceStateOfPlan<PlanValue>,
|
|
5812
|
+
FactsOfPlan<PlanValue>
|
|
5124
5813
|
>
|
|
5125
5814
|
|
|
5126
5815
|
type JoinApi = <
|
|
@@ -5137,10 +5826,10 @@ type AsCurriedResult<
|
|
|
5137
5826
|
keyof AvailableOfPlan<PlanValue> extends never ? never : unknown
|
|
5138
5827
|
) & (
|
|
5139
5828
|
SourceNameOf<CurrentTable> extends ScopedNamesOfPlan<PlanValue> ? never : unknown
|
|
5140
|
-
)
|
|
5829
|
+
) & SourceRequirementConstraint<PlanValue, CurrentTable> & SourceDialectConstraint<CurrentTable, Dialect>
|
|
5141
5830
|
) => QueryPlan<
|
|
5142
5831
|
SelectionOfPlan<PlanValue>,
|
|
5143
|
-
AddJoinRequired<RequiredOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, Predicate, Kind
|
|
5832
|
+
AddJoinRequired<RequiredOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, Predicate, Kind, SourceRequiredOf<CurrentTable>>,
|
|
5144
5833
|
AvailableAfterJoin<
|
|
5145
5834
|
AvailableOfPlan<PlanValue>,
|
|
5146
5835
|
SourceNameOf<CurrentTable>,
|
|
@@ -5151,10 +5840,13 @@ type AsCurriedResult<
|
|
|
5151
5840
|
PlanDialectOf<PlanValue> | SourceDialectOf<CurrentTable> | DialectOfDialectInput<Predicate, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5152
5841
|
GroupedOfPlan<PlanValue>,
|
|
5153
5842
|
ScopedNamesOfPlan<PlanValue> | SourceNameOf<CurrentTable>,
|
|
5154
|
-
AddJoinRequired<OutstandingOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, Predicate, Kind
|
|
5843
|
+
AddJoinRequired<OutstandingOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, Predicate, Kind, SourceRequiredOf<CurrentTable>>,
|
|
5155
5844
|
PlanAssumptionsAfterJoin<PlanValue, Predicate, Kind, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5156
5845
|
MergeCapabilities<CapabilitiesOfPlan<PlanValue>, SourceCapabilitiesOf<CurrentTable>>,
|
|
5157
|
-
StatementOfPlan<PlanValue
|
|
5846
|
+
StatementOfPlan<PlanValue>,
|
|
5847
|
+
MutationTargetOfPlan<PlanValue>,
|
|
5848
|
+
InsertSourceStateOfPlan<PlanValue>,
|
|
5849
|
+
PlanFactsAfterJoin<PlanValue, Predicate, Kind, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
5158
5850
|
>
|
|
5159
5851
|
|
|
5160
5852
|
type BinaryJoinApi<Kind extends QueryAst.JoinKind> = <
|
|
@@ -5169,10 +5861,10 @@ type AsCurriedResult<
|
|
|
5169
5861
|
keyof AvailableOfPlan<PlanValue> extends never ? never : unknown
|
|
5170
5862
|
) & (
|
|
5171
5863
|
SourceNameOf<CurrentTable> extends ScopedNamesOfPlan<PlanValue> ? never : unknown
|
|
5172
|
-
)
|
|
5864
|
+
) & SourceRequirementConstraint<PlanValue, CurrentTable> & SourceDialectConstraint<CurrentTable, Dialect>
|
|
5173
5865
|
) => QueryPlan<
|
|
5174
5866
|
SelectionOfPlan<PlanValue>,
|
|
5175
|
-
AddJoinRequired<RequiredOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, Predicate, Kind
|
|
5867
|
+
AddJoinRequired<RequiredOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, Predicate, Kind, SourceRequiredOf<CurrentTable>>,
|
|
5176
5868
|
AvailableAfterJoin<
|
|
5177
5869
|
AvailableOfPlan<PlanValue>,
|
|
5178
5870
|
SourceNameOf<CurrentTable>,
|
|
@@ -5183,12 +5875,17 @@ type AsCurriedResult<
|
|
|
5183
5875
|
PlanDialectOf<PlanValue> | SourceDialectOf<CurrentTable> | DialectOfDialectInput<Predicate, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5184
5876
|
GroupedOfPlan<PlanValue>,
|
|
5185
5877
|
ScopedNamesOfPlan<PlanValue> | SourceNameOf<CurrentTable>,
|
|
5186
|
-
AddJoinRequired<OutstandingOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, Predicate, Kind
|
|
5878
|
+
AddJoinRequired<OutstandingOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, Predicate, Kind, SourceRequiredOf<CurrentTable>>,
|
|
5187
5879
|
PlanAssumptionsAfterJoin<PlanValue, Predicate, Kind, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5188
5880
|
MergeCapabilities<CapabilitiesOfPlan<PlanValue>, SourceCapabilitiesOf<CurrentTable>>,
|
|
5189
|
-
StatementOfPlan<PlanValue
|
|
5881
|
+
StatementOfPlan<PlanValue>,
|
|
5882
|
+
MutationTargetOfPlan<PlanValue>,
|
|
5883
|
+
InsertSourceStateOfPlan<PlanValue>,
|
|
5884
|
+
PlanFactsAfterJoin<PlanValue, Predicate, Kind, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
5190
5885
|
>
|
|
5191
5886
|
|
|
5887
|
+
type FullJoinApi = Dialect extends "postgres" ? BinaryJoinApi<"full"> : FullJoinUnsupportedError<Dialect>
|
|
5888
|
+
|
|
5192
5889
|
type OrderByApi = <Value extends ExpressionInput>(
|
|
5193
5890
|
value: Value,
|
|
5194
5891
|
direction?: OrderDirection
|
|
@@ -5205,7 +5902,10 @@ type AsCurriedResult<
|
|
|
5205
5902
|
AddExpressionRequired<OutstandingOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, Value>,
|
|
5206
5903
|
AssumptionsOfPlan<PlanValue>,
|
|
5207
5904
|
CapabilitiesOfPlan<PlanValue>,
|
|
5208
|
-
StatementOfPlan<PlanValue
|
|
5905
|
+
StatementOfPlan<PlanValue>,
|
|
5906
|
+
MutationTargetOfPlan<PlanValue>,
|
|
5907
|
+
InsertSourceStateOfPlan<PlanValue>,
|
|
5908
|
+
FactsOfPlan<PlanValue>
|
|
5209
5909
|
>
|
|
5210
5910
|
|
|
5211
5911
|
interface LockApi {
|
|
@@ -5221,7 +5921,10 @@ type AsCurriedResult<
|
|
|
5221
5921
|
OutstandingOfPlan<PlanValue>,
|
|
5222
5922
|
AssumptionsOfPlan<PlanValue>,
|
|
5223
5923
|
MergeCapabilities<CapabilitiesOfPlan<PlanValue>, "transaction">,
|
|
5224
|
-
StatementOfPlan<PlanValue
|
|
5924
|
+
StatementOfPlan<PlanValue>,
|
|
5925
|
+
MutationTargetOfPlan<PlanValue>,
|
|
5926
|
+
InsertSourceStateOfPlan<PlanValue>,
|
|
5927
|
+
FactsOfPlan<PlanValue>
|
|
5225
5928
|
>
|
|
5226
5929
|
<Mode extends Dialect extends "mysql" ? "lowPriority" | "ignore" | "quick" : never>(
|
|
5227
5930
|
mode: Mode,
|
|
@@ -5246,7 +5949,10 @@ type AsCurriedResult<
|
|
|
5246
5949
|
OutstandingOfPlan<PlanValue>,
|
|
5247
5950
|
AssumptionsOfPlan<PlanValue>,
|
|
5248
5951
|
MergeCapabilities<CapabilitiesOfPlan<PlanValue>, "transaction">,
|
|
5249
|
-
StatementOfPlan<PlanValue
|
|
5952
|
+
StatementOfPlan<PlanValue>,
|
|
5953
|
+
MutationTargetOfPlan<PlanValue>,
|
|
5954
|
+
InsertSourceStateOfPlan<PlanValue>,
|
|
5955
|
+
FactsOfPlan<PlanValue>
|
|
5250
5956
|
>
|
|
5251
5957
|
}
|
|
5252
5958
|
|
|
@@ -5263,7 +5969,10 @@ type AsCurriedResult<
|
|
|
5263
5969
|
OutstandingOfPlan<PlanValue>,
|
|
5264
5970
|
AssumptionsOfPlan<PlanValue>,
|
|
5265
5971
|
CapabilitiesOfPlan<PlanValue>,
|
|
5266
|
-
StatementOfPlan<PlanValue
|
|
5972
|
+
StatementOfPlan<PlanValue>,
|
|
5973
|
+
MutationTargetOfPlan<PlanValue>,
|
|
5974
|
+
InsertSourceStateOfPlan<PlanValue>,
|
|
5975
|
+
FactsOfPlan<PlanValue>
|
|
5267
5976
|
>
|
|
5268
5977
|
|
|
5269
5978
|
type LimitApi = <Value extends NumericExpressionInput>(
|
|
@@ -5281,7 +5990,10 @@ type AsCurriedResult<
|
|
|
5281
5990
|
AddExpressionRequired<OutstandingOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, DialectAsNumericExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
|
|
5282
5991
|
AssumptionsOfPlan<PlanValue>,
|
|
5283
5992
|
CapabilitiesOfPlan<PlanValue>,
|
|
5284
|
-
StatementOfPlan<PlanValue
|
|
5993
|
+
StatementOfPlan<PlanValue>,
|
|
5994
|
+
MutationTargetOfPlan<PlanValue>,
|
|
5995
|
+
InsertSourceStateOfPlan<PlanValue>,
|
|
5996
|
+
FactsOfPlan<PlanValue>
|
|
5285
5997
|
>
|
|
5286
5998
|
|
|
5287
5999
|
type OffsetApi = <Value extends NumericExpressionInput>(
|
|
@@ -5299,7 +6011,10 @@ type AsCurriedResult<
|
|
|
5299
6011
|
AddExpressionRequired<OutstandingOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, DialectAsNumericExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
|
|
5300
6012
|
AssumptionsOfPlan<PlanValue>,
|
|
5301
6013
|
CapabilitiesOfPlan<PlanValue>,
|
|
5302
|
-
StatementOfPlan<PlanValue
|
|
6014
|
+
StatementOfPlan<PlanValue>,
|
|
6015
|
+
MutationTargetOfPlan<PlanValue>,
|
|
6016
|
+
InsertSourceStateOfPlan<PlanValue>,
|
|
6017
|
+
FactsOfPlan<PlanValue>
|
|
5303
6018
|
>
|
|
5304
6019
|
|
|
5305
6020
|
const {
|
|
@@ -5368,7 +6083,7 @@ type AsCurriedResult<
|
|
|
5368
6083
|
|
|
5369
6084
|
const rightJoin = ((table, on) => (join as any)("right", table, on)) as BinaryJoinApi<"right">
|
|
5370
6085
|
|
|
5371
|
-
const fullJoin = ((table, on) => (join as any)("full", table, on)) as
|
|
6086
|
+
const fullJoin = ((table: any, on: any) => (join as any)("full", table, on)) as unknown as FullJoinApi
|
|
5372
6087
|
|
|
5373
6088
|
const distinctOn = {
|
|
5374
6089
|
__effect_qb_error__: "effect-qb: distinctOn(...) is only supported by the postgres dialect",
|
|
@@ -5391,29 +6106,46 @@ type AsCurriedResult<
|
|
|
5391
6106
|
Exclude<OutstandingOfPlan<PlanValue> | RequiredFromDependencies<TupleDependencies<Values>>, AvailableNames<AvailableOfPlan<PlanValue>>>,
|
|
5392
6107
|
AssumptionsOfPlan<PlanValue>,
|
|
5393
6108
|
CapabilitiesOfPlan<PlanValue>,
|
|
5394
|
-
StatementOfPlan<PlanValue>
|
|
5395
|
-
>
|
|
5396
|
-
|
|
5397
|
-
type ReturningApi = <Selection extends SelectionShape>(
|
|
5398
|
-
selection: Selection
|
|
5399
|
-
) =>
|
|
5400
|
-
<PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
|
|
5401
|
-
plan: PlanValue & RequireMutationStatement<PlanValue>
|
|
5402
|
-
) => QueryPlan<
|
|
5403
|
-
Selection,
|
|
5404
|
-
Exclude<RequiredOfPlan<PlanValue> | ExtractRequired<Selection>, AvailableNames<AvailableOfPlan<PlanValue>>>,
|
|
5405
|
-
AvailableOfPlan<PlanValue>,
|
|
5406
|
-
PlanDialectOf<PlanValue> | ExtractDialect<Selection>,
|
|
5407
|
-
GroupedOfPlan<PlanValue>,
|
|
5408
|
-
ScopedNamesOfPlan<PlanValue>,
|
|
5409
|
-
Exclude<OutstandingOfPlan<PlanValue> | ExtractRequired<Selection>, AvailableNames<AvailableOfPlan<PlanValue>>>,
|
|
5410
|
-
AssumptionsOfPlan<PlanValue>,
|
|
5411
|
-
CapabilitiesOfPlan<PlanValue>,
|
|
5412
6109
|
StatementOfPlan<PlanValue>,
|
|
5413
6110
|
MutationTargetOfPlan<PlanValue>,
|
|
5414
|
-
InsertSourceStateOfPlan<PlanValue
|
|
6111
|
+
InsertSourceStateOfPlan<PlanValue>,
|
|
6112
|
+
FactsOfPlan<PlanValue>
|
|
5415
6113
|
>
|
|
5416
6114
|
|
|
6115
|
+
type ReturningSelectionNonEmptyError<Selection> = Selection & {
|
|
6116
|
+
readonly __effect_qb_error__: "effect-qb: returning(...) requires at least one selected expression"
|
|
6117
|
+
}
|
|
6118
|
+
|
|
6119
|
+
type ReturningSelectionNonEmptyConstraint<Selection> =
|
|
6120
|
+
Selection extends Expression.Any
|
|
6121
|
+
? unknown
|
|
6122
|
+
: [Extract<keyof Selection, string>] extends [never]
|
|
6123
|
+
? ReturningSelectionNonEmptyError<Selection>
|
|
6124
|
+
: unknown
|
|
6125
|
+
|
|
6126
|
+
type ReturningApi = Dialect extends "postgres"
|
|
6127
|
+
? <Selection extends SelectionShape>(
|
|
6128
|
+
selection: Selection & SelectionRootObjectConstraint<Selection> & SelectionNestedNonEmptyConstraint<Selection> & ReturningSelectionNonEmptyConstraint<Selection>
|
|
6129
|
+
) =>
|
|
6130
|
+
<PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
|
|
6131
|
+
plan: PlanValue & RequireMutationStatement<PlanValue>
|
|
6132
|
+
) => QueryPlan<
|
|
6133
|
+
Selection,
|
|
6134
|
+
Exclude<RequiredOfPlan<PlanValue> | ExtractRequired<Selection>, AvailableNames<AvailableOfPlan<PlanValue>>>,
|
|
6135
|
+
AvailableOfPlan<PlanValue>,
|
|
6136
|
+
PlanDialectOf<PlanValue> | ExtractDialect<Selection>,
|
|
6137
|
+
GroupedOfPlan<PlanValue>,
|
|
6138
|
+
ScopedNamesOfPlan<PlanValue>,
|
|
6139
|
+
Exclude<OutstandingOfPlan<PlanValue> | ExtractRequired<Selection>, AvailableNames<AvailableOfPlan<PlanValue>>>,
|
|
6140
|
+
AssumptionsOfPlan<PlanValue>,
|
|
6141
|
+
CapabilitiesOfPlan<PlanValue>,
|
|
6142
|
+
StatementOfPlan<PlanValue>,
|
|
6143
|
+
MutationTargetOfPlan<PlanValue>,
|
|
6144
|
+
InsertSourceStateOfPlan<PlanValue>,
|
|
6145
|
+
FactsOfPlan<PlanValue>
|
|
6146
|
+
>
|
|
6147
|
+
: ReturningUnsupportedError<Dialect>
|
|
6148
|
+
|
|
5417
6149
|
export interface InsertApi {
|
|
5418
6150
|
<Target extends MutationTargetLike>(
|
|
5419
6151
|
target: Target
|
|
@@ -5429,16 +6161,17 @@ type AsCurriedResult<
|
|
|
5429
6161
|
"write",
|
|
5430
6162
|
"insert",
|
|
5431
6163
|
Target,
|
|
5432
|
-
"missing"
|
|
6164
|
+
"missing",
|
|
6165
|
+
EmptyFacts
|
|
5433
6166
|
>
|
|
5434
6167
|
<Target extends MutationTargetLike, Values extends Record<string, unknown>>(
|
|
5435
6168
|
target: Target,
|
|
5436
|
-
values: MutationValuesInput<"insert", Target, Values>
|
|
6169
|
+
values: MutationValuesInput<"insert", Target, Values> & MutationValuesDialectConstraint<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
5437
6170
|
): QueryPlan<
|
|
5438
6171
|
{},
|
|
5439
6172
|
Exclude<MutationRequiredFromValues<Values>, SourceNameOf<Target>>,
|
|
5440
6173
|
AddAvailable<{}, SourceNameOf<Target>>,
|
|
5441
|
-
TableDialectOf<Target>,
|
|
6174
|
+
TableDialectOf<Target> | KnownMutationDialectFromValues<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5442
6175
|
never,
|
|
5443
6176
|
SourceNameOf<Target>,
|
|
5444
6177
|
Exclude<MutationRequiredFromValues<Values>, SourceNameOf<Target>>,
|
|
@@ -5446,7 +6179,8 @@ type AsCurriedResult<
|
|
|
5446
6179
|
"write",
|
|
5447
6180
|
"insert",
|
|
5448
6181
|
Target,
|
|
5449
|
-
"ready"
|
|
6182
|
+
"ready",
|
|
6183
|
+
EmptyFacts
|
|
5450
6184
|
>
|
|
5451
6185
|
}
|
|
5452
6186
|
|
|
@@ -5459,58 +6193,66 @@ type AsCurriedResult<
|
|
|
5459
6193
|
Target extends MutationTargetLike,
|
|
5460
6194
|
const Columns extends DdlColumnInput,
|
|
5461
6195
|
UpdateValues extends MutationInputOf<Table.UpdateOf<Target>> | undefined = MutationInputOf<Table.UpdateOf<Target>> | undefined,
|
|
5462
|
-
Options extends ConflictActionInput<Target, Dialect, UpdateValues> = ConflictActionInput<Target, Dialect, UpdateValues
|
|
6196
|
+
Options extends ConflictActionInput<Target, Dialect, UpdateValues> = ConflictActionInput<Target, Dialect, UpdateValues>,
|
|
6197
|
+
ConflictTarget extends ConflictTargetInput<Target, Dialect, Columns> = ConflictTargetInput<Target, Dialect, Columns>
|
|
5463
6198
|
>(
|
|
5464
|
-
target:
|
|
5465
|
-
options?: Options
|
|
6199
|
+
target: ConflictTarget,
|
|
6200
|
+
options?: Options & ConflictActionUpdateNonEmptyConstraint<Options>
|
|
5466
6201
|
) =>
|
|
5467
6202
|
<PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
|
|
5468
6203
|
plan: PlanValue & RequireInsertStatement<PlanValue>
|
|
5469
6204
|
) => QueryPlan<
|
|
5470
6205
|
SelectionOfPlan<PlanValue>,
|
|
5471
|
-
Exclude<RequiredOfPlan<PlanValue> |
|
|
6206
|
+
Exclude<RequiredOfPlan<PlanValue> | ConflictRequired<UpdateValues, Options, ConflictTarget>, AvailableNames<AvailableOfPlan<PlanValue>>>,
|
|
5472
6207
|
AvailableOfPlan<PlanValue>,
|
|
5473
|
-
PlanDialectOf<PlanValue>,
|
|
6208
|
+
PlanDialectOf<PlanValue> | ConflictDialect<UpdateValues, Options, ConflictTarget, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5474
6209
|
GroupedOfPlan<PlanValue>,
|
|
5475
6210
|
ScopedNamesOfPlan<PlanValue>,
|
|
5476
|
-
Exclude<OutstandingOfPlan<PlanValue> |
|
|
6211
|
+
Exclude<OutstandingOfPlan<PlanValue> | ConflictRequired<UpdateValues, Options, ConflictTarget>, AvailableNames<AvailableOfPlan<PlanValue>>>,
|
|
5477
6212
|
AssumptionsOfPlan<PlanValue>,
|
|
5478
6213
|
CapabilitiesOfPlan<PlanValue>,
|
|
5479
6214
|
StatementOfPlan<PlanValue>,
|
|
5480
6215
|
MutationTargetOfPlan<PlanValue>,
|
|
5481
|
-
InsertSourceStateOfPlan<PlanValue
|
|
6216
|
+
InsertSourceStateOfPlan<PlanValue>,
|
|
6217
|
+
FactsOfPlan<PlanValue>
|
|
5482
6218
|
>
|
|
5483
6219
|
|
|
5484
6220
|
interface UpdateApi {
|
|
5485
6221
|
<Targets extends MutationTargetTuple, Values extends UpdateInputOfTarget<Targets>>(
|
|
5486
|
-
target: Dialect extends "mysql" ? Targets : never,
|
|
5487
|
-
values: Values
|
|
6222
|
+
target: Dialect extends "mysql" ? Targets & MutationTargetTupleDialectConstraint<Targets, Dialect> & MutationTargetTupleUniqueNamesConstraint<Targets> : never,
|
|
6223
|
+
values: Values & NestedUpdateValuesNonEmptyConstraint<Values> & MutationValuesDialectConstraint<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
5488
6224
|
): QueryPlan<
|
|
5489
6225
|
{},
|
|
5490
6226
|
Exclude<NestedMutationRequiredFromValues<Values>, MutationTargetNamesOf<Targets>>,
|
|
5491
6227
|
AddAvailableMany<{}, MutationTargetNamesOf<Targets>>,
|
|
5492
|
-
TableDialectOf<Targets[0]>,
|
|
6228
|
+
TableDialectOf<Targets[0]> | KnownMutationDialectFromValues<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5493
6229
|
never,
|
|
5494
6230
|
MutationTargetNamesOf<Targets>,
|
|
5495
6231
|
Exclude<NestedMutationRequiredFromValues<Values>, MutationTargetNamesOf<Targets>>,
|
|
5496
6232
|
TrueFormula,
|
|
5497
6233
|
"write",
|
|
5498
|
-
"update"
|
|
6234
|
+
"update",
|
|
6235
|
+
any,
|
|
6236
|
+
"ready",
|
|
6237
|
+
EmptyFacts
|
|
5499
6238
|
>
|
|
5500
6239
|
<Target extends MutationTargetLike, Values extends Record<string, unknown>>(
|
|
5501
6240
|
target: Target,
|
|
5502
|
-
values: MutationValuesInput<"update", Target, Values>
|
|
6241
|
+
values: MutationValuesInput<"update", Target, Values> & UpdateValuesNonEmptyConstraint<Values> & MutationValuesDialectConstraint<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
5503
6242
|
): QueryPlan<
|
|
5504
6243
|
{},
|
|
5505
6244
|
Exclude<MutationRequiredFromValues<Values>, SourceNameOf<Target>>,
|
|
5506
6245
|
AddAvailable<{}, SourceNameOf<Target>>,
|
|
5507
|
-
TableDialectOf<Target>,
|
|
6246
|
+
TableDialectOf<Target> | KnownMutationDialectFromValues<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5508
6247
|
never,
|
|
5509
6248
|
SourceNameOf<Target>,
|
|
5510
6249
|
Exclude<MutationRequiredFromValues<Values>, SourceNameOf<Target>>,
|
|
5511
6250
|
TrueFormula,
|
|
5512
6251
|
"write",
|
|
5513
|
-
"update"
|
|
6252
|
+
"update",
|
|
6253
|
+
any,
|
|
6254
|
+
"ready",
|
|
6255
|
+
EmptyFacts
|
|
5514
6256
|
>
|
|
5515
6257
|
}
|
|
5516
6258
|
|
|
@@ -5518,25 +6260,28 @@ type AsCurriedResult<
|
|
|
5518
6260
|
Target extends MutationTargetLike,
|
|
5519
6261
|
Values extends MutationInputOf<Table.InsertOf<Target>>,
|
|
5520
6262
|
const Columns extends DdlColumnInput,
|
|
5521
|
-
UpdateValues extends MutationInputOf<Table.UpdateOf<Target>>
|
|
6263
|
+
UpdateValues extends MutationInputOf<Table.UpdateOf<Target>> | undefined = undefined
|
|
5522
6264
|
>(
|
|
5523
6265
|
target: Target,
|
|
5524
|
-
values: Values,
|
|
5525
|
-
conflictColumns:
|
|
5526
|
-
updateValues?: UpdateValues
|
|
6266
|
+
values: Values & MutationValuesDialectConstraint<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
6267
|
+
conflictColumns: ValidateTargetColumnInput<Target, Columns>,
|
|
6268
|
+
updateValues?: UpdateValues & UpdateValuesNonEmptyConstraint<Exclude<UpdateValues, undefined>> & MutationValuesDialectConstraint<Exclude<UpdateValues, undefined>, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
5527
6269
|
) => QueryPlan<
|
|
5528
6270
|
{},
|
|
5529
|
-
Exclude<MutationRequiredFromValues<Values> | MutationRequiredFromValues<UpdateValues
|
|
6271
|
+
Exclude<MutationRequiredFromValues<Values> | MutationRequiredFromValues<Exclude<UpdateValues, undefined>>, SourceNameOf<Target>>,
|
|
5530
6272
|
AddAvailable<{}, SourceNameOf<Target>>,
|
|
5531
|
-
TableDialectOf<Target
|
|
6273
|
+
| TableDialectOf<Target>
|
|
6274
|
+
| KnownMutationDialectFromValues<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
6275
|
+
| KnownMutationDialectFromValues<Exclude<UpdateValues, undefined>, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
5532
6276
|
never,
|
|
5533
6277
|
SourceNameOf<Target>,
|
|
5534
|
-
Exclude<MutationRequiredFromValues<Values> | MutationRequiredFromValues<UpdateValues
|
|
6278
|
+
Exclude<MutationRequiredFromValues<Values> | MutationRequiredFromValues<Exclude<UpdateValues, undefined>>, SourceNameOf<Target>>,
|
|
5535
6279
|
TrueFormula,
|
|
5536
6280
|
"write",
|
|
5537
6281
|
"insert",
|
|
5538
6282
|
Target,
|
|
5539
|
-
"ready"
|
|
6283
|
+
"ready",
|
|
6284
|
+
EmptyFacts
|
|
5540
6285
|
>
|
|
5541
6286
|
|
|
5542
6287
|
interface DeleteApi {
|
|
@@ -5552,10 +6297,13 @@ type AsCurriedResult<
|
|
|
5552
6297
|
never,
|
|
5553
6298
|
TrueFormula,
|
|
5554
6299
|
"write",
|
|
5555
|
-
"delete"
|
|
6300
|
+
"delete",
|
|
6301
|
+
any,
|
|
6302
|
+
"ready",
|
|
6303
|
+
EmptyFacts
|
|
5556
6304
|
>
|
|
5557
6305
|
<Targets extends MutationTargetTuple>(
|
|
5558
|
-
target: Dialect extends "mysql" ? Targets : never
|
|
6306
|
+
target: Dialect extends "mysql" ? Targets & MutationTargetTupleDialectConstraint<Targets, Dialect> & MutationTargetTupleUniqueNamesConstraint<Targets> : never
|
|
5559
6307
|
): QueryPlan<
|
|
5560
6308
|
{},
|
|
5561
6309
|
never,
|
|
@@ -5566,7 +6314,10 @@ type AsCurriedResult<
|
|
|
5566
6314
|
never,
|
|
5567
6315
|
TrueFormula,
|
|
5568
6316
|
"write",
|
|
5569
|
-
"delete"
|
|
6317
|
+
"delete",
|
|
6318
|
+
any,
|
|
6319
|
+
"ready",
|
|
6320
|
+
EmptyFacts
|
|
5570
6321
|
>
|
|
5571
6322
|
}
|
|
5572
6323
|
|
|
@@ -5583,10 +6334,19 @@ type AsCurriedResult<
|
|
|
5583
6334
|
never,
|
|
5584
6335
|
TrueFormula,
|
|
5585
6336
|
"write",
|
|
5586
|
-
"truncate"
|
|
6337
|
+
"truncate",
|
|
6338
|
+
any,
|
|
6339
|
+
"ready",
|
|
6340
|
+
EmptyFacts
|
|
5587
6341
|
>
|
|
5588
6342
|
|
|
5589
|
-
type
|
|
6343
|
+
type MergeUnsupportedError<Dialect extends string> = {
|
|
6344
|
+
readonly __effect_qb_error__: "effect-qb: merge(...) is only supported by the postgres dialect"
|
|
6345
|
+
readonly __effect_qb_dialect__: Dialect
|
|
6346
|
+
readonly __effect_qb_hint__: "Use postgres.Query.merge(...) or dialect-specific insert/update/delete logic"
|
|
6347
|
+
}
|
|
6348
|
+
|
|
6349
|
+
type MergeSupportedApi = <
|
|
5590
6350
|
Target extends MutationTargetLike,
|
|
5591
6351
|
Source extends SourceLike,
|
|
5592
6352
|
On extends PredicateInput,
|
|
@@ -5600,7 +6360,7 @@ type AsCurriedResult<
|
|
|
5600
6360
|
SourceRequiredOf<Source> extends never ? unknown : SourceRequirementError<Source>
|
|
5601
6361
|
),
|
|
5602
6362
|
on: On,
|
|
5603
|
-
options
|
|
6363
|
+
options: MergeOptions<Target, MatchedValues, InsertValues, MatchedPredicate, NotMatchedPredicate>
|
|
5604
6364
|
) => QueryPlan<
|
|
5605
6365
|
{},
|
|
5606
6366
|
Exclude<
|
|
@@ -5637,10 +6397,16 @@ type AsCurriedResult<
|
|
|
5637
6397
|
>,
|
|
5638
6398
|
TrueFormula,
|
|
5639
6399
|
MergeCapabilities<"write", SourceCapabilitiesOf<Source>>,
|
|
5640
|
-
"merge"
|
|
6400
|
+
"merge",
|
|
6401
|
+
any,
|
|
6402
|
+
"ready",
|
|
6403
|
+
EmptyFacts
|
|
5641
6404
|
>
|
|
5642
6405
|
|
|
6406
|
+
type MergeApi = Dialect extends "postgres" ? MergeSupportedApi : MergeUnsupportedError<Dialect>
|
|
6407
|
+
|
|
5643
6408
|
const mutationRuntime = makeDslMutationRuntime({
|
|
6409
|
+
profile,
|
|
5644
6410
|
makePlan,
|
|
5645
6411
|
getAst,
|
|
5646
6412
|
getQueryState,
|
|
@@ -5653,7 +6419,7 @@ type AsCurriedResult<
|
|
|
5653
6419
|
buildConflictTarget,
|
|
5654
6420
|
mutationTargetClauses,
|
|
5655
6421
|
mutationAvailableSources,
|
|
5656
|
-
|
|
6422
|
+
normalizeConflictColumns,
|
|
5657
6423
|
targetSourceDetails,
|
|
5658
6424
|
sourceDetails
|
|
5659
6425
|
})
|
|
@@ -5669,61 +6435,21 @@ type AsCurriedResult<
|
|
|
5669
6435
|
): QueryPlan<any, any, any, any, any, any, any, any, any, "insert", MutationTargetLike, "ready"> =>
|
|
5670
6436
|
mutationRuntime.attachInsertSource(plan, source)
|
|
5671
6437
|
|
|
5672
|
-
const onConflict:
|
|
5673
|
-
|
|
5674
|
-
|
|
5675
|
-
UpdateValues extends MutationInputOf<Table.UpdateOf<Target>> | undefined = MutationInputOf<Table.UpdateOf<Target>> | undefined,
|
|
5676
|
-
Options extends ConflictActionInput<Target, Dialect, UpdateValues> = ConflictActionInput<Target, Dialect, UpdateValues>
|
|
5677
|
-
>(
|
|
5678
|
-
target: ConflictTargetInput<Target, Dialect, Columns>,
|
|
5679
|
-
options: Options = {} as Options
|
|
5680
|
-
) =>
|
|
5681
|
-
<PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
|
|
5682
|
-
plan: PlanValue & RequireInsertStatement<PlanValue>
|
|
5683
|
-
): QueryPlan<
|
|
5684
|
-
SelectionOfPlan<PlanValue>,
|
|
5685
|
-
Exclude<RequiredOfPlan<PlanValue> | MutationRequiredFromValues<Exclude<UpdateValues, undefined>> | RequiredFromInput<Extract<Options["where"], PredicateInput>>, AvailableNames<AvailableOfPlan<PlanValue>>>,
|
|
5686
|
-
AvailableOfPlan<PlanValue>,
|
|
5687
|
-
PlanDialectOf<PlanValue>,
|
|
5688
|
-
GroupedOfPlan<PlanValue>,
|
|
5689
|
-
ScopedNamesOfPlan<PlanValue>,
|
|
5690
|
-
Exclude<OutstandingOfPlan<PlanValue> | MutationRequiredFromValues<Exclude<UpdateValues, undefined>> | RequiredFromInput<Extract<Options["where"], PredicateInput>>, AvailableNames<AvailableOfPlan<PlanValue>>>,
|
|
5691
|
-
AssumptionsOfPlan<PlanValue>,
|
|
5692
|
-
CapabilitiesOfPlan<PlanValue>,
|
|
5693
|
-
StatementOfPlan<PlanValue>,
|
|
5694
|
-
MutationTargetOfPlan<PlanValue>,
|
|
5695
|
-
InsertSourceStateOfPlan<PlanValue>
|
|
5696
|
-
> => mutationRuntime.onConflict(target, options)(plan)
|
|
6438
|
+
const onConflict = ((target: unknown, options: unknown = {}) =>
|
|
6439
|
+
(plan: QueryPlan<any, any, any, any, any, any, any, any, any, any>) =>
|
|
6440
|
+
mutationRuntime.onConflict(target, options)(plan)) as OnConflictApi
|
|
5697
6441
|
|
|
5698
6442
|
const update: UpdateApi = ((
|
|
5699
6443
|
target: MutationTargetInput,
|
|
5700
6444
|
values: Record<string, unknown>
|
|
5701
6445
|
) => mutationRuntime.update(target, values)) as UpdateApi
|
|
5702
6446
|
|
|
5703
|
-
const upsert
|
|
5704
|
-
|
|
5705
|
-
|
|
5706
|
-
|
|
5707
|
-
|
|
5708
|
-
|
|
5709
|
-
target: Target,
|
|
5710
|
-
values: Values,
|
|
5711
|
-
conflictColumns: ValidateTargetColumns<Target, NormalizeDdlColumns<Columns>>,
|
|
5712
|
-
updateValues?: UpdateValues
|
|
5713
|
-
): QueryPlan<
|
|
5714
|
-
{},
|
|
5715
|
-
Exclude<MutationRequiredFromValues<Values> | MutationRequiredFromValues<UpdateValues>, SourceNameOf<Target>>,
|
|
5716
|
-
AddAvailable<{}, SourceNameOf<Target>>,
|
|
5717
|
-
TableDialectOf<Target>,
|
|
5718
|
-
never,
|
|
5719
|
-
SourceNameOf<Target>,
|
|
5720
|
-
Exclude<MutationRequiredFromValues<Values> | MutationRequiredFromValues<UpdateValues>, SourceNameOf<Target>>,
|
|
5721
|
-
TrueFormula,
|
|
5722
|
-
"write",
|
|
5723
|
-
"insert",
|
|
5724
|
-
Target,
|
|
5725
|
-
"ready"
|
|
5726
|
-
> => mutationRuntime.upsert(target, values, conflictColumns as string | readonly string[], updateValues)
|
|
6447
|
+
const upsert = ((
|
|
6448
|
+
target: MutationTargetLike,
|
|
6449
|
+
values: Record<string, unknown>,
|
|
6450
|
+
conflictColumns: DdlColumnInput,
|
|
6451
|
+
updateValues?: Record<string, unknown>
|
|
6452
|
+
) => mutationRuntime.upsert(target, values, conflictColumns as string | readonly string[], updateValues)) as UpsertApi
|
|
5727
6453
|
|
|
5728
6454
|
const delete_: DeleteApi = ((
|
|
5729
6455
|
target: MutationTargetInput
|
|
@@ -5744,10 +6470,13 @@ type AsCurriedResult<
|
|
|
5744
6470
|
never,
|
|
5745
6471
|
TrueFormula,
|
|
5746
6472
|
"write",
|
|
5747
|
-
"truncate"
|
|
6473
|
+
"truncate",
|
|
6474
|
+
any,
|
|
6475
|
+
"ready",
|
|
6476
|
+
EmptyFacts
|
|
5748
6477
|
> => mutationRuntime.truncate(target, options)
|
|
5749
6478
|
|
|
5750
|
-
const merge
|
|
6479
|
+
const merge = (<
|
|
5751
6480
|
Target extends MutationTargetLike,
|
|
5752
6481
|
Source extends SourceLike,
|
|
5753
6482
|
On extends PredicateInput,
|
|
@@ -5761,7 +6490,7 @@ type AsCurriedResult<
|
|
|
5761
6490
|
SourceRequiredOf<Source> extends never ? unknown : SourceRequirementError<Source>
|
|
5762
6491
|
),
|
|
5763
6492
|
on: On,
|
|
5764
|
-
options: MergeOptions<Target, MatchedValues, InsertValues, MatchedPredicate, NotMatchedPredicate>
|
|
6493
|
+
options: MergeOptions<Target, MatchedValues, InsertValues, MatchedPredicate, NotMatchedPredicate>
|
|
5765
6494
|
): QueryPlan<
|
|
5766
6495
|
{},
|
|
5767
6496
|
Exclude<
|
|
@@ -5798,8 +6527,11 @@ type AsCurriedResult<
|
|
|
5798
6527
|
>,
|
|
5799
6528
|
TrueFormula,
|
|
5800
6529
|
MergeCapabilities<"write", SourceCapabilitiesOf<Source>>,
|
|
5801
|
-
"merge"
|
|
5802
|
-
|
|
6530
|
+
"merge",
|
|
6531
|
+
any,
|
|
6532
|
+
"ready",
|
|
6533
|
+
EmptyFacts
|
|
6534
|
+
> => mutationRuntime.merge(target, source, on, options)) as unknown as MergeApi
|
|
5803
6535
|
|
|
5804
6536
|
type TransactionApi = (options?: TransactionOptions) => QueryPlan<
|
|
5805
6537
|
{},
|
|
@@ -5913,7 +6645,7 @@ type AsCurriedResult<
|
|
|
5913
6645
|
|
|
5914
6646
|
type CreateIndexApi = <Target extends SchemaTableLike, const Columns extends DdlColumnInput>(
|
|
5915
6647
|
target: Target,
|
|
5916
|
-
columns: Columns &
|
|
6648
|
+
columns: Columns & ValidateDdlColumnInput<Target, Columns>,
|
|
5917
6649
|
options?: CreateIndexOptions
|
|
5918
6650
|
) => QueryPlan<
|
|
5919
6651
|
{},
|
|
@@ -5930,7 +6662,7 @@ type AsCurriedResult<
|
|
|
5930
6662
|
|
|
5931
6663
|
type DropIndexApi = <Target extends SchemaTableLike, const Columns extends DdlColumnInput>(
|
|
5932
6664
|
target: Target,
|
|
5933
|
-
columns: Columns &
|
|
6665
|
+
columns: Columns & ValidateDdlColumnInput<Target, Columns>,
|
|
5934
6666
|
options?: DropIndexOptions
|
|
5935
6667
|
) => QueryPlan<
|
|
5936
6668
|
{},
|