effect-qb 0.20.0 → 0.22.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/index.js +663 -261
- package/dist/mysql.js +2840 -492
- package/dist/postgres/metadata.js +113 -14
- package/dist/postgres.js +2596 -285
- package/dist/sqlite.js +2783 -450
- package/dist/standard.js +663 -261
- package/package.json +2 -3
- package/src/internal/analytics.ts +264 -0
- package/src/internal/coercion/errors.d.ts +1 -1
- package/src/internal/coercion/errors.ts +1 -1
- package/src/internal/custom-sql-renderer.ts +20 -0
- package/src/internal/dialect-numeric.ts +332 -0
- package/src/internal/dialect-renderers/mysql.ts +68 -13
- package/src/internal/dialect-renderers/postgres.ts +83 -13
- package/src/internal/dialect-renderers/sqlite.ts +57 -13
- package/src/internal/dynamic.ts +131 -0
- package/src/internal/executor.ts +198 -7
- package/src/internal/expression-ast.ts +62 -1
- package/src/internal/fragment.ts +120 -0
- package/src/internal/function-constraints.ts +105 -0
- package/src/internal/grouping-key.ts +26 -0
- package/src/internal/numeric.ts +204 -0
- package/src/internal/query.ts +13 -1
- package/src/internal/runtime/normalize.ts +5 -2
- package/src/internal/runtime/schema.ts +2 -1
- package/src/internal/standard-dsl.ts +43 -20
- package/src/internal/window-frame.ts +30 -0
- package/src/internal/window-renderer.ts +25 -0
- package/src/mysql/executor.ts +126 -45
- package/src/mysql/function/aggregate.ts +87 -1
- package/src/mysql/function/index.ts +5 -2
- package/src/mysql/function/numeric.ts +185 -0
- package/src/mysql/function/temporal.ts +6 -6
- package/src/mysql/function/window.ts +12 -0
- package/src/mysql/internal/dsl.ts +38 -20
- package/src/mysql.ts +2 -0
- package/src/postgres/executor.ts +111 -45
- package/src/postgres/function/aggregate.ts +124 -1
- package/src/postgres/function/core.ts +2 -1
- package/src/postgres/function/index.ts +19 -1
- package/src/postgres/function/numeric.ts +246 -0
- package/src/postgres/function/window.ts +12 -0
- package/src/postgres/internal/dsl.ts +38 -20
- package/src/sqlite/executor.ts +96 -45
- package/src/sqlite/function/aggregate.ts +90 -1
- package/src/sqlite/function/index.ts +5 -2
- package/src/sqlite/function/numeric.ts +139 -0
- package/src/sqlite/function/window.ts +12 -0
- package/src/sqlite/internal/dsl.ts +38 -20
- package/src/sqlite.ts +2 -0
- package/src/standard/function/core.ts +8 -1
- package/src/standard/function/index.ts +18 -11
- package/src/standard/function/string.ts +1 -1
- package/src/standard/function/window.ts +10 -1
- package/src/standard/query.ts +19 -7
- package/src/standard/type.ts +16 -0
- package/src/standard.ts +4 -0
- package/src/standard/function/temporal.ts +0 -78
package/dist/sqlite.js
CHANGED
|
@@ -1752,14 +1752,46 @@ var narrowSqliteDriverErrorForReadQuery = (error) => {
|
|
|
1752
1752
|
cause: error
|
|
1753
1753
|
};
|
|
1754
1754
|
};
|
|
1755
|
-
// src/sqlite/
|
|
1756
|
-
var
|
|
1757
|
-
__export(
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1755
|
+
// src/sqlite/function/index.ts
|
|
1756
|
+
var exports_function = {};
|
|
1757
|
+
__export(exports_function, {
|
|
1758
|
+
window: () => exports_window,
|
|
1759
|
+
upper: () => upper,
|
|
1760
|
+
temporal: () => exports_temporal,
|
|
1761
|
+
sum: () => sum,
|
|
1762
|
+
string: () => exports_string,
|
|
1763
|
+
rowNumber: () => rowNumber,
|
|
1764
|
+
round: () => round2,
|
|
1765
|
+
rank: () => rank,
|
|
1766
|
+
over: () => over,
|
|
1767
|
+
numeric: () => exports_numeric,
|
|
1768
|
+
now: () => now,
|
|
1769
|
+
modulo: () => modulo2,
|
|
1770
|
+
min: () => min,
|
|
1771
|
+
max: () => max,
|
|
1772
|
+
lower: () => lower,
|
|
1773
|
+
localTimestamp: () => localTimestamp,
|
|
1774
|
+
localTime: () => localTime,
|
|
1775
|
+
lastValue: () => lastValue2,
|
|
1776
|
+
firstValue: () => firstValue2,
|
|
1777
|
+
denseRank: () => denseRank,
|
|
1778
|
+
currentTimestamp: () => currentTimestamp,
|
|
1779
|
+
currentTime: () => currentTime,
|
|
1780
|
+
currentDate: () => currentDate,
|
|
1781
|
+
count: () => count,
|
|
1782
|
+
core: () => exports_core,
|
|
1783
|
+
concat: () => concat,
|
|
1784
|
+
coalesce: () => coalesce,
|
|
1785
|
+
call: () => call,
|
|
1786
|
+
avg: () => avg,
|
|
1787
|
+
aggregate: () => exports_aggregate
|
|
1788
|
+
});
|
|
1789
|
+
|
|
1790
|
+
// src/sqlite/function/core.ts
|
|
1791
|
+
var exports_core = {};
|
|
1792
|
+
__export(exports_core, {
|
|
1793
|
+
coalesce: () => coalesce,
|
|
1794
|
+
call: () => call
|
|
1763
1795
|
});
|
|
1764
1796
|
|
|
1765
1797
|
// src/sqlite/internal/dsl.ts
|
|
@@ -2593,8 +2625,9 @@ var normalizeOffsetTime = (value) => {
|
|
|
2593
2625
|
return `${formatLocalTime(validDate(value))}Z`;
|
|
2594
2626
|
}
|
|
2595
2627
|
const raw = expectString(value, "offset time").trim();
|
|
2596
|
-
|
|
2597
|
-
|
|
2628
|
+
const canonical = raw.replace(/([+-]\d{2})$/, "$1:00").replace(/([+-]\d{2})(\d{2})$/, "$1:$2");
|
|
2629
|
+
if (isValidOffsetTimeString(canonical)) {
|
|
2630
|
+
return canonical;
|
|
2598
2631
|
}
|
|
2599
2632
|
throw new Error("Expected an offset-time value");
|
|
2600
2633
|
};
|
|
@@ -3652,6 +3685,14 @@ var castTargetGroupingKey = (target) => {
|
|
|
3652
3685
|
};
|
|
3653
3686
|
var escapeGroupingText = (value) => value.replace(/\\/g, "\\\\").replace(/,/g, "\\,").replace(/\|/g, "\\|").replace(/=/g, "\\=").replace(/>/g, "\\>");
|
|
3654
3687
|
var functionCallNameGroupingKey = (name) => escapeGroupingText(name);
|
|
3688
|
+
var customSqlGroupingKey = (strings, values) => strings.map((part, index4) => {
|
|
3689
|
+
const value = values[index4];
|
|
3690
|
+
if (value === undefined) {
|
|
3691
|
+
return escapeGroupingText(part);
|
|
3692
|
+
}
|
|
3693
|
+
const rendered = isExpression2(value) ? groupingKeyOfExpression(value) : `identifier:${value.parts.map(escapeGroupingText).join(".")}`;
|
|
3694
|
+
return `${escapeGroupingText(part)}${rendered}`;
|
|
3695
|
+
}).join("|");
|
|
3655
3696
|
var quantifiedComparisonGroupingName = (kind) => kind === "comparisonAny" ? "compareAny" : "compareAll";
|
|
3656
3697
|
var caseGroupingKey = (branches, fallback) => {
|
|
3657
3698
|
const typedBranches = branches;
|
|
@@ -3733,12 +3774,19 @@ var groupingKeyOfExpression = (expression) => {
|
|
|
3733
3774
|
return `collate(${requiredExpressionGroupingKey("collate", ast.value)},${collationGroupingKey(ast.collation)})`;
|
|
3734
3775
|
case "function":
|
|
3735
3776
|
return `function(${functionCallNameGroupingKey(ast.name)},${functionCallArgsGroupingKey(ast.args)})`;
|
|
3777
|
+
case "customSql":
|
|
3778
|
+
return `customSql(${customSqlGroupingKey(ast.strings, ast.values)})`;
|
|
3736
3779
|
case "isNull":
|
|
3737
3780
|
case "isNotNull":
|
|
3738
3781
|
case "not":
|
|
3739
3782
|
case "upper":
|
|
3740
3783
|
case "lower":
|
|
3741
3784
|
case "count":
|
|
3785
|
+
case "sum":
|
|
3786
|
+
case "avg":
|
|
3787
|
+
case "abs":
|
|
3788
|
+
case "round":
|
|
3789
|
+
case "negate":
|
|
3742
3790
|
case "max":
|
|
3743
3791
|
case "min":
|
|
3744
3792
|
return `${ast.kind}(${requiredExpressionGroupingKey(ast.kind, ast.value)})`;
|
|
@@ -3759,6 +3807,11 @@ var groupingKeyOfExpression = (expression) => {
|
|
|
3759
3807
|
case "contains":
|
|
3760
3808
|
case "containedBy":
|
|
3761
3809
|
case "overlaps":
|
|
3810
|
+
case "add":
|
|
3811
|
+
case "subtract":
|
|
3812
|
+
case "multiply":
|
|
3813
|
+
case "divide":
|
|
3814
|
+
case "modulo":
|
|
3762
3815
|
return `${ast.kind}(${requiredBinaryExpressionGroupingKey(ast.kind, ast.left, ast.right)})`;
|
|
3763
3816
|
case "and":
|
|
3764
3817
|
case "or":
|
|
@@ -3834,6 +3887,31 @@ var dedupeGroupedExpressions = (values) => {
|
|
|
3834
3887
|
});
|
|
3835
3888
|
};
|
|
3836
3889
|
|
|
3890
|
+
// src/internal/window-frame.ts
|
|
3891
|
+
var validateBoundary = (boundary) => {
|
|
3892
|
+
if (typeof boundary === "object") {
|
|
3893
|
+
const value = "preceding" in boundary ? boundary.preceding : boundary.following;
|
|
3894
|
+
if (!Number.isSafeInteger(value) || value < 0) {
|
|
3895
|
+
throw new Error("window frame offsets must be non-negative safe integers");
|
|
3896
|
+
}
|
|
3897
|
+
}
|
|
3898
|
+
};
|
|
3899
|
+
var validateWindowFrame = (frame) => {
|
|
3900
|
+
if (frame === undefined) {
|
|
3901
|
+
return;
|
|
3902
|
+
}
|
|
3903
|
+
validateBoundary(frame.start);
|
|
3904
|
+
if (frame.end !== undefined) {
|
|
3905
|
+
validateBoundary(frame.end);
|
|
3906
|
+
}
|
|
3907
|
+
if (frame.start === "unboundedFollowing") {
|
|
3908
|
+
throw new Error("window frame cannot start with unbounded following");
|
|
3909
|
+
}
|
|
3910
|
+
if (frame.end === "unboundedPreceding") {
|
|
3911
|
+
throw new Error("window frame cannot end with unbounded preceding");
|
|
3912
|
+
}
|
|
3913
|
+
};
|
|
3914
|
+
|
|
3837
3915
|
// src/internal/dsl-transaction-ddl-runtime.ts
|
|
3838
3916
|
var renderTransactionIsolationLevel = (isolationLevel) => {
|
|
3839
3917
|
if (isolationLevel === undefined) {
|
|
@@ -5088,6 +5166,23 @@ var extractRequiredFromDialectInputRuntime = (value) => {
|
|
|
5088
5166
|
const expression = toDialectExpression(value);
|
|
5089
5167
|
return Object.keys(expression[TypeId].dependencies);
|
|
5090
5168
|
};
|
|
5169
|
+
var normalizeWindowSpec = (spec) => {
|
|
5170
|
+
validateWindowFrame(spec?.frame);
|
|
5171
|
+
const partitionBy = [...spec?.partitionBy ?? []];
|
|
5172
|
+
const orderBy = (spec?.orderBy ?? []).map((term) => {
|
|
5173
|
+
const direction = term.direction ?? "asc";
|
|
5174
|
+
return {
|
|
5175
|
+
value: term.value,
|
|
5176
|
+
direction
|
|
5177
|
+
};
|
|
5178
|
+
});
|
|
5179
|
+
return {
|
|
5180
|
+
partitionBy,
|
|
5181
|
+
orderBy,
|
|
5182
|
+
frame: spec?.frame
|
|
5183
|
+
};
|
|
5184
|
+
};
|
|
5185
|
+
var mergeWindowExpressions = (value, partitionBy, orderBy) => value === undefined ? [...partitionBy, ...orderBy.map((term) => term.value)] : [value, ...partitionBy, ...orderBy.map((term) => term.value)];
|
|
5091
5186
|
var extractRequiredFromDialectNumericInputRuntime = (value) => {
|
|
5092
5187
|
const expression = toDialectNumericExpression(value);
|
|
5093
5188
|
return Object.keys(expression[TypeId].dependencies);
|
|
@@ -5107,6 +5202,34 @@ var buildBinaryPredicate = (left, right, kind, nullability = "maybe") => {
|
|
|
5107
5202
|
right: rightExpression
|
|
5108
5203
|
});
|
|
5109
5204
|
};
|
|
5205
|
+
var upper = (value) => {
|
|
5206
|
+
const expression = toDialectStringExpression(value);
|
|
5207
|
+
return makeExpression2({
|
|
5208
|
+
runtime: "",
|
|
5209
|
+
dbType: profile.textDb,
|
|
5210
|
+
nullability: expression[TypeId].nullability,
|
|
5211
|
+
dialect: profile.dialect,
|
|
5212
|
+
kind: expression[TypeId].kind,
|
|
5213
|
+
dependencies: expression[TypeId].dependencies
|
|
5214
|
+
}, {
|
|
5215
|
+
kind: "upper",
|
|
5216
|
+
value: expression
|
|
5217
|
+
});
|
|
5218
|
+
};
|
|
5219
|
+
var lower = (value) => {
|
|
5220
|
+
const expression = toDialectStringExpression(value);
|
|
5221
|
+
return makeExpression2({
|
|
5222
|
+
runtime: "",
|
|
5223
|
+
dbType: profile.textDb,
|
|
5224
|
+
nullability: expression[TypeId].nullability,
|
|
5225
|
+
dialect: profile.dialect,
|
|
5226
|
+
kind: expression[TypeId].kind,
|
|
5227
|
+
dependencies: expression[TypeId].dependencies
|
|
5228
|
+
}, {
|
|
5229
|
+
kind: "lower",
|
|
5230
|
+
value: expression
|
|
5231
|
+
});
|
|
5232
|
+
};
|
|
5110
5233
|
var array2 = (element) => ({
|
|
5111
5234
|
dialect: profile.dialect,
|
|
5112
5235
|
kind: `${element.kind}[]`,
|
|
@@ -5592,6 +5715,127 @@ var jsonb = {
|
|
|
5592
5715
|
pathExists: jsonPathExists,
|
|
5593
5716
|
pathMatch: jsonPathMatch
|
|
5594
5717
|
};
|
|
5718
|
+
var concat = (...values) => {
|
|
5719
|
+
const expressions = values.map((value) => toDialectStringExpression(value));
|
|
5720
|
+
return makeExpression2({
|
|
5721
|
+
runtime: "",
|
|
5722
|
+
dbType: profile.textDb,
|
|
5723
|
+
nullability: mergeNullabilityManyRuntime(expressions),
|
|
5724
|
+
dialect: expressions.find((value) => value[TypeId].dialect !== undefined)?.[TypeId].dialect ?? profile.dialect,
|
|
5725
|
+
kind: mergeAggregationManyRuntime(expressions),
|
|
5726
|
+
dependencies: mergeManyDependencies(expressions)
|
|
5727
|
+
}, {
|
|
5728
|
+
kind: "concat",
|
|
5729
|
+
values: expressions
|
|
5730
|
+
});
|
|
5731
|
+
};
|
|
5732
|
+
var count = (value) => {
|
|
5733
|
+
const expression = toDialectExpression(value);
|
|
5734
|
+
return makeExpression2({
|
|
5735
|
+
runtime: undefined,
|
|
5736
|
+
dbType: sqliteDatatypes.bigint(),
|
|
5737
|
+
nullability: "never",
|
|
5738
|
+
dialect: expression[TypeId].dialect,
|
|
5739
|
+
kind: "aggregate",
|
|
5740
|
+
dependencies: expression[TypeId].dependencies
|
|
5741
|
+
}, {
|
|
5742
|
+
kind: "count",
|
|
5743
|
+
value: expression
|
|
5744
|
+
});
|
|
5745
|
+
};
|
|
5746
|
+
var over = (value, spec = {}) => {
|
|
5747
|
+
const normalized = normalizeWindowSpec(spec);
|
|
5748
|
+
const expressions = mergeWindowExpressions(value, normalized.partitionBy, normalized.orderBy);
|
|
5749
|
+
return makeExpression2({
|
|
5750
|
+
runtime: undefined,
|
|
5751
|
+
dbType: value[TypeId].dbType,
|
|
5752
|
+
nullability: value[TypeId].nullability,
|
|
5753
|
+
dialect: expressions.find((expression) => expression[TypeId].dialect !== undefined)?.[TypeId].dialect ?? profile.dialect,
|
|
5754
|
+
kind: "window",
|
|
5755
|
+
dependencies: mergeManyDependencies(expressions)
|
|
5756
|
+
}, {
|
|
5757
|
+
kind: "window",
|
|
5758
|
+
function: "over",
|
|
5759
|
+
value,
|
|
5760
|
+
partitionBy: normalized.partitionBy,
|
|
5761
|
+
orderBy: normalized.orderBy,
|
|
5762
|
+
frame: normalized.frame
|
|
5763
|
+
});
|
|
5764
|
+
};
|
|
5765
|
+
var buildNumberWindow = (kind, spec) => {
|
|
5766
|
+
const normalized = normalizeWindowSpec(spec);
|
|
5767
|
+
const expressions = mergeWindowExpressions(undefined, normalized.partitionBy, normalized.orderBy);
|
|
5768
|
+
return makeExpression2({
|
|
5769
|
+
runtime: undefined,
|
|
5770
|
+
dbType: sqliteDatatypes.bigint(),
|
|
5771
|
+
nullability: "never",
|
|
5772
|
+
dialect: expressions.find((expression) => expression[TypeId].dialect !== undefined)?.[TypeId].dialect ?? profile.dialect,
|
|
5773
|
+
kind: "window",
|
|
5774
|
+
dependencies: mergeManyDependencies(expressions)
|
|
5775
|
+
}, {
|
|
5776
|
+
kind: "window",
|
|
5777
|
+
function: kind,
|
|
5778
|
+
partitionBy: normalized.partitionBy,
|
|
5779
|
+
orderBy: normalized.orderBy,
|
|
5780
|
+
frame: normalized.frame
|
|
5781
|
+
});
|
|
5782
|
+
};
|
|
5783
|
+
var rowNumber = (spec) => buildNumberWindow("rowNumber", spec);
|
|
5784
|
+
var rank = (spec) => buildNumberWindow("rank", spec);
|
|
5785
|
+
var denseRank = (spec) => buildNumberWindow("denseRank", spec);
|
|
5786
|
+
var max = (value) => makeExpression2({
|
|
5787
|
+
runtime: undefined,
|
|
5788
|
+
dbType: value[TypeId].dbType,
|
|
5789
|
+
nullability: "maybe",
|
|
5790
|
+
dialect: value[TypeId].dialect,
|
|
5791
|
+
kind: "aggregate",
|
|
5792
|
+
dependencies: value[TypeId].dependencies
|
|
5793
|
+
}, {
|
|
5794
|
+
kind: "max",
|
|
5795
|
+
value
|
|
5796
|
+
});
|
|
5797
|
+
var min = (value) => makeExpression2({
|
|
5798
|
+
runtime: undefined,
|
|
5799
|
+
dbType: value[TypeId].dbType,
|
|
5800
|
+
nullability: "maybe",
|
|
5801
|
+
dialect: value[TypeId].dialect,
|
|
5802
|
+
kind: "aggregate",
|
|
5803
|
+
dependencies: value[TypeId].dependencies
|
|
5804
|
+
}, {
|
|
5805
|
+
kind: "min",
|
|
5806
|
+
value
|
|
5807
|
+
});
|
|
5808
|
+
var resolveCoalesceNullabilityRuntime = (values) => values.some((value) => value[TypeId].nullability === "never") ? "never" : values.some((value) => value[TypeId].nullability === "maybe") ? "maybe" : "always";
|
|
5809
|
+
var coalesce = (...values) => {
|
|
5810
|
+
const expressions = values.map((value) => toDialectExpression(value));
|
|
5811
|
+
const representative = expressions.find((value) => value[TypeId].nullability !== "always") ?? expressions[0];
|
|
5812
|
+
return makeExpression2({
|
|
5813
|
+
runtime: undefined,
|
|
5814
|
+
dbType: representative[TypeId].dbType,
|
|
5815
|
+
nullability: resolveCoalesceNullabilityRuntime(expressions),
|
|
5816
|
+
dialect: expressions.find((value) => value[TypeId].dialect !== undefined)?.[TypeId].dialect ?? profile.dialect,
|
|
5817
|
+
kind: mergeAggregationManyRuntime(expressions),
|
|
5818
|
+
dependencies: mergeManyDependencies(expressions)
|
|
5819
|
+
}, {
|
|
5820
|
+
kind: "coalesce",
|
|
5821
|
+
values: expressions
|
|
5822
|
+
});
|
|
5823
|
+
};
|
|
5824
|
+
var call = (name, ...args) => {
|
|
5825
|
+
const expressions = args.map((value) => toDialectExpression(value));
|
|
5826
|
+
return makeExpression2({
|
|
5827
|
+
runtime: undefined,
|
|
5828
|
+
dbType: profile.textDb,
|
|
5829
|
+
nullability: "maybe",
|
|
5830
|
+
dialect: expressions.find((value) => value[TypeId].dialect !== undefined)?.[TypeId].dialect ?? profile.dialect,
|
|
5831
|
+
kind: mergeAggregationManyRuntime(expressions),
|
|
5832
|
+
dependencies: mergeManyDependencies(expressions)
|
|
5833
|
+
}, {
|
|
5834
|
+
kind: "function",
|
|
5835
|
+
name,
|
|
5836
|
+
args: expressions
|
|
5837
|
+
});
|
|
5838
|
+
};
|
|
5595
5839
|
var toMutationValueExpression = (value, column) => {
|
|
5596
5840
|
const columnState = column[TypeId];
|
|
5597
5841
|
const normalizeMutationValue = (candidate) => {
|
|
@@ -5882,135 +6126,1988 @@ var {
|
|
|
5882
6126
|
normalizeColumnList,
|
|
5883
6127
|
defaultIndexName
|
|
5884
6128
|
});
|
|
5885
|
-
|
|
5886
|
-
|
|
5887
|
-
|
|
5888
|
-
|
|
5889
|
-
|
|
5890
|
-
|
|
5891
|
-
var pathMatch = json.pathMatch;
|
|
5892
|
-
// src/sqlite/executor.ts
|
|
5893
|
-
var exports_executor2 = {};
|
|
5894
|
-
__export(exports_executor2, {
|
|
5895
|
-
withTransaction: () => withTransaction2,
|
|
5896
|
-
make: () => make4,
|
|
5897
|
-
driver: () => driver2,
|
|
5898
|
-
custom: () => custom3
|
|
6129
|
+
// src/sqlite/function/string.ts
|
|
6130
|
+
var exports_string = {};
|
|
6131
|
+
__export(exports_string, {
|
|
6132
|
+
upper: () => upper,
|
|
6133
|
+
lower: () => lower,
|
|
6134
|
+
concat: () => concat
|
|
5899
6135
|
});
|
|
5900
|
-
|
|
5901
|
-
|
|
5902
|
-
|
|
5903
|
-
|
|
5904
|
-
|
|
5905
|
-
|
|
5906
|
-
|
|
5907
|
-
|
|
5908
|
-
streamFromSqlClient: () => streamFromSqlClient,
|
|
5909
|
-
remapRows: () => remapRows,
|
|
5910
|
-
makeRowDecoder: () => makeRowDecoder,
|
|
5911
|
-
make: () => make3,
|
|
5912
|
-
hasWriteCapability: () => hasWriteCapability,
|
|
5913
|
-
fromSqlClient: () => fromSqlClient,
|
|
5914
|
-
fromDriver: () => fromDriver,
|
|
5915
|
-
driver: () => driver,
|
|
5916
|
-
decodeRows: () => decodeRows,
|
|
5917
|
-
decodeChunk: () => decodeChunk
|
|
6136
|
+
// src/sqlite/function/aggregate.ts
|
|
6137
|
+
var exports_aggregate = {};
|
|
6138
|
+
__export(exports_aggregate, {
|
|
6139
|
+
sum: () => sum,
|
|
6140
|
+
min: () => min,
|
|
6141
|
+
max: () => max,
|
|
6142
|
+
count: () => count,
|
|
6143
|
+
avg: () => avg
|
|
5918
6144
|
});
|
|
5919
|
-
import * as Chunk from "effect/Chunk";
|
|
5920
|
-
import * as Effect from "effect/Effect";
|
|
5921
|
-
import * as Exit from "effect/Exit";
|
|
5922
|
-
import * as Option from "effect/Option";
|
|
5923
|
-
import * as Schema9 from "effect/Schema";
|
|
5924
|
-
import * as SqlClient from "effect/unstable/sql/SqlClient";
|
|
5925
|
-
import * as Stream from "effect/Stream";
|
|
5926
6145
|
|
|
5927
|
-
// src/internal/
|
|
5928
|
-
|
|
5929
|
-
|
|
5930
|
-
|
|
5931
|
-
|
|
5932
|
-
|
|
5933
|
-
|
|
5934
|
-
|
|
5935
|
-
}
|
|
5936
|
-
|
|
5937
|
-
|
|
5938
|
-
|
|
5939
|
-
|
|
5940
|
-
|
|
5941
|
-
|
|
5942
|
-
|
|
5943
|
-
|
|
5944
|
-
|
|
5945
|
-
|
|
5946
|
-
|
|
5947
|
-
|
|
5948
|
-
|
|
6146
|
+
// src/internal/dialect-numeric.ts
|
|
6147
|
+
var literal2 = (value, dbType, dialect) => makeExpression2({
|
|
6148
|
+
runtime: value,
|
|
6149
|
+
dbType,
|
|
6150
|
+
driverValueMapping: dbType.driverValueMapping,
|
|
6151
|
+
nullability: "never",
|
|
6152
|
+
dialect,
|
|
6153
|
+
kind: "scalar",
|
|
6154
|
+
dependencies: {}
|
|
6155
|
+
}, {
|
|
6156
|
+
kind: "literal",
|
|
6157
|
+
value
|
|
6158
|
+
});
|
|
6159
|
+
var asExpression = (value, literalDb, dialect) => typeof value === "number" ? literal2(value, literalDb, dialect) : value;
|
|
6160
|
+
var modulo = (left, right, options2) => {
|
|
6161
|
+
const leftExpression = asExpression(left, options2.literalDb, options2.dialect);
|
|
6162
|
+
const rightExpression = asExpression(right, options2.literalDb, options2.dialect);
|
|
6163
|
+
const values2 = [leftExpression, rightExpression];
|
|
6164
|
+
return makeExpression2({
|
|
6165
|
+
runtime: undefined,
|
|
6166
|
+
dbType: options2.resultDb,
|
|
6167
|
+
driverValueMapping: options2.resultDb.driverValueMapping,
|
|
6168
|
+
nullability: options2.nullability,
|
|
6169
|
+
dialect: options2.dialect,
|
|
6170
|
+
kind: mergeAggregationManyRuntime(values2),
|
|
6171
|
+
dependencies: mergeManyDependencies(values2)
|
|
6172
|
+
}, {
|
|
6173
|
+
kind: "modulo",
|
|
6174
|
+
left: leftExpression,
|
|
6175
|
+
right: rightExpression
|
|
6176
|
+
});
|
|
5949
6177
|
};
|
|
5950
|
-
var
|
|
5951
|
-
|
|
5952
|
-
|
|
6178
|
+
var round = (value, scale, options2) => {
|
|
6179
|
+
const expression = asExpression(value, options2.literalDb, options2.dialect);
|
|
6180
|
+
if (scale === undefined) {
|
|
6181
|
+
return makeExpression2({
|
|
6182
|
+
runtime: undefined,
|
|
6183
|
+
dbType: options2.resultDb,
|
|
6184
|
+
driverValueMapping: options2.resultDb.driverValueMapping,
|
|
6185
|
+
nullability: options2.nullability,
|
|
6186
|
+
dialect: options2.dialect,
|
|
6187
|
+
kind: expression[TypeId].kind,
|
|
6188
|
+
dependencies: expression[TypeId].dependencies
|
|
6189
|
+
}, {
|
|
6190
|
+
kind: "round",
|
|
6191
|
+
value: expression
|
|
6192
|
+
});
|
|
5953
6193
|
}
|
|
5954
|
-
if (
|
|
5955
|
-
|
|
6194
|
+
if (!Number.isSafeInteger(scale)) {
|
|
6195
|
+
throw new Error("round scale must be a safe integer");
|
|
5956
6196
|
}
|
|
5957
|
-
|
|
6197
|
+
const scaleExpression = literal2(scale, options2.scaleDb, options2.dialect);
|
|
6198
|
+
return makeExpression2({
|
|
6199
|
+
runtime: undefined,
|
|
6200
|
+
dbType: options2.resultDb,
|
|
6201
|
+
driverValueMapping: options2.resultDb.driverValueMapping,
|
|
6202
|
+
nullability: options2.nullability,
|
|
6203
|
+
dialect: options2.dialect,
|
|
6204
|
+
kind: expression[TypeId].kind,
|
|
6205
|
+
dependencies: expression[TypeId].dependencies
|
|
6206
|
+
}, {
|
|
6207
|
+
kind: "function",
|
|
6208
|
+
name: "round",
|
|
6209
|
+
args: [expression, scaleExpression]
|
|
6210
|
+
});
|
|
5958
6211
|
};
|
|
5959
|
-
var
|
|
5960
|
-
const
|
|
5961
|
-
|
|
5962
|
-
|
|
5963
|
-
|
|
5964
|
-
|
|
5965
|
-
|
|
5966
|
-
|
|
5967
|
-
|
|
5968
|
-
|
|
5969
|
-
|
|
6212
|
+
var aggregate = (kind, value, options2) => {
|
|
6213
|
+
const expression = asExpression(value, options2.literalDb, options2.dialect);
|
|
6214
|
+
return makeExpression2({
|
|
6215
|
+
runtime: undefined,
|
|
6216
|
+
dbType: options2.resultDb,
|
|
6217
|
+
driverValueMapping: options2.resultDb.driverValueMapping,
|
|
6218
|
+
nullability: "maybe",
|
|
6219
|
+
dialect: options2.dialect,
|
|
6220
|
+
kind: "aggregate",
|
|
6221
|
+
dependencies: expression[TypeId].dependencies
|
|
6222
|
+
}, {
|
|
6223
|
+
kind,
|
|
6224
|
+
value: expression
|
|
6225
|
+
});
|
|
5970
6226
|
};
|
|
5971
|
-
var
|
|
5972
|
-
|
|
5973
|
-
|
|
5974
|
-
|
|
5975
|
-
|
|
5976
|
-
|
|
6227
|
+
var inputNullability = (value) => typeof value === "number" ? "never" : value[TypeId].nullability;
|
|
6228
|
+
var binaryInputNullability = (left, right) => {
|
|
6229
|
+
const leftNullability = inputNullability(left);
|
|
6230
|
+
const rightNullability = inputNullability(right);
|
|
6231
|
+
if (leftNullability === "always" || rightNullability === "always") {
|
|
6232
|
+
return "always";
|
|
5977
6233
|
}
|
|
5978
|
-
return;
|
|
6234
|
+
return leftNullability === "maybe" || rightNullability === "maybe" ? "maybe" : "never";
|
|
5979
6235
|
};
|
|
5980
|
-
var
|
|
5981
|
-
|
|
5982
|
-
|
|
5983
|
-
|
|
5984
|
-
if ("base" in dbType) {
|
|
5985
|
-
return isJsonDbType(dbType.base);
|
|
6236
|
+
var nullableForZeroDivisor = (left, right) => {
|
|
6237
|
+
const merged = binaryInputNullability(left, right);
|
|
6238
|
+
if (merged === "always") {
|
|
6239
|
+
return "always";
|
|
5986
6240
|
}
|
|
5987
|
-
if (
|
|
5988
|
-
return
|
|
6241
|
+
if (typeof right === "number") {
|
|
6242
|
+
return right === 0 ? "always" : merged;
|
|
5989
6243
|
}
|
|
5990
|
-
|
|
5991
|
-
return variant === "json" || variant === "jsonb";
|
|
6244
|
+
return "maybe";
|
|
5992
6245
|
};
|
|
5993
|
-
|
|
5994
|
-
|
|
5995
|
-
|
|
5996
|
-
|
|
6246
|
+
|
|
6247
|
+
// src/sqlite/function/aggregate.ts
|
|
6248
|
+
var baseDb = (db) => ("base" in db) ? baseDb(db.base) : db;
|
|
6249
|
+
var sumResultDb = (value) => {
|
|
6250
|
+
if (typeof value === "number")
|
|
6251
|
+
return sqliteDatatypes.double();
|
|
6252
|
+
const db = baseDb(value[TypeId].dbType);
|
|
6253
|
+
if (db.kind === "int" || db.kind === "integer") {
|
|
6254
|
+
return sqliteDatatypes.integer();
|
|
5997
6255
|
}
|
|
5998
|
-
if (
|
|
5999
|
-
return
|
|
6256
|
+
if (db.kind === "bigint") {
|
|
6257
|
+
return sqliteDatatypes.bigint();
|
|
6000
6258
|
}
|
|
6259
|
+
return sqliteDatatypes.double();
|
|
6260
|
+
};
|
|
6261
|
+
var sum = (value) => aggregate("sum", value, {
|
|
6262
|
+
dialect: "sqlite",
|
|
6263
|
+
literalDb: sqliteDatatypes.double(),
|
|
6264
|
+
resultDb: sumResultDb(value)
|
|
6265
|
+
});
|
|
6266
|
+
var avg = (value) => aggregate("avg", value, {
|
|
6267
|
+
dialect: "sqlite",
|
|
6268
|
+
literalDb: sqliteDatatypes.double(),
|
|
6269
|
+
resultDb: sqliteDatatypes.double()
|
|
6270
|
+
});
|
|
6271
|
+
// src/sqlite/function/numeric.ts
|
|
6272
|
+
var exports_numeric = {};
|
|
6273
|
+
__export(exports_numeric, {
|
|
6274
|
+
round: () => round2,
|
|
6275
|
+
modulo: () => modulo2
|
|
6276
|
+
});
|
|
6277
|
+
var baseDb2 = (db) => ("base" in db) ? baseDb2(db.base) : db;
|
|
6278
|
+
var category = (value) => {
|
|
6279
|
+
if (typeof value === "number")
|
|
6280
|
+
return "approximate";
|
|
6281
|
+
const db = baseDb2(value[TypeId].dbType);
|
|
6282
|
+
if (db.kind === "int" || db.kind === "integer")
|
|
6283
|
+
return "integer";
|
|
6284
|
+
if (db.kind === "bigint")
|
|
6285
|
+
return "bigint";
|
|
6286
|
+
if (db.kind === "numeric" || db.kind === "decimal")
|
|
6287
|
+
return "exact";
|
|
6288
|
+
return "approximate";
|
|
6289
|
+
};
|
|
6290
|
+
var moduloResultDb = (left, right) => {
|
|
6291
|
+
const categories = [category(left), category(right)];
|
|
6292
|
+
if (categories.every((value) => value === "integer" || value === "bigint")) {
|
|
6293
|
+
return categories.includes("bigint") ? sqliteDatatypes.bigint() : sqliteDatatypes.integer();
|
|
6294
|
+
}
|
|
6295
|
+
return sqliteDatatypes.double();
|
|
6296
|
+
};
|
|
6297
|
+
var modulo2 = (left, right) => modulo(left, right, {
|
|
6298
|
+
dialect: "sqlite",
|
|
6299
|
+
literalDb: sqliteDatatypes.double(),
|
|
6300
|
+
resultDb: moduloResultDb(left, right),
|
|
6301
|
+
nullability: nullableForZeroDivisor(left, right)
|
|
6302
|
+
});
|
|
6303
|
+
function round2(value, scale) {
|
|
6304
|
+
return round(value, scale, {
|
|
6305
|
+
dialect: "sqlite",
|
|
6306
|
+
literalDb: sqliteDatatypes.double(),
|
|
6307
|
+
scaleDb: sqliteDatatypes.integer(),
|
|
6308
|
+
resultDb: sqliteDatatypes.double(),
|
|
6309
|
+
nullability: typeof value === "number" ? "never" : value[TypeId].nullability
|
|
6310
|
+
});
|
|
6311
|
+
}
|
|
6312
|
+
// src/sqlite/function/window.ts
|
|
6313
|
+
var exports_window = {};
|
|
6314
|
+
__export(exports_window, {
|
|
6315
|
+
rowNumber: () => rowNumber,
|
|
6316
|
+
rank: () => rank,
|
|
6317
|
+
over: () => over,
|
|
6318
|
+
lastValue: () => lastValue2,
|
|
6319
|
+
firstValue: () => firstValue2,
|
|
6320
|
+
denseRank: () => denseRank
|
|
6321
|
+
});
|
|
6322
|
+
|
|
6323
|
+
// src/internal/standard-dsl.ts
|
|
6324
|
+
import { pipeArguments as pipeArguments8 } from "effect/Pipeable";
|
|
6325
|
+
import * as Schema7 from "effect/Schema";
|
|
6326
|
+
|
|
6327
|
+
// src/standard/datatypes/index.ts
|
|
6328
|
+
var exports_datatypes2 = {};
|
|
6329
|
+
__export(exports_datatypes2, {
|
|
6330
|
+
standardDatatypes: () => standardDatatypes
|
|
6331
|
+
});
|
|
6332
|
+
|
|
6333
|
+
// src/standard/datatypes/spec.ts
|
|
6334
|
+
var standardDatatypeFamilies = portableDatatypeFamilies;
|
|
6335
|
+
var standardDatatypeKinds = portableDatatypeKinds;
|
|
6336
|
+
|
|
6337
|
+
// src/standard/datatypes/index.ts
|
|
6338
|
+
var withMetadata2 = (kind) => {
|
|
6339
|
+
const kindSpec = standardDatatypeKinds[kind];
|
|
6340
|
+
const familySpec = standardDatatypeFamilies[kindSpec.family];
|
|
6001
6341
|
return {
|
|
6002
|
-
|
|
6003
|
-
|
|
6342
|
+
dialect: "standard",
|
|
6343
|
+
kind,
|
|
6344
|
+
family: kindSpec.family,
|
|
6345
|
+
runtime: kindSpec.runtime,
|
|
6346
|
+
compareGroup: familySpec?.compareGroup,
|
|
6347
|
+
castTargets: familySpec?.castTargets,
|
|
6348
|
+
implicitTargets: familySpec.implicitTargets,
|
|
6349
|
+
traits: familySpec?.traits
|
|
6004
6350
|
};
|
|
6005
6351
|
};
|
|
6006
|
-
var
|
|
6007
|
-
|
|
6008
|
-
|
|
6009
|
-
|
|
6010
|
-
|
|
6011
|
-
|
|
6012
|
-
|
|
6013
|
-
|
|
6352
|
+
var standardDatatypeModule = {
|
|
6353
|
+
custom: (kind) => ({
|
|
6354
|
+
dialect: "standard",
|
|
6355
|
+
kind
|
|
6356
|
+
}),
|
|
6357
|
+
uuid: () => ({
|
|
6358
|
+
dialect: "standard",
|
|
6359
|
+
kind: "uuid",
|
|
6360
|
+
family: "uuid",
|
|
6361
|
+
runtime: "string",
|
|
6362
|
+
compareGroup: "uuid",
|
|
6363
|
+
castTargets: ["uuid", "char", "varchar", "text"],
|
|
6364
|
+
traits: {
|
|
6365
|
+
textual: true
|
|
6366
|
+
}
|
|
6367
|
+
})
|
|
6368
|
+
};
|
|
6369
|
+
for (const kind of Object.keys(standardDatatypeKinds)) {
|
|
6370
|
+
standardDatatypeModule[kind] = () => withMetadata2(kind);
|
|
6371
|
+
}
|
|
6372
|
+
standardDatatypeModule.json = () => ({
|
|
6373
|
+
...withMetadata2("json"),
|
|
6374
|
+
driverValueMapping: {
|
|
6375
|
+
toDriver: (value) => JSON.stringify(value)
|
|
6376
|
+
}
|
|
6377
|
+
});
|
|
6378
|
+
var standardDatatypes = {
|
|
6379
|
+
...standardDatatypeModule
|
|
6380
|
+
};
|
|
6381
|
+
|
|
6382
|
+
// src/internal/standard-dsl.ts
|
|
6383
|
+
var profile2 = {
|
|
6384
|
+
dialect: "standard",
|
|
6385
|
+
textDb: standardDatatypes.text(),
|
|
6386
|
+
numericDb: standardDatatypes.real(),
|
|
6387
|
+
boolDb: standardDatatypes.boolean(),
|
|
6388
|
+
timestampDb: standardDatatypes.timestamp(),
|
|
6389
|
+
nullDb: {
|
|
6390
|
+
dialect: "standard",
|
|
6391
|
+
kind: "null",
|
|
6392
|
+
family: "null",
|
|
6393
|
+
runtime: "unknown",
|
|
6394
|
+
compareGroup: "null",
|
|
6395
|
+
traits: {}
|
|
6396
|
+
},
|
|
6397
|
+
type: standardDatatypes
|
|
6398
|
+
};
|
|
6399
|
+
var ValuesInputProto2 = {
|
|
6400
|
+
pipe() {
|
|
6401
|
+
return pipeArguments8(this, arguments);
|
|
6402
|
+
}
|
|
6403
|
+
};
|
|
6404
|
+
var literalSchemaOf2 = (value) => {
|
|
6405
|
+
if (value === null || value instanceof Date) {
|
|
6406
|
+
return;
|
|
6407
|
+
}
|
|
6408
|
+
if (typeof value === "number" && !Number.isFinite(value)) {
|
|
6409
|
+
return;
|
|
6410
|
+
}
|
|
6411
|
+
return Schema7.Literal(value);
|
|
6412
|
+
};
|
|
6413
|
+
var literal3 = (value) => makeExpression2({
|
|
6414
|
+
runtime: undefined,
|
|
6415
|
+
dbType: value === null ? profile2.nullDb : value instanceof Date ? profile2.timestampDb : typeof value === "string" ? profile2.textDb : typeof value === "number" ? profile2.numericDb : profile2.boolDb,
|
|
6416
|
+
runtimeSchema: literalSchemaOf2(value),
|
|
6417
|
+
nullability: value === null ? "always" : "never",
|
|
6418
|
+
dialect: profile2.dialect,
|
|
6419
|
+
kind: "scalar",
|
|
6420
|
+
dependencies: {}
|
|
6421
|
+
}, {
|
|
6422
|
+
kind: "literal",
|
|
6423
|
+
value
|
|
6424
|
+
});
|
|
6425
|
+
var column = (name, dbType, nullable2 = false) => makeExpression2({
|
|
6426
|
+
runtime: undefined,
|
|
6427
|
+
dbType,
|
|
6428
|
+
nullability: nullable2 ? "maybe" : "never",
|
|
6429
|
+
dialect: profile2.dialect,
|
|
6430
|
+
kind: "scalar",
|
|
6431
|
+
dependencies: {}
|
|
6432
|
+
}, {
|
|
6433
|
+
kind: "column",
|
|
6434
|
+
tableName: "",
|
|
6435
|
+
columnName: name
|
|
6436
|
+
});
|
|
6437
|
+
var toDialectExpression2 = (value) => {
|
|
6438
|
+
if (value !== null && typeof value === "object" && TypeId in value) {
|
|
6439
|
+
return value;
|
|
6440
|
+
}
|
|
6441
|
+
return literal3(value);
|
|
6442
|
+
};
|
|
6443
|
+
var retargetLiteralExpression2 = (value, target) => {
|
|
6444
|
+
const ast = value[TypeId2];
|
|
6445
|
+
if (ast.kind !== "literal") {
|
|
6446
|
+
return value;
|
|
6447
|
+
}
|
|
6448
|
+
const targetState = target[TypeId];
|
|
6449
|
+
return makeExpression2({
|
|
6450
|
+
runtime: value[TypeId].runtime,
|
|
6451
|
+
dbType: targetState.dbType,
|
|
6452
|
+
runtimeSchema: targetState.runtimeSchema,
|
|
6453
|
+
driverValueMapping: targetState.driverValueMapping,
|
|
6454
|
+
nullability: value[TypeId].nullability,
|
|
6455
|
+
dialect: targetState.dialect,
|
|
6456
|
+
kind: "scalar",
|
|
6457
|
+
dependencies: {}
|
|
6458
|
+
}, ast);
|
|
6459
|
+
};
|
|
6460
|
+
var alignBinaryPredicateExpressions2 = (left, right) => {
|
|
6461
|
+
const leftAst = left[TypeId2];
|
|
6462
|
+
const rightAst = right[TypeId2];
|
|
6463
|
+
if (leftAst.kind === "literal" && rightAst.kind !== "literal") {
|
|
6464
|
+
return [retargetLiteralExpression2(left, right), right];
|
|
6465
|
+
}
|
|
6466
|
+
if (rightAst.kind === "literal" && leftAst.kind !== "literal") {
|
|
6467
|
+
return [left, retargetLiteralExpression2(right, left)];
|
|
6468
|
+
}
|
|
6469
|
+
return [left, right];
|
|
6470
|
+
};
|
|
6471
|
+
var toDialectStringExpression2 = (value) => typeof value === "string" ? literal3(value) : value;
|
|
6472
|
+
var toDialectNumericExpression2 = (value) => typeof value === "number" ? literal3(value) : value;
|
|
6473
|
+
var flattenVariadicBooleanExpressions = (kind, values2) => {
|
|
6474
|
+
const flattened = [];
|
|
6475
|
+
for (const value of values2) {
|
|
6476
|
+
const ast = value[TypeId2];
|
|
6477
|
+
if (ast.kind === kind) {
|
|
6478
|
+
flattened.push(...ast.values);
|
|
6479
|
+
} else {
|
|
6480
|
+
flattened.push(value);
|
|
6481
|
+
}
|
|
6482
|
+
}
|
|
6483
|
+
return flattened;
|
|
6484
|
+
};
|
|
6485
|
+
var makeVariadicBooleanExpression = (kind, values2) => {
|
|
6486
|
+
const expressions = flattenVariadicBooleanExpressions(kind, values2);
|
|
6487
|
+
const expression = makeExpression2({
|
|
6488
|
+
runtime: true,
|
|
6489
|
+
dbType: profile2.boolDb,
|
|
6490
|
+
nullability: mergeNullabilityManyRuntime(expressions),
|
|
6491
|
+
dialect: expressions.find((value) => value[TypeId].dialect !== undefined)?.[TypeId].dialect ?? profile2.dialect,
|
|
6492
|
+
kind: "scalar",
|
|
6493
|
+
dependencies: mergeManyDependencies(expressions)
|
|
6494
|
+
}, {
|
|
6495
|
+
kind,
|
|
6496
|
+
values: expressions
|
|
6497
|
+
});
|
|
6498
|
+
Object.defineProperty(expression, "pipe", {
|
|
6499
|
+
configurable: true,
|
|
6500
|
+
writable: true,
|
|
6501
|
+
value() {
|
|
6502
|
+
if (arguments.length === 0) {
|
|
6503
|
+
return this;
|
|
6504
|
+
}
|
|
6505
|
+
const operations = Array.from(arguments);
|
|
6506
|
+
if (operations.every((operation) => typeof operation !== "function")) {
|
|
6507
|
+
const appended = operations.map((operation) => toDialectExpression2(operation));
|
|
6508
|
+
return makeVariadicBooleanExpression(kind, [...expressions, ...appended]);
|
|
6509
|
+
}
|
|
6510
|
+
if (operations.every((operation) => typeof operation === "function")) {
|
|
6511
|
+
return pipeArguments8(this, arguments);
|
|
6512
|
+
}
|
|
6513
|
+
const valuesForMixedPipe = (value) => {
|
|
6514
|
+
if (typeof value !== "object" || value === null || !(TypeId in value)) {
|
|
6515
|
+
return [];
|
|
6516
|
+
}
|
|
6517
|
+
const expression2 = value;
|
|
6518
|
+
const ast = expression2[TypeId2];
|
|
6519
|
+
if (ast.kind === kind) {
|
|
6520
|
+
return ast.values;
|
|
6521
|
+
}
|
|
6522
|
+
return [expression2];
|
|
6523
|
+
};
|
|
6524
|
+
let current = this;
|
|
6525
|
+
for (const operation of operations) {
|
|
6526
|
+
if (typeof operation === "function") {
|
|
6527
|
+
current = operation(current);
|
|
6528
|
+
continue;
|
|
6529
|
+
}
|
|
6530
|
+
current = makeVariadicBooleanExpression(kind, [...valuesForMixedPipe(current), toDialectExpression2(operation)]);
|
|
6531
|
+
}
|
|
6532
|
+
return current;
|
|
6533
|
+
}
|
|
6534
|
+
});
|
|
6535
|
+
return expression;
|
|
6536
|
+
};
|
|
6537
|
+
var extractRequiredFromDialectInputRuntime2 = (value) => {
|
|
6538
|
+
const expression = toDialectExpression2(value);
|
|
6539
|
+
return Object.keys(expression[TypeId].dependencies);
|
|
6540
|
+
};
|
|
6541
|
+
var normalizeWindowSpec2 = (spec) => {
|
|
6542
|
+
if (spec?.frame !== undefined) {
|
|
6543
|
+
throw new Error("over does not accept an explicit frame on the portable Function API; use a dialect Function.over helper");
|
|
6544
|
+
}
|
|
6545
|
+
validateWindowFrame(spec?.frame);
|
|
6546
|
+
const partitionBy = [...spec?.partitionBy ?? []];
|
|
6547
|
+
const orderBy2 = (spec?.orderBy ?? []).map((term) => {
|
|
6548
|
+
const direction = term.direction ?? "asc";
|
|
6549
|
+
return {
|
|
6550
|
+
value: term.value,
|
|
6551
|
+
direction
|
|
6552
|
+
};
|
|
6553
|
+
});
|
|
6554
|
+
return {
|
|
6555
|
+
partitionBy,
|
|
6556
|
+
orderBy: orderBy2,
|
|
6557
|
+
frame: spec?.frame
|
|
6558
|
+
};
|
|
6559
|
+
};
|
|
6560
|
+
var mergeWindowExpressions2 = (value, partitionBy, orderBy2) => value === undefined ? [...partitionBy, ...orderBy2.map((term) => term.value)] : [value, ...partitionBy, ...orderBy2.map((term) => term.value)];
|
|
6561
|
+
var extractRequiredFromDialectNumericInputRuntime2 = (value) => {
|
|
6562
|
+
const expression = toDialectNumericExpression2(value);
|
|
6563
|
+
return Object.keys(expression[TypeId].dependencies);
|
|
6564
|
+
};
|
|
6565
|
+
var buildBinaryPredicate2 = (left, right, kind, nullability = "maybe") => {
|
|
6566
|
+
const [leftExpression, rightExpression] = alignBinaryPredicateExpressions2(toDialectExpression2(left), toDialectExpression2(right));
|
|
6567
|
+
return makeExpression2({
|
|
6568
|
+
runtime: true,
|
|
6569
|
+
dbType: profile2.boolDb,
|
|
6570
|
+
nullability,
|
|
6571
|
+
dialect: leftExpression[TypeId].dialect ?? rightExpression[TypeId].dialect,
|
|
6572
|
+
kind: "scalar",
|
|
6573
|
+
dependencies: mergeDependencies(leftExpression[TypeId].dependencies, rightExpression[TypeId].dependencies)
|
|
6574
|
+
}, {
|
|
6575
|
+
kind,
|
|
6576
|
+
left: leftExpression,
|
|
6577
|
+
right: rightExpression
|
|
6578
|
+
});
|
|
6579
|
+
};
|
|
6580
|
+
var buildVariadicPredicate = (values2, kind) => {
|
|
6581
|
+
const expressions = values2.map((value) => toDialectExpression2(value));
|
|
6582
|
+
const [head, ...tail] = expressions;
|
|
6583
|
+
const alignedExpressions = head !== undefined && (kind === "in" || kind === "notIn" || kind === "between") ? [head, ...tail.map((value) => retargetLiteralExpression2(value, head))] : expressions;
|
|
6584
|
+
return makeExpression2({
|
|
6585
|
+
runtime: true,
|
|
6586
|
+
dbType: profile2.boolDb,
|
|
6587
|
+
nullability: "maybe",
|
|
6588
|
+
dialect: alignedExpressions.find((value) => value[TypeId].dialect !== undefined)?.[TypeId].dialect ?? profile2.dialect,
|
|
6589
|
+
kind: "scalar",
|
|
6590
|
+
dependencies: mergeManyDependencies(alignedExpressions)
|
|
6591
|
+
}, {
|
|
6592
|
+
kind,
|
|
6593
|
+
values: alignedExpressions
|
|
6594
|
+
});
|
|
6595
|
+
};
|
|
6596
|
+
var eq = (...args) => {
|
|
6597
|
+
const left = args[0];
|
|
6598
|
+
const right = args[1];
|
|
6599
|
+
return buildBinaryPredicate2(left, right, "eq");
|
|
6600
|
+
};
|
|
6601
|
+
var neq = (...args) => {
|
|
6602
|
+
const left = args[0];
|
|
6603
|
+
const right = args[1];
|
|
6604
|
+
return buildBinaryPredicate2(left, right, "neq");
|
|
6605
|
+
};
|
|
6606
|
+
var lt = (...args) => {
|
|
6607
|
+
const left = args[0];
|
|
6608
|
+
const right = args[1];
|
|
6609
|
+
return buildBinaryPredicate2(left, right, "lt");
|
|
6610
|
+
};
|
|
6611
|
+
var lte = (...args) => {
|
|
6612
|
+
const left = args[0];
|
|
6613
|
+
const right = args[1];
|
|
6614
|
+
return buildBinaryPredicate2(left, right, "lte");
|
|
6615
|
+
};
|
|
6616
|
+
var gt = (...args) => {
|
|
6617
|
+
const left = args[0];
|
|
6618
|
+
const right = args[1];
|
|
6619
|
+
return buildBinaryPredicate2(left, right, "gt");
|
|
6620
|
+
};
|
|
6621
|
+
var gte = (...args) => {
|
|
6622
|
+
const left = args[0];
|
|
6623
|
+
const right = args[1];
|
|
6624
|
+
return buildBinaryPredicate2(left, right, "gte");
|
|
6625
|
+
};
|
|
6626
|
+
var like = (...args) => {
|
|
6627
|
+
const left = args[0];
|
|
6628
|
+
const right = args[1];
|
|
6629
|
+
return buildBinaryPredicate2(left, right, "like");
|
|
6630
|
+
};
|
|
6631
|
+
var ilike = (...args) => {
|
|
6632
|
+
const left = args[0];
|
|
6633
|
+
const right = args[1];
|
|
6634
|
+
return buildBinaryPredicate2(left, right, "ilike");
|
|
6635
|
+
};
|
|
6636
|
+
var regexMatch = (...args) => {
|
|
6637
|
+
const left = args[0];
|
|
6638
|
+
const right = args[1];
|
|
6639
|
+
return buildBinaryPredicate2(left, right, "regexMatch");
|
|
6640
|
+
};
|
|
6641
|
+
var regexIMatch = (...args) => {
|
|
6642
|
+
const left = args[0];
|
|
6643
|
+
const right = args[1];
|
|
6644
|
+
return buildBinaryPredicate2(left, right, "regexIMatch");
|
|
6645
|
+
};
|
|
6646
|
+
var regexNotMatch = (...args) => {
|
|
6647
|
+
const left = args[0];
|
|
6648
|
+
const right = args[1];
|
|
6649
|
+
return buildBinaryPredicate2(left, right, "regexNotMatch");
|
|
6650
|
+
};
|
|
6651
|
+
var regexNotIMatch = (...args) => {
|
|
6652
|
+
const left = args[0];
|
|
6653
|
+
const right = args[1];
|
|
6654
|
+
return buildBinaryPredicate2(left, right, "regexNotIMatch");
|
|
6655
|
+
};
|
|
6656
|
+
var isDistinctFrom = (...args) => {
|
|
6657
|
+
const left = args[0];
|
|
6658
|
+
const right = args[1];
|
|
6659
|
+
return buildBinaryPredicate2(left, right, "isDistinctFrom", "never");
|
|
6660
|
+
};
|
|
6661
|
+
var isNotDistinctFrom = (...args) => {
|
|
6662
|
+
const left = args[0];
|
|
6663
|
+
const right = args[1];
|
|
6664
|
+
return buildBinaryPredicate2(left, right, "isNotDistinctFrom", "never");
|
|
6665
|
+
};
|
|
6666
|
+
var isNull = (value) => {
|
|
6667
|
+
const expression = toDialectExpression2(value);
|
|
6668
|
+
return makeExpression2({
|
|
6669
|
+
runtime: true,
|
|
6670
|
+
dbType: profile2.boolDb,
|
|
6671
|
+
nullability: "never",
|
|
6672
|
+
dialect: expression[TypeId].dialect,
|
|
6673
|
+
kind: "scalar",
|
|
6674
|
+
dependencies: expression[TypeId].dependencies
|
|
6675
|
+
}, {
|
|
6676
|
+
kind: "isNull",
|
|
6677
|
+
value: expression
|
|
6678
|
+
});
|
|
6679
|
+
};
|
|
6680
|
+
var isNotNull = (value) => {
|
|
6681
|
+
const expression = toDialectExpression2(value);
|
|
6682
|
+
return makeExpression2({
|
|
6683
|
+
runtime: true,
|
|
6684
|
+
dbType: profile2.boolDb,
|
|
6685
|
+
nullability: "never",
|
|
6686
|
+
dialect: expression[TypeId].dialect,
|
|
6687
|
+
kind: "scalar",
|
|
6688
|
+
dependencies: expression[TypeId].dependencies
|
|
6689
|
+
}, {
|
|
6690
|
+
kind: "isNotNull",
|
|
6691
|
+
value: expression
|
|
6692
|
+
});
|
|
6693
|
+
};
|
|
6694
|
+
var collate = (value, collation) => {
|
|
6695
|
+
const expression = toDialectStringExpression2(value);
|
|
6696
|
+
const normalizedCollation = typeof collation === "string" ? [collation] : collation;
|
|
6697
|
+
return makeExpression2({
|
|
6698
|
+
runtime: expression[TypeId].runtime,
|
|
6699
|
+
dbType: expression[TypeId].dbType,
|
|
6700
|
+
nullability: expression[TypeId].nullability,
|
|
6701
|
+
dialect: expression[TypeId].dialect,
|
|
6702
|
+
kind: expression[TypeId].kind,
|
|
6703
|
+
dependencies: expression[TypeId].dependencies
|
|
6704
|
+
}, {
|
|
6705
|
+
kind: "collate",
|
|
6706
|
+
value: expression,
|
|
6707
|
+
collation: normalizedCollation
|
|
6708
|
+
});
|
|
6709
|
+
};
|
|
6710
|
+
var cast = (value, target) => {
|
|
6711
|
+
const expression = toDialectExpression2(value);
|
|
6712
|
+
return makeExpression2({
|
|
6713
|
+
runtime: undefined,
|
|
6714
|
+
dbType: target,
|
|
6715
|
+
runtimeSchema: undefined,
|
|
6716
|
+
driverValueMapping: target.driverValueMapping,
|
|
6717
|
+
nullability: expression[TypeId].nullability,
|
|
6718
|
+
dialect: expression[TypeId].dialect,
|
|
6719
|
+
kind: expression[TypeId].kind,
|
|
6720
|
+
dependencies: expression[TypeId].dependencies
|
|
6721
|
+
}, {
|
|
6722
|
+
kind: "cast",
|
|
6723
|
+
value: expression,
|
|
6724
|
+
target
|
|
6725
|
+
});
|
|
6726
|
+
};
|
|
6727
|
+
var custom3 = (kind) => ({
|
|
6728
|
+
dialect: profile2.dialect,
|
|
6729
|
+
kind
|
|
6730
|
+
});
|
|
6731
|
+
var driverValueMapping3 = (dbType, mapping) => ({
|
|
6732
|
+
...dbType,
|
|
6733
|
+
driverValueMapping: mapping
|
|
6734
|
+
});
|
|
6735
|
+
var type2 = {
|
|
6736
|
+
...profile2.type,
|
|
6737
|
+
custom: custom3,
|
|
6738
|
+
driverValueMapping: driverValueMapping3
|
|
6739
|
+
};
|
|
6740
|
+
var makeJsonDb2 = (kind) => ({
|
|
6741
|
+
dialect: profile2.dialect,
|
|
6742
|
+
kind,
|
|
6743
|
+
variant: kind === "jsonb" ? "jsonb" : "json"
|
|
6744
|
+
});
|
|
6745
|
+
var jsonDb2 = makeJsonDb2("json");
|
|
6746
|
+
var jsonbDb2 = makeJsonDb2("jsonb");
|
|
6747
|
+
var isExpressionValue2 = (value) => value !== null && typeof value === "object" && (TypeId in value);
|
|
6748
|
+
var isJsonExpressionValue2 = (value) => isExpressionValue2(value) && (() => {
|
|
6749
|
+
const dbType = value[TypeId].dbType;
|
|
6750
|
+
return dbType.variant === "json" || dbType.kind === "json" || dbType.kind === "jsonb";
|
|
6751
|
+
})();
|
|
6752
|
+
var isJsonPathValue2 = (value) => value !== null && typeof value === "object" && (TypeId3 in value);
|
|
6753
|
+
var normalizeJsonPathInput2 = (value) => isJsonPathValue2(value) ? value.segments : [value];
|
|
6754
|
+
var isExactJsonSegmentValue2 = (segment) => segment.kind === "key" || segment.kind === "index";
|
|
6755
|
+
var isExactJsonPathValue2 = (segments) => segments.every(isExactJsonSegmentValue2);
|
|
6756
|
+
var buildJsonNodeExpression2 = (expressions, state, ast) => withJsonPathAccess(makeExpression2({
|
|
6757
|
+
runtime: state.runtime,
|
|
6758
|
+
dbType: state.dbType,
|
|
6759
|
+
nullability: state.nullability,
|
|
6760
|
+
dialect: expressions.find((expression) => expression[TypeId].dialect !== undefined)?.[TypeId].dialect ?? profile2.dialect,
|
|
6761
|
+
kind: mergeAggregationManyRuntime(expressions),
|
|
6762
|
+
dependencies: mergeManyDependencies(expressions)
|
|
6763
|
+
}, ast));
|
|
6764
|
+
var jsonDbTypeOf2 = (base) => base[TypeId].dbType;
|
|
6765
|
+
var resolveJsonMergeDbType2 = (..._values) => jsonbDb2;
|
|
6766
|
+
var makeJsonLiteralExpression2 = (value, dbType = jsonDb2) => withJsonPathAccess(makeExpression2({
|
|
6767
|
+
runtime: value,
|
|
6768
|
+
dbType,
|
|
6769
|
+
nullability: value === null ? "always" : "never",
|
|
6770
|
+
dialect: profile2.dialect,
|
|
6771
|
+
kind: "scalar",
|
|
6772
|
+
dependencies: {}
|
|
6773
|
+
}, {
|
|
6774
|
+
kind: "literal",
|
|
6775
|
+
value
|
|
6776
|
+
}));
|
|
6777
|
+
var wrapJsonExpression2 = (value, kind, dbType) => buildJsonNodeExpression2([value], {
|
|
6778
|
+
runtime: undefined,
|
|
6779
|
+
dbType,
|
|
6780
|
+
nullability: value[TypeId].nullability
|
|
6781
|
+
}, {
|
|
6782
|
+
kind,
|
|
6783
|
+
value
|
|
6784
|
+
});
|
|
6785
|
+
var toJsonValueExpression2 = (value, kind = "jsonToJson", dbType = jsonDb2) => {
|
|
6786
|
+
if (isJsonExpressionValue2(value)) {
|
|
6787
|
+
return value;
|
|
6788
|
+
}
|
|
6789
|
+
if (isExpressionValue2(value)) {
|
|
6790
|
+
return wrapJsonExpression2(value, kind, dbType);
|
|
6791
|
+
}
|
|
6792
|
+
return makeJsonLiteralExpression2(value, dbType);
|
|
6793
|
+
};
|
|
6794
|
+
var jsonQueryExpression2 = (query) => toDialectStringExpression2(query);
|
|
6795
|
+
var jsonGet2 = (base, target) => {
|
|
6796
|
+
const segments = normalizeJsonPathInput2(target);
|
|
6797
|
+
const kind = isJsonPathValue2(target) ? isExactJsonPathValue2(segments) ? "jsonPath" : "jsonTraverse" : isExactJsonSegmentValue2(target) ? "jsonGet" : "jsonAccess";
|
|
6798
|
+
return buildJsonNodeExpression2([base], {
|
|
6799
|
+
runtime: undefined,
|
|
6800
|
+
dbType: jsonDbTypeOf2(base),
|
|
6801
|
+
nullability: undefined
|
|
6802
|
+
}, {
|
|
6803
|
+
kind,
|
|
6804
|
+
base,
|
|
6805
|
+
segments
|
|
6806
|
+
});
|
|
6807
|
+
};
|
|
6808
|
+
var jsonText2 = (base, target) => {
|
|
6809
|
+
const segments = normalizeJsonPathInput2(target);
|
|
6810
|
+
const kind = isJsonPathValue2(target) ? isExactJsonPathValue2(segments) ? "jsonPathText" : "jsonTraverseText" : isExactJsonSegmentValue2(target) ? "jsonGetText" : "jsonAccessText";
|
|
6811
|
+
return buildJsonNodeExpression2([base], {
|
|
6812
|
+
runtime: undefined,
|
|
6813
|
+
dbType: profile2.textDb,
|
|
6814
|
+
nullability: undefined
|
|
6815
|
+
}, {
|
|
6816
|
+
kind,
|
|
6817
|
+
base,
|
|
6818
|
+
segments
|
|
6819
|
+
});
|
|
6820
|
+
};
|
|
6821
|
+
var jsonAccess2 = (base, target) => {
|
|
6822
|
+
const segments = normalizeJsonPathInput2(target);
|
|
6823
|
+
return buildJsonNodeExpression2([base], {
|
|
6824
|
+
runtime: undefined,
|
|
6825
|
+
dbType: jsonDbTypeOf2(base),
|
|
6826
|
+
nullability: undefined
|
|
6827
|
+
}, {
|
|
6828
|
+
kind: isJsonPathValue2(target) || segments.length > 1 ? "jsonTraverse" : "jsonAccess",
|
|
6829
|
+
base,
|
|
6830
|
+
segments
|
|
6831
|
+
});
|
|
6832
|
+
};
|
|
6833
|
+
var jsonTraverse2 = (base, target) => {
|
|
6834
|
+
const segments = normalizeJsonPathInput2(target);
|
|
6835
|
+
return buildJsonNodeExpression2([base], {
|
|
6836
|
+
runtime: undefined,
|
|
6837
|
+
dbType: jsonDbTypeOf2(base),
|
|
6838
|
+
nullability: undefined
|
|
6839
|
+
}, {
|
|
6840
|
+
kind: "jsonTraverse",
|
|
6841
|
+
base,
|
|
6842
|
+
segments
|
|
6843
|
+
});
|
|
6844
|
+
};
|
|
6845
|
+
var jsonAccessText2 = (base, target) => {
|
|
6846
|
+
const segments = normalizeJsonPathInput2(target);
|
|
6847
|
+
return buildJsonNodeExpression2([base], {
|
|
6848
|
+
runtime: undefined,
|
|
6849
|
+
dbType: profile2.textDb,
|
|
6850
|
+
nullability: undefined
|
|
6851
|
+
}, {
|
|
6852
|
+
kind: isJsonPathValue2(target) || segments.length > 1 ? "jsonTraverseText" : "jsonAccessText",
|
|
6853
|
+
base,
|
|
6854
|
+
segments
|
|
6855
|
+
});
|
|
6856
|
+
};
|
|
6857
|
+
var jsonTraverseText2 = (base, target) => {
|
|
6858
|
+
const segments = normalizeJsonPathInput2(target);
|
|
6859
|
+
return buildJsonNodeExpression2([base], {
|
|
6860
|
+
runtime: undefined,
|
|
6861
|
+
dbType: profile2.textDb,
|
|
6862
|
+
nullability: undefined
|
|
6863
|
+
}, {
|
|
6864
|
+
kind: "jsonTraverseText",
|
|
6865
|
+
base,
|
|
6866
|
+
segments
|
|
6867
|
+
});
|
|
6868
|
+
};
|
|
6869
|
+
var jsonContains2 = (left, right) => buildBinaryPredicate2(left, toJsonValueExpression2(right), "contains");
|
|
6870
|
+
var jsonContainedBy2 = (left, right) => buildBinaryPredicate2(left, toJsonValueExpression2(right), "containedBy");
|
|
6871
|
+
var jsonHasKey2 = (base, key2) => buildJsonNodeExpression2([base], {
|
|
6872
|
+
runtime: true,
|
|
6873
|
+
dbType: profile2.boolDb,
|
|
6874
|
+
nullability: "never"
|
|
6875
|
+
}, {
|
|
6876
|
+
kind: "jsonHasKey",
|
|
6877
|
+
base,
|
|
6878
|
+
keys: [key2]
|
|
6879
|
+
});
|
|
6880
|
+
var jsonHasAnyKeys2 = (base, ...keys) => buildJsonNodeExpression2([base], {
|
|
6881
|
+
runtime: true,
|
|
6882
|
+
dbType: profile2.boolDb,
|
|
6883
|
+
nullability: "never"
|
|
6884
|
+
}, {
|
|
6885
|
+
kind: "jsonHasAnyKeys",
|
|
6886
|
+
base,
|
|
6887
|
+
keys
|
|
6888
|
+
});
|
|
6889
|
+
var jsonHasAllKeys2 = (base, ...keys) => buildJsonNodeExpression2([base], {
|
|
6890
|
+
runtime: true,
|
|
6891
|
+
dbType: profile2.boolDb,
|
|
6892
|
+
nullability: "never"
|
|
6893
|
+
}, {
|
|
6894
|
+
kind: "jsonHasAllKeys",
|
|
6895
|
+
base,
|
|
6896
|
+
keys
|
|
6897
|
+
});
|
|
6898
|
+
var jsonDelete2 = (base, target) => {
|
|
6899
|
+
const segments = normalizeJsonPathInput2(target);
|
|
6900
|
+
return buildJsonNodeExpression2([base], {
|
|
6901
|
+
runtime: undefined,
|
|
6902
|
+
dbType: jsonDbTypeOf2(base),
|
|
6903
|
+
nullability: undefined
|
|
6904
|
+
}, {
|
|
6905
|
+
kind: isJsonPathValue2(target) ? "jsonDeletePath" : "jsonDelete",
|
|
6906
|
+
base,
|
|
6907
|
+
segments
|
|
6908
|
+
});
|
|
6909
|
+
};
|
|
6910
|
+
var jsonRemove2 = (base, target) => {
|
|
6911
|
+
const segments = normalizeJsonPathInput2(target);
|
|
6912
|
+
return buildJsonNodeExpression2([base], {
|
|
6913
|
+
runtime: undefined,
|
|
6914
|
+
dbType: jsonDbTypeOf2(base),
|
|
6915
|
+
nullability: undefined
|
|
6916
|
+
}, {
|
|
6917
|
+
kind: "jsonRemove",
|
|
6918
|
+
base,
|
|
6919
|
+
segments
|
|
6920
|
+
});
|
|
6921
|
+
};
|
|
6922
|
+
var jsonSet2 = (base, target, next, options2 = {}) => {
|
|
6923
|
+
const segments = normalizeJsonPathInput2(target);
|
|
6924
|
+
const newValue = toJsonValueExpression2(next);
|
|
6925
|
+
return buildJsonNodeExpression2([base, newValue], {
|
|
6926
|
+
runtime: undefined,
|
|
6927
|
+
dbType: jsonDbTypeOf2(base),
|
|
6928
|
+
nullability: undefined
|
|
6929
|
+
}, {
|
|
6930
|
+
kind: "jsonSet",
|
|
6931
|
+
base,
|
|
6932
|
+
segments,
|
|
6933
|
+
newValue,
|
|
6934
|
+
createMissing: options2.createMissing ?? true
|
|
6935
|
+
});
|
|
6936
|
+
};
|
|
6937
|
+
var jsonInsert2 = (base, target, next, options2 = {}) => {
|
|
6938
|
+
const segments = normalizeJsonPathInput2(target);
|
|
6939
|
+
const insert = toJsonValueExpression2(next);
|
|
6940
|
+
const insertAfter = options2.insertAfter ?? false;
|
|
6941
|
+
return buildJsonNodeExpression2([base, insert], {
|
|
6942
|
+
runtime: undefined,
|
|
6943
|
+
dbType: jsonDbTypeOf2(base),
|
|
6944
|
+
nullability: undefined
|
|
6945
|
+
}, {
|
|
6946
|
+
kind: "jsonInsert",
|
|
6947
|
+
base,
|
|
6948
|
+
segments,
|
|
6949
|
+
insert,
|
|
6950
|
+
insertAfter
|
|
6951
|
+
});
|
|
6952
|
+
};
|
|
6953
|
+
var jsonConcatAs2 = (dbType) => (left, right) => {
|
|
6954
|
+
const leftExpression = toJsonValueExpression2(left);
|
|
6955
|
+
const rightExpression = toJsonValueExpression2(right);
|
|
6956
|
+
return buildJsonNodeExpression2([leftExpression, rightExpression], {
|
|
6957
|
+
runtime: undefined,
|
|
6958
|
+
dbType,
|
|
6959
|
+
nullability: "maybe"
|
|
6960
|
+
}, {
|
|
6961
|
+
kind: "jsonConcat",
|
|
6962
|
+
left: leftExpression,
|
|
6963
|
+
right: rightExpression
|
|
6964
|
+
});
|
|
6965
|
+
};
|
|
6966
|
+
var jsonMergeAs2 = (dbType) => (left, right) => {
|
|
6967
|
+
const leftExpression = toJsonValueExpression2(left);
|
|
6968
|
+
const rightExpression = toJsonValueExpression2(right);
|
|
6969
|
+
return buildJsonNodeExpression2([leftExpression, rightExpression], {
|
|
6970
|
+
runtime: undefined,
|
|
6971
|
+
dbType,
|
|
6972
|
+
nullability: "maybe"
|
|
6973
|
+
}, {
|
|
6974
|
+
kind: "jsonMerge",
|
|
6975
|
+
left: leftExpression,
|
|
6976
|
+
right: rightExpression
|
|
6977
|
+
});
|
|
6978
|
+
};
|
|
6979
|
+
var jsonConcat2 = jsonConcatAs2(resolveJsonMergeDbType2());
|
|
6980
|
+
var jsonMerge2 = jsonMergeAs2(resolveJsonMergeDbType2());
|
|
6981
|
+
var jsonKeyExists2 = (base, key2) => buildJsonNodeExpression2([base], {
|
|
6982
|
+
runtime: true,
|
|
6983
|
+
dbType: profile2.boolDb,
|
|
6984
|
+
nullability: "never"
|
|
6985
|
+
}, {
|
|
6986
|
+
kind: "jsonKeyExists",
|
|
6987
|
+
base,
|
|
6988
|
+
keys: [key2]
|
|
6989
|
+
});
|
|
6990
|
+
var jsonBuildObjectAs2 = (dbType) => (shape) => {
|
|
6991
|
+
const entries = Object.entries(shape).map(([key2, value]) => ({
|
|
6992
|
+
key: key2,
|
|
6993
|
+
value: toJsonValueExpression2(value)
|
|
6994
|
+
}));
|
|
6995
|
+
return buildJsonNodeExpression2(entries.map((entry) => entry.value), {
|
|
6996
|
+
runtime: {},
|
|
6997
|
+
dbType,
|
|
6998
|
+
nullability: "never"
|
|
6999
|
+
}, {
|
|
7000
|
+
kind: "jsonBuildObject",
|
|
7001
|
+
entries
|
|
7002
|
+
});
|
|
7003
|
+
};
|
|
7004
|
+
var jsonBuildArrayAs2 = (dbType) => (...values2) => {
|
|
7005
|
+
const expressions = values2.map((value) => toJsonValueExpression2(value));
|
|
7006
|
+
return buildJsonNodeExpression2(expressions, {
|
|
7007
|
+
runtime: [],
|
|
7008
|
+
dbType,
|
|
7009
|
+
nullability: "never"
|
|
7010
|
+
}, {
|
|
7011
|
+
kind: "jsonBuildArray",
|
|
7012
|
+
values: expressions
|
|
7013
|
+
});
|
|
7014
|
+
};
|
|
7015
|
+
var jsonBuildObject2 = jsonBuildObjectAs2(jsonDb2);
|
|
7016
|
+
var jsonBuildArray2 = jsonBuildArrayAs2(jsonDb2);
|
|
7017
|
+
var jsonbBuildObject2 = jsonBuildObjectAs2(jsonbDb2);
|
|
7018
|
+
var jsonbBuildArray2 = jsonBuildArrayAs2(jsonbDb2);
|
|
7019
|
+
var jsonToJson2 = (value) => toJsonValueExpression2(value, "jsonToJson", jsonDb2);
|
|
7020
|
+
var jsonToJsonb2 = (value) => toJsonValueExpression2(value, "jsonToJsonb", jsonbDb2);
|
|
7021
|
+
var jsonTypeOf2 = (base) => buildJsonNodeExpression2([base], {
|
|
7022
|
+
runtime: undefined,
|
|
7023
|
+
dbType: profile2.textDb,
|
|
7024
|
+
nullability: base[TypeId].nullability
|
|
7025
|
+
}, {
|
|
7026
|
+
kind: "jsonTypeOf",
|
|
7027
|
+
value: base
|
|
7028
|
+
});
|
|
7029
|
+
var jsonLength2 = (base) => buildJsonNodeExpression2([base], {
|
|
7030
|
+
runtime: undefined,
|
|
7031
|
+
dbType: profile2.numericDb,
|
|
7032
|
+
nullability: undefined
|
|
7033
|
+
}, {
|
|
7034
|
+
kind: "jsonLength",
|
|
7035
|
+
value: base
|
|
7036
|
+
});
|
|
7037
|
+
var jsonKeys2 = (base) => buildJsonNodeExpression2([base], {
|
|
7038
|
+
runtime: undefined,
|
|
7039
|
+
dbType: jsonDb2,
|
|
7040
|
+
nullability: undefined
|
|
7041
|
+
}, {
|
|
7042
|
+
kind: "jsonKeys",
|
|
7043
|
+
value: base
|
|
7044
|
+
});
|
|
7045
|
+
var jsonPathExists2 = (base, query) => {
|
|
7046
|
+
if (isJsonPathValue2(query)) {
|
|
7047
|
+
return buildJsonNodeExpression2([base], {
|
|
7048
|
+
runtime: true,
|
|
7049
|
+
dbType: profile2.boolDb,
|
|
7050
|
+
nullability: "never"
|
|
7051
|
+
}, {
|
|
7052
|
+
kind: "jsonPathExists",
|
|
7053
|
+
base,
|
|
7054
|
+
query
|
|
7055
|
+
});
|
|
7056
|
+
}
|
|
7057
|
+
const queryExpression = jsonQueryExpression2(query);
|
|
7058
|
+
return buildJsonNodeExpression2([base, queryExpression], {
|
|
7059
|
+
runtime: true,
|
|
7060
|
+
dbType: profile2.boolDb,
|
|
7061
|
+
nullability: "never"
|
|
7062
|
+
}, {
|
|
7063
|
+
kind: "jsonPathExists",
|
|
7064
|
+
base,
|
|
7065
|
+
query: queryExpression
|
|
7066
|
+
});
|
|
7067
|
+
};
|
|
7068
|
+
var jsonStripNulls2 = (base) => buildJsonNodeExpression2([base], {
|
|
7069
|
+
runtime: undefined,
|
|
7070
|
+
dbType: jsonDbTypeOf2(base),
|
|
7071
|
+
nullability: undefined
|
|
7072
|
+
}, {
|
|
7073
|
+
kind: "jsonStripNulls",
|
|
7074
|
+
value: base
|
|
7075
|
+
});
|
|
7076
|
+
var jsonPathMatch2 = (base, query) => {
|
|
7077
|
+
if (isJsonPathValue2(query)) {
|
|
7078
|
+
return buildJsonNodeExpression2([base], {
|
|
7079
|
+
runtime: true,
|
|
7080
|
+
dbType: profile2.boolDb,
|
|
7081
|
+
nullability: "never"
|
|
7082
|
+
}, {
|
|
7083
|
+
kind: "jsonPathMatch",
|
|
7084
|
+
base,
|
|
7085
|
+
query
|
|
7086
|
+
});
|
|
7087
|
+
}
|
|
7088
|
+
const queryExpression = jsonQueryExpression2(query);
|
|
7089
|
+
return buildJsonNodeExpression2([base, queryExpression], {
|
|
7090
|
+
runtime: true,
|
|
7091
|
+
dbType: profile2.boolDb,
|
|
7092
|
+
nullability: "never"
|
|
7093
|
+
}, {
|
|
7094
|
+
kind: "jsonPathMatch",
|
|
7095
|
+
base,
|
|
7096
|
+
query: queryExpression
|
|
7097
|
+
});
|
|
7098
|
+
};
|
|
7099
|
+
var json2 = {
|
|
7100
|
+
key,
|
|
7101
|
+
index,
|
|
7102
|
+
wildcard,
|
|
7103
|
+
slice,
|
|
7104
|
+
descend,
|
|
7105
|
+
path,
|
|
7106
|
+
get: jsonGet2,
|
|
7107
|
+
access: jsonAccess2,
|
|
7108
|
+
traverse: jsonTraverse2,
|
|
7109
|
+
text: jsonText2,
|
|
7110
|
+
accessText: jsonAccessText2,
|
|
7111
|
+
traverseText: jsonTraverseText2,
|
|
7112
|
+
contains: jsonContains2,
|
|
7113
|
+
containedBy: jsonContainedBy2,
|
|
7114
|
+
hasKey: jsonHasKey2,
|
|
7115
|
+
keyExists: jsonKeyExists2,
|
|
7116
|
+
hasAnyKeys: jsonHasAnyKeys2,
|
|
7117
|
+
hasAllKeys: jsonHasAllKeys2,
|
|
7118
|
+
delete: jsonDelete2,
|
|
7119
|
+
remove: jsonRemove2,
|
|
7120
|
+
set: jsonSet2,
|
|
7121
|
+
insert: jsonInsert2,
|
|
7122
|
+
concat: jsonConcat2,
|
|
7123
|
+
merge: jsonMerge2,
|
|
7124
|
+
buildObject: jsonBuildObject2,
|
|
7125
|
+
buildArray: jsonBuildArray2,
|
|
7126
|
+
toJson: jsonToJson2,
|
|
7127
|
+
toJsonb: jsonToJsonb2,
|
|
7128
|
+
typeOf: jsonTypeOf2,
|
|
7129
|
+
length: jsonLength2,
|
|
7130
|
+
keys: jsonKeys2,
|
|
7131
|
+
stripNulls: jsonStripNulls2,
|
|
7132
|
+
pathExists: jsonPathExists2,
|
|
7133
|
+
pathMatch: jsonPathMatch2
|
|
7134
|
+
};
|
|
7135
|
+
var jsonb2 = {
|
|
7136
|
+
key,
|
|
7137
|
+
index,
|
|
7138
|
+
wildcard,
|
|
7139
|
+
slice,
|
|
7140
|
+
descend,
|
|
7141
|
+
path,
|
|
7142
|
+
get: jsonGet2,
|
|
7143
|
+
access: jsonAccess2,
|
|
7144
|
+
traverse: jsonTraverse2,
|
|
7145
|
+
text: jsonText2,
|
|
7146
|
+
accessText: jsonAccessText2,
|
|
7147
|
+
traverseText: jsonTraverseText2,
|
|
7148
|
+
contains: jsonContains2,
|
|
7149
|
+
containedBy: jsonContainedBy2,
|
|
7150
|
+
hasKey: jsonHasKey2,
|
|
7151
|
+
keyExists: jsonKeyExists2,
|
|
7152
|
+
hasAnyKeys: jsonHasAnyKeys2,
|
|
7153
|
+
hasAllKeys: jsonHasAllKeys2,
|
|
7154
|
+
delete: jsonDelete2,
|
|
7155
|
+
remove: jsonRemove2,
|
|
7156
|
+
set: jsonSet2,
|
|
7157
|
+
insert: jsonInsert2,
|
|
7158
|
+
concat: jsonConcatAs2(jsonbDb2),
|
|
7159
|
+
merge: jsonMergeAs2(jsonbDb2),
|
|
7160
|
+
buildObject: jsonbBuildObject2,
|
|
7161
|
+
buildArray: jsonbBuildArray2,
|
|
7162
|
+
toJsonb: jsonToJsonb2,
|
|
7163
|
+
typeOf: jsonTypeOf2,
|
|
7164
|
+
length: jsonLength2,
|
|
7165
|
+
keys: jsonKeys2,
|
|
7166
|
+
stripNulls: jsonStripNulls2,
|
|
7167
|
+
pathExists: jsonPathExists2,
|
|
7168
|
+
pathMatch: jsonPathMatch2
|
|
7169
|
+
};
|
|
7170
|
+
var and = (...values2) => makeVariadicBooleanExpression("and", values2.map((value) => toDialectExpression2(value)));
|
|
7171
|
+
var or = (...values2) => makeVariadicBooleanExpression("or", values2.map((value) => toDialectExpression2(value)));
|
|
7172
|
+
var not = (value) => {
|
|
7173
|
+
const expression = toDialectExpression2(value);
|
|
7174
|
+
return makeExpression2({
|
|
7175
|
+
runtime: true,
|
|
7176
|
+
dbType: profile2.boolDb,
|
|
7177
|
+
nullability: expression[TypeId].nullability,
|
|
7178
|
+
dialect: expression[TypeId].dialect,
|
|
7179
|
+
kind: expression[TypeId].kind,
|
|
7180
|
+
dependencies: expression[TypeId].dependencies
|
|
7181
|
+
}, {
|
|
7182
|
+
kind: "not",
|
|
7183
|
+
value: expression
|
|
7184
|
+
});
|
|
7185
|
+
};
|
|
7186
|
+
var in_ = (head, ...tail) => buildVariadicPredicate([head, ...tail], "in");
|
|
7187
|
+
var notIn = (head, ...tail) => buildVariadicPredicate([head, ...tail], "notIn");
|
|
7188
|
+
var between = (...values2) => buildVariadicPredicate(values2, "between");
|
|
7189
|
+
var contains = (...args) => {
|
|
7190
|
+
const left = args[0];
|
|
7191
|
+
const right = args[1];
|
|
7192
|
+
return buildBinaryPredicate2(left, right, "contains");
|
|
7193
|
+
};
|
|
7194
|
+
var containedBy = (...args) => {
|
|
7195
|
+
const left = args[0];
|
|
7196
|
+
const right = args[1];
|
|
7197
|
+
return buildBinaryPredicate2(left, right, "containedBy");
|
|
7198
|
+
};
|
|
7199
|
+
var overlaps = (...args) => {
|
|
7200
|
+
const left = args[0];
|
|
7201
|
+
const right = args[1];
|
|
7202
|
+
return buildBinaryPredicate2(left, right, "overlaps");
|
|
7203
|
+
};
|
|
7204
|
+
var concat2 = (...values2) => {
|
|
7205
|
+
const expressions = values2.map((value) => toDialectStringExpression2(value));
|
|
7206
|
+
return makeExpression2({
|
|
7207
|
+
runtime: "",
|
|
7208
|
+
dbType: profile2.textDb,
|
|
7209
|
+
nullability: mergeNullabilityManyRuntime(expressions),
|
|
7210
|
+
dialect: expressions.find((value) => value[TypeId].dialect !== undefined)?.[TypeId].dialect ?? profile2.dialect,
|
|
7211
|
+
kind: mergeAggregationManyRuntime(expressions),
|
|
7212
|
+
dependencies: mergeManyDependencies(expressions)
|
|
7213
|
+
}, {
|
|
7214
|
+
kind: "concat",
|
|
7215
|
+
values: expressions
|
|
7216
|
+
});
|
|
7217
|
+
};
|
|
7218
|
+
var all_ = (...values2) => and(...values2);
|
|
7219
|
+
var any_ = (...values2) => or(...values2);
|
|
7220
|
+
var count2 = (value) => {
|
|
7221
|
+
const expression = toDialectExpression2(value);
|
|
7222
|
+
return makeExpression2({
|
|
7223
|
+
runtime: undefined,
|
|
7224
|
+
dbType: standardDatatypes.bigint(),
|
|
7225
|
+
nullability: "never",
|
|
7226
|
+
dialect: expression[TypeId].dialect,
|
|
7227
|
+
kind: "aggregate",
|
|
7228
|
+
dependencies: expression[TypeId].dependencies
|
|
7229
|
+
}, {
|
|
7230
|
+
kind: "count",
|
|
7231
|
+
value: expression
|
|
7232
|
+
});
|
|
7233
|
+
};
|
|
7234
|
+
var exists = (plan) => {
|
|
7235
|
+
const dependencies = Object.fromEntries(currentRequiredList(plan[TypeId4].required).map((name) => [name, true]));
|
|
7236
|
+
return makeExpression2({
|
|
7237
|
+
runtime: true,
|
|
7238
|
+
dbType: profile2.boolDb,
|
|
7239
|
+
nullability: "never",
|
|
7240
|
+
dialect: profile2.dialect,
|
|
7241
|
+
kind: "scalar",
|
|
7242
|
+
dependencies
|
|
7243
|
+
}, {
|
|
7244
|
+
kind: "exists",
|
|
7245
|
+
plan
|
|
7246
|
+
});
|
|
7247
|
+
};
|
|
7248
|
+
var scalar = (plan) => {
|
|
7249
|
+
const dependencies = Object.fromEntries(currentRequiredList(plan[TypeId4].required).map((name) => [name, true]));
|
|
7250
|
+
const expression = extractSingleSelectedExpressionRuntime(plan[TypeId4].selection);
|
|
7251
|
+
return makeExpression2({
|
|
7252
|
+
runtime: undefined,
|
|
7253
|
+
dbType: expression[TypeId].dbType,
|
|
7254
|
+
runtimeSchema: expression[TypeId].runtimeSchema,
|
|
7255
|
+
driverValueMapping: expression[TypeId].driverValueMapping,
|
|
7256
|
+
nullability: "maybe",
|
|
7257
|
+
dialect: profile2.dialect,
|
|
7258
|
+
kind: "scalar",
|
|
7259
|
+
dependencies
|
|
7260
|
+
}, {
|
|
7261
|
+
kind: "scalarSubquery",
|
|
7262
|
+
plan
|
|
7263
|
+
});
|
|
7264
|
+
};
|
|
7265
|
+
var inSubquery = (left, plan) => {
|
|
7266
|
+
const leftExpression = toDialectExpression2(left);
|
|
7267
|
+
const dependencies = Object.fromEntries(currentRequiredList(plan[TypeId4].required).map((name) => [name, true]));
|
|
7268
|
+
return makeExpression2({
|
|
7269
|
+
runtime: true,
|
|
7270
|
+
dbType: profile2.boolDb,
|
|
7271
|
+
nullability: "maybe",
|
|
7272
|
+
dialect: leftExpression[TypeId].dialect ?? profile2.dialect,
|
|
7273
|
+
kind: leftExpression[TypeId].kind,
|
|
7274
|
+
dependencies: mergeDependencies(leftExpression[TypeId].dependencies, dependencies)
|
|
7275
|
+
}, {
|
|
7276
|
+
kind: "inSubquery",
|
|
7277
|
+
left: leftExpression,
|
|
7278
|
+
plan
|
|
7279
|
+
});
|
|
7280
|
+
};
|
|
7281
|
+
var quantifiedComparison = (left, plan, operator, quantifier) => {
|
|
7282
|
+
const leftExpression = toDialectExpression2(left);
|
|
7283
|
+
const dependencies = Object.fromEntries(currentRequiredList(plan[TypeId4].required).map((name) => [name, true]));
|
|
7284
|
+
return makeExpression2({
|
|
7285
|
+
runtime: true,
|
|
7286
|
+
dbType: profile2.boolDb,
|
|
7287
|
+
nullability: "maybe",
|
|
7288
|
+
dialect: leftExpression[TypeId].dialect ?? profile2.dialect,
|
|
7289
|
+
kind: leftExpression[TypeId].kind,
|
|
7290
|
+
dependencies: mergeDependencies(leftExpression[TypeId].dependencies, dependencies)
|
|
7291
|
+
}, renderQuantifiedComparisonAst(leftExpression, plan, operator, quantifier));
|
|
7292
|
+
};
|
|
7293
|
+
var compareAny = (left, plan, operator) => quantifiedComparison(left, plan, operator, "any");
|
|
7294
|
+
var compareAll = (left, plan, operator) => quantifiedComparison(left, plan, operator, "all");
|
|
7295
|
+
var over2 = (value, spec = {}) => {
|
|
7296
|
+
const normalized = normalizeWindowSpec2(spec);
|
|
7297
|
+
const expressions = mergeWindowExpressions2(value, normalized.partitionBy, normalized.orderBy);
|
|
7298
|
+
return makeExpression2({
|
|
7299
|
+
runtime: undefined,
|
|
7300
|
+
dbType: value[TypeId].dbType,
|
|
7301
|
+
nullability: value[TypeId].nullability,
|
|
7302
|
+
dialect: expressions.find((expression) => expression[TypeId].dialect !== undefined)?.[TypeId].dialect ?? profile2.dialect,
|
|
7303
|
+
kind: "window",
|
|
7304
|
+
dependencies: mergeManyDependencies(expressions)
|
|
7305
|
+
}, {
|
|
7306
|
+
kind: "window",
|
|
7307
|
+
function: "over",
|
|
7308
|
+
value,
|
|
7309
|
+
partitionBy: normalized.partitionBy,
|
|
7310
|
+
orderBy: normalized.orderBy,
|
|
7311
|
+
frame: normalized.frame
|
|
7312
|
+
});
|
|
7313
|
+
};
|
|
7314
|
+
var buildNumberWindow2 = (kind, spec) => {
|
|
7315
|
+
const normalized = normalizeWindowSpec2(spec);
|
|
7316
|
+
const expressions = mergeWindowExpressions2(undefined, normalized.partitionBy, normalized.orderBy);
|
|
7317
|
+
return makeExpression2({
|
|
7318
|
+
runtime: undefined,
|
|
7319
|
+
dbType: standardDatatypes.bigint(),
|
|
7320
|
+
nullability: "never",
|
|
7321
|
+
dialect: expressions.find((expression) => expression[TypeId].dialect !== undefined)?.[TypeId].dialect ?? profile2.dialect,
|
|
7322
|
+
kind: "window",
|
|
7323
|
+
dependencies: mergeManyDependencies(expressions)
|
|
7324
|
+
}, {
|
|
7325
|
+
kind: "window",
|
|
7326
|
+
function: kind,
|
|
7327
|
+
partitionBy: normalized.partitionBy,
|
|
7328
|
+
orderBy: normalized.orderBy,
|
|
7329
|
+
frame: normalized.frame
|
|
7330
|
+
});
|
|
7331
|
+
};
|
|
7332
|
+
var rowNumber2 = (spec) => buildNumberWindow2("rowNumber", spec);
|
|
7333
|
+
var rank2 = (spec) => buildNumberWindow2("rank", spec);
|
|
7334
|
+
var denseRank2 = (spec) => buildNumberWindow2("denseRank", spec);
|
|
7335
|
+
var max2 = (value) => makeExpression2({
|
|
7336
|
+
runtime: undefined,
|
|
7337
|
+
dbType: value[TypeId].dbType,
|
|
7338
|
+
nullability: "maybe",
|
|
7339
|
+
dialect: value[TypeId].dialect,
|
|
7340
|
+
kind: "aggregate",
|
|
7341
|
+
dependencies: value[TypeId].dependencies
|
|
7342
|
+
}, {
|
|
7343
|
+
kind: "max",
|
|
7344
|
+
value
|
|
7345
|
+
});
|
|
7346
|
+
var min2 = (value) => makeExpression2({
|
|
7347
|
+
runtime: undefined,
|
|
7348
|
+
dbType: value[TypeId].dbType,
|
|
7349
|
+
nullability: "maybe",
|
|
7350
|
+
dialect: value[TypeId].dialect,
|
|
7351
|
+
kind: "aggregate",
|
|
7352
|
+
dependencies: value[TypeId].dependencies
|
|
7353
|
+
}, {
|
|
7354
|
+
kind: "min",
|
|
7355
|
+
value
|
|
7356
|
+
});
|
|
7357
|
+
var resolveCoalesceNullabilityRuntime2 = (values2) => values2.some((value) => value[TypeId].nullability === "never") ? "never" : values2.some((value) => value[TypeId].nullability === "maybe") ? "maybe" : "always";
|
|
7358
|
+
var coalesce2 = (...values2) => {
|
|
7359
|
+
const expressions = values2.map((value) => toDialectExpression2(value));
|
|
7360
|
+
const representative = expressions.find((value) => value[TypeId].nullability !== "always") ?? expressions[0];
|
|
7361
|
+
return makeExpression2({
|
|
7362
|
+
runtime: undefined,
|
|
7363
|
+
dbType: representative[TypeId].dbType,
|
|
7364
|
+
nullability: resolveCoalesceNullabilityRuntime2(expressions),
|
|
7365
|
+
dialect: expressions.find((value) => value[TypeId].dialect !== undefined)?.[TypeId].dialect ?? profile2.dialect,
|
|
7366
|
+
kind: mergeAggregationManyRuntime(expressions),
|
|
7367
|
+
dependencies: mergeManyDependencies(expressions)
|
|
7368
|
+
}, {
|
|
7369
|
+
kind: "coalesce",
|
|
7370
|
+
values: expressions
|
|
7371
|
+
});
|
|
7372
|
+
};
|
|
7373
|
+
var resolveCaseNullabilityRuntime = (values2) => {
|
|
7374
|
+
let sawNever = false;
|
|
7375
|
+
let sawMaybe = false;
|
|
7376
|
+
let sawAlways = false;
|
|
7377
|
+
for (const value of values2) {
|
|
7378
|
+
switch (value[TypeId].nullability) {
|
|
7379
|
+
case "never":
|
|
7380
|
+
sawNever = true;
|
|
7381
|
+
break;
|
|
7382
|
+
case "maybe":
|
|
7383
|
+
sawMaybe = true;
|
|
7384
|
+
break;
|
|
7385
|
+
case "always":
|
|
7386
|
+
sawAlways = true;
|
|
7387
|
+
break;
|
|
7388
|
+
}
|
|
7389
|
+
}
|
|
7390
|
+
return sawNever ? sawMaybe || sawAlways ? "maybe" : "never" : sawMaybe ? "maybe" : "always";
|
|
7391
|
+
};
|
|
7392
|
+
var finalizeCase = (branches, fallback) => {
|
|
7393
|
+
const resultExpressions = [...branches.map((branch) => branch.then), fallback];
|
|
7394
|
+
const allExpressions = [...branches.flatMap((branch) => [branch.when, branch.then]), fallback];
|
|
7395
|
+
const representative = resultExpressions.find((value) => value[TypeId].nullability !== "always") ?? fallback;
|
|
7396
|
+
return makeExpression2({
|
|
7397
|
+
runtime: undefined,
|
|
7398
|
+
dbType: representative[TypeId].dbType,
|
|
7399
|
+
nullability: resolveCaseNullabilityRuntime(resultExpressions),
|
|
7400
|
+
dialect: allExpressions.find((value) => value[TypeId].dialect !== undefined)?.[TypeId].dialect ?? profile2.dialect,
|
|
7401
|
+
kind: mergeAggregationManyRuntime(allExpressions),
|
|
7402
|
+
dependencies: mergeManyDependencies(allExpressions)
|
|
7403
|
+
}, {
|
|
7404
|
+
kind: "case",
|
|
7405
|
+
branches: branches.map((branch) => ({
|
|
7406
|
+
when: branch.when,
|
|
7407
|
+
then: branch.then
|
|
7408
|
+
})),
|
|
7409
|
+
else: fallback
|
|
7410
|
+
});
|
|
7411
|
+
};
|
|
7412
|
+
var case_ = () => {
|
|
7413
|
+
const build = (branches) => ({
|
|
7414
|
+
when(predicate, result) {
|
|
7415
|
+
return build([
|
|
7416
|
+
...branches,
|
|
7417
|
+
{
|
|
7418
|
+
when: toDialectExpression2(predicate),
|
|
7419
|
+
then: toDialectExpression2(result)
|
|
7420
|
+
}
|
|
7421
|
+
]);
|
|
7422
|
+
},
|
|
7423
|
+
else(fallback) {
|
|
7424
|
+
return finalizeCase(branches, toDialectExpression2(fallback));
|
|
7425
|
+
}
|
|
7426
|
+
});
|
|
7427
|
+
return {
|
|
7428
|
+
when(predicate, result) {
|
|
7429
|
+
return build([{
|
|
7430
|
+
when: toDialectExpression2(predicate),
|
|
7431
|
+
then: toDialectExpression2(result)
|
|
7432
|
+
}]);
|
|
7433
|
+
}
|
|
7434
|
+
};
|
|
7435
|
+
};
|
|
7436
|
+
var match = (value) => {
|
|
7437
|
+
const subject = toDialectExpression2(value);
|
|
7438
|
+
const build = (branches) => ({
|
|
7439
|
+
when(compare, result) {
|
|
7440
|
+
return build([
|
|
7441
|
+
...branches,
|
|
7442
|
+
{
|
|
7443
|
+
when: buildBinaryPredicate2(subject, compare, "eq"),
|
|
7444
|
+
then: toDialectExpression2(result)
|
|
7445
|
+
}
|
|
7446
|
+
]);
|
|
7447
|
+
},
|
|
7448
|
+
else(fallback) {
|
|
7449
|
+
return finalizeCase(branches, toDialectExpression2(fallback));
|
|
7450
|
+
}
|
|
7451
|
+
});
|
|
7452
|
+
return {
|
|
7453
|
+
when(compare, result) {
|
|
7454
|
+
const predicate = buildBinaryPredicate2(subject, compare, "eq");
|
|
7455
|
+
return build([{
|
|
7456
|
+
when: predicate,
|
|
7457
|
+
then: toDialectExpression2(result)
|
|
7458
|
+
}]);
|
|
7459
|
+
}
|
|
7460
|
+
};
|
|
7461
|
+
};
|
|
7462
|
+
var excluded = (value) => {
|
|
7463
|
+
const ast = value[TypeId2];
|
|
7464
|
+
return makeExpression2({
|
|
7465
|
+
runtime: undefined,
|
|
7466
|
+
dbType: value[TypeId].dbType,
|
|
7467
|
+
runtimeSchema: value[TypeId].runtimeSchema,
|
|
7468
|
+
driverValueMapping: value[TypeId].driverValueMapping,
|
|
7469
|
+
nullability: value[TypeId].nullability,
|
|
7470
|
+
dialect: profile2.dialect,
|
|
7471
|
+
kind: "scalar",
|
|
7472
|
+
dependencies: {}
|
|
7473
|
+
}, {
|
|
7474
|
+
kind: "excluded",
|
|
7475
|
+
columnName: ast.columnName
|
|
7476
|
+
});
|
|
7477
|
+
};
|
|
7478
|
+
var toMutationValueExpression2 = (value, column2) => {
|
|
7479
|
+
const columnState = column2[TypeId];
|
|
7480
|
+
const normalizeMutationValue = (candidate) => {
|
|
7481
|
+
if (candidate === null && columnState.nullability !== "never") {
|
|
7482
|
+
return null;
|
|
7483
|
+
}
|
|
7484
|
+
const runtimeSchemaAccepts = columnState.runtimeSchema !== undefined && Schema7.is(columnState.runtimeSchema)(candidate);
|
|
7485
|
+
if (runtimeSchemaAccepts) {
|
|
7486
|
+
return candidate;
|
|
7487
|
+
}
|
|
7488
|
+
const normalized = normalizeDbValue(columnState.dbType, candidate);
|
|
7489
|
+
return columnState.runtimeSchema === undefined ? normalized : Schema7.decodeUnknownSync(columnState.runtimeSchema)(normalized);
|
|
7490
|
+
};
|
|
7491
|
+
if (value !== null && typeof value === "object" && TypeId in value) {
|
|
7492
|
+
const expression = value;
|
|
7493
|
+
const ast = expression[TypeId2];
|
|
7494
|
+
if (ast.kind === "literal") {
|
|
7495
|
+
const normalizedValue2 = normalizeMutationValue(ast.value);
|
|
7496
|
+
return makeExpression2({
|
|
7497
|
+
runtime: normalizedValue2,
|
|
7498
|
+
dbType: columnState.dbType,
|
|
7499
|
+
runtimeSchema: columnState.runtimeSchema,
|
|
7500
|
+
driverValueMapping: columnState.driverValueMapping,
|
|
7501
|
+
nullability: normalizedValue2 === null ? "always" : "never",
|
|
7502
|
+
dialect: columnState.dialect,
|
|
7503
|
+
kind: "scalar",
|
|
7504
|
+
dependencies: {}
|
|
7505
|
+
}, {
|
|
7506
|
+
kind: "literal",
|
|
7507
|
+
value: normalizedValue2
|
|
7508
|
+
});
|
|
7509
|
+
}
|
|
7510
|
+
return retargetLiteralExpression2(value, column2);
|
|
7511
|
+
}
|
|
7512
|
+
const normalizedValue = normalizeMutationValue(value);
|
|
7513
|
+
return makeExpression2({
|
|
7514
|
+
runtime: normalizedValue,
|
|
7515
|
+
dbType: columnState.dbType,
|
|
7516
|
+
runtimeSchema: columnState.runtimeSchema,
|
|
7517
|
+
driverValueMapping: columnState.driverValueMapping,
|
|
7518
|
+
nullability: normalizedValue === null ? "always" : "never",
|
|
7519
|
+
dialect: columnState.dialect,
|
|
7520
|
+
kind: "scalar",
|
|
7521
|
+
dependencies: {}
|
|
7522
|
+
}, {
|
|
7523
|
+
kind: "literal",
|
|
7524
|
+
value: normalizedValue
|
|
7525
|
+
});
|
|
7526
|
+
};
|
|
7527
|
+
var renderQuantifiedComparisonAst = (left, plan, operator, quantifier) => ({
|
|
7528
|
+
kind: quantifier === "any" ? "comparisonAny" : "comparisonAll",
|
|
7529
|
+
operator,
|
|
7530
|
+
left,
|
|
7531
|
+
plan
|
|
7532
|
+
});
|
|
7533
|
+
var targetSourceDetails2 = (table) => {
|
|
7534
|
+
const sourceName = table[TypeId7].name;
|
|
7535
|
+
const sourceBaseName = table[TypeId7].baseName;
|
|
7536
|
+
return {
|
|
7537
|
+
sourceName,
|
|
7538
|
+
sourceBaseName
|
|
7539
|
+
};
|
|
7540
|
+
};
|
|
7541
|
+
var sourceDetails2 = (source) => {
|
|
7542
|
+
if (TypeId7 in source) {
|
|
7543
|
+
return targetSourceDetails2(source);
|
|
7544
|
+
}
|
|
7545
|
+
const record2 = source;
|
|
7546
|
+
return {
|
|
7547
|
+
sourceName: record2.name,
|
|
7548
|
+
sourceBaseName: record2.baseName
|
|
7549
|
+
};
|
|
7550
|
+
};
|
|
7551
|
+
var makeColumnReferenceSelection2 = (alias2, selection) => {
|
|
7552
|
+
const columns = {};
|
|
7553
|
+
for (const [columnName, expression] of Object.entries(selection)) {
|
|
7554
|
+
const state = expression[TypeId];
|
|
7555
|
+
columns[columnName] = makeExpression2({
|
|
7556
|
+
runtime: undefined,
|
|
7557
|
+
dbType: state.dbType,
|
|
7558
|
+
runtimeSchema: state.runtimeSchema,
|
|
7559
|
+
driverValueMapping: state.driverValueMapping,
|
|
7560
|
+
nullability: state.nullability,
|
|
7561
|
+
dialect: state.dialect,
|
|
7562
|
+
kind: "scalar",
|
|
7563
|
+
dependencies: {
|
|
7564
|
+
[alias2]: true
|
|
7565
|
+
}
|
|
7566
|
+
}, {
|
|
7567
|
+
kind: "column",
|
|
7568
|
+
tableName: alias2,
|
|
7569
|
+
columnName
|
|
7570
|
+
});
|
|
7571
|
+
}
|
|
7572
|
+
return columns;
|
|
7573
|
+
};
|
|
7574
|
+
var makeAliasedValuesSource = (rows, selection, alias2) => {
|
|
7575
|
+
const columns = makeColumnReferenceSelection2(alias2, selection);
|
|
7576
|
+
const source = {
|
|
7577
|
+
kind: "values",
|
|
7578
|
+
name: alias2,
|
|
7579
|
+
baseName: alias2,
|
|
7580
|
+
dialect: profile2.dialect,
|
|
7581
|
+
rows,
|
|
7582
|
+
columns
|
|
7583
|
+
};
|
|
7584
|
+
return Object.assign(source, columns);
|
|
7585
|
+
};
|
|
7586
|
+
var normalizeValuesRow2 = (row) => Object.fromEntries(Object.entries(row).map(([key2, value]) => [key2, toDialectExpression2(value)]));
|
|
7587
|
+
var normalizeUnnestColumns2 = (columns) => Object.fromEntries(Object.entries(columns).map(([key2, values2]) => [key2, values2.map((value) => toDialectExpression2(value))]));
|
|
7588
|
+
var normalizeMutationTargets2 = (target) => Array.isArray(target) ? target : [target];
|
|
7589
|
+
var mutationTargetClauses2 = (target) => normalizeMutationTargets2(target).map((table) => {
|
|
7590
|
+
const { sourceName, sourceBaseName } = targetSourceDetails2(table);
|
|
7591
|
+
return {
|
|
7592
|
+
kind: "from",
|
|
7593
|
+
tableName: sourceName,
|
|
7594
|
+
baseTableName: sourceBaseName,
|
|
7595
|
+
source: table
|
|
7596
|
+
};
|
|
7597
|
+
});
|
|
7598
|
+
var mutationAvailableSources2 = (target, mode = "required") => Object.fromEntries(normalizeMutationTargets2(target).map((table) => {
|
|
7599
|
+
const { sourceName, sourceBaseName } = targetSourceDetails2(table);
|
|
7600
|
+
return [
|
|
7601
|
+
sourceName,
|
|
7602
|
+
{
|
|
7603
|
+
name: sourceName,
|
|
7604
|
+
mode,
|
|
7605
|
+
baseName: sourceBaseName
|
|
7606
|
+
}
|
|
7607
|
+
];
|
|
7608
|
+
}));
|
|
7609
|
+
var getMutationColumn2 = (columns, columnName) => columns[columnName];
|
|
7610
|
+
var buildMutationAssignments2 = (target, values2) => {
|
|
7611
|
+
const targets = normalizeMutationTargets2(target);
|
|
7612
|
+
if (targets.length === 1 && !Array.isArray(target)) {
|
|
7613
|
+
const columns = target;
|
|
7614
|
+
return Object.entries(values2).map(([columnName, value]) => ({
|
|
7615
|
+
columnName,
|
|
7616
|
+
value: toMutationValueExpression2(value, getMutationColumn2(columns, columnName))
|
|
7617
|
+
}));
|
|
7618
|
+
}
|
|
7619
|
+
const valueMap = values2;
|
|
7620
|
+
return targets.flatMap((table) => {
|
|
7621
|
+
const targetName = table[TypeId7].name;
|
|
7622
|
+
const scopedValues = valueMap[targetName] ?? {};
|
|
7623
|
+
const columns = table;
|
|
7624
|
+
return Object.entries(scopedValues).map(([columnName, value]) => ({
|
|
7625
|
+
tableName: targetName,
|
|
7626
|
+
columnName,
|
|
7627
|
+
value: toMutationValueExpression2(value, getMutationColumn2(columns, columnName))
|
|
7628
|
+
}));
|
|
7629
|
+
});
|
|
7630
|
+
};
|
|
7631
|
+
var buildInsertValuesRows2 = (target, rows) => {
|
|
7632
|
+
const firstRow = rows[0];
|
|
7633
|
+
const firstColumns = Object.keys(firstRow);
|
|
7634
|
+
const columns = firstColumns;
|
|
7635
|
+
const normalizeRow = (row) => {
|
|
7636
|
+
const assignments = buildMutationAssignments2(target, row);
|
|
7637
|
+
return {
|
|
7638
|
+
values: columns.map((columnName) => assignments.find((assignment) => assignment.columnName === columnName))
|
|
7639
|
+
};
|
|
7640
|
+
};
|
|
7641
|
+
const normalizedRows = [
|
|
7642
|
+
normalizeRow(rows[0]),
|
|
7643
|
+
...rows.slice(1).map(normalizeRow)
|
|
7644
|
+
];
|
|
7645
|
+
const required = normalizedRows.flatMap((row) => row.values.flatMap((entry) => Object.keys(entry.value[TypeId].dependencies)));
|
|
7646
|
+
return {
|
|
7647
|
+
columns,
|
|
7648
|
+
rows: normalizedRows,
|
|
7649
|
+
required: required.filter((name, index4, list) => list.indexOf(name) === index4)
|
|
7650
|
+
};
|
|
7651
|
+
};
|
|
7652
|
+
var normalizeInsertSelectColumns2 = (selection) => {
|
|
7653
|
+
const columns = Object.keys(selection);
|
|
7654
|
+
return columns;
|
|
7655
|
+
};
|
|
7656
|
+
var normalizeInsertUnnestValues2 = (target, values2) => {
|
|
7657
|
+
const entries = Object.entries(values2);
|
|
7658
|
+
const columns = entries.map(([columnName]) => columnName);
|
|
7659
|
+
const normalized = entries.map(([columnName, items]) => ({
|
|
7660
|
+
columnName,
|
|
7661
|
+
values: items
|
|
7662
|
+
}));
|
|
7663
|
+
return {
|
|
7664
|
+
columns,
|
|
7665
|
+
values: normalized
|
|
7666
|
+
};
|
|
7667
|
+
};
|
|
7668
|
+
var normalizeConflictColumns2 = (target, columnsInput) => {
|
|
7669
|
+
const columns = normalizeColumnList(columnsInput);
|
|
7670
|
+
return columns;
|
|
7671
|
+
};
|
|
7672
|
+
var buildConflictTarget2 = (target, input) => {
|
|
7673
|
+
if (typeof input === "string" || Array.isArray(input)) {
|
|
7674
|
+
return {
|
|
7675
|
+
kind: "columns",
|
|
7676
|
+
columns: normalizeConflictColumns2(target, input)
|
|
7677
|
+
};
|
|
7678
|
+
}
|
|
7679
|
+
if (!Array.isArray(input) && "constraint" in input) {
|
|
7680
|
+
return {
|
|
7681
|
+
kind: "constraint",
|
|
7682
|
+
name: input.constraint
|
|
7683
|
+
};
|
|
7684
|
+
}
|
|
7685
|
+
const columnTarget = input;
|
|
7686
|
+
return {
|
|
7687
|
+
kind: "columns",
|
|
7688
|
+
columns: normalizeConflictColumns2(target, columnTarget.columns),
|
|
7689
|
+
where: columnTarget.where === undefined ? undefined : toDialectExpression2(columnTarget.where)
|
|
7690
|
+
};
|
|
7691
|
+
};
|
|
7692
|
+
var defaultIndexName2 = (tableName, columns, unique3) => `${tableName}_${columns.join("_")}_${unique3 ? "uniq" : "idx"}`;
|
|
7693
|
+
function as(valueOrAlias, alias2) {
|
|
7694
|
+
if (alias2 === undefined) {
|
|
7695
|
+
return (value2) => as(value2, valueOrAlias);
|
|
7696
|
+
}
|
|
7697
|
+
const resolvedAlias = alias2;
|
|
7698
|
+
const value = valueOrAlias;
|
|
7699
|
+
if (typeof value !== "object" || value === null || TypeId in value) {
|
|
7700
|
+
const expression = toDialectExpression2(value);
|
|
7701
|
+
const projected = Object.create(Object.getPrototypeOf(expression));
|
|
7702
|
+
const runtimeExpression = expression;
|
|
7703
|
+
projected[TypeId] = runtimeExpression[TypeId];
|
|
7704
|
+
projected[TypeId2] = runtimeExpression[TypeId2];
|
|
7705
|
+
if ("schema" in runtimeExpression) {
|
|
7706
|
+
projected.schema = runtimeExpression.schema;
|
|
7707
|
+
}
|
|
7708
|
+
projected[TypeId9] = {
|
|
7709
|
+
alias: resolvedAlias
|
|
7710
|
+
};
|
|
7711
|
+
return projected;
|
|
7712
|
+
}
|
|
7713
|
+
if ("kind" in value && value.kind === "values" && !("name" in value)) {
|
|
7714
|
+
const valuesInput = value;
|
|
7715
|
+
return makeAliasedValuesSource(valuesInput.rows, valuesInput.selection, resolvedAlias);
|
|
7716
|
+
}
|
|
7717
|
+
return makeDerivedSource(value, resolvedAlias);
|
|
7718
|
+
}
|
|
7719
|
+
function with_(valueOrAlias, alias2) {
|
|
7720
|
+
if (alias2 === undefined) {
|
|
7721
|
+
return (value) => with_(value, valueOrAlias);
|
|
7722
|
+
}
|
|
7723
|
+
return makeCteSource(valueOrAlias, alias2);
|
|
7724
|
+
}
|
|
7725
|
+
function withRecursive_(valueOrAlias, alias2) {
|
|
7726
|
+
if (alias2 === undefined) {
|
|
7727
|
+
return (value) => withRecursive_(value, valueOrAlias);
|
|
7728
|
+
}
|
|
7729
|
+
return makeCteSource(valueOrAlias, alias2, true);
|
|
7730
|
+
}
|
|
7731
|
+
function lateral(valueOrAlias, alias2) {
|
|
7732
|
+
if (alias2 === undefined) {
|
|
7733
|
+
return (value) => lateral(value, valueOrAlias);
|
|
7734
|
+
}
|
|
7735
|
+
return makeLateralSource(valueOrAlias, alias2);
|
|
7736
|
+
}
|
|
7737
|
+
var {
|
|
7738
|
+
values: values2,
|
|
7739
|
+
unnest: unnest2,
|
|
7740
|
+
generateSeries: generateSeries2,
|
|
7741
|
+
select: select2,
|
|
7742
|
+
groupBy: groupBy2,
|
|
7743
|
+
returning: returning2
|
|
7744
|
+
} = makeDslQueryRuntime({
|
|
7745
|
+
profile: profile2,
|
|
7746
|
+
ValuesInputProto: ValuesInputProto2,
|
|
7747
|
+
normalizeValuesRow: normalizeValuesRow2,
|
|
7748
|
+
normalizeUnnestColumns: normalizeUnnestColumns2,
|
|
7749
|
+
makeColumnReferenceSelection: makeColumnReferenceSelection2,
|
|
7750
|
+
toDialectNumericExpression: toDialectNumericExpression2,
|
|
7751
|
+
extractRequiredRuntime,
|
|
7752
|
+
makePlan,
|
|
7753
|
+
getAst,
|
|
7754
|
+
getQueryState,
|
|
7755
|
+
currentRequiredList,
|
|
7756
|
+
dedupeGroupedExpressions
|
|
7757
|
+
});
|
|
7758
|
+
var {
|
|
7759
|
+
buildSetOperation: buildSetOperation2,
|
|
7760
|
+
where: where2,
|
|
7761
|
+
from: from2,
|
|
7762
|
+
having: having2,
|
|
7763
|
+
crossJoin: crossJoin2,
|
|
7764
|
+
join: join2,
|
|
7765
|
+
orderBy: orderBy2,
|
|
7766
|
+
lock: lock2,
|
|
7767
|
+
distinct: distinct2,
|
|
7768
|
+
limit: limit2,
|
|
7769
|
+
offset: offset2
|
|
7770
|
+
} = makeDslPlanRuntime({
|
|
7771
|
+
profile: profile2,
|
|
7772
|
+
makePlan,
|
|
7773
|
+
getAst,
|
|
7774
|
+
getQueryState,
|
|
7775
|
+
currentRequiredList,
|
|
7776
|
+
toDialectExpression: toDialectExpression2,
|
|
7777
|
+
toDialectNumericExpression: toDialectNumericExpression2,
|
|
7778
|
+
extractRequiredFromDialectInputRuntime: extractRequiredFromDialectInputRuntime2,
|
|
7779
|
+
extractRequiredFromDialectNumericInputRuntime: extractRequiredFromDialectNumericInputRuntime2,
|
|
7780
|
+
formulaOfExpressionRuntime: formulaOfExpression,
|
|
7781
|
+
assumeFormulaTrue,
|
|
7782
|
+
trueFormula,
|
|
7783
|
+
sourceDetails: sourceDetails2,
|
|
7784
|
+
presenceWitnessesOfSourceLike,
|
|
7785
|
+
attachInsertSource: (...args) => attachInsertSource2(args[0], args[1])
|
|
7786
|
+
});
|
|
7787
|
+
var union = (left, right) => buildSetOperation2("union", false, left, right);
|
|
7788
|
+
var unionAll = (left, right) => buildSetOperation2("union", true, left, right);
|
|
7789
|
+
var intersect = (left, right) => buildSetOperation2("intersect", false, left, right);
|
|
7790
|
+
var intersectAll = (left, right) => buildSetOperation2("intersect", true, left, right);
|
|
7791
|
+
var except = (left, right) => buildSetOperation2("except", false, left, right);
|
|
7792
|
+
var exceptAll = (left, right) => buildSetOperation2("except", true, left, right);
|
|
7793
|
+
var innerJoin = (table, on) => join2("inner", table, on);
|
|
7794
|
+
var leftJoin = (table, on) => join2("left", table, on);
|
|
7795
|
+
var rightJoin = (table, on) => join2("right", table, on);
|
|
7796
|
+
var fullJoin = (table, on) => join2("full", table, on);
|
|
7797
|
+
var distinctOn2 = {
|
|
7798
|
+
__effect_qb_error__: "effect-qb: distinctOn(...) is only supported by the postgres dialect",
|
|
7799
|
+
__effect_qb_dialect__: profile2.dialect,
|
|
7800
|
+
__effect_qb_hint__: "Use postgres.Query.distinctOn(...) or regular distinct()/grouping logic"
|
|
7801
|
+
};
|
|
7802
|
+
var mutationRuntime2 = makeDslMutationRuntime({
|
|
7803
|
+
profile: profile2,
|
|
7804
|
+
makePlan,
|
|
7805
|
+
getAst,
|
|
7806
|
+
getQueryState,
|
|
7807
|
+
currentRequiredList,
|
|
7808
|
+
toDialectExpression: toDialectExpression2,
|
|
7809
|
+
buildMutationAssignments: buildMutationAssignments2,
|
|
7810
|
+
buildInsertValuesRows: buildInsertValuesRows2,
|
|
7811
|
+
normalizeInsertUnnestValues: normalizeInsertUnnestValues2,
|
|
7812
|
+
normalizeInsertSelectColumns: normalizeInsertSelectColumns2,
|
|
7813
|
+
buildConflictTarget: buildConflictTarget2,
|
|
7814
|
+
mutationTargetClauses: mutationTargetClauses2,
|
|
7815
|
+
mutationAvailableSources: mutationAvailableSources2,
|
|
7816
|
+
normalizeConflictColumns: normalizeConflictColumns2,
|
|
7817
|
+
targetSourceDetails: targetSourceDetails2,
|
|
7818
|
+
sourceDetails: sourceDetails2
|
|
7819
|
+
});
|
|
7820
|
+
var insert = (target, values3) => mutationRuntime2.insert(target, values3);
|
|
7821
|
+
var attachInsertSource2 = (plan, source) => mutationRuntime2.attachInsertSource(plan, source);
|
|
7822
|
+
var onConflict2 = (target, options2 = {}) => (plan) => mutationRuntime2.onConflict(target, options2)(plan);
|
|
7823
|
+
var update = (target, values3) => mutationRuntime2.update(target, values3);
|
|
7824
|
+
var upsert = (target, values3, conflictColumns, updateValues) => mutationRuntime2.upsert(target, values3, conflictColumns, updateValues);
|
|
7825
|
+
var delete_ = (target) => mutationRuntime2.delete_(target);
|
|
7826
|
+
var truncate = (target, options2 = {}) => mutationRuntime2.truncate(target, options2);
|
|
7827
|
+
var merge2 = (target, source, on, options2) => mutationRuntime2.merge(target, source, on, options2);
|
|
7828
|
+
var {
|
|
7829
|
+
transaction: transaction2,
|
|
7830
|
+
commit: commit2,
|
|
7831
|
+
rollback: rollback2,
|
|
7832
|
+
savepoint: savepoint2,
|
|
7833
|
+
rollbackTo: rollbackTo2,
|
|
7834
|
+
releaseSavepoint: releaseSavepoint2,
|
|
7835
|
+
createTable: createTable2,
|
|
7836
|
+
dropTable: dropTable2,
|
|
7837
|
+
createIndex: createIndex2,
|
|
7838
|
+
dropIndex: dropIndex2
|
|
7839
|
+
} = makeDslTransactionDdlRuntime({
|
|
7840
|
+
profile: profile2,
|
|
7841
|
+
makePlan,
|
|
7842
|
+
targetSourceDetails: targetSourceDetails2,
|
|
7843
|
+
normalizeColumnList,
|
|
7844
|
+
defaultIndexName: defaultIndexName2
|
|
7845
|
+
});
|
|
7846
|
+
var {
|
|
7847
|
+
values: exportedValues,
|
|
7848
|
+
unnest: exportedUnnest,
|
|
7849
|
+
select: exportedSelect,
|
|
7850
|
+
from: exportedFrom,
|
|
7851
|
+
insert: exportedInsert
|
|
7852
|
+
} = {
|
|
7853
|
+
values: values2,
|
|
7854
|
+
unnest: unnest2,
|
|
7855
|
+
select: select2,
|
|
7856
|
+
from: from2,
|
|
7857
|
+
insert
|
|
7858
|
+
};
|
|
7859
|
+
|
|
7860
|
+
// src/internal/analytics.ts
|
|
7861
|
+
var normalizeSpec = (spec) => {
|
|
7862
|
+
validateWindowFrame(spec.frame);
|
|
7863
|
+
return {
|
|
7864
|
+
partitionBy: spec.partitionBy ?? [],
|
|
7865
|
+
orderBy: spec.orderBy.map((term) => ({
|
|
7866
|
+
value: term.value,
|
|
7867
|
+
direction: term.direction ?? "asc"
|
|
7868
|
+
})),
|
|
7869
|
+
frame: spec.frame
|
|
7870
|
+
};
|
|
7871
|
+
};
|
|
7872
|
+
var rejectExplicitPortableFrame = (functionName, spec) => {
|
|
7873
|
+
if (spec.frame !== undefined) {
|
|
7874
|
+
throw new Error(`${functionName} does not accept an explicit frame on the portable Function API; use a dialect Function helper`);
|
|
7875
|
+
}
|
|
7876
|
+
};
|
|
7877
|
+
var windowExpression = (kind, value, spec, nullability, options2 = {}) => {
|
|
7878
|
+
const normalized = normalizeSpec(spec);
|
|
7879
|
+
const { fallbackDialect, ...astOptions } = options2;
|
|
7880
|
+
const expressions = [
|
|
7881
|
+
value,
|
|
7882
|
+
...normalized.partitionBy,
|
|
7883
|
+
...normalized.orderBy.map((term) => term.value),
|
|
7884
|
+
...options2.offset === undefined ? [] : [options2.offset],
|
|
7885
|
+
...options2.defaultValue === undefined ? [] : [options2.defaultValue]
|
|
7886
|
+
];
|
|
7887
|
+
return makeExpression2({
|
|
7888
|
+
runtime: undefined,
|
|
7889
|
+
dbType: value[TypeId].dbType,
|
|
7890
|
+
runtimeSchema: value[TypeId].runtimeSchema,
|
|
7891
|
+
driverValueMapping: value[TypeId].driverValueMapping,
|
|
7892
|
+
nullability,
|
|
7893
|
+
dialect: expressions.find((entry) => entry[TypeId].dialect !== "standard")?.[TypeId].dialect ?? fallbackDialect ?? value[TypeId].dialect,
|
|
7894
|
+
kind: "window",
|
|
7895
|
+
dependencies: mergeManyDependencies(expressions)
|
|
7896
|
+
}, {
|
|
7897
|
+
kind: "window",
|
|
7898
|
+
function: kind,
|
|
7899
|
+
value,
|
|
7900
|
+
...astOptions,
|
|
7901
|
+
...normalized
|
|
7902
|
+
});
|
|
7903
|
+
};
|
|
7904
|
+
var lag = (value, options2) => {
|
|
7905
|
+
rejectExplicitPortableFrame("lag", options2.spec);
|
|
7906
|
+
if (options2.offset !== undefined && (!Number.isSafeInteger(options2.offset) || options2.offset < 0)) {
|
|
7907
|
+
throw new Error("lag offset must be a non-negative safe integer");
|
|
7908
|
+
}
|
|
7909
|
+
return windowExpression("lag", value, options2.spec, "maybe", {
|
|
7910
|
+
...options2.offset === undefined && options2.default === undefined ? {} : { offset: literal3(options2.offset ?? 1) },
|
|
7911
|
+
...options2.default === undefined ? {} : { defaultValue: literal3(options2.default) }
|
|
7912
|
+
});
|
|
7913
|
+
};
|
|
7914
|
+
var lead = (value, options2) => {
|
|
7915
|
+
rejectExplicitPortableFrame("lead", options2.spec);
|
|
7916
|
+
if (options2.offset !== undefined && (!Number.isSafeInteger(options2.offset) || options2.offset < 0)) {
|
|
7917
|
+
throw new Error("lead offset must be a non-negative safe integer");
|
|
7918
|
+
}
|
|
7919
|
+
return windowExpression("lead", value, options2.spec, "maybe", {
|
|
7920
|
+
...options2.offset === undefined && options2.default === undefined ? {} : { offset: literal3(options2.offset ?? 1) },
|
|
7921
|
+
...options2.default === undefined ? {} : { defaultValue: literal3(options2.default) }
|
|
7922
|
+
});
|
|
7923
|
+
};
|
|
7924
|
+
var firstValue = (value, spec) => {
|
|
7925
|
+
rejectExplicitPortableFrame("firstValue", spec);
|
|
7926
|
+
return windowExpression("firstValue", value, spec, value[TypeId].nullability);
|
|
7927
|
+
};
|
|
7928
|
+
var lastValue = (value, spec) => {
|
|
7929
|
+
rejectExplicitPortableFrame("lastValue", spec);
|
|
7930
|
+
return windowExpression("lastValue", value, spec, value[TypeId].nullability);
|
|
7931
|
+
};
|
|
7932
|
+
var makeDialectFirstValue = (dialect) => (value, spec) => windowExpression("firstValue", value, spec, "maybe", { fallbackDialect: dialect });
|
|
7933
|
+
var makeDialectLastValue = (dialect) => (value, spec) => windowExpression("lastValue", value, spec, "maybe", { fallbackDialect: dialect });
|
|
7934
|
+
|
|
7935
|
+
// src/sqlite/function/window.ts
|
|
7936
|
+
var firstValue2 = makeDialectFirstValue("sqlite");
|
|
7937
|
+
var lastValue2 = makeDialectLastValue("sqlite");
|
|
7938
|
+
// src/sqlite/function/temporal.ts
|
|
7939
|
+
var exports_temporal = {};
|
|
7940
|
+
__export(exports_temporal, {
|
|
7941
|
+
now: () => now,
|
|
7942
|
+
localTimestamp: () => localTimestamp,
|
|
7943
|
+
localTime: () => localTime,
|
|
7944
|
+
currentTimestamp: () => currentTimestamp,
|
|
7945
|
+
currentTime: () => currentTime,
|
|
7946
|
+
currentDate: () => currentDate
|
|
7947
|
+
});
|
|
7948
|
+
var makeTemporal = (name, dbType, runtimeSchema) => makeExpression2({
|
|
7949
|
+
runtime: undefined,
|
|
7950
|
+
dbType,
|
|
7951
|
+
runtimeSchema,
|
|
7952
|
+
nullability: "never",
|
|
7953
|
+
dialect: "sqlite",
|
|
7954
|
+
kind: "scalar",
|
|
7955
|
+
dependencies: {}
|
|
7956
|
+
}, {
|
|
7957
|
+
kind: "function",
|
|
7958
|
+
name,
|
|
7959
|
+
args: []
|
|
7960
|
+
});
|
|
7961
|
+
var currentDate = () => makeTemporal("current_date", sqliteDatatypes.date(), LocalDateStringSchema);
|
|
7962
|
+
var currentTime = () => makeTemporal("current_time", sqliteDatatypes.time(), LocalTimeStringSchema);
|
|
7963
|
+
var currentTimestamp = () => makeTemporal("current_timestamp", sqliteDatatypes.timestamp(), LocalDateTimeStringSchema);
|
|
7964
|
+
var localTime = () => makeTemporal("localtime", sqliteDatatypes.time(), LocalTimeStringSchema);
|
|
7965
|
+
var localTimestamp = () => makeTemporal("localtimestamp", sqliteDatatypes.timestamp(), LocalDateTimeStringSchema);
|
|
7966
|
+
var now = () => makeTemporal("now", sqliteDatatypes.timestamp(), LocalDateTimeStringSchema);
|
|
7967
|
+
// src/sqlite/json.ts
|
|
7968
|
+
var exports_json = {};
|
|
7969
|
+
__export(exports_json, {
|
|
7970
|
+
typeOf: () => typeOf,
|
|
7971
|
+
stripNulls: () => stripNulls,
|
|
7972
|
+
pathMatch: () => pathMatch,
|
|
7973
|
+
length: () => length,
|
|
7974
|
+
insert: () => insert2
|
|
7975
|
+
});
|
|
7976
|
+
var insert2 = json.insert;
|
|
7977
|
+
var typeOf = json.typeOf;
|
|
7978
|
+
var length = json.length;
|
|
7979
|
+
var stripNulls = json.stripNulls;
|
|
7980
|
+
var pathMatch = json.pathMatch;
|
|
7981
|
+
// src/sqlite/executor.ts
|
|
7982
|
+
var exports_executor2 = {};
|
|
7983
|
+
__export(exports_executor2, {
|
|
7984
|
+
withTransaction: () => withTransaction2,
|
|
7985
|
+
nonEmpty: () => nonEmpty2,
|
|
7986
|
+
make: () => make4,
|
|
7987
|
+
exactlyOne: () => exactlyOne2,
|
|
7988
|
+
driver: () => driver2,
|
|
7989
|
+
custom: () => custom4,
|
|
7990
|
+
atMostOne: () => atMostOne2
|
|
7991
|
+
});
|
|
7992
|
+
import * as Effect2 from "effect/Effect";
|
|
7993
|
+
import * as SqlClient3 from "effect/unstable/sql/SqlClient";
|
|
7994
|
+
import * as Stream2 from "effect/Stream";
|
|
7995
|
+
|
|
7996
|
+
// src/internal/executor.ts
|
|
7997
|
+
var exports_executor = {};
|
|
7998
|
+
__export(exports_executor, {
|
|
7999
|
+
withTransaction: () => withTransaction,
|
|
8000
|
+
withResultContracts: () => withResultContracts,
|
|
8001
|
+
streamFromSqlClient: () => streamFromSqlClient,
|
|
8002
|
+
remapRows: () => remapRows,
|
|
8003
|
+
nonEmpty: () => nonEmpty,
|
|
8004
|
+
makeRowDecoder: () => makeRowDecoder,
|
|
8005
|
+
make: () => make3,
|
|
8006
|
+
hasWriteCapability: () => hasWriteCapability,
|
|
8007
|
+
fromSqlClient: () => fromSqlClient,
|
|
8008
|
+
fromDriver: () => fromDriver,
|
|
8009
|
+
explainQuery: () => explainQuery,
|
|
8010
|
+
exactlyOne: () => exactlyOne,
|
|
8011
|
+
driver: () => driver,
|
|
8012
|
+
decodeRows: () => decodeRows,
|
|
8013
|
+
decodeChunk: () => decodeChunk,
|
|
8014
|
+
atMostOne: () => atMostOne
|
|
8015
|
+
});
|
|
8016
|
+
import * as Chunk from "effect/Chunk";
|
|
8017
|
+
import * as Effect from "effect/Effect";
|
|
8018
|
+
import * as Exit from "effect/Exit";
|
|
8019
|
+
import * as Option from "effect/Option";
|
|
8020
|
+
import * as Schema10 from "effect/Schema";
|
|
8021
|
+
import * as SqlClient from "effect/unstable/sql/SqlClient";
|
|
8022
|
+
import * as Stream from "effect/Stream";
|
|
8023
|
+
|
|
8024
|
+
// src/internal/runtime/driver-value-mapping.ts
|
|
8025
|
+
import * as Schema8 from "effect/Schema";
|
|
8026
|
+
var runtimeTagOfDbType = (dbType) => {
|
|
8027
|
+
if (dbType === undefined) {
|
|
8028
|
+
return;
|
|
8029
|
+
}
|
|
8030
|
+
if ("base" in dbType) {
|
|
8031
|
+
return runtimeTagOfDbType(dbType.base);
|
|
8032
|
+
}
|
|
8033
|
+
if ("element" in dbType) {
|
|
8034
|
+
return "array";
|
|
8035
|
+
}
|
|
8036
|
+
if ("fields" in dbType) {
|
|
8037
|
+
return "record";
|
|
8038
|
+
}
|
|
8039
|
+
if ("variant" in dbType && dbType.variant === "json") {
|
|
8040
|
+
return "json";
|
|
8041
|
+
}
|
|
8042
|
+
if ("variant" in dbType && (dbType.variant === "enum" || dbType.variant === "set")) {
|
|
8043
|
+
return "string";
|
|
8044
|
+
}
|
|
8045
|
+
return dbType.runtime;
|
|
8046
|
+
};
|
|
8047
|
+
var familyOfDbType = (dbType) => {
|
|
8048
|
+
if (dbType === undefined) {
|
|
8049
|
+
return;
|
|
8050
|
+
}
|
|
8051
|
+
if ("base" in dbType) {
|
|
8052
|
+
return familyOfDbType(dbType.base);
|
|
8053
|
+
}
|
|
8054
|
+
return dbType.family;
|
|
8055
|
+
};
|
|
8056
|
+
var mappingCandidates = (context) => {
|
|
8057
|
+
const dbType = context.dbType;
|
|
8058
|
+
const runtimeTag = runtimeTagOfDbType(dbType);
|
|
8059
|
+
const family = familyOfDbType(dbType);
|
|
8060
|
+
return [
|
|
8061
|
+
context.driverValueMapping,
|
|
8062
|
+
dbType?.driverValueMapping,
|
|
8063
|
+
dbType === undefined ? undefined : context.valueMappings?.[dbType.kind],
|
|
8064
|
+
family === undefined ? undefined : context.valueMappings?.[family],
|
|
8065
|
+
runtimeTag === undefined ? undefined : context.valueMappings?.[runtimeTag]
|
|
8066
|
+
];
|
|
8067
|
+
};
|
|
8068
|
+
var findMapping = (context, key2) => {
|
|
8069
|
+
for (const candidate of mappingCandidates(context)) {
|
|
8070
|
+
const value = candidate?.[key2];
|
|
8071
|
+
if (value !== undefined) {
|
|
8072
|
+
return value;
|
|
8073
|
+
}
|
|
8074
|
+
}
|
|
8075
|
+
return;
|
|
8076
|
+
};
|
|
8077
|
+
var isJsonDbType = (dbType) => {
|
|
8078
|
+
if (dbType === undefined) {
|
|
8079
|
+
return false;
|
|
8080
|
+
}
|
|
8081
|
+
if ("base" in dbType) {
|
|
8082
|
+
return isJsonDbType(dbType.base);
|
|
8083
|
+
}
|
|
8084
|
+
if (!("variant" in dbType)) {
|
|
8085
|
+
return false;
|
|
8086
|
+
}
|
|
8087
|
+
const variant = dbType.variant;
|
|
8088
|
+
return variant === "json" || variant === "jsonb";
|
|
8089
|
+
};
|
|
8090
|
+
var schemaAccepts = (schema2, value) => schema2 !== undefined && Schema8.is(schema2)(value);
|
|
8091
|
+
var encodeWithSchema = (schema2, value) => {
|
|
8092
|
+
if (schema2 === undefined) {
|
|
8093
|
+
return { value, encoded: false };
|
|
8094
|
+
}
|
|
8095
|
+
if (!Schema8.is(schema2)(value)) {
|
|
8096
|
+
return { value, encoded: false };
|
|
8097
|
+
}
|
|
8098
|
+
return {
|
|
8099
|
+
value: Schema8.encodeUnknownSync(schema2)(value),
|
|
8100
|
+
encoded: true
|
|
8101
|
+
};
|
|
8102
|
+
};
|
|
8103
|
+
var normalizeJsonDriverString = (value, context) => {
|
|
8104
|
+
if (!isJsonDbType(context.dbType) || context.runtimeSchema === undefined) {
|
|
8105
|
+
return;
|
|
8106
|
+
}
|
|
8107
|
+
try {
|
|
8108
|
+
const parsed = JSON.parse(value);
|
|
8109
|
+
if (value.trimStart().startsWith('"') && schemaAccepts(context.runtimeSchema, parsed)) {
|
|
8110
|
+
return parsed;
|
|
6014
8111
|
}
|
|
6015
8112
|
if (schemaAccepts(context.runtimeSchema, value) && !schemaAccepts(context.runtimeSchema, parsed)) {
|
|
6016
8113
|
return value;
|
|
@@ -6035,9 +8132,9 @@ var toDriverValue = (value, context) => {
|
|
|
6035
8132
|
const dbType = context.dbType;
|
|
6036
8133
|
const encoded = encodeWithSchema(context.runtimeSchema, value);
|
|
6037
8134
|
let current = encoded.value;
|
|
6038
|
-
const
|
|
6039
|
-
if (
|
|
6040
|
-
return
|
|
8135
|
+
const custom4 = findMapping(context, "toDriver");
|
|
8136
|
+
if (custom4 !== undefined && dbType !== undefined) {
|
|
8137
|
+
return custom4(current, dbType);
|
|
6041
8138
|
}
|
|
6042
8139
|
if (encoded.encoded && typeof current === "string" && isJsonDbType(dbType)) {
|
|
6043
8140
|
return current;
|
|
@@ -6049,9 +8146,9 @@ var fromDriverValue = (value, context) => {
|
|
|
6049
8146
|
return null;
|
|
6050
8147
|
}
|
|
6051
8148
|
const dbType = context.dbType;
|
|
6052
|
-
const
|
|
6053
|
-
if (
|
|
6054
|
-
return
|
|
8149
|
+
const custom4 = findMapping(context, "fromDriver");
|
|
8150
|
+
if (custom4 !== undefined && dbType !== undefined) {
|
|
8151
|
+
return custom4(value, dbType);
|
|
6055
8152
|
}
|
|
6056
8153
|
if (typeof value === "string") {
|
|
6057
8154
|
const normalizedJsonString = normalizeJsonDriverString(value, context);
|
|
@@ -6082,33 +8179,33 @@ var postgresJsonSql = (sql, dbType) => {
|
|
|
6082
8179
|
};
|
|
6083
8180
|
var renderSelectSql = (sql, context) => {
|
|
6084
8181
|
const dbType = context.dbType;
|
|
6085
|
-
const
|
|
6086
|
-
return
|
|
8182
|
+
const custom4 = findMapping(context, "selectSql");
|
|
8183
|
+
return custom4 !== undefined && dbType !== undefined ? custom4(sql, dbType) : sql;
|
|
6087
8184
|
};
|
|
6088
8185
|
var renderJsonSelectSql = (sql, context) => {
|
|
6089
8186
|
const dbType = context.dbType;
|
|
6090
|
-
const
|
|
6091
|
-
if (
|
|
6092
|
-
return
|
|
8187
|
+
const custom4 = findMapping(context, "jsonSelectSql");
|
|
8188
|
+
if (custom4 !== undefined && dbType !== undefined) {
|
|
8189
|
+
return custom4(sql, dbType);
|
|
6093
8190
|
}
|
|
6094
8191
|
return context.dialect === "postgres" && dbType !== undefined ? postgresJsonSql(sql, dbType) : sql;
|
|
6095
8192
|
};
|
|
6096
8193
|
|
|
6097
8194
|
// src/internal/runtime/schema.ts
|
|
6098
|
-
import * as
|
|
8195
|
+
import * as Schema9 from "effect/Schema";
|
|
6099
8196
|
import * as SchemaAST from "effect/SchemaAST";
|
|
6100
8197
|
var schemaCache = new WeakMap;
|
|
6101
|
-
var FiniteNumberSchema =
|
|
8198
|
+
var FiniteNumberSchema = Schema9.Number.check(Schema9.isFinite());
|
|
6102
8199
|
var runtimeSchemaForTag = (tag) => {
|
|
6103
8200
|
switch (tag) {
|
|
6104
8201
|
case "string":
|
|
6105
|
-
return
|
|
8202
|
+
return Schema9.String;
|
|
6106
8203
|
case "number":
|
|
6107
8204
|
return FiniteNumberSchema;
|
|
6108
8205
|
case "bigintString":
|
|
6109
8206
|
return BigIntStringSchema;
|
|
6110
8207
|
case "boolean":
|
|
6111
|
-
return
|
|
8208
|
+
return Schema9.Boolean;
|
|
6112
8209
|
case "json":
|
|
6113
8210
|
return JsonValueSchema;
|
|
6114
8211
|
case "localDate":
|
|
@@ -6126,13 +8223,13 @@ var runtimeSchemaForTag = (tag) => {
|
|
|
6126
8223
|
case "decimalString":
|
|
6127
8224
|
return DecimalStringSchema;
|
|
6128
8225
|
case "bytes":
|
|
6129
|
-
return
|
|
8226
|
+
return Schema9.Uint8Array;
|
|
6130
8227
|
case "array":
|
|
6131
|
-
return
|
|
8228
|
+
return Schema9.Array(Schema9.Unknown);
|
|
6132
8229
|
case "record":
|
|
6133
|
-
return
|
|
8230
|
+
return Schema9.Record(Schema9.String, Schema9.Unknown);
|
|
6134
8231
|
case "null":
|
|
6135
|
-
return
|
|
8232
|
+
return Schema9.Null;
|
|
6136
8233
|
case "unknown":
|
|
6137
8234
|
return;
|
|
6138
8235
|
}
|
|
@@ -6145,22 +8242,22 @@ var runtimeSchemaForDbType = (dbType) => {
|
|
|
6145
8242
|
return runtimeSchemaForDbType(dbType.base);
|
|
6146
8243
|
}
|
|
6147
8244
|
if ("element" in dbType) {
|
|
6148
|
-
return
|
|
8245
|
+
return Schema9.Array(runtimeSchemaForDbType(dbType.element) ?? Schema9.Unknown);
|
|
6149
8246
|
}
|
|
6150
8247
|
if ("fields" in dbType) {
|
|
6151
|
-
const fields2 = Object.fromEntries(Object.entries(dbType.fields).map(([key2, field]) => [key2, runtimeSchemaForDbType(field) ??
|
|
6152
|
-
return
|
|
8248
|
+
const fields2 = Object.fromEntries(Object.entries(dbType.fields).map(([key2, field]) => [key2, runtimeSchemaForDbType(field) ?? Schema9.Unknown]));
|
|
8249
|
+
return Schema9.Struct(fields2);
|
|
6153
8250
|
}
|
|
6154
8251
|
if ("variant" in dbType && dbType.variant === "json") {
|
|
6155
8252
|
return JsonValueSchema;
|
|
6156
8253
|
}
|
|
6157
8254
|
if ("variant" in dbType && (dbType.variant === "enum" || dbType.variant === "set")) {
|
|
6158
|
-
return
|
|
8255
|
+
return Schema9.String;
|
|
6159
8256
|
}
|
|
6160
8257
|
const runtimeTag = runtimeTagOfBaseDbType2(dbType);
|
|
6161
8258
|
return runtimeTag === undefined ? undefined : runtimeSchemaForTag(runtimeTag);
|
|
6162
8259
|
};
|
|
6163
|
-
var makeSchemaFromAst = (ast) =>
|
|
8260
|
+
var makeSchemaFromAst = (ast) => Schema9.make(ast);
|
|
6164
8261
|
var unionAst = (asts) => {
|
|
6165
8262
|
if (asts.length === 0) {
|
|
6166
8263
|
return;
|
|
@@ -6183,11 +8280,11 @@ var propertyAstOf = (ast, key2) => {
|
|
|
6183
8280
|
return index4?.type;
|
|
6184
8281
|
}
|
|
6185
8282
|
case "Union": {
|
|
6186
|
-
const
|
|
8283
|
+
const values3 = ast.types.flatMap((member) => {
|
|
6187
8284
|
const next = propertyAstOf(member, key2);
|
|
6188
8285
|
return next === undefined ? [] : [next];
|
|
6189
8286
|
});
|
|
6190
|
-
return unionAst(
|
|
8287
|
+
return unionAst(values3);
|
|
6191
8288
|
}
|
|
6192
8289
|
default:
|
|
6193
8290
|
return;
|
|
@@ -6208,11 +8305,11 @@ var numberAstOf = (ast, index4) => {
|
|
|
6208
8305
|
return unionAst(ast.rest);
|
|
6209
8306
|
}
|
|
6210
8307
|
case "Union": {
|
|
6211
|
-
const
|
|
8308
|
+
const values3 = ast.types.flatMap((member) => {
|
|
6212
8309
|
const next = numberAstOf(member, index4);
|
|
6213
8310
|
return next === undefined ? [] : [next];
|
|
6214
8311
|
});
|
|
6215
|
-
return unionAst(
|
|
8312
|
+
return unionAst(values3);
|
|
6216
8313
|
}
|
|
6217
8314
|
default:
|
|
6218
8315
|
return;
|
|
@@ -6250,7 +8347,7 @@ var unionSchemas = (schemas) => {
|
|
|
6250
8347
|
if (resolved.length === 1) {
|
|
6251
8348
|
return resolved[0];
|
|
6252
8349
|
}
|
|
6253
|
-
return
|
|
8350
|
+
return Schema9.Union(resolved);
|
|
6254
8351
|
};
|
|
6255
8352
|
var firstSelectedExpression = (plan) => {
|
|
6256
8353
|
const selection = getAst(plan).select;
|
|
@@ -6285,9 +8382,9 @@ var jsonCompatibleSchema = (schema2) => {
|
|
|
6285
8382
|
};
|
|
6286
8383
|
var buildStructSchema = (entries, context) => {
|
|
6287
8384
|
const fields2 = Object.fromEntries(entries.map((entry) => [entry.key, expressionRuntimeSchema(entry.value, context) ?? JsonValueSchema]));
|
|
6288
|
-
return
|
|
8385
|
+
return Schema9.Struct(fields2);
|
|
6289
8386
|
};
|
|
6290
|
-
var buildTupleSchema = (
|
|
8387
|
+
var buildTupleSchema = (values3, context) => Schema9.Tuple(values3.map((value) => expressionRuntimeSchema(value, context) ?? JsonValueSchema));
|
|
6291
8388
|
var deriveCaseSchema = (ast, context) => {
|
|
6292
8389
|
if (context === undefined) {
|
|
6293
8390
|
return unionSchemas([
|
|
@@ -6327,10 +8424,10 @@ var deriveRuntimeSchema = (expression, context) => {
|
|
|
6327
8424
|
return state.runtimeSchema;
|
|
6328
8425
|
case "literal":
|
|
6329
8426
|
if (ast.value === null) {
|
|
6330
|
-
return
|
|
8427
|
+
return Schema9.Null;
|
|
6331
8428
|
}
|
|
6332
8429
|
if (typeof ast.value === "string" || typeof ast.value === "number" || typeof ast.value === "boolean") {
|
|
6333
|
-
return
|
|
8430
|
+
return Schema9.Literal(ast.value);
|
|
6334
8431
|
}
|
|
6335
8432
|
return runtimeSchemaForDbType(state.dbType);
|
|
6336
8433
|
case "cast":
|
|
@@ -6366,7 +8463,7 @@ var deriveRuntimeSchema = (expression, context) => {
|
|
|
6366
8463
|
case "jsonHasAllKeys":
|
|
6367
8464
|
case "jsonPathExists":
|
|
6368
8465
|
case "jsonPathMatch":
|
|
6369
|
-
return
|
|
8466
|
+
return Schema9.Boolean;
|
|
6370
8467
|
case "upper":
|
|
6371
8468
|
case "lower":
|
|
6372
8469
|
case "concat":
|
|
@@ -6375,8 +8472,9 @@ var deriveRuntimeSchema = (expression, context) => {
|
|
|
6375
8472
|
case "jsonAccessText":
|
|
6376
8473
|
case "jsonTraverseText":
|
|
6377
8474
|
case "jsonTypeOf":
|
|
6378
|
-
return
|
|
8475
|
+
return Schema9.String;
|
|
6379
8476
|
case "count":
|
|
8477
|
+
return runtimeSchemaForDbType(state.dbType);
|
|
6380
8478
|
case "jsonLength":
|
|
6381
8479
|
return FiniteNumberSchema;
|
|
6382
8480
|
case "max":
|
|
@@ -6391,7 +8489,7 @@ var deriveRuntimeSchema = (expression, context) => {
|
|
|
6391
8489
|
return selection === undefined ? undefined : expressionRuntimeSchema(selection, context);
|
|
6392
8490
|
}
|
|
6393
8491
|
case "window":
|
|
6394
|
-
return ast.function === "over" && ast.value !== undefined ? expressionRuntimeSchema(ast.value, context) :
|
|
8492
|
+
return ast.function === "over" && ast.value !== undefined ? expressionRuntimeSchema(ast.value, context) : runtimeSchemaForDbType(state.dbType);
|
|
6395
8493
|
case "jsonGet":
|
|
6396
8494
|
case "jsonPath":
|
|
6397
8495
|
case "jsonAccess":
|
|
@@ -6423,7 +8521,7 @@ var deriveRuntimeSchema = (expression, context) => {
|
|
|
6423
8521
|
case "jsonToJsonb":
|
|
6424
8522
|
return jsonCompatibleSchema(expressionRuntimeSchema(ast.value, context));
|
|
6425
8523
|
case "jsonKeys":
|
|
6426
|
-
return
|
|
8524
|
+
return Schema9.Array(Schema9.String);
|
|
6427
8525
|
}
|
|
6428
8526
|
};
|
|
6429
8527
|
var expressionRuntimeSchema = (expression, context) => {
|
|
@@ -6439,7 +8537,86 @@ var expressionRuntimeSchema = (expression, context) => {
|
|
|
6439
8537
|
return resolved;
|
|
6440
8538
|
};
|
|
6441
8539
|
|
|
8540
|
+
// src/internal/renderer.ts
|
|
8541
|
+
var TypeId10 = Symbol.for("effect-qb/Renderer");
|
|
8542
|
+
var projectionPathKey = (path2) => JSON.stringify(path2);
|
|
8543
|
+
var formatProjectionPath2 = (path2) => path2.join(".");
|
|
8544
|
+
var validateProjectionPathsMatchSelection = (plan, projections) => {
|
|
8545
|
+
const expected = flattenSelection(getAst(plan).select);
|
|
8546
|
+
const expectedPaths = new Set(expected.map((projection) => projectionPathKey(projection.path)));
|
|
8547
|
+
const actualPaths = new Set(projections.map((projection) => projectionPathKey(projection.path)));
|
|
8548
|
+
for (const projection of projections) {
|
|
8549
|
+
if (!expectedPaths.has(projectionPathKey(projection.path))) {
|
|
8550
|
+
throw new Error(`Projection path ${formatProjectionPath2(projection.path)} does not exist in the query selection`);
|
|
8551
|
+
}
|
|
8552
|
+
}
|
|
8553
|
+
for (const projection of expected) {
|
|
8554
|
+
if (!actualPaths.has(projectionPathKey(projection.path))) {
|
|
8555
|
+
throw new Error(`Projection path ${formatProjectionPath2(projection.path)} is missing from rendered projections`);
|
|
8556
|
+
}
|
|
8557
|
+
}
|
|
8558
|
+
};
|
|
8559
|
+
function makeTrusted(dialect, render2) {
|
|
8560
|
+
return makeRenderer(dialect, render2, false);
|
|
8561
|
+
}
|
|
8562
|
+
var makeRenderer = (dialect, render2, validate) => {
|
|
8563
|
+
if (typeof render2 !== "function") {
|
|
8564
|
+
throw new Error(`Renderer.make requires an explicit render implementation for dialect: ${dialect}`);
|
|
8565
|
+
}
|
|
8566
|
+
return {
|
|
8567
|
+
dialect,
|
|
8568
|
+
render(plan) {
|
|
8569
|
+
const rendered = render2(plan);
|
|
8570
|
+
const projections = rendered.projections ?? [];
|
|
8571
|
+
if (validate) {
|
|
8572
|
+
validateProjections(projections);
|
|
8573
|
+
validateProjectionPathsMatchSelection(plan, projections);
|
|
8574
|
+
}
|
|
8575
|
+
return {
|
|
8576
|
+
sql: rendered.sql,
|
|
8577
|
+
params: rendered.params ?? [],
|
|
8578
|
+
projections,
|
|
8579
|
+
valueMappings: rendered.valueMappings,
|
|
8580
|
+
dialect,
|
|
8581
|
+
[TypeId10]: {
|
|
8582
|
+
row: undefined,
|
|
8583
|
+
dialect
|
|
8584
|
+
}
|
|
8585
|
+
};
|
|
8586
|
+
}
|
|
8587
|
+
};
|
|
8588
|
+
};
|
|
8589
|
+
|
|
6442
8590
|
// src/internal/executor.ts
|
|
8591
|
+
var atMostOne = (self) => Effect.flatMap(self, (rows) => rows.length <= 1 ? Effect.succeed(rows.length === 0 ? Option.none() : Option.some(rows[0])) : Effect.fail({
|
|
8592
|
+
_tag: "ResultCardinalityError",
|
|
8593
|
+
expected: "zeroOrOne",
|
|
8594
|
+
actual: rows.length
|
|
8595
|
+
}));
|
|
8596
|
+
var exactlyOne = (self) => Effect.flatMap(self, (rows) => rows.length === 1 ? Effect.succeed(rows[0]) : Effect.fail({
|
|
8597
|
+
_tag: "ResultCardinalityError",
|
|
8598
|
+
expected: "exactlyOne",
|
|
8599
|
+
actual: rows.length
|
|
8600
|
+
}));
|
|
8601
|
+
var nonEmpty = (self) => Effect.flatMap(self, (rows) => rows.length > 0 ? Effect.succeed(rows) : Effect.fail({
|
|
8602
|
+
_tag: "ResultCardinalityError",
|
|
8603
|
+
expected: "nonEmpty",
|
|
8604
|
+
actual: 0
|
|
8605
|
+
}));
|
|
8606
|
+
var withResultContracts = (base) => {
|
|
8607
|
+
const executeResult = base.executeResult ?? ((plan) => Effect.map(base.execute(plan), (rows) => ({ rows })));
|
|
8608
|
+
return {
|
|
8609
|
+
...base,
|
|
8610
|
+
executeResult,
|
|
8611
|
+
prepare(plan) {
|
|
8612
|
+
return {
|
|
8613
|
+
execute: base.execute(plan),
|
|
8614
|
+
executeResult: executeResult(plan),
|
|
8615
|
+
stream: base.stream(plan)
|
|
8616
|
+
};
|
|
8617
|
+
}
|
|
8618
|
+
};
|
|
8619
|
+
};
|
|
6443
8620
|
var setPath2 = (target, path2, value) => {
|
|
6444
8621
|
let current = target;
|
|
6445
8622
|
for (let index4 = 0;index4 < path2.length - 1; index4++) {
|
|
@@ -6479,7 +8656,7 @@ var hasWriteCapability = (plan) => {
|
|
|
6479
8656
|
if (ast.target && hasWriteCapabilityInSource(ast.target.source)) {
|
|
6480
8657
|
return true;
|
|
6481
8658
|
}
|
|
6482
|
-
if ((ast.joins ?? []).some((
|
|
8659
|
+
if ((ast.joins ?? []).some((join3) => hasWriteCapabilityInSource(join3.source))) {
|
|
6483
8660
|
return true;
|
|
6484
8661
|
}
|
|
6485
8662
|
return false;
|
|
@@ -6494,7 +8671,7 @@ var remapRows = (query, rows) => rows.map((row) => {
|
|
|
6494
8671
|
return decoded;
|
|
6495
8672
|
});
|
|
6496
8673
|
var makeRowDecodeError = (rendered, projection, expression, raw, stage, cause, normalized) => {
|
|
6497
|
-
const schemaError =
|
|
8674
|
+
const schemaError = Schema10.isSchemaError(cause) ? {
|
|
6498
8675
|
message: cause.message,
|
|
6499
8676
|
issue: cause.issue
|
|
6500
8677
|
} : undefined;
|
|
@@ -6548,7 +8725,7 @@ var dbTypeAllowsTopLevelJsonNull = (dbType) => {
|
|
|
6548
8725
|
}
|
|
6549
8726
|
return "variant" in dbType && dbType.variant === "json" || dbType.runtime === "json";
|
|
6550
8727
|
};
|
|
6551
|
-
var schemaAcceptsNull = (schema2) => schema2 !== undefined &&
|
|
8728
|
+
var schemaAcceptsNull = (schema2) => schema2 !== undefined && Schema10.is(schema2)(null);
|
|
6552
8729
|
var decodeProjectionValue = (rendered, projection, expression, raw, scope, driverMode, valueMappings) => {
|
|
6553
8730
|
let normalized = raw;
|
|
6554
8731
|
if (driverMode === "raw") {
|
|
@@ -6584,10 +8761,10 @@ var decodeProjectionValue = (rendered, projection, expression, raw, scope, drive
|
|
|
6584
8761
|
if (schema2 === undefined) {
|
|
6585
8762
|
return normalized;
|
|
6586
8763
|
}
|
|
6587
|
-
if (
|
|
8764
|
+
if (Schema10.is(schema2)(normalized)) {
|
|
6588
8765
|
return normalized;
|
|
6589
8766
|
}
|
|
6590
|
-
const decoded =
|
|
8767
|
+
const decoded = Schema10.decodeUnknownExit(schema2)(normalized);
|
|
6591
8768
|
if (Exit.isSuccess(decoded)) {
|
|
6592
8769
|
return decoded.value;
|
|
6593
8770
|
}
|
|
@@ -6626,7 +8803,7 @@ var decodeRows = (rendered, plan, rows, options2 = {}) => {
|
|
|
6626
8803
|
const decodeRow = makeRowDecoder(rendered, plan, options2);
|
|
6627
8804
|
return rows.map((row) => decodeRow(row));
|
|
6628
8805
|
};
|
|
6629
|
-
var make3 = (dialect, execute) => ({
|
|
8806
|
+
var make3 = (dialect, execute) => withResultContracts({
|
|
6630
8807
|
dialect,
|
|
6631
8808
|
execute(plan) {
|
|
6632
8809
|
return execute(plan);
|
|
@@ -6646,23 +8823,81 @@ function driver(dialect, executeOrHandlers) {
|
|
|
6646
8823
|
return Stream.unwrap(Effect.map(executeOrHandlers(query), (rows) => Stream.fromIterable(rows)));
|
|
6647
8824
|
}
|
|
6648
8825
|
return executeOrHandlers.stream(query);
|
|
6649
|
-
}
|
|
8826
|
+
},
|
|
8827
|
+
...typeof executeOrHandlers === "function" || executeOrHandlers.executeResult === undefined ? {} : { executeResult: executeOrHandlers.executeResult }
|
|
6650
8828
|
};
|
|
6651
8829
|
}
|
|
6652
8830
|
var fromDriver = (renderer, sqlDriver) => {
|
|
6653
|
-
const
|
|
8831
|
+
const renderedCache = new WeakMap;
|
|
8832
|
+
const render2 = (plan) => {
|
|
8833
|
+
const cached = renderedCache.get(plan);
|
|
8834
|
+
if (cached !== undefined) {
|
|
8835
|
+
return cached;
|
|
8836
|
+
}
|
|
8837
|
+
const rendered = renderer.render(plan);
|
|
8838
|
+
renderedCache.set(plan, rendered);
|
|
8839
|
+
return rendered;
|
|
8840
|
+
};
|
|
8841
|
+
const executor = withResultContracts({
|
|
6654
8842
|
dialect: renderer.dialect,
|
|
6655
8843
|
execute(plan) {
|
|
6656
|
-
const rendered =
|
|
8844
|
+
const rendered = render2(plan);
|
|
6657
8845
|
return Effect.map(sqlDriver.execute(rendered), (rows) => remapRows(rendered, rows));
|
|
6658
8846
|
},
|
|
8847
|
+
executeResult(plan) {
|
|
8848
|
+
const rendered = render2(plan);
|
|
8849
|
+
const result = sqlDriver.executeResult ? sqlDriver.executeResult(rendered) : Effect.map(sqlDriver.execute(rendered), (rows) => ({ rows }));
|
|
8850
|
+
return Effect.map(result, ({ rows, ...metadata }) => ({
|
|
8851
|
+
...metadata,
|
|
8852
|
+
rows: remapRows(rendered, rows)
|
|
8853
|
+
}));
|
|
8854
|
+
},
|
|
6659
8855
|
stream(plan) {
|
|
6660
|
-
const rendered =
|
|
8856
|
+
const rendered = render2(plan);
|
|
6661
8857
|
return Stream.mapArray(sqlDriver.stream(rendered), (rows) => remapRows(rendered, rows));
|
|
6662
8858
|
}
|
|
6663
|
-
};
|
|
8859
|
+
});
|
|
6664
8860
|
return executor;
|
|
6665
8861
|
};
|
|
8862
|
+
var explainQuery = (query, options2 = {}) => {
|
|
8863
|
+
const analyze = options2.analyze ?? false;
|
|
8864
|
+
const format = options2.format ?? "text";
|
|
8865
|
+
let prefix;
|
|
8866
|
+
switch (query.dialect) {
|
|
8867
|
+
case "postgres":
|
|
8868
|
+
prefix = `explain (${[
|
|
8869
|
+
...analyze ? ["analyze true"] : [],
|
|
8870
|
+
`format ${format}`
|
|
8871
|
+
].join(", ")}) `;
|
|
8872
|
+
break;
|
|
8873
|
+
case "mysql":
|
|
8874
|
+
if (analyze && format === "json") {
|
|
8875
|
+
throw new Error("MySQL EXPLAIN ANALYZE cannot be combined with JSON format");
|
|
8876
|
+
}
|
|
8877
|
+
prefix = analyze ? "explain analyze " : format === "json" ? "explain format=json " : "explain ";
|
|
8878
|
+
break;
|
|
8879
|
+
case "sqlite":
|
|
8880
|
+
if (analyze || format === "json") {
|
|
8881
|
+
throw new Error("SQLite EXPLAIN QUERY PLAN does not support analyze or JSON format");
|
|
8882
|
+
}
|
|
8883
|
+
prefix = "explain query plan ";
|
|
8884
|
+
break;
|
|
8885
|
+
default:
|
|
8886
|
+
if (analyze || format === "json") {
|
|
8887
|
+
throw new Error("Portable EXPLAIN only supports text plans without analyze");
|
|
8888
|
+
}
|
|
8889
|
+
prefix = "explain ";
|
|
8890
|
+
}
|
|
8891
|
+
return {
|
|
8892
|
+
...query,
|
|
8893
|
+
sql: prefix + query.sql,
|
|
8894
|
+
projections: [],
|
|
8895
|
+
[TypeId10]: {
|
|
8896
|
+
row: undefined,
|
|
8897
|
+
dialect: query.dialect
|
|
8898
|
+
}
|
|
8899
|
+
};
|
|
8900
|
+
};
|
|
6666
8901
|
var streamFromSqlClient = (query) => Stream.unwrap(Effect.flatMap(SqlClient.SqlClient, (sql) => Effect.flatMap(Effect.serviceOption(sql.transactionService), Option.match({
|
|
6667
8902
|
onNone: () => sql.reserve,
|
|
6668
8903
|
onSome: ([connection]) => Effect.succeed(connection)
|
|
@@ -6673,56 +8908,6 @@ var fromSqlClient = (renderer) => fromDriver(renderer, driver(renderer.dialect,
|
|
|
6673
8908
|
}));
|
|
6674
8909
|
var withTransaction = (effect) => Effect.flatMap(SqlClient.SqlClient, (sql) => sql.withTransaction(effect));
|
|
6675
8910
|
|
|
6676
|
-
// src/internal/renderer.ts
|
|
6677
|
-
var TypeId10 = Symbol.for("effect-qb/Renderer");
|
|
6678
|
-
var projectionPathKey = (path2) => JSON.stringify(path2);
|
|
6679
|
-
var formatProjectionPath2 = (path2) => path2.join(".");
|
|
6680
|
-
var validateProjectionPathsMatchSelection = (plan, projections) => {
|
|
6681
|
-
const expected = flattenSelection(getAst(plan).select);
|
|
6682
|
-
const expectedPaths = new Set(expected.map((projection) => projectionPathKey(projection.path)));
|
|
6683
|
-
const actualPaths = new Set(projections.map((projection) => projectionPathKey(projection.path)));
|
|
6684
|
-
for (const projection of projections) {
|
|
6685
|
-
if (!expectedPaths.has(projectionPathKey(projection.path))) {
|
|
6686
|
-
throw new Error(`Projection path ${formatProjectionPath2(projection.path)} does not exist in the query selection`);
|
|
6687
|
-
}
|
|
6688
|
-
}
|
|
6689
|
-
for (const projection of expected) {
|
|
6690
|
-
if (!actualPaths.has(projectionPathKey(projection.path))) {
|
|
6691
|
-
throw new Error(`Projection path ${formatProjectionPath2(projection.path)} is missing from rendered projections`);
|
|
6692
|
-
}
|
|
6693
|
-
}
|
|
6694
|
-
};
|
|
6695
|
-
function makeTrusted(dialect, render2) {
|
|
6696
|
-
return makeRenderer(dialect, render2, false);
|
|
6697
|
-
}
|
|
6698
|
-
var makeRenderer = (dialect, render2, validate) => {
|
|
6699
|
-
if (typeof render2 !== "function") {
|
|
6700
|
-
throw new Error(`Renderer.make requires an explicit render implementation for dialect: ${dialect}`);
|
|
6701
|
-
}
|
|
6702
|
-
return {
|
|
6703
|
-
dialect,
|
|
6704
|
-
render(plan) {
|
|
6705
|
-
const rendered = render2(plan);
|
|
6706
|
-
const projections = rendered.projections ?? [];
|
|
6707
|
-
if (validate) {
|
|
6708
|
-
validateProjections(projections);
|
|
6709
|
-
validateProjectionPathsMatchSelection(plan, projections);
|
|
6710
|
-
}
|
|
6711
|
-
return {
|
|
6712
|
-
sql: rendered.sql,
|
|
6713
|
-
params: rendered.params ?? [],
|
|
6714
|
-
projections,
|
|
6715
|
-
valueMappings: rendered.valueMappings,
|
|
6716
|
-
dialect,
|
|
6717
|
-
[TypeId10]: {
|
|
6718
|
-
row: undefined,
|
|
6719
|
-
dialect
|
|
6720
|
-
}
|
|
6721
|
-
};
|
|
6722
|
-
}
|
|
6723
|
-
};
|
|
6724
|
-
};
|
|
6725
|
-
|
|
6726
8911
|
// src/internal/dialect.ts
|
|
6727
8912
|
var quoteDoubleQuotedIdentifier = (value) => {
|
|
6728
8913
|
return `"${value.replaceAll('"', '""')}"`;
|
|
@@ -6733,7 +8918,36 @@ var quoteBacktickIdentifier = (value) => {
|
|
|
6733
8918
|
var renderDbTypeName = (value) => value;
|
|
6734
8919
|
|
|
6735
8920
|
// src/internal/dialect-renderers/sqlite.ts
|
|
6736
|
-
import * as
|
|
8921
|
+
import * as Schema11 from "effect/Schema";
|
|
8922
|
+
|
|
8923
|
+
// src/internal/custom-sql-renderer.ts
|
|
8924
|
+
var renderCustomSql = (node, state, dialect, renderExpression) => node.strings.map((part, index4) => {
|
|
8925
|
+
const value = node.values[index4];
|
|
8926
|
+
if (value === undefined) {
|
|
8927
|
+
return part;
|
|
8928
|
+
}
|
|
8929
|
+
return part + (TypeId in value ? renderExpression(value, state, dialect) : value.parts.map((segment) => dialect.quoteIdentifier(segment)).join("."));
|
|
8930
|
+
}).join("");
|
|
8931
|
+
|
|
8932
|
+
// src/internal/window-renderer.ts
|
|
8933
|
+
var renderBoundary = (boundary) => {
|
|
8934
|
+
if (boundary === "unboundedPreceding") {
|
|
8935
|
+
return "unbounded preceding";
|
|
8936
|
+
}
|
|
8937
|
+
if (boundary === "currentRow") {
|
|
8938
|
+
return "current row";
|
|
8939
|
+
}
|
|
8940
|
+
if (boundary === "unboundedFollowing") {
|
|
8941
|
+
return "unbounded following";
|
|
8942
|
+
}
|
|
8943
|
+
if ("preceding" in boundary) {
|
|
8944
|
+
return `${boundary.preceding} preceding`;
|
|
8945
|
+
}
|
|
8946
|
+
return `${boundary.following} following`;
|
|
8947
|
+
};
|
|
8948
|
+
var renderWindowFrame = (frame) => frame.end === undefined ? `${frame.unit} ${renderBoundary(frame.start)}` : `${frame.unit} between ${renderBoundary(frame.start)} and ${renderBoundary(frame.end)}`;
|
|
8949
|
+
|
|
8950
|
+
// src/internal/dialect-renderers/sqlite.ts
|
|
6737
8951
|
var renderDbType = (dialect, dbType) => {
|
|
6738
8952
|
return renderDbTypeName(renderPortableDatatypeDdlType(dialect.name, dbType.kind) ?? dbType.kind);
|
|
6739
8953
|
};
|
|
@@ -6870,8 +9084,8 @@ var registerQuerySources = (ast, state) => {
|
|
|
6870
9084
|
for (const source of ast.fromSources ?? []) {
|
|
6871
9085
|
registerSourceReference(source.source, source.tableName, state);
|
|
6872
9086
|
}
|
|
6873
|
-
for (const
|
|
6874
|
-
registerSourceReference(
|
|
9087
|
+
for (const join3 of ast.joins) {
|
|
9088
|
+
registerSourceReference(join3.source, join3.tableName, state);
|
|
6875
9089
|
}
|
|
6876
9090
|
if (ast.into !== undefined) {
|
|
6877
9091
|
registerSourceReference(ast.into.source, ast.into.tableName, state);
|
|
@@ -6886,23 +9100,23 @@ var registerQuerySources = (ast, state) => {
|
|
|
6886
9100
|
registerSourceReference(ast.using.source, ast.using.tableName, state);
|
|
6887
9101
|
}
|
|
6888
9102
|
};
|
|
6889
|
-
var renderColumnDefinition = (dialect, state, columnName,
|
|
9103
|
+
var renderColumnDefinition = (dialect, state, columnName, column2, tableName, casing) => {
|
|
6890
9104
|
const expressionState = { ...state, casing, rowLocalColumns: true };
|
|
6891
|
-
if (isArrayDbType(
|
|
9105
|
+
if (isArrayDbType(column2.metadata.dbType)) {
|
|
6892
9106
|
throw new Error("Unsupported sqlite array column options");
|
|
6893
9107
|
}
|
|
6894
9108
|
const clauses = [
|
|
6895
9109
|
quoteColumn(columnName, state, dialect, tableName),
|
|
6896
|
-
|
|
9110
|
+
column2.metadata.ddlType === undefined ? renderDbType(dialect, column2.metadata.dbType) : renderDbTypeName(column2.metadata.ddlType)
|
|
6897
9111
|
];
|
|
6898
|
-
if (
|
|
9112
|
+
if (column2.metadata.identity) {
|
|
6899
9113
|
throw new Error("Unsupported sqlite identity column options");
|
|
6900
|
-
} else if (
|
|
6901
|
-
clauses.push(`generated always as (${renderDdlExpression(
|
|
6902
|
-
} else if (
|
|
6903
|
-
clauses.push(`default ${renderDdlExpression(
|
|
9114
|
+
} else if (column2.metadata.generatedValue) {
|
|
9115
|
+
clauses.push(`generated always as (${renderDdlExpression(column2.metadata.generatedValue, expressionState, dialect)}) stored`);
|
|
9116
|
+
} else if (column2.metadata.defaultValue) {
|
|
9117
|
+
clauses.push(`default ${renderDdlExpression(column2.metadata.defaultValue, expressionState, dialect)}`);
|
|
6904
9118
|
}
|
|
6905
|
-
if (!
|
|
9119
|
+
if (!column2.metadata.nullable) {
|
|
6906
9120
|
clauses.push("not null");
|
|
6907
9121
|
}
|
|
6908
9122
|
return clauses.join(" ");
|
|
@@ -6912,7 +9126,7 @@ var renderCreateTableSql = (targetSource, state, dialect, ifNotExists) => {
|
|
|
6912
9126
|
const table = targetSource.source;
|
|
6913
9127
|
const tableCasing = casingForTable(table, state);
|
|
6914
9128
|
const fields2 = table[TypeId7].fields;
|
|
6915
|
-
const definitions = Object.entries(fields2).map(([columnName,
|
|
9129
|
+
const definitions = Object.entries(fields2).map(([columnName, column2]) => renderColumnDefinition(dialect, state, columnName, column2, targetSource.tableName, tableCasing));
|
|
6916
9130
|
const options2 = table[OptionsSymbol];
|
|
6917
9131
|
const tableOptions = Array.isArray(options2) ? options2 : [options2];
|
|
6918
9132
|
validateOptions(table[TypeId7].name, fields2, tableOptions);
|
|
@@ -6925,17 +9139,17 @@ var renderCreateTableSql = (targetSource, state, dialect, ifNotExists) => {
|
|
|
6925
9139
|
if (option2.deferrable || option2.initiallyDeferred) {
|
|
6926
9140
|
throw new Error("Unsupported sqlite primary key constraint options");
|
|
6927
9141
|
}
|
|
6928
|
-
definitions.push(`${option2.name ? `constraint ${dialect.quoteIdentifier(applyCategory(tableCasing, "constraints", option2.name))} ` : ""}primary key (${option2.columns.map((
|
|
9142
|
+
definitions.push(`${option2.name ? `constraint ${dialect.quoteIdentifier(applyCategory(tableCasing, "constraints", option2.name))} ` : ""}primary key (${option2.columns.map((column2) => quoteColumn(column2, state, dialect, targetSource.tableName)).join(", ")})${option2.deferrable ? ` deferrable${option2.initiallyDeferred ? " initially deferred" : ""}` : ""}`);
|
|
6929
9143
|
break;
|
|
6930
9144
|
case "unique":
|
|
6931
9145
|
if (option2.nullsNotDistinct || option2.deferrable || option2.initiallyDeferred) {
|
|
6932
9146
|
throw new Error("Unsupported sqlite unique constraint options");
|
|
6933
9147
|
}
|
|
6934
|
-
definitions.push(`${option2.name ? `constraint ${dialect.quoteIdentifier(applyCategory(tableCasing, "constraints", option2.name))} ` : ""}unique${option2.nullsNotDistinct ? " nulls not distinct" : ""} (${option2.columns.map((
|
|
9148
|
+
definitions.push(`${option2.name ? `constraint ${dialect.quoteIdentifier(applyCategory(tableCasing, "constraints", option2.name))} ` : ""}unique${option2.nullsNotDistinct ? " nulls not distinct" : ""} (${option2.columns.map((column2) => quoteColumn(column2, state, dialect, targetSource.tableName)).join(", ")})${option2.deferrable ? ` deferrable${option2.initiallyDeferred ? " initially deferred" : ""}` : ""}`);
|
|
6935
9149
|
break;
|
|
6936
9150
|
case "foreignKey": {
|
|
6937
9151
|
const reference = typeof option2.references === "function" ? option2.references() : option2.references;
|
|
6938
|
-
definitions.push(`${option2.name ? `constraint ${dialect.quoteIdentifier(applyCategory(tableCasing, "constraints", option2.name))} ` : ""}foreign key (${option2.columns.map((
|
|
9152
|
+
definitions.push(`${option2.name ? `constraint ${dialect.quoteIdentifier(applyCategory(tableCasing, "constraints", option2.name))} ` : ""}foreign key (${option2.columns.map((column2) => quoteColumn(column2, state, dialect, targetSource.tableName)).join(", ")}) references ${renderReferenceTable(reference, state, dialect)} (${reference.columns.map((column2) => quoteReferenceColumn(column2, reference, state, dialect)).join(", ")})${option2.onDelete !== undefined ? ` on delete ${renderReferentialAction(option2.onDelete)}` : ""}${option2.onUpdate !== undefined ? ` on update ${renderReferentialAction(option2.onUpdate)}` : ""}${option2.deferrable ? ` deferrable${option2.initiallyDeferred ? " initially deferred" : ""}` : ""}`);
|
|
6939
9153
|
break;
|
|
6940
9154
|
}
|
|
6941
9155
|
case "check":
|
|
@@ -6959,7 +9173,7 @@ var renderCreateIndexSql = (targetSource, ddl, state, dialect) => {
|
|
|
6959
9173
|
const maybeIfNotExists = (dialect.name === "postgres" || dialect.name === "sqlite") && ifNotExists ? " if not exists" : "";
|
|
6960
9174
|
const table = targetSource.source;
|
|
6961
9175
|
const tableCasing = casingForTable(table, state);
|
|
6962
|
-
return `create${unique3 ? " unique" : ""} index${maybeIfNotExists} ${dialect.quoteIdentifier(applyCategory(tableCasing, "indexes", name))} on ${renderSourceReference(targetSource.source, targetSource.tableName, targetSource.baseTableName, state, dialect)} (${ddl.columns.map((
|
|
9176
|
+
return `create${unique3 ? " unique" : ""} index${maybeIfNotExists} ${dialect.quoteIdentifier(applyCategory(tableCasing, "indexes", name))} on ${renderSourceReference(targetSource.source, targetSource.tableName, targetSource.baseTableName, state, dialect)} (${ddl.columns.map((column2) => quoteColumn(column2, state, dialect, targetSource.tableName)).join(", ")})`;
|
|
6963
9177
|
};
|
|
6964
9178
|
var renderDropIndexSql = (targetSource, ddl, state, dialect) => {
|
|
6965
9179
|
const ifExists = normalizeStatementFlag(ddl.ifExists);
|
|
@@ -6987,7 +9201,7 @@ var unsupportedJsonFeature = (dialect, feature) => {
|
|
|
6987
9201
|
throw error;
|
|
6988
9202
|
};
|
|
6989
9203
|
var extractJsonBase = (node) => node.value ?? node.base ?? node.input ?? node.left ?? node.target;
|
|
6990
|
-
var
|
|
9204
|
+
var isJsonPathValue3 = (value) => value !== null && typeof value === "object" && (TypeId3 in value);
|
|
6991
9205
|
var isOptionalJsonPathNumber = (value) => value === undefined || typeof value === "number" && Number.isFinite(value);
|
|
6992
9206
|
var isJsonPathSegment = (segment) => {
|
|
6993
9207
|
if (typeof segment === "string") {
|
|
@@ -7026,7 +9240,7 @@ var validateJsonPathSegments = (segments) => {
|
|
|
7026
9240
|
};
|
|
7027
9241
|
var extractJsonPathSegments = (node) => {
|
|
7028
9242
|
const path2 = node.path ?? node.segments ?? node.keys;
|
|
7029
|
-
if (
|
|
9243
|
+
if (isJsonPathValue3(path2)) {
|
|
7030
9244
|
return validateJsonPathSegments(path2.segments);
|
|
7031
9245
|
}
|
|
7032
9246
|
if (Array.isArray(path2)) {
|
|
@@ -7051,7 +9265,7 @@ var extractJsonPathSegments = (node) => {
|
|
|
7051
9265
|
}
|
|
7052
9266
|
return [];
|
|
7053
9267
|
}
|
|
7054
|
-
if ("right" in node &&
|
|
9268
|
+
if ("right" in node && isJsonPathValue3(node.right)) {
|
|
7055
9269
|
return validateJsonPathSegments(node.right.segments);
|
|
7056
9270
|
}
|
|
7057
9271
|
return [];
|
|
@@ -7161,24 +9375,24 @@ var renderJsonInputExpression = (expression, state, dialect) => {
|
|
|
7161
9375
|
}
|
|
7162
9376
|
return renderJsonSelectSql(renderExpression(expression, state, dialect), expressionDriverContext(expression, state, dialect));
|
|
7163
9377
|
};
|
|
7164
|
-
var encodeArrayValues = (
|
|
7165
|
-
if (value === null &&
|
|
9378
|
+
var encodeArrayValues = (values3, column2, state, dialect) => values3.map((value) => {
|
|
9379
|
+
if (value === null && column2.metadata.nullable) {
|
|
7166
9380
|
return null;
|
|
7167
9381
|
}
|
|
7168
|
-
const runtimeSchemaAccepts =
|
|
7169
|
-
const normalizedValue = runtimeSchemaAccepts ? value : normalizeDbValue(
|
|
7170
|
-
const encodedValue =
|
|
9382
|
+
const runtimeSchemaAccepts = column2.schema !== undefined && Schema11.is(column2.schema)(value);
|
|
9383
|
+
const normalizedValue = runtimeSchemaAccepts ? value : normalizeDbValue(column2.metadata.dbType, value);
|
|
9384
|
+
const encodedValue = column2.schema === undefined || runtimeSchemaAccepts ? normalizedValue : Schema11.decodeUnknownSync(column2.schema)(normalizedValue);
|
|
7171
9385
|
return toDriverValue(encodedValue, {
|
|
7172
9386
|
dialect: dialect.name,
|
|
7173
9387
|
valueMappings: state.valueMappings,
|
|
7174
|
-
dbType:
|
|
7175
|
-
runtimeSchema:
|
|
7176
|
-
driverValueMapping:
|
|
9388
|
+
dbType: column2.metadata.dbType,
|
|
9389
|
+
runtimeSchema: column2.schema,
|
|
9390
|
+
driverValueMapping: column2.metadata.driverValueMapping
|
|
7177
9391
|
});
|
|
7178
9392
|
});
|
|
7179
9393
|
var renderPostgresJsonKind = (value) => value[TypeId].dbType.kind === "jsonb" ? "jsonb" : "json";
|
|
7180
9394
|
var renderJsonOpaquePath = (value, state, dialect) => {
|
|
7181
|
-
if (
|
|
9395
|
+
if (isJsonPathValue3(value)) {
|
|
7182
9396
|
const renderSegment = dialect.name === "sqlite" ? renderSqliteJsonPathSegment : renderJsonPathSegment;
|
|
7183
9397
|
return dialect.renderLiteral(renderJsonPathStringLiteral(value.segments, renderSegment), state);
|
|
7184
9398
|
}
|
|
@@ -7332,8 +9546,8 @@ var renderJsonExpression = (expression, ast, state, dialect) => {
|
|
|
7332
9546
|
return;
|
|
7333
9547
|
}
|
|
7334
9548
|
case "jsonBuildArray": {
|
|
7335
|
-
const
|
|
7336
|
-
const renderedValues =
|
|
9549
|
+
const values3 = ast.values;
|
|
9550
|
+
const renderedValues = values3.map((value) => renderJsonInputExpression(value, state, dialect)).join(", ");
|
|
7337
9551
|
if (dialect.name === "postgres") {
|
|
7338
9552
|
return `${postgresExpressionKind === "jsonb" ? "jsonb" : "json"}_build_array(${renderedValues})`;
|
|
7339
9553
|
}
|
|
@@ -7500,12 +9714,12 @@ var selectionProjections = (selection) => flattenSelection(selection).map(({ pat
|
|
|
7500
9714
|
alias: alias2
|
|
7501
9715
|
}));
|
|
7502
9716
|
var renderMutationAssignment = (entry, state, dialect, targetTableName) => {
|
|
7503
|
-
const
|
|
7504
|
-
return `${
|
|
9717
|
+
const column2 = entry.tableName && dialect.name === "sqlite" ? `${dialect.quoteIdentifier(casedTableReferenceName(entry.tableName, state))}.${quoteColumn(entry.columnName, state, dialect, entry.tableName)}` : quoteColumn(entry.columnName, state, dialect, targetTableName);
|
|
9718
|
+
return `${column2} = ${renderExpression(entry.value, state, dialect)}`;
|
|
7505
9719
|
};
|
|
7506
|
-
var renderJoinSourcesForMutation = (joins, state, dialect) => joins.map((
|
|
9720
|
+
var renderJoinSourcesForMutation = (joins, state, dialect) => joins.map((join3) => renderSourceReference(join3.source, join3.tableName, join3.baseTableName, state, dialect)).join(", ");
|
|
7507
9721
|
var renderFromSources = (sources, state, dialect) => sources.map((source) => renderSourceReference(source.source, source.tableName, source.baseTableName, state, dialect)).join(", ");
|
|
7508
|
-
var renderJoinPredicatesForMutation = (joins, state, dialect) => joins.flatMap((
|
|
9722
|
+
var renderJoinPredicatesForMutation = (joins, state, dialect) => joins.flatMap((join3) => join3.kind === "cross" || !join3.on ? [] : [renderExpression(join3.on, state, dialect)]);
|
|
7509
9723
|
var renderDeleteTargets = (targets, dialect) => targets.map((target) => dialect.quoteIdentifier(target.tableName)).join(", ");
|
|
7510
9724
|
var renderTransactionClause = (clause, dialect) => {
|
|
7511
9725
|
switch (clause.kind) {
|
|
@@ -7563,9 +9777,9 @@ var renderQueryAst = (ast, state, dialect, options2 = {}) => {
|
|
|
7563
9777
|
if (ast.from) {
|
|
7564
9778
|
clauses.push(`from ${renderSourceReference(ast.from.source, ast.from.tableName, ast.from.baseTableName, state, dialect)}`);
|
|
7565
9779
|
}
|
|
7566
|
-
for (const
|
|
7567
|
-
const source = renderSourceReference(
|
|
7568
|
-
clauses.push(
|
|
9780
|
+
for (const join3 of ast.joins) {
|
|
9781
|
+
const source = renderSourceReference(join3.source, join3.tableName, join3.baseTableName, state, dialect);
|
|
9782
|
+
clauses.push(join3.kind === "cross" ? `cross join ${source}` : `${join3.kind} join ${source} on ${renderExpression(join3.on, state, dialect)}`);
|
|
7569
9783
|
}
|
|
7570
9784
|
if (ast.where.length > 0) {
|
|
7571
9785
|
clauses.push(`where ${ast.where.map((entry) => renderExpression(entry.predicate, state, dialect)).join(" and ")}`);
|
|
@@ -7616,15 +9830,15 @@ var renderQueryAst = (ast, state, dialect, options2 = {}) => {
|
|
|
7616
9830
|
const conflict = expectConflictClause(insertAst.conflict);
|
|
7617
9831
|
sql = `insert into ${target}`;
|
|
7618
9832
|
if (insertSource?.kind === "values") {
|
|
7619
|
-
const columns = insertSource.columns.map((
|
|
9833
|
+
const columns = insertSource.columns.map((column2) => quoteColumn(column2, state, dialect, targetSource.tableName)).join(", ");
|
|
7620
9834
|
const rows = insertSource.rows.map((row) => `(${row.values.map((entry) => renderExpression(entry.value, targetCasingState, dialect)).join(", ")})`).join(", ");
|
|
7621
9835
|
sql += ` (${columns}) values ${rows}`;
|
|
7622
9836
|
} else if (insertSource?.kind === "query") {
|
|
7623
|
-
const columns = insertSource.columns.map((
|
|
9837
|
+
const columns = insertSource.columns.map((column2) => quoteColumn(column2, state, dialect, targetSource.tableName)).join(", ");
|
|
7624
9838
|
const renderedQuery = renderQueryAst(getAst(insertSource.query), state, dialect);
|
|
7625
9839
|
sql += ` (${columns}) ${renderedQuery.sql}`;
|
|
7626
9840
|
} else if (insertSource?.kind === "unnest") {
|
|
7627
|
-
const columns = insertSource.columns.map((
|
|
9841
|
+
const columns = insertSource.columns.map((column2) => quoteColumn(column2, state, dialect, targetSource.tableName)).join(", ");
|
|
7628
9842
|
if (dialect.name === "postgres") {
|
|
7629
9843
|
const table = targetSource.source;
|
|
7630
9844
|
const fields2 = table[TypeId7].fields;
|
|
@@ -7644,9 +9858,9 @@ var renderQueryAst = (ast, state, dialect, options2 = {}) => {
|
|
|
7644
9858
|
} else {
|
|
7645
9859
|
const insertValues = insertAst.values ?? [];
|
|
7646
9860
|
const columns = insertValues.map((entry) => quoteColumn(entry.columnName, state, dialect, targetSource.tableName)).join(", ");
|
|
7647
|
-
const
|
|
9861
|
+
const values3 = insertValues.map((entry) => renderExpression(entry.value, targetCasingState, dialect)).join(", ");
|
|
7648
9862
|
if (insertValues.length > 0) {
|
|
7649
|
-
sql += ` (${columns}) values (${
|
|
9863
|
+
sql += ` (${columns}) values (${values3})`;
|
|
7650
9864
|
} else {
|
|
7651
9865
|
sql += " default values";
|
|
7652
9866
|
}
|
|
@@ -7655,7 +9869,7 @@ var renderQueryAst = (ast, state, dialect, options2 = {}) => {
|
|
|
7655
9869
|
const conflictValueState = { ...targetCasingState, allowExcluded: true };
|
|
7656
9870
|
const updateValues = (conflict.values ?? []).map((entry) => `${quoteColumn(entry.columnName, state, dialect, targetSource.tableName)} = ${renderExpression(entry.value, conflictValueState, dialect)}`).join(", ");
|
|
7657
9871
|
if (dialect.name === "postgres" || dialect.name === "sqlite") {
|
|
7658
|
-
const targetSql = conflict.target?.kind === "constraint" ? ` on conflict on constraint ${dialect.quoteIdentifier(applyCategory(targetCasingState.casing, "constraints", conflict.target.name))}` : conflict.target?.kind === "columns" ? ` on conflict (${conflict.target.columns.map((
|
|
9872
|
+
const targetSql = conflict.target?.kind === "constraint" ? ` on conflict on constraint ${dialect.quoteIdentifier(applyCategory(targetCasingState.casing, "constraints", conflict.target.name))}` : conflict.target?.kind === "columns" ? ` on conflict (${conflict.target.columns.map((column2) => quoteColumn(column2, state, dialect, targetSource.tableName)).join(", ")})${conflict.target.where ? ` where ${renderExpression(conflict.target.where, targetCasingState, dialect)}` : ""}` : " on conflict";
|
|
7659
9873
|
sql += targetSql;
|
|
7660
9874
|
sql += conflict.action === "doNothing" ? " do nothing" : ` do update set ${updateValues}${conflict.where ? ` where ${renderExpression(conflict.where, conflictValueState, dialect)}` : ""}`;
|
|
7661
9875
|
} else if (conflict.action === "doNothing") {
|
|
@@ -7664,10 +9878,10 @@ var renderQueryAst = (ast, state, dialect, options2 = {}) => {
|
|
|
7664
9878
|
sql += ` on duplicate key update ${updateValues}`;
|
|
7665
9879
|
}
|
|
7666
9880
|
}
|
|
7667
|
-
const
|
|
7668
|
-
projections =
|
|
7669
|
-
if (
|
|
7670
|
-
sql += ` returning ${
|
|
9881
|
+
const returning3 = renderSelectionList(insertAst.select, state, dialect);
|
|
9882
|
+
projections = returning3.projections;
|
|
9883
|
+
if (returning3.sql.length > 0) {
|
|
9884
|
+
sql += ` returning ${returning3.sql}`;
|
|
7671
9885
|
}
|
|
7672
9886
|
break;
|
|
7673
9887
|
}
|
|
@@ -7684,9 +9898,9 @@ var renderQueryAst = (ast, state, dialect, options2 = {}) => {
|
|
|
7684
9898
|
if (dialect.name === "mysql") {
|
|
7685
9899
|
const modifiers = "";
|
|
7686
9900
|
const extraSources = renderFromSources(fromSources, state, dialect);
|
|
7687
|
-
const joinSources = updateAst.joins.map((
|
|
9901
|
+
const joinSources = updateAst.joins.map((join3) => join3.kind === "full" ? (() => {
|
|
7688
9902
|
throw new Error("Unsupported sqlite full join");
|
|
7689
|
-
})() :
|
|
9903
|
+
})() : join3.kind === "cross" ? `cross join ${renderSourceReference(join3.source, join3.tableName, join3.baseTableName, state, dialect)}` : `${join3.kind} join ${renderSourceReference(join3.source, join3.tableName, join3.baseTableName, state, dialect)} on ${renderExpression(join3.on, state, dialect)}`).join(" ");
|
|
7690
9904
|
const targetList = [
|
|
7691
9905
|
...targets.map((entry) => renderSourceReference(entry.source, entry.tableName, entry.baseTableName, state, dialect)),
|
|
7692
9906
|
...extraSources.length > 0 ? [extraSources] : []
|
|
@@ -7715,10 +9929,10 @@ var renderQueryAst = (ast, state, dialect, options2 = {}) => {
|
|
|
7715
9929
|
if (dialect.name === "mysql" && updateAst.limit) {
|
|
7716
9930
|
sql += ` limit ${renderSqliteMutationLimit(updateAst.limit, state, dialect)}`;
|
|
7717
9931
|
}
|
|
7718
|
-
const
|
|
7719
|
-
projections =
|
|
7720
|
-
if (
|
|
7721
|
-
sql += ` returning ${
|
|
9932
|
+
const returning3 = renderSelectionList(updateAst.select, state, dialect);
|
|
9933
|
+
projections = returning3.projections;
|
|
9934
|
+
if (returning3.sql.length > 0) {
|
|
9935
|
+
sql += ` returning ${returning3.sql}`;
|
|
7722
9936
|
}
|
|
7723
9937
|
break;
|
|
7724
9938
|
}
|
|
@@ -7735,9 +9949,9 @@ var renderQueryAst = (ast, state, dialect, options2 = {}) => {
|
|
|
7735
9949
|
const hasJoinedSources = deleteAst.joins.length > 0 || targets.length > 1;
|
|
7736
9950
|
const targetList = renderDeleteTargets(targets, dialect);
|
|
7737
9951
|
const fromSources = targets.map((entry) => renderSourceReference(entry.source, entry.tableName, entry.baseTableName, state, dialect)).join(", ");
|
|
7738
|
-
const joinSources = deleteAst.joins.map((
|
|
9952
|
+
const joinSources = deleteAst.joins.map((join3) => join3.kind === "full" ? (() => {
|
|
7739
9953
|
throw new Error("Unsupported sqlite full join");
|
|
7740
|
-
})() :
|
|
9954
|
+
})() : join3.kind === "cross" ? `cross join ${renderSourceReference(join3.source, join3.tableName, join3.baseTableName, state, dialect)}` : `${join3.kind} join ${renderSourceReference(join3.source, join3.tableName, join3.baseTableName, state, dialect)} on ${renderExpression(join3.on, state, dialect)}`).join(" ");
|
|
7741
9955
|
sql = hasJoinedSources ? `delete${modifiers} ${targetList} from ${fromSources}${joinSources.length > 0 ? ` ${joinSources}` : ""}` : `delete${modifiers} from ${fromSources}`;
|
|
7742
9956
|
} else {
|
|
7743
9957
|
if (dialect.name === "sqlite" && deleteAst.joins.length > 0) {
|
|
@@ -7761,10 +9975,10 @@ var renderQueryAst = (ast, state, dialect, options2 = {}) => {
|
|
|
7761
9975
|
if (dialect.name === "mysql" && deleteAst.limit) {
|
|
7762
9976
|
sql += ` limit ${renderSqliteMutationLimit(deleteAst.limit, state, dialect)}`;
|
|
7763
9977
|
}
|
|
7764
|
-
const
|
|
7765
|
-
projections =
|
|
7766
|
-
if (
|
|
7767
|
-
sql += ` returning ${
|
|
9978
|
+
const returning3 = renderSelectionList(deleteAst.select, state, dialect);
|
|
9979
|
+
projections = returning3.projections;
|
|
9980
|
+
if (returning3.sql.length > 0) {
|
|
9981
|
+
sql += ` returning ${returning3.sql}`;
|
|
7768
9982
|
}
|
|
7769
9983
|
break;
|
|
7770
9984
|
}
|
|
@@ -7780,25 +9994,25 @@ var renderQueryAst = (ast, state, dialect, options2 = {}) => {
|
|
|
7780
9994
|
const mergeAst = ast;
|
|
7781
9995
|
const targetSource = mergeAst.target;
|
|
7782
9996
|
const usingSource = mergeAst.using;
|
|
7783
|
-
const
|
|
7784
|
-
sql = `merge into ${renderSourceReference(targetSource.source, targetSource.tableName, targetSource.baseTableName, state, dialect)} using ${renderSourceReference(usingSource.source, usingSource.tableName, usingSource.baseTableName, state, dialect)} on ${renderExpression(
|
|
7785
|
-
if (
|
|
9997
|
+
const merge3 = mergeAst.merge;
|
|
9998
|
+
sql = `merge into ${renderSourceReference(targetSource.source, targetSource.tableName, targetSource.baseTableName, state, dialect)} using ${renderSourceReference(usingSource.source, usingSource.tableName, usingSource.baseTableName, state, dialect)} on ${renderExpression(merge3.on, state, dialect)}`;
|
|
9999
|
+
if (merge3.whenMatched) {
|
|
7786
10000
|
sql += " when matched";
|
|
7787
|
-
if (
|
|
7788
|
-
sql += ` and ${renderExpression(
|
|
10001
|
+
if (merge3.whenMatched.predicate) {
|
|
10002
|
+
sql += ` and ${renderExpression(merge3.whenMatched.predicate, state, dialect)}`;
|
|
7789
10003
|
}
|
|
7790
|
-
if (
|
|
10004
|
+
if (merge3.whenMatched.kind === "delete") {
|
|
7791
10005
|
sql += " then delete";
|
|
7792
10006
|
} else {
|
|
7793
|
-
sql += ` then update set ${
|
|
10007
|
+
sql += ` then update set ${merge3.whenMatched.values.map((entry) => `${dialect.quoteIdentifier(entry.columnName)} = ${renderExpression(entry.value, state, dialect)}`).join(", ")}`;
|
|
7794
10008
|
}
|
|
7795
10009
|
}
|
|
7796
|
-
if (
|
|
10010
|
+
if (merge3.whenNotMatched) {
|
|
7797
10011
|
sql += " when not matched";
|
|
7798
|
-
if (
|
|
7799
|
-
sql += ` and ${renderExpression(
|
|
10012
|
+
if (merge3.whenNotMatched.predicate) {
|
|
10013
|
+
sql += ` and ${renderExpression(merge3.whenNotMatched.predicate, state, dialect)}`;
|
|
7800
10014
|
}
|
|
7801
|
-
sql += ` then insert (${
|
|
10015
|
+
sql += ` then insert (${merge3.whenNotMatched.values.map((entry) => dialect.quoteIdentifier(entry.columnName)).join(", ")}) values (${merge3.whenNotMatched.values.map((entry) => renderExpression(entry.value, state, dialect)).join(", ")})`;
|
|
7802
10016
|
}
|
|
7803
10017
|
break;
|
|
7804
10018
|
}
|
|
@@ -7894,19 +10108,19 @@ var renderSourceReference = (source, tableName, baseTableName, state, dialect) =
|
|
|
7894
10108
|
return `(${renderQueryAst(getAst(derived.plan), nestedRenderState(state), dialect).sql}) as ${dialect.quoteIdentifier(derived.name)}`;
|
|
7895
10109
|
}
|
|
7896
10110
|
if (typeof source === "object" && source !== null && "kind" in source && source.kind === "lateral") {
|
|
7897
|
-
const
|
|
10111
|
+
const lateral2 = source;
|
|
7898
10112
|
if (dialect.name === "sqlite") {
|
|
7899
10113
|
throw new Error("Unsupported sqlite lateral source");
|
|
7900
10114
|
}
|
|
7901
|
-
return `lateral (${renderQueryAst(getAst(
|
|
10115
|
+
return `lateral (${renderQueryAst(getAst(lateral2.plan), nestedRenderState(state), dialect).sql}) as ${dialect.quoteIdentifier(lateral2.name)}`;
|
|
7902
10116
|
}
|
|
7903
10117
|
if (typeof source === "object" && source !== null && source.kind === "values") {
|
|
7904
|
-
const
|
|
7905
|
-
return renderSelectRows(
|
|
10118
|
+
const values3 = source;
|
|
10119
|
+
return renderSelectRows(values3.rows, Object.keys(values3.columns));
|
|
7906
10120
|
}
|
|
7907
10121
|
if (typeof source === "object" && source !== null && source.kind === "unnest") {
|
|
7908
|
-
const
|
|
7909
|
-
return renderUnnestRows(
|
|
10122
|
+
const unnest3 = source;
|
|
10123
|
+
return renderUnnestRows(unnest3.arrays, Object.keys(unnest3.columns));
|
|
7910
10124
|
}
|
|
7911
10125
|
if (typeof source === "object" && source !== null && source.kind === "tableFunction") {
|
|
7912
10126
|
const tableFunction = source;
|
|
@@ -7968,6 +10182,8 @@ var renderExpression = (expression, state, dialect) => {
|
|
|
7968
10182
|
return `cast(${renderExpression(expectValueExpression("cast", ast.value), state, dialect)} as ${renderCastType(dialect, ast.target)})`;
|
|
7969
10183
|
case "function":
|
|
7970
10184
|
return renderFunctionCall(ast.name, ast.args, state, dialect);
|
|
10185
|
+
case "customSql":
|
|
10186
|
+
return renderCustomSql(ast, state, dialect, renderExpression);
|
|
7971
10187
|
case "eq":
|
|
7972
10188
|
return renderBinaryExpression("eq", "=", ast.left, ast.right, state, dialect);
|
|
7973
10189
|
case "neq":
|
|
@@ -7980,6 +10196,16 @@ var renderExpression = (expression, state, dialect) => {
|
|
|
7980
10196
|
return renderBinaryExpression("gt", ">", ast.left, ast.right, state, dialect);
|
|
7981
10197
|
case "gte":
|
|
7982
10198
|
return renderBinaryExpression("gte", ">=", ast.left, ast.right, state, dialect);
|
|
10199
|
+
case "add":
|
|
10200
|
+
return renderBinaryExpression("add", "+", ast.left, ast.right, state, dialect);
|
|
10201
|
+
case "subtract":
|
|
10202
|
+
return renderBinaryExpression("subtract", "-", ast.left, ast.right, state, dialect);
|
|
10203
|
+
case "multiply":
|
|
10204
|
+
return renderBinaryExpression("multiply", "*", ast.left, ast.right, state, dialect);
|
|
10205
|
+
case "divide":
|
|
10206
|
+
return renderBinaryExpression("divide", "/", ast.left, ast.right, state, dialect);
|
|
10207
|
+
case "modulo":
|
|
10208
|
+
return renderBinaryExpression("modulo", "%", ast.left, ast.right, state, dialect);
|
|
7983
10209
|
case "like":
|
|
7984
10210
|
return renderBinaryExpression("like", "like", ast.left, ast.right, state, dialect);
|
|
7985
10211
|
case "ilike": {
|
|
@@ -8053,6 +10279,16 @@ var renderExpression = (expression, state, dialect) => {
|
|
|
8053
10279
|
return `lower(${renderExpression(expectValueExpression("lower", ast.value), state, dialect)})`;
|
|
8054
10280
|
case "count":
|
|
8055
10281
|
return `count(${renderExpression(expectValueExpression("count", ast.value), state, dialect)})`;
|
|
10282
|
+
case "sum":
|
|
10283
|
+
return `sum(${renderExpression(expectValueExpression("sum", ast.value), state, dialect)})`;
|
|
10284
|
+
case "avg":
|
|
10285
|
+
return `avg(${renderExpression(expectValueExpression("avg", ast.value), state, dialect)})`;
|
|
10286
|
+
case "abs":
|
|
10287
|
+
return `abs(${renderExpression(expectValueExpression("abs", ast.value), state, dialect)})`;
|
|
10288
|
+
case "round":
|
|
10289
|
+
return `round(${renderExpression(expectValueExpression("round", ast.value), state, dialect)})`;
|
|
10290
|
+
case "negate":
|
|
10291
|
+
return `(-${renderExpression(expectValueExpression("negate", ast.value), state, dialect)})`;
|
|
8056
10292
|
case "max":
|
|
8057
10293
|
return `max(${renderExpression(expectValueExpression("max", ast.value), state, dialect)})`;
|
|
8058
10294
|
case "min":
|
|
@@ -8097,24 +10333,44 @@ var renderExpression = (expression, state, dialect) => {
|
|
|
8097
10333
|
}
|
|
8098
10334
|
case "window": {
|
|
8099
10335
|
const partitionBy = ast.partitionBy;
|
|
8100
|
-
const
|
|
8101
|
-
const
|
|
8102
|
-
|
|
8103
|
-
|
|
8104
|
-
|
|
8105
|
-
|
|
8106
|
-
|
|
8107
|
-
|
|
8108
|
-
|
|
10336
|
+
const orderBy3 = ast.orderBy;
|
|
10337
|
+
const renderSpecification = () => {
|
|
10338
|
+
const clauses = [];
|
|
10339
|
+
if (partitionBy.length > 0) {
|
|
10340
|
+
clauses.push(`partition by ${partitionBy.map((value) => renderExpression(value, state, dialect)).join(", ")}`);
|
|
10341
|
+
}
|
|
10342
|
+
if (orderBy3.length > 0) {
|
|
10343
|
+
clauses.push(`order by ${orderBy3.map((entry) => `${renderExpression(entry.value, state, dialect)} ${entry.direction}`).join(", ")}`);
|
|
10344
|
+
}
|
|
10345
|
+
if (ast.frame !== undefined) {
|
|
10346
|
+
clauses.push(renderWindowFrame(ast.frame));
|
|
10347
|
+
}
|
|
10348
|
+
return clauses.join(" ");
|
|
10349
|
+
};
|
|
8109
10350
|
switch (ast.function) {
|
|
8110
10351
|
case "rowNumber":
|
|
8111
|
-
return `row_number() over (${
|
|
10352
|
+
return `row_number() over (${renderSpecification()})`;
|
|
8112
10353
|
case "rank":
|
|
8113
|
-
return `rank() over (${
|
|
10354
|
+
return `rank() over (${renderSpecification()})`;
|
|
8114
10355
|
case "denseRank":
|
|
8115
|
-
return `dense_rank() over (${
|
|
10356
|
+
return `dense_rank() over (${renderSpecification()})`;
|
|
8116
10357
|
case "over":
|
|
8117
|
-
return `${renderExpression(ast.value, state, dialect)} over (${
|
|
10358
|
+
return `${renderExpression(ast.value, state, dialect)} over (${renderSpecification()})`;
|
|
10359
|
+
case "lag":
|
|
10360
|
+
case "lead": {
|
|
10361
|
+
const args = [renderExpression(ast.value, state, dialect)];
|
|
10362
|
+
if (ast.offset !== undefined) {
|
|
10363
|
+
args.push(renderExpression(ast.offset, state, dialect));
|
|
10364
|
+
}
|
|
10365
|
+
if (ast.defaultValue !== undefined) {
|
|
10366
|
+
args.push(renderExpression(ast.defaultValue, state, dialect));
|
|
10367
|
+
}
|
|
10368
|
+
return `${ast.function}(${args.join(", ")}) over (${renderSpecification()})`;
|
|
10369
|
+
}
|
|
10370
|
+
case "firstValue":
|
|
10371
|
+
return `first_value(${renderExpression(ast.value, state, dialect)}) over (${renderSpecification()})`;
|
|
10372
|
+
case "lastValue":
|
|
10373
|
+
return `last_value(${renderExpression(ast.value, state, dialect)}) over (${renderSpecification()})`;
|
|
8118
10374
|
}
|
|
8119
10375
|
break;
|
|
8120
10376
|
}
|
|
@@ -8123,7 +10379,7 @@ var renderExpression = (expression, state, dialect) => {
|
|
|
8123
10379
|
};
|
|
8124
10380
|
|
|
8125
10381
|
// src/internal/dialect-renderers/postgres.ts
|
|
8126
|
-
import * as
|
|
10382
|
+
import * as Schema12 from "effect/Schema";
|
|
8127
10383
|
var renderDbType2 = (dialect, dbType) => {
|
|
8128
10384
|
return renderDbTypeName(renderPortableDatatypeDdlType(dialect.name, dbType.kind) ?? dbType.kind);
|
|
8129
10385
|
};
|
|
@@ -8217,8 +10473,8 @@ var registerQuerySources2 = (ast, state) => {
|
|
|
8217
10473
|
for (const source of ast.fromSources ?? []) {
|
|
8218
10474
|
registerSourceReference2(source.source, source.tableName, state);
|
|
8219
10475
|
}
|
|
8220
|
-
for (const
|
|
8221
|
-
registerSourceReference2(
|
|
10476
|
+
for (const join3 of ast.joins) {
|
|
10477
|
+
registerSourceReference2(join3.source, join3.tableName, state);
|
|
8222
10478
|
}
|
|
8223
10479
|
if (ast.into !== undefined) {
|
|
8224
10480
|
registerSourceReference2(ast.into.source, ast.into.tableName, state);
|
|
@@ -8273,26 +10529,26 @@ var renderDdlExpression2 = (expression, state, dialect) => {
|
|
|
8273
10529
|
renderLiteral: renderPostgresDdlLiteral
|
|
8274
10530
|
});
|
|
8275
10531
|
};
|
|
8276
|
-
var renderColumnDefinition2 = (dialect, state, columnName,
|
|
10532
|
+
var renderColumnDefinition2 = (dialect, state, columnName, column2, tableName, casing) => {
|
|
8277
10533
|
const expressionState = { ...state, casing, rowLocalColumns: true };
|
|
8278
|
-
if (dialect.name !== "postgres" && isArrayDbType2(
|
|
10534
|
+
if (dialect.name !== "postgres" && isArrayDbType2(column2.metadata.dbType)) {
|
|
8279
10535
|
throw new Error(`Unsupported ${dialect.name} array column options`);
|
|
8280
10536
|
}
|
|
8281
10537
|
const clauses = [
|
|
8282
10538
|
quoteColumn2(columnName, state, dialect, tableName),
|
|
8283
|
-
|
|
10539
|
+
column2.metadata.ddlType === undefined ? renderDbType2(dialect, column2.metadata.dbType) : renderDbTypeName(column2.metadata.ddlType)
|
|
8284
10540
|
];
|
|
8285
|
-
if (
|
|
10541
|
+
if (column2.metadata.identity) {
|
|
8286
10542
|
if (dialect.name !== "postgres") {
|
|
8287
10543
|
throw new Error(`Unsupported ${dialect.name} identity column options`);
|
|
8288
10544
|
}
|
|
8289
|
-
clauses.push(`generated ${
|
|
8290
|
-
} else if (
|
|
8291
|
-
clauses.push(`generated always as (${renderDdlExpression2(
|
|
8292
|
-
} else if (
|
|
8293
|
-
clauses.push(`default ${renderDdlExpression2(
|
|
10545
|
+
clauses.push(`generated ${column2.metadata.identity.generation === "byDefault" ? "by default" : "always"} as identity`);
|
|
10546
|
+
} else if (column2.metadata.generatedValue) {
|
|
10547
|
+
clauses.push(`generated always as (${renderDdlExpression2(column2.metadata.generatedValue, expressionState, dialect)}) stored`);
|
|
10548
|
+
} else if (column2.metadata.defaultValue) {
|
|
10549
|
+
clauses.push(`default ${renderDdlExpression2(column2.metadata.defaultValue, expressionState, dialect)}`);
|
|
8294
10550
|
}
|
|
8295
|
-
if (!
|
|
10551
|
+
if (!column2.metadata.nullable) {
|
|
8296
10552
|
clauses.push("not null");
|
|
8297
10553
|
}
|
|
8298
10554
|
return clauses.join(" ");
|
|
@@ -8305,7 +10561,7 @@ var renderCreateTableSql2 = (targetSource, state, dialect, ifNotExists) => {
|
|
|
8305
10561
|
const table = targetSource.source;
|
|
8306
10562
|
const tableCasing = casingForTable2(table, state);
|
|
8307
10563
|
const fields2 = table[TypeId7].fields;
|
|
8308
|
-
const definitions = Object.entries(fields2).map(([columnName,
|
|
10564
|
+
const definitions = Object.entries(fields2).map(([columnName, column2]) => renderColumnDefinition2(dialect, state, columnName, column2, targetSource.tableName, tableCasing));
|
|
8309
10565
|
const options2 = table[OptionsSymbol];
|
|
8310
10566
|
const tableOptions = Array.isArray(options2) ? options2 : [options2];
|
|
8311
10567
|
validateOptions(table[TypeId7].name, fields2, tableOptions);
|
|
@@ -8318,20 +10574,20 @@ var renderCreateTableSql2 = (targetSource, state, dialect, ifNotExists) => {
|
|
|
8318
10574
|
if (dialect.name !== "postgres" && (option2.deferrable || option2.initiallyDeferred)) {
|
|
8319
10575
|
throw new Error(`Unsupported ${dialect.name} primary key constraint options`);
|
|
8320
10576
|
}
|
|
8321
|
-
definitions.push(`${option2.name ? `constraint ${dialect.quoteIdentifier(applyCategory(tableCasing, "constraints", option2.name))} ` : ""}primary key (${option2.columns.map((
|
|
10577
|
+
definitions.push(`${option2.name ? `constraint ${dialect.quoteIdentifier(applyCategory(tableCasing, "constraints", option2.name))} ` : ""}primary key (${option2.columns.map((column2) => quoteColumn2(column2, state, dialect, targetSource.tableName)).join(", ")})${option2.deferrable ? ` deferrable${option2.initiallyDeferred ? " initially deferred" : ""}` : ""}`);
|
|
8322
10578
|
break;
|
|
8323
10579
|
case "unique":
|
|
8324
10580
|
if (dialect.name !== "postgres" && (option2.nullsNotDistinct || option2.deferrable || option2.initiallyDeferred)) {
|
|
8325
10581
|
throw new Error(`Unsupported ${dialect.name} unique constraint options`);
|
|
8326
10582
|
}
|
|
8327
|
-
definitions.push(`${option2.name ? `constraint ${dialect.quoteIdentifier(applyCategory(tableCasing, "constraints", option2.name))} ` : ""}unique${option2.nullsNotDistinct ? " nulls not distinct" : ""} (${option2.columns.map((
|
|
10583
|
+
definitions.push(`${option2.name ? `constraint ${dialect.quoteIdentifier(applyCategory(tableCasing, "constraints", option2.name))} ` : ""}unique${option2.nullsNotDistinct ? " nulls not distinct" : ""} (${option2.columns.map((column2) => quoteColumn2(column2, state, dialect, targetSource.tableName)).join(", ")})${option2.deferrable ? ` deferrable${option2.initiallyDeferred ? " initially deferred" : ""}` : ""}`);
|
|
8328
10584
|
break;
|
|
8329
10585
|
case "foreignKey": {
|
|
8330
10586
|
if (dialect.name !== "postgres" && (option2.deferrable || option2.initiallyDeferred)) {
|
|
8331
10587
|
throw new Error(`Unsupported ${dialect.name} foreign key constraint options`);
|
|
8332
10588
|
}
|
|
8333
10589
|
const reference = typeof option2.references === "function" ? option2.references() : option2.references;
|
|
8334
|
-
definitions.push(`${option2.name ? `constraint ${dialect.quoteIdentifier(applyCategory(tableCasing, "constraints", option2.name))} ` : ""}foreign key (${option2.columns.map((
|
|
10590
|
+
definitions.push(`${option2.name ? `constraint ${dialect.quoteIdentifier(applyCategory(tableCasing, "constraints", option2.name))} ` : ""}foreign key (${option2.columns.map((column2) => quoteColumn2(column2, state, dialect, targetSource.tableName)).join(", ")}) references ${renderReferenceTable2(reference, state, dialect)} (${reference.columns.map((column2) => quoteReferenceColumn2(column2, reference, state, dialect)).join(", ")})${option2.onDelete !== undefined ? ` on delete ${renderReferentialAction(option2.onDelete)}` : ""}${option2.onUpdate !== undefined ? ` on update ${renderReferentialAction(option2.onUpdate)}` : ""}${option2.deferrable ? ` deferrable${option2.initiallyDeferred ? " initially deferred" : ""}` : ""}`);
|
|
8335
10591
|
break;
|
|
8336
10592
|
}
|
|
8337
10593
|
case "check":
|
|
@@ -8358,7 +10614,7 @@ var renderCreateIndexSql2 = (targetSource, ddl, state, dialect) => {
|
|
|
8358
10614
|
const maybeIfNotExists = dialect.name === "postgres" && ifNotExists ? " if not exists" : "";
|
|
8359
10615
|
const table = targetSource.source;
|
|
8360
10616
|
const tableCasing = casingForTable2(table, state);
|
|
8361
|
-
return `create${unique3 ? " unique" : ""} index${maybeIfNotExists} ${dialect.quoteIdentifier(applyCategory(tableCasing, "indexes", name))} on ${renderSourceReference2(targetSource.source, targetSource.tableName, targetSource.baseTableName, state, dialect)} (${ddl.columns.map((
|
|
10617
|
+
return `create${unique3 ? " unique" : ""} index${maybeIfNotExists} ${dialect.quoteIdentifier(applyCategory(tableCasing, "indexes", name))} on ${renderSourceReference2(targetSource.source, targetSource.tableName, targetSource.baseTableName, state, dialect)} (${ddl.columns.map((column2) => quoteColumn2(column2, state, dialect, targetSource.tableName)).join(", ")})`;
|
|
8362
10618
|
};
|
|
8363
10619
|
var renderDropIndexSql2 = (targetSource, ddl, state, dialect) => {
|
|
8364
10620
|
const ifExists = normalizeStatementFlag(ddl.ifExists);
|
|
@@ -8397,6 +10653,15 @@ var renderBinaryExpression2 = (functionName, operator, left, right, state, diale
|
|
|
8397
10653
|
const [leftExpression, rightExpression] = expectBinaryExpressions2(functionName, left, right);
|
|
8398
10654
|
return `(${renderExpression2(leftExpression, state, dialect)} ${operator} ${renderExpression2(rightExpression, state, dialect)})`;
|
|
8399
10655
|
};
|
|
10656
|
+
var renderNumericExpression = (expression, state, dialect) => {
|
|
10657
|
+
const rendered = renderExpression2(expression, state, dialect);
|
|
10658
|
+
const ast = expression[TypeId2];
|
|
10659
|
+
return dialect.name === "postgres" && ast.kind === "literal" ? `cast(${rendered} as ${renderCastType2(dialect, expression[TypeId].dbType)})` : rendered;
|
|
10660
|
+
};
|
|
10661
|
+
var renderNumericBinaryExpression = (functionName, operator, left, right, state, dialect) => {
|
|
10662
|
+
const [leftExpression, rightExpression] = expectBinaryExpressions2(functionName, left, right);
|
|
10663
|
+
return `(${renderNumericExpression(leftExpression, state, dialect)} ${operator} ${renderNumericExpression(rightExpression, state, dialect)})`;
|
|
10664
|
+
};
|
|
8400
10665
|
var postgresRangeSubtypeByKind = {
|
|
8401
10666
|
int4range: "int4",
|
|
8402
10667
|
int8range: "int8",
|
|
@@ -8437,7 +10702,7 @@ var unsupportedJsonFeature2 = (dialect, feature) => {
|
|
|
8437
10702
|
throw error;
|
|
8438
10703
|
};
|
|
8439
10704
|
var extractJsonBase2 = (node) => node.value ?? node.base ?? node.input ?? node.left ?? node.target;
|
|
8440
|
-
var
|
|
10705
|
+
var isJsonPathValue4 = (value) => value !== null && typeof value === "object" && (TypeId3 in value);
|
|
8441
10706
|
var isOptionalJsonPathNumber2 = (value) => value === undefined || typeof value === "number" && Number.isFinite(value);
|
|
8442
10707
|
var isJsonPathSegment2 = (segment) => {
|
|
8443
10708
|
if (typeof segment === "string") {
|
|
@@ -8476,7 +10741,7 @@ var validateJsonPathSegments2 = (segments) => {
|
|
|
8476
10741
|
};
|
|
8477
10742
|
var extractJsonPathSegments2 = (node) => {
|
|
8478
10743
|
const path2 = node.path ?? node.segments ?? node.keys;
|
|
8479
|
-
if (
|
|
10744
|
+
if (isJsonPathValue4(path2)) {
|
|
8480
10745
|
return validateJsonPathSegments2(path2.segments);
|
|
8481
10746
|
}
|
|
8482
10747
|
if (Array.isArray(path2)) {
|
|
@@ -8501,7 +10766,7 @@ var extractJsonPathSegments2 = (node) => {
|
|
|
8501
10766
|
}
|
|
8502
10767
|
return [];
|
|
8503
10768
|
}
|
|
8504
|
-
if ("right" in node &&
|
|
10769
|
+
if ("right" in node && isJsonPathValue4(node.right)) {
|
|
8505
10770
|
return validateJsonPathSegments2(node.right.segments);
|
|
8506
10771
|
}
|
|
8507
10772
|
return [];
|
|
@@ -8585,24 +10850,24 @@ var expressionDriverContext2 = (expression, state, dialect) => ({
|
|
|
8585
10850
|
driverValueMapping: expression[TypeId].driverValueMapping
|
|
8586
10851
|
});
|
|
8587
10852
|
var renderJsonInputExpression2 = (expression, state, dialect) => renderJsonSelectSql(renderExpression2(expression, state, dialect), expressionDriverContext2(expression, state, dialect));
|
|
8588
|
-
var encodeArrayValues2 = (
|
|
8589
|
-
if (value === null &&
|
|
10853
|
+
var encodeArrayValues2 = (values3, column2, state, dialect) => values3.map((value) => {
|
|
10854
|
+
if (value === null && column2.metadata.nullable) {
|
|
8590
10855
|
return null;
|
|
8591
10856
|
}
|
|
8592
|
-
const runtimeSchemaAccepts =
|
|
8593
|
-
const normalizedValue = runtimeSchemaAccepts ? value : normalizeDbValue(
|
|
8594
|
-
const encodedValue =
|
|
10857
|
+
const runtimeSchemaAccepts = column2.schema !== undefined && Schema12.is(column2.schema)(value);
|
|
10858
|
+
const normalizedValue = runtimeSchemaAccepts ? value : normalizeDbValue(column2.metadata.dbType, value);
|
|
10859
|
+
const encodedValue = column2.schema === undefined || runtimeSchemaAccepts ? normalizedValue : Schema12.decodeUnknownSync(column2.schema)(normalizedValue);
|
|
8595
10860
|
return toDriverValue(encodedValue, {
|
|
8596
10861
|
dialect: dialect.name,
|
|
8597
10862
|
valueMappings: state.valueMappings,
|
|
8598
|
-
dbType:
|
|
8599
|
-
runtimeSchema:
|
|
8600
|
-
driverValueMapping:
|
|
10863
|
+
dbType: column2.metadata.dbType,
|
|
10864
|
+
runtimeSchema: column2.schema,
|
|
10865
|
+
driverValueMapping: column2.metadata.driverValueMapping
|
|
8601
10866
|
});
|
|
8602
10867
|
});
|
|
8603
10868
|
var renderPostgresJsonKind2 = (value) => value[TypeId].dbType.kind === "jsonb" ? "jsonb" : "json";
|
|
8604
10869
|
var renderJsonOpaquePath2 = (value, state, dialect) => {
|
|
8605
|
-
if (
|
|
10870
|
+
if (isJsonPathValue4(value)) {
|
|
8606
10871
|
return dialect.renderLiteral(renderJsonPathStringLiteral2(value.segments), state);
|
|
8607
10872
|
}
|
|
8608
10873
|
if (typeof value === "string") {
|
|
@@ -8751,8 +11016,8 @@ var renderJsonExpression2 = (expression, ast, state, dialect) => {
|
|
|
8751
11016
|
return;
|
|
8752
11017
|
}
|
|
8753
11018
|
case "jsonBuildArray": {
|
|
8754
|
-
const
|
|
8755
|
-
const renderedValues =
|
|
11019
|
+
const values3 = ast.values;
|
|
11020
|
+
const renderedValues = values3.map((value) => renderJsonInputExpression2(value, state, dialect)).join(", ");
|
|
8756
11021
|
if (dialect.name === "postgres") {
|
|
8757
11022
|
return `${postgresExpressionKind === "jsonb" ? "jsonb" : "json"}_build_array(${renderedValues})`;
|
|
8758
11023
|
}
|
|
@@ -8911,18 +11176,18 @@ var selectionProjections2 = (selection) => flattenSelection(selection).map(({ pa
|
|
|
8911
11176
|
alias: alias2
|
|
8912
11177
|
}));
|
|
8913
11178
|
var renderMutationAssignment2 = (entry, state, dialect, targetTableName) => {
|
|
8914
|
-
const
|
|
8915
|
-
return `${
|
|
11179
|
+
const column2 = entry.tableName && dialect.name === "mysql" ? `${dialect.quoteIdentifier(casedTableReferenceName2(entry.tableName, state))}.${quoteColumn2(entry.columnName, state, dialect, entry.tableName)}` : quoteColumn2(entry.columnName, state, dialect, targetTableName);
|
|
11180
|
+
return `${column2} = ${renderExpression2(entry.value, state, dialect)}`;
|
|
8916
11181
|
};
|
|
8917
|
-
var renderJoinSourcesForMutation2 = (joins, state, dialect) => joins.map((
|
|
11182
|
+
var renderJoinSourcesForMutation2 = (joins, state, dialect) => joins.map((join3) => renderSourceReference2(join3.source, join3.tableName, join3.baseTableName, state, dialect)).join(", ");
|
|
8918
11183
|
var renderFromSources2 = (sources, state, dialect) => sources.map((source) => renderSourceReference2(source.source, source.tableName, source.baseTableName, state, dialect)).join(", ");
|
|
8919
|
-
var renderJoinPredicatesForMutation2 = (joins, state, dialect) => joins.flatMap((
|
|
11184
|
+
var renderJoinPredicatesForMutation2 = (joins, state, dialect) => joins.flatMap((join3) => join3.kind === "cross" || !join3.on ? [] : [renderExpression2(join3.on, state, dialect)]);
|
|
8920
11185
|
var renderDeleteTargets2 = (targets, dialect) => targets.map((target) => dialect.quoteIdentifier(target.tableName)).join(", ");
|
|
8921
|
-
var renderMysqlMutationLock = (
|
|
8922
|
-
if (!
|
|
11186
|
+
var renderMysqlMutationLock = (lock3, statement) => {
|
|
11187
|
+
if (!lock3) {
|
|
8923
11188
|
return "";
|
|
8924
11189
|
}
|
|
8925
|
-
switch (
|
|
11190
|
+
switch (lock3.mode) {
|
|
8926
11191
|
case "lowPriority":
|
|
8927
11192
|
return " low_priority";
|
|
8928
11193
|
case "ignore":
|
|
@@ -8982,12 +11247,12 @@ var assertSupportedMutationReturning = (dialect, selection) => {
|
|
|
8982
11247
|
throw new Error("Unsupported standard returning");
|
|
8983
11248
|
}
|
|
8984
11249
|
};
|
|
8985
|
-
var validateDistinctOnOrdering = (
|
|
8986
|
-
if (
|
|
11250
|
+
var validateDistinctOnOrdering = (distinctOn3, orderBy3) => {
|
|
11251
|
+
if (distinctOn3 === undefined || distinctOn3.length === 0 || orderBy3.length === 0) {
|
|
8987
11252
|
return;
|
|
8988
11253
|
}
|
|
8989
|
-
const remainingDistinctKeys = new Set(
|
|
8990
|
-
for (const order of
|
|
11254
|
+
const remainingDistinctKeys = new Set(distinctOn3.map(groupingKeyOfExpression));
|
|
11255
|
+
for (const order of orderBy3) {
|
|
8991
11256
|
const key2 = groupingKeyOfExpression(order.value);
|
|
8992
11257
|
if (remainingDistinctKeys.has(key2)) {
|
|
8993
11258
|
remainingDistinctKeys.delete(key2);
|
|
@@ -9015,12 +11280,12 @@ var renderQueryAst2 = (ast, state, dialect, options2 = {}) => {
|
|
|
9015
11280
|
if (ast.from) {
|
|
9016
11281
|
clauses.push(`from ${renderSourceReference2(ast.from.source, ast.from.tableName, ast.from.baseTableName, state, dialect)}`);
|
|
9017
11282
|
}
|
|
9018
|
-
for (const
|
|
9019
|
-
if (dialect.name === "standard" &&
|
|
11283
|
+
for (const join3 of ast.joins) {
|
|
11284
|
+
if (dialect.name === "standard" && join3.kind === "full") {
|
|
9020
11285
|
throw new Error("Unsupported standard full join");
|
|
9021
11286
|
}
|
|
9022
|
-
const source = renderSourceReference2(
|
|
9023
|
-
clauses.push(
|
|
11287
|
+
const source = renderSourceReference2(join3.source, join3.tableName, join3.baseTableName, state, dialect);
|
|
11288
|
+
clauses.push(join3.kind === "cross" ? `cross join ${source}` : `${join3.kind} join ${source} on ${renderExpression2(join3.on, state, dialect)}`);
|
|
9024
11289
|
}
|
|
9025
11290
|
if (ast.where.length > 0) {
|
|
9026
11291
|
clauses.push(`where ${ast.where.map((entry) => renderExpression2(entry.predicate, state, dialect)).join(" and ")}`);
|
|
@@ -9074,15 +11339,15 @@ var renderQueryAst2 = (ast, state, dialect, options2 = {}) => {
|
|
|
9074
11339
|
const conflict = expectConflictClause(insertAst.conflict);
|
|
9075
11340
|
sql = `insert into ${target}`;
|
|
9076
11341
|
if (insertSource?.kind === "values") {
|
|
9077
|
-
const columns = insertSource.columns.map((
|
|
11342
|
+
const columns = insertSource.columns.map((column2) => quoteColumn2(column2, state, dialect, targetSource.tableName)).join(", ");
|
|
9078
11343
|
const rows = insertSource.rows.map((row) => `(${row.values.map((entry) => renderExpression2(entry.value, targetCasingState, dialect)).join(", ")})`).join(", ");
|
|
9079
11344
|
sql += ` (${columns}) values ${rows}`;
|
|
9080
11345
|
} else if (insertSource?.kind === "query") {
|
|
9081
|
-
const columns = insertSource.columns.map((
|
|
11346
|
+
const columns = insertSource.columns.map((column2) => quoteColumn2(column2, state, dialect, targetSource.tableName)).join(", ");
|
|
9082
11347
|
const renderedQuery = renderQueryAst2(getAst(insertSource.query), state, dialect);
|
|
9083
11348
|
sql += ` (${columns}) ${renderedQuery.sql}`;
|
|
9084
11349
|
} else if (insertSource?.kind === "unnest") {
|
|
9085
|
-
const columns = insertSource.columns.map((
|
|
11350
|
+
const columns = insertSource.columns.map((column2) => quoteColumn2(column2, state, dialect, targetSource.tableName)).join(", ");
|
|
9086
11351
|
if (dialect.name === "postgres") {
|
|
9087
11352
|
const table = targetSource.source;
|
|
9088
11353
|
const fields2 = table[TypeId7].fields;
|
|
@@ -9096,9 +11361,9 @@ var renderQueryAst2 = (ast, state, dialect, options2 = {}) => {
|
|
|
9096
11361
|
} else {
|
|
9097
11362
|
const insertValues = insertAst.values ?? [];
|
|
9098
11363
|
const columns = insertValues.map((entry) => quoteColumn2(entry.columnName, state, dialect, targetSource.tableName)).join(", ");
|
|
9099
|
-
const
|
|
11364
|
+
const values3 = insertValues.map((entry) => renderExpression2(entry.value, targetCasingState, dialect)).join(", ");
|
|
9100
11365
|
if (insertValues.length > 0) {
|
|
9101
|
-
sql += ` (${columns}) values (${
|
|
11366
|
+
sql += ` (${columns}) values (${values3})`;
|
|
9102
11367
|
} else {
|
|
9103
11368
|
sql += " default values";
|
|
9104
11369
|
}
|
|
@@ -9110,7 +11375,7 @@ var renderQueryAst2 = (ast, state, dialect, options2 = {}) => {
|
|
|
9110
11375
|
const conflictValueState = { ...targetCasingState, allowExcluded: true };
|
|
9111
11376
|
const updateValues = (conflict.values ?? []).map((entry) => `${quoteColumn2(entry.columnName, state, dialect, targetSource.tableName)} = ${renderExpression2(entry.value, conflictValueState, dialect)}`).join(", ");
|
|
9112
11377
|
if (dialect.name === "postgres") {
|
|
9113
|
-
const targetSql = conflict.target?.kind === "constraint" ? ` on conflict on constraint ${dialect.quoteIdentifier(applyCategory(targetCasingState.casing, "constraints", conflict.target.name))}` : conflict.target?.kind === "columns" ? ` on conflict (${conflict.target.columns.map((
|
|
11378
|
+
const targetSql = conflict.target?.kind === "constraint" ? ` on conflict on constraint ${dialect.quoteIdentifier(applyCategory(targetCasingState.casing, "constraints", conflict.target.name))}` : conflict.target?.kind === "columns" ? ` on conflict (${conflict.target.columns.map((column2) => quoteColumn2(column2, state, dialect, targetSource.tableName)).join(", ")})${conflict.target.where ? ` where ${renderExpression2(conflict.target.where, targetCasingState, dialect)}` : ""}` : " on conflict";
|
|
9114
11379
|
sql += targetSql;
|
|
9115
11380
|
sql += conflict.action === "doNothing" ? " do nothing" : ` do update set ${updateValues}${conflict.where ? ` where ${renderExpression2(conflict.where, conflictValueState, dialect)}` : ""}`;
|
|
9116
11381
|
} else if (conflict.action === "doNothing") {
|
|
@@ -9120,10 +11385,10 @@ var renderQueryAst2 = (ast, state, dialect, options2 = {}) => {
|
|
|
9120
11385
|
}
|
|
9121
11386
|
}
|
|
9122
11387
|
assertSupportedMutationReturning(dialect, insertAst.select);
|
|
9123
|
-
const
|
|
9124
|
-
projections =
|
|
9125
|
-
if (
|
|
9126
|
-
sql += ` returning ${
|
|
11388
|
+
const returning3 = renderSelectionList2(insertAst.select, state, dialect);
|
|
11389
|
+
projections = returning3.projections;
|
|
11390
|
+
if (returning3.sql.length > 0) {
|
|
11391
|
+
sql += ` returning ${returning3.sql}`;
|
|
9127
11392
|
}
|
|
9128
11393
|
break;
|
|
9129
11394
|
}
|
|
@@ -9140,7 +11405,7 @@ var renderQueryAst2 = (ast, state, dialect, options2 = {}) => {
|
|
|
9140
11405
|
if (dialect.name === "mysql") {
|
|
9141
11406
|
const modifiers = renderMysqlMutationLock(updateAst.lock, "update");
|
|
9142
11407
|
const extraSources = renderFromSources2(fromSources, state, dialect);
|
|
9143
|
-
const joinSources = updateAst.joins.map((
|
|
11408
|
+
const joinSources = updateAst.joins.map((join3) => join3.kind === "cross" ? `cross join ${renderSourceReference2(join3.source, join3.tableName, join3.baseTableName, state, dialect)}` : `${join3.kind} join ${renderSourceReference2(join3.source, join3.tableName, join3.baseTableName, state, dialect)} on ${renderExpression2(join3.on, state, dialect)}`).join(" ");
|
|
9144
11409
|
const targetList = [
|
|
9145
11410
|
...targets.map((entry) => renderSourceReference2(entry.source, entry.tableName, entry.baseTableName, state, dialect)),
|
|
9146
11411
|
...extraSources.length > 0 ? [extraSources] : []
|
|
@@ -9170,10 +11435,10 @@ var renderQueryAst2 = (ast, state, dialect, options2 = {}) => {
|
|
|
9170
11435
|
sql += ` limit ${renderExpression2(updateAst.limit, state, dialect)}`;
|
|
9171
11436
|
}
|
|
9172
11437
|
assertSupportedMutationReturning(dialect, updateAst.select);
|
|
9173
|
-
const
|
|
9174
|
-
projections =
|
|
9175
|
-
if (
|
|
9176
|
-
sql += ` returning ${
|
|
11438
|
+
const returning3 = renderSelectionList2(updateAst.select, state, dialect);
|
|
11439
|
+
projections = returning3.projections;
|
|
11440
|
+
if (returning3.sql.length > 0) {
|
|
11441
|
+
sql += ` returning ${returning3.sql}`;
|
|
9177
11442
|
}
|
|
9178
11443
|
break;
|
|
9179
11444
|
}
|
|
@@ -9190,7 +11455,7 @@ var renderQueryAst2 = (ast, state, dialect, options2 = {}) => {
|
|
|
9190
11455
|
const hasJoinedSources = deleteAst.joins.length > 0 || targets.length > 1;
|
|
9191
11456
|
const targetList = renderDeleteTargets2(targets, dialect);
|
|
9192
11457
|
const fromSources = targets.map((entry) => renderSourceReference2(entry.source, entry.tableName, entry.baseTableName, state, dialect)).join(", ");
|
|
9193
|
-
const joinSources = deleteAst.joins.map((
|
|
11458
|
+
const joinSources = deleteAst.joins.map((join3) => join3.kind === "cross" ? `cross join ${renderSourceReference2(join3.source, join3.tableName, join3.baseTableName, state, dialect)}` : `${join3.kind} join ${renderSourceReference2(join3.source, join3.tableName, join3.baseTableName, state, dialect)} on ${renderExpression2(join3.on, state, dialect)}`).join(" ");
|
|
9194
11459
|
sql = hasJoinedSources ? `delete${modifiers} ${targetList} from ${fromSources}${joinSources.length > 0 ? ` ${joinSources}` : ""}` : `delete${modifiers} from ${fromSources}`;
|
|
9195
11460
|
} else {
|
|
9196
11461
|
sql = `delete from ${target}`;
|
|
@@ -9212,10 +11477,10 @@ var renderQueryAst2 = (ast, state, dialect, options2 = {}) => {
|
|
|
9212
11477
|
sql += ` limit ${renderExpression2(deleteAst.limit, state, dialect)}`;
|
|
9213
11478
|
}
|
|
9214
11479
|
assertSupportedMutationReturning(dialect, deleteAst.select);
|
|
9215
|
-
const
|
|
9216
|
-
projections =
|
|
9217
|
-
if (
|
|
9218
|
-
sql += ` returning ${
|
|
11480
|
+
const returning3 = renderSelectionList2(deleteAst.select, state, dialect);
|
|
11481
|
+
projections = returning3.projections;
|
|
11482
|
+
if (returning3.sql.length > 0) {
|
|
11483
|
+
sql += ` returning ${returning3.sql}`;
|
|
9219
11484
|
}
|
|
9220
11485
|
break;
|
|
9221
11486
|
}
|
|
@@ -9224,10 +11489,10 @@ var renderQueryAst2 = (ast, state, dialect, options2 = {}) => {
|
|
|
9224
11489
|
if (dialect.name === "standard") {
|
|
9225
11490
|
throw new Error("Unsupported standard truncate statement");
|
|
9226
11491
|
}
|
|
9227
|
-
const
|
|
11492
|
+
const truncate2 = expectTruncateClause(truncateAst.truncate);
|
|
9228
11493
|
const targetSource = truncateAst.target;
|
|
9229
|
-
const restartIdentity =
|
|
9230
|
-
const cascade =
|
|
11494
|
+
const restartIdentity = truncate2.restartIdentity;
|
|
11495
|
+
const cascade = truncate2.cascade;
|
|
9231
11496
|
sql = `truncate table ${renderSourceReference2(targetSource.source, targetSource.tableName, targetSource.baseTableName, state, dialect)}`;
|
|
9232
11497
|
if (restartIdentity) {
|
|
9233
11498
|
sql += " restart identity";
|
|
@@ -9244,27 +11509,27 @@ var renderQueryAst2 = (ast, state, dialect, options2 = {}) => {
|
|
|
9244
11509
|
const mergeAst = ast;
|
|
9245
11510
|
const targetSource = mergeAst.target;
|
|
9246
11511
|
const usingSource = mergeAst.using;
|
|
9247
|
-
const
|
|
9248
|
-
sql = `merge into ${renderSourceReference2(targetSource.source, targetSource.tableName, targetSource.baseTableName, state, dialect)} using ${renderSourceReference2(usingSource.source, usingSource.tableName, usingSource.baseTableName, state, dialect)} on ${renderExpression2(
|
|
9249
|
-
if (
|
|
9250
|
-
const matchedKind =
|
|
11512
|
+
const merge3 = mergeAst.merge;
|
|
11513
|
+
sql = `merge into ${renderSourceReference2(targetSource.source, targetSource.tableName, targetSource.baseTableName, state, dialect)} using ${renderSourceReference2(usingSource.source, usingSource.tableName, usingSource.baseTableName, state, dialect)} on ${renderExpression2(merge3.on, state, dialect)}`;
|
|
11514
|
+
if (merge3.whenMatched) {
|
|
11515
|
+
const matchedKind = merge3.whenMatched.kind === "delete" ? "delete" : "update";
|
|
9251
11516
|
sql += " when matched";
|
|
9252
|
-
if (
|
|
9253
|
-
sql += ` and ${renderExpression2(
|
|
11517
|
+
if (merge3.whenMatched.predicate) {
|
|
11518
|
+
sql += ` and ${renderExpression2(merge3.whenMatched.predicate, state, dialect)}`;
|
|
9254
11519
|
}
|
|
9255
11520
|
if (matchedKind === "delete") {
|
|
9256
11521
|
sql += " then delete";
|
|
9257
11522
|
} else {
|
|
9258
|
-
const matchedUpdate =
|
|
11523
|
+
const matchedUpdate = merge3.whenMatched;
|
|
9259
11524
|
sql += ` then update set ${matchedUpdate.values.map((entry) => `${quoteColumn2(entry.columnName, state, dialect, targetSource.tableName)} = ${renderExpression2(entry.value, state, dialect)}`).join(", ")}`;
|
|
9260
11525
|
}
|
|
9261
11526
|
}
|
|
9262
|
-
if (
|
|
11527
|
+
if (merge3.whenNotMatched) {
|
|
9263
11528
|
sql += " when not matched";
|
|
9264
|
-
if (
|
|
9265
|
-
sql += ` and ${renderExpression2(
|
|
11529
|
+
if (merge3.whenNotMatched.predicate) {
|
|
11530
|
+
sql += ` and ${renderExpression2(merge3.whenNotMatched.predicate, state, dialect)}`;
|
|
9266
11531
|
}
|
|
9267
|
-
sql += ` then insert (${
|
|
11532
|
+
sql += ` then insert (${merge3.whenNotMatched.values.map((entry) => quoteColumn2(entry.columnName, state, dialect, targetSource.tableName)).join(", ")}) values (${merge3.whenNotMatched.values.map((entry) => renderExpression2(entry.value, state, dialect)).join(", ")})`;
|
|
9268
11533
|
}
|
|
9269
11534
|
break;
|
|
9270
11535
|
}
|
|
@@ -9355,19 +11620,19 @@ var renderSourceReference2 = (source, tableName, baseTableName, state, dialect)
|
|
|
9355
11620
|
return `(${renderQueryAst2(getAst(derived.plan), nestedRenderState2(state), dialect).sql}) as ${dialect.quoteIdentifier(derived.name)}`;
|
|
9356
11621
|
}
|
|
9357
11622
|
if (typeof source === "object" && source !== null && "kind" in source && source.kind === "lateral") {
|
|
9358
|
-
const
|
|
11623
|
+
const lateral2 = source;
|
|
9359
11624
|
if (dialect.name === "standard") {
|
|
9360
11625
|
throw new Error("Unsupported standard lateral source");
|
|
9361
11626
|
}
|
|
9362
|
-
return `lateral (${renderQueryAst2(getAst(
|
|
11627
|
+
return `lateral (${renderQueryAst2(getAst(lateral2.plan), nestedRenderState2(state), dialect).sql}) as ${dialect.quoteIdentifier(lateral2.name)}`;
|
|
9363
11628
|
}
|
|
9364
11629
|
if (typeof source === "object" && source !== null && source.kind === "values") {
|
|
9365
|
-
const
|
|
9366
|
-
return renderSelectRows(
|
|
11630
|
+
const values3 = source;
|
|
11631
|
+
return renderSelectRows(values3.rows, Object.keys(values3.columns));
|
|
9367
11632
|
}
|
|
9368
11633
|
if (typeof source === "object" && source !== null && source.kind === "unnest") {
|
|
9369
|
-
const
|
|
9370
|
-
return renderUnnestRows(
|
|
11634
|
+
const unnest3 = source;
|
|
11635
|
+
return renderUnnestRows(unnest3.arrays, Object.keys(unnest3.columns));
|
|
9371
11636
|
}
|
|
9372
11637
|
if (typeof source === "object" && source !== null && source.kind === "tableFunction") {
|
|
9373
11638
|
const tableFunction = source;
|
|
@@ -9431,6 +11696,8 @@ var renderExpression2 = (expression, state, dialect) => {
|
|
|
9431
11696
|
return `(${renderExpression2(expectValueExpression2("collate", ast.value), state, dialect)} collate ${renderCollation(ast.collation)})`;
|
|
9432
11697
|
case "function":
|
|
9433
11698
|
return renderFunctionCall2(ast.name, ast.args, state, dialect);
|
|
11699
|
+
case "customSql":
|
|
11700
|
+
return renderCustomSql(ast, state, dialect, renderExpression2);
|
|
9434
11701
|
case "eq":
|
|
9435
11702
|
return renderBinaryExpression2("eq", "=", ast.left, ast.right, state, dialect);
|
|
9436
11703
|
case "neq":
|
|
@@ -9443,6 +11710,16 @@ var renderExpression2 = (expression, state, dialect) => {
|
|
|
9443
11710
|
return renderBinaryExpression2("gt", ">", ast.left, ast.right, state, dialect);
|
|
9444
11711
|
case "gte":
|
|
9445
11712
|
return renderBinaryExpression2("gte", ">=", ast.left, ast.right, state, dialect);
|
|
11713
|
+
case "add":
|
|
11714
|
+
return renderNumericBinaryExpression("add", "+", ast.left, ast.right, state, dialect);
|
|
11715
|
+
case "subtract":
|
|
11716
|
+
return renderNumericBinaryExpression("subtract", "-", ast.left, ast.right, state, dialect);
|
|
11717
|
+
case "multiply":
|
|
11718
|
+
return renderNumericBinaryExpression("multiply", "*", ast.left, ast.right, state, dialect);
|
|
11719
|
+
case "divide":
|
|
11720
|
+
return renderNumericBinaryExpression("divide", "/", ast.left, ast.right, state, dialect);
|
|
11721
|
+
case "modulo":
|
|
11722
|
+
return renderNumericBinaryExpression("modulo", "%", ast.left, ast.right, state, dialect);
|
|
9446
11723
|
case "like":
|
|
9447
11724
|
return renderBinaryExpression2("like", "like", ast.left, ast.right, state, dialect);
|
|
9448
11725
|
case "ilike": {
|
|
@@ -9536,6 +11813,16 @@ var renderExpression2 = (expression, state, dialect) => {
|
|
|
9536
11813
|
return `lower(${renderExpression2(expectValueExpression2("lower", ast.value), state, dialect)})`;
|
|
9537
11814
|
case "count":
|
|
9538
11815
|
return `count(${renderExpression2(expectValueExpression2("count", ast.value), state, dialect)})`;
|
|
11816
|
+
case "sum":
|
|
11817
|
+
return `sum(${renderNumericExpression(expectValueExpression2("sum", ast.value), state, dialect)})`;
|
|
11818
|
+
case "avg":
|
|
11819
|
+
return `avg(${renderNumericExpression(expectValueExpression2("avg", ast.value), state, dialect)})`;
|
|
11820
|
+
case "abs":
|
|
11821
|
+
return `abs(${renderNumericExpression(expectValueExpression2("abs", ast.value), state, dialect)})`;
|
|
11822
|
+
case "round":
|
|
11823
|
+
return `round(${renderNumericExpression(expectValueExpression2("round", ast.value), state, dialect)})`;
|
|
11824
|
+
case "negate":
|
|
11825
|
+
return `(-${renderNumericExpression(expectValueExpression2("negate", ast.value), state, dialect)})`;
|
|
9539
11826
|
case "max":
|
|
9540
11827
|
return `max(${renderExpression2(expectValueExpression2("max", ast.value), state, dialect)})`;
|
|
9541
11828
|
case "min":
|
|
@@ -9580,24 +11867,44 @@ var renderExpression2 = (expression, state, dialect) => {
|
|
|
9580
11867
|
}
|
|
9581
11868
|
case "window": {
|
|
9582
11869
|
const partitionBy = ast.partitionBy;
|
|
9583
|
-
const
|
|
9584
|
-
const
|
|
9585
|
-
|
|
9586
|
-
|
|
9587
|
-
|
|
9588
|
-
|
|
9589
|
-
|
|
9590
|
-
|
|
9591
|
-
|
|
11870
|
+
const orderBy3 = ast.orderBy;
|
|
11871
|
+
const renderSpecification = () => {
|
|
11872
|
+
const clauses = [];
|
|
11873
|
+
if (partitionBy.length > 0) {
|
|
11874
|
+
clauses.push(`partition by ${partitionBy.map((value) => renderExpression2(value, state, dialect)).join(", ")}`);
|
|
11875
|
+
}
|
|
11876
|
+
if (orderBy3.length > 0) {
|
|
11877
|
+
clauses.push(`order by ${orderBy3.map((entry) => `${renderExpression2(entry.value, state, dialect)} ${entry.direction}`).join(", ")}`);
|
|
11878
|
+
}
|
|
11879
|
+
if (ast.frame !== undefined) {
|
|
11880
|
+
clauses.push(renderWindowFrame(ast.frame));
|
|
11881
|
+
}
|
|
11882
|
+
return clauses.join(" ");
|
|
11883
|
+
};
|
|
9592
11884
|
switch (ast.function) {
|
|
9593
11885
|
case "rowNumber":
|
|
9594
|
-
return `row_number() over (${
|
|
11886
|
+
return `row_number() over (${renderSpecification()})`;
|
|
9595
11887
|
case "rank":
|
|
9596
|
-
return `rank() over (${
|
|
11888
|
+
return `rank() over (${renderSpecification()})`;
|
|
9597
11889
|
case "denseRank":
|
|
9598
|
-
return `dense_rank() over (${
|
|
11890
|
+
return `dense_rank() over (${renderSpecification()})`;
|
|
9599
11891
|
case "over":
|
|
9600
|
-
return `${renderExpression2(ast.value, state, dialect)} over (${
|
|
11892
|
+
return `${renderExpression2(ast.value, state, dialect)} over (${renderSpecification()})`;
|
|
11893
|
+
case "lag":
|
|
11894
|
+
case "lead": {
|
|
11895
|
+
const args = [renderExpression2(ast.value, state, dialect)];
|
|
11896
|
+
if (ast.offset !== undefined) {
|
|
11897
|
+
args.push(renderExpression2(ast.offset, state, dialect));
|
|
11898
|
+
}
|
|
11899
|
+
if (ast.defaultValue !== undefined) {
|
|
11900
|
+
args.push(renderExpression2(ast.defaultValue, state, dialect));
|
|
11901
|
+
}
|
|
11902
|
+
return `${ast.function}(${args.join(", ")}) over (${renderSpecification()})`;
|
|
11903
|
+
}
|
|
11904
|
+
case "firstValue":
|
|
11905
|
+
return `first_value(${renderExpression2(ast.value, state, dialect)}) over (${renderSpecification()})`;
|
|
11906
|
+
case "lastValue":
|
|
11907
|
+
return `last_value(${renderExpression2(ast.value, state, dialect)}) over (${renderSpecification()})`;
|
|
9601
11908
|
}
|
|
9602
11909
|
break;
|
|
9603
11910
|
}
|
|
@@ -9630,8 +11937,8 @@ var standardDialect = {
|
|
|
9630
11937
|
const renderedBase = schemaName && schemaName !== "public" ? `${quoteIdentifier(schemaName)}.${quoteIdentifier(baseTableName)}` : quoteIdentifier(baseTableName);
|
|
9631
11938
|
return tableName === baseTableName ? renderedBase : `${renderedBase} as ${quoteIdentifier(tableName)}`;
|
|
9632
11939
|
},
|
|
9633
|
-
renderConcat(
|
|
9634
|
-
return `(${
|
|
11940
|
+
renderConcat(values3) {
|
|
11941
|
+
return `(${values3.join(" || ")})`;
|
|
9635
11942
|
},
|
|
9636
11943
|
renderQueryAst: renderQueryAst2,
|
|
9637
11944
|
renderExpression: renderExpression2
|
|
@@ -9660,8 +11967,8 @@ var sqliteDialect = {
|
|
|
9660
11967
|
const renderedBase = schemaName && schemaName !== "public" ? `${quoteIdentifier2(schemaName)}.${quoteIdentifier2(baseTableName)}` : quoteIdentifier2(baseTableName);
|
|
9661
11968
|
return tableName === baseTableName ? renderedBase : `${renderedBase} as ${quoteIdentifier2(tableName)}`;
|
|
9662
11969
|
},
|
|
9663
|
-
renderConcat(
|
|
9664
|
-
return `(${
|
|
11970
|
+
renderConcat(values3) {
|
|
11971
|
+
return `(${values3.join(" || ")})`;
|
|
9665
11972
|
},
|
|
9666
11973
|
renderQueryAst,
|
|
9667
11974
|
renderExpression
|
|
@@ -9696,40 +12003,65 @@ var renderSqlitePlan = (plan, options2 = {}) => {
|
|
|
9696
12003
|
};
|
|
9697
12004
|
|
|
9698
12005
|
// src/sqlite/executor.ts
|
|
12006
|
+
var atMostOne2 = atMostOne;
|
|
12007
|
+
var exactlyOne2 = exactlyOne;
|
|
12008
|
+
var nonEmpty2 = nonEmpty;
|
|
9699
12009
|
var withTransaction2 = withTransaction;
|
|
9700
12010
|
function driver2(dialectOrExecute, maybeExecute) {
|
|
9701
12011
|
const executeOrHandlers = typeof dialectOrExecute === "string" ? maybeExecute : dialectOrExecute;
|
|
9702
12012
|
return typeof executeOrHandlers === "function" ? driver("sqlite", executeOrHandlers) : driver("sqlite", executeOrHandlers);
|
|
9703
12013
|
}
|
|
9704
|
-
var fromDriver2 = (renderer, sqlDriver, driverMode = "raw", valueMappings) =>
|
|
9705
|
-
|
|
9706
|
-
|
|
9707
|
-
const
|
|
9708
|
-
|
|
9709
|
-
|
|
9710
|
-
|
|
9711
|
-
})), (error) => {
|
|
9712
|
-
if (typeof error === "object" && error !== null && "_tag" in error && error._tag === "RowDecodeError") {
|
|
9713
|
-
return error;
|
|
9714
|
-
}
|
|
9715
|
-
const normalized = normalizeSqliteDriverError(error, rendered);
|
|
9716
|
-
return hasWriteCapability(plan) ? normalized : narrowSqliteDriverErrorForReadQuery(normalized);
|
|
9717
|
-
});
|
|
9718
|
-
},
|
|
9719
|
-
stream(plan) {
|
|
12014
|
+
var fromDriver2 = (renderer, sqlDriver, driverMode = "raw", valueMappings) => {
|
|
12015
|
+
const renderedCache = new WeakMap;
|
|
12016
|
+
const render2 = (plan) => {
|
|
12017
|
+
const cached = renderedCache.get(plan);
|
|
12018
|
+
if (cached !== undefined) {
|
|
12019
|
+
return cached;
|
|
12020
|
+
}
|
|
9720
12021
|
const rendered = renderer.render(plan);
|
|
9721
|
-
|
|
9722
|
-
|
|
9723
|
-
|
|
9724
|
-
|
|
9725
|
-
|
|
9726
|
-
|
|
9727
|
-
|
|
9728
|
-
|
|
9729
|
-
|
|
9730
|
-
|
|
9731
|
-
|
|
9732
|
-
|
|
12022
|
+
renderedCache.set(plan, rendered);
|
|
12023
|
+
return rendered;
|
|
12024
|
+
};
|
|
12025
|
+
const mapExecutionError = (error, rendered, plan) => {
|
|
12026
|
+
if (typeof error === "object" && error !== null && "_tag" in error && error._tag === "RowDecodeError") {
|
|
12027
|
+
return error;
|
|
12028
|
+
}
|
|
12029
|
+
const normalized = normalizeSqliteDriverError(error, rendered);
|
|
12030
|
+
return hasWriteCapability(plan) ? normalized : narrowSqliteDriverErrorForReadQuery(normalized);
|
|
12031
|
+
};
|
|
12032
|
+
return withResultContracts({
|
|
12033
|
+
dialect: "sqlite",
|
|
12034
|
+
execute(plan) {
|
|
12035
|
+
const rendered = render2(plan);
|
|
12036
|
+
return Effect2.mapError(Effect2.flatMap(sqlDriver.execute(rendered), (rows) => Effect2.try({
|
|
12037
|
+
try: () => decodeRows(rendered, plan, rows, { driverMode, valueMappings }),
|
|
12038
|
+
catch: (error) => error
|
|
12039
|
+
})), (error) => mapExecutionError(error, rendered, plan));
|
|
12040
|
+
},
|
|
12041
|
+
executeResult(plan) {
|
|
12042
|
+
const rendered = render2(plan);
|
|
12043
|
+
const result = sqlDriver.executeResult ? sqlDriver.executeResult(rendered) : Effect2.map(sqlDriver.execute(rendered), (rows) => ({ rows }));
|
|
12044
|
+
return Effect2.mapError(Effect2.flatMap(result, ({ rows, ...metadata }) => Effect2.try({
|
|
12045
|
+
try: () => ({
|
|
12046
|
+
...metadata,
|
|
12047
|
+
rows: decodeRows(rendered, plan, rows, { driverMode, valueMappings })
|
|
12048
|
+
}),
|
|
12049
|
+
catch: (error) => error
|
|
12050
|
+
})), (error) => mapExecutionError(error, rendered, plan));
|
|
12051
|
+
},
|
|
12052
|
+
stream(plan) {
|
|
12053
|
+
const rendered = render2(plan);
|
|
12054
|
+
return Stream2.mapError(Stream2.mapArrayEffect(sqlDriver.stream(rendered), (rows) => Effect2.try({
|
|
12055
|
+
try: () => decodeRows(rendered, plan, rows, { driverMode, valueMappings }),
|
|
12056
|
+
catch: (error) => error
|
|
12057
|
+
})), (error) => mapExecutionError(error, rendered, plan));
|
|
12058
|
+
},
|
|
12059
|
+
explain(plan, options2) {
|
|
12060
|
+
const rendered = explainQuery(render2(plan), options2);
|
|
12061
|
+
return Effect2.mapError(sqlDriver.execute(rendered), (error) => mapExecutionError(error, rendered, plan));
|
|
12062
|
+
}
|
|
12063
|
+
});
|
|
12064
|
+
};
|
|
9733
12065
|
var sqlClientDriver = () => driver2({
|
|
9734
12066
|
execute: (query) => Effect2.flatMap(SqlClient3.SqlClient, (sql) => sql.unsafe(query.sql, [...query.params])),
|
|
9735
12067
|
stream: (query) => Stream2.unwrap(Effect2.map(Effect2.flatMap(SqlClient3.SqlClient, (sql) => sql.unsafe(query.sql, [...query.params])), (rows) => Stream2.fromIterable(rows)))
|
|
@@ -9740,25 +12072,25 @@ function make4(options2 = {}) {
|
|
|
9740
12072
|
}
|
|
9741
12073
|
return fromDriver2(options2.renderer ?? makeTrusted("sqlite", (plan) => renderSqlitePlan(plan, { valueMappings: options2.valueMappings })), sqlClientDriver(), options2.driverMode, options2.valueMappings);
|
|
9742
12074
|
}
|
|
9743
|
-
var
|
|
12075
|
+
var custom4 = (execute) => make3("sqlite", execute);
|
|
9744
12076
|
// src/sqlite/query-extension.ts
|
|
9745
12077
|
var exports_query_extension = {};
|
|
9746
12078
|
__export(exports_query_extension, {
|
|
9747
12079
|
onConflict: () => onConflict
|
|
9748
12080
|
});
|
|
9749
12081
|
// src/sqlite/type.ts
|
|
9750
|
-
var
|
|
12082
|
+
var custom5 = (kind) => ({
|
|
9751
12083
|
dialect: "sqlite",
|
|
9752
12084
|
kind
|
|
9753
12085
|
});
|
|
9754
|
-
var
|
|
12086
|
+
var driverValueMapping4 = (dbType, mapping) => ({
|
|
9755
12087
|
...dbType,
|
|
9756
12088
|
driverValueMapping: mapping
|
|
9757
12089
|
});
|
|
9758
|
-
var
|
|
12090
|
+
var type3 = {
|
|
9759
12091
|
...pickDatatypeConstructors(sqliteDatatypes, sqliteSpecificDatatypeKeys),
|
|
9760
|
-
custom:
|
|
9761
|
-
driverValueMapping:
|
|
12092
|
+
custom: custom5,
|
|
12093
|
+
driverValueMapping: driverValueMapping4
|
|
9762
12094
|
};
|
|
9763
12095
|
// src/sqlite/renderer.ts
|
|
9764
12096
|
var exports_renderer2 = {};
|
|
@@ -9767,10 +12099,10 @@ __export(exports_renderer2, {
|
|
|
9767
12099
|
make: () => make5,
|
|
9768
12100
|
TypeId: () => TypeId10
|
|
9769
12101
|
});
|
|
9770
|
-
import { pipeArguments as
|
|
12102
|
+
import { pipeArguments as pipeArguments9 } from "effect/Pipeable";
|
|
9771
12103
|
var RendererProto = {
|
|
9772
12104
|
pipe() {
|
|
9773
|
-
return
|
|
12105
|
+
return pipeArguments9(this, arguments);
|
|
9774
12106
|
}
|
|
9775
12107
|
};
|
|
9776
12108
|
var makeWithState = (state = {}) => {
|
|
@@ -9788,10 +12120,11 @@ var makeWithState = (state = {}) => {
|
|
|
9788
12120
|
var make5 = (options2 = {}) => makeWithState({ valueMappings: options2.valueMappings });
|
|
9789
12121
|
var sqlite = make5();
|
|
9790
12122
|
export {
|
|
9791
|
-
|
|
12123
|
+
type3 as Type,
|
|
9792
12124
|
exports_renderer2 as Renderer,
|
|
9793
12125
|
exports_query_extension as Query,
|
|
9794
12126
|
exports_json as Json,
|
|
12127
|
+
exports_function as Function,
|
|
9795
12128
|
exports_executor2 as Executor,
|
|
9796
12129
|
exports_errors as Errors,
|
|
9797
12130
|
exports_datatypes as Datatypes,
|