prisma-sql 1.40.0 → 1.42.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/generator.cjs +10 -9
- package/dist/generator.cjs.map +1 -1
- package/dist/generator.js +10 -9
- package/dist/generator.js.map +1 -1
- package/dist/index.cjs +51 -60
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +51 -60
- package/dist/index.js.map +1 -1
- package/package.json +3 -1
package/dist/index.cjs
CHANGED
|
@@ -2438,12 +2438,6 @@ function validateState(params, mappings, index) {
|
|
|
2438
2438
|
validateMappings(mappings);
|
|
2439
2439
|
assertNextIndexMatches(mappings.length, index);
|
|
2440
2440
|
}
|
|
2441
|
-
function normalizeValue2(value) {
|
|
2442
|
-
if (value instanceof Date) {
|
|
2443
|
-
return value.toISOString();
|
|
2444
|
-
}
|
|
2445
|
-
return value;
|
|
2446
|
-
}
|
|
2447
2441
|
function createStoreInternal(startIndex, initialParams = [], initialMappings = []) {
|
|
2448
2442
|
let index = startIndex;
|
|
2449
2443
|
const params = [...initialParams];
|
|
@@ -2486,7 +2480,7 @@ function createStoreInternal(startIndex, initialParams = [], initialMappings = [
|
|
|
2486
2480
|
}
|
|
2487
2481
|
function addStatic(value) {
|
|
2488
2482
|
const position = index;
|
|
2489
|
-
const normalizedValue =
|
|
2483
|
+
const normalizedValue = normalizeValue(value);
|
|
2490
2484
|
params.push(normalizedValue);
|
|
2491
2485
|
mappings.push({ index: position, value: normalizedValue });
|
|
2492
2486
|
index++;
|
|
@@ -3708,7 +3702,12 @@ function buildSelectSpec(input) {
|
|
|
3708
3702
|
model,
|
|
3709
3703
|
alias
|
|
3710
3704
|
);
|
|
3711
|
-
const orderByClause = buildOrderByClause(
|
|
3705
|
+
const orderByClause = buildOrderByClause(
|
|
3706
|
+
normalizedArgs,
|
|
3707
|
+
alias,
|
|
3708
|
+
dialect,
|
|
3709
|
+
model
|
|
3710
|
+
);
|
|
3712
3711
|
const { take, skip, cursor } = getPaginationParams(method, normalizedArgs);
|
|
3713
3712
|
const params = createParamStoreFrom(
|
|
3714
3713
|
whereResult.params,
|
|
@@ -4771,48 +4770,27 @@ function toSqliteParams(sql, params) {
|
|
|
4771
4770
|
return { sql: parts.join(""), params: reorderedParams };
|
|
4772
4771
|
}
|
|
4773
4772
|
function canonicalizeQuery(modelName, method, args) {
|
|
4774
|
-
function normalize(obj
|
|
4775
|
-
if (obj === null ||
|
|
4776
|
-
if (
|
|
4777
|
-
|
|
4778
|
-
|
|
4779
|
-
|
|
4780
|
-
|
|
4781
|
-
|
|
4782
|
-
|
|
4783
|
-
|
|
4784
|
-
|
|
4785
|
-
|
|
4773
|
+
function normalize(obj) {
|
|
4774
|
+
if (obj === null || obj === void 0) return obj;
|
|
4775
|
+
if (obj instanceof Date) {
|
|
4776
|
+
return "__DATE_PARAM__";
|
|
4777
|
+
}
|
|
4778
|
+
if (Array.isArray(obj)) {
|
|
4779
|
+
return obj.map(normalize);
|
|
4780
|
+
}
|
|
4781
|
+
if (typeof obj === "object") {
|
|
4782
|
+
const sorted = {};
|
|
4783
|
+
for (const key of Object.keys(obj).sort()) {
|
|
4784
|
+
const value = obj[key];
|
|
4785
|
+
sorted[key] = schemaParser.isDynamicParameter(value) ? "__DYN__" : normalize(value);
|
|
4786
4786
|
}
|
|
4787
|
+
return sorted;
|
|
4787
4788
|
}
|
|
4788
|
-
return
|
|
4789
|
+
return obj;
|
|
4789
4790
|
}
|
|
4790
4791
|
const canonical = normalize(args);
|
|
4791
4792
|
return `${modelName}:${method}:${JSON.stringify(canonical)}`;
|
|
4792
4793
|
}
|
|
4793
|
-
function extractValueFromPath(obj, path) {
|
|
4794
|
-
const parts = path.split(".");
|
|
4795
|
-
let current = obj;
|
|
4796
|
-
for (const part of parts) {
|
|
4797
|
-
if (current === void 0 || current === null) return void 0;
|
|
4798
|
-
current = current[part];
|
|
4799
|
-
}
|
|
4800
|
-
return current;
|
|
4801
|
-
}
|
|
4802
|
-
function rebuildParams(mappings, args) {
|
|
4803
|
-
const params = new Array(mappings.length);
|
|
4804
|
-
for (let i = 0; i < mappings.length; i++) {
|
|
4805
|
-
const mapping = mappings[i];
|
|
4806
|
-
if (mapping.dynamicName !== void 0) {
|
|
4807
|
-
const parts = mapping.dynamicName.split(":");
|
|
4808
|
-
const path = parts.length === 2 ? parts[1] : mapping.dynamicName;
|
|
4809
|
-
params[i] = extractValueFromPath(args, path);
|
|
4810
|
-
} else {
|
|
4811
|
-
params[i] = mapping.value;
|
|
4812
|
-
}
|
|
4813
|
-
}
|
|
4814
|
-
return params;
|
|
4815
|
-
}
|
|
4816
4794
|
function buildSQLFull(model, models, method, args, dialect) {
|
|
4817
4795
|
const tableName = buildTableReference(
|
|
4818
4796
|
SQL_TEMPLATES.PUBLIC_SCHEMA,
|
|
@@ -4835,13 +4813,32 @@ function buildSQLFull(model, models, method, args, dialect) {
|
|
|
4835
4813
|
let result;
|
|
4836
4814
|
switch (method) {
|
|
4837
4815
|
case "aggregate":
|
|
4838
|
-
result = buildAggregateSql(
|
|
4816
|
+
result = buildAggregateSql(
|
|
4817
|
+
withMethod,
|
|
4818
|
+
whereResult,
|
|
4819
|
+
tableName,
|
|
4820
|
+
alias,
|
|
4821
|
+
model
|
|
4822
|
+
);
|
|
4839
4823
|
break;
|
|
4840
4824
|
case "groupBy":
|
|
4841
|
-
result = buildGroupBySql(
|
|
4825
|
+
result = buildGroupBySql(
|
|
4826
|
+
withMethod,
|
|
4827
|
+
whereResult,
|
|
4828
|
+
tableName,
|
|
4829
|
+
alias,
|
|
4830
|
+
model,
|
|
4831
|
+
dialect
|
|
4832
|
+
);
|
|
4842
4833
|
break;
|
|
4843
4834
|
case "count":
|
|
4844
|
-
result = buildCountSql(
|
|
4835
|
+
result = buildCountSql(
|
|
4836
|
+
whereResult,
|
|
4837
|
+
tableName,
|
|
4838
|
+
alias,
|
|
4839
|
+
args.skip,
|
|
4840
|
+
dialect
|
|
4841
|
+
);
|
|
4845
4842
|
break;
|
|
4846
4843
|
default:
|
|
4847
4844
|
result = buildSelectSql({
|
|
@@ -4854,24 +4851,18 @@ function buildSQLFull(model, models, method, args, dialect) {
|
|
|
4854
4851
|
dialect
|
|
4855
4852
|
});
|
|
4856
4853
|
}
|
|
4857
|
-
|
|
4858
|
-
return __spreadProps(__spreadValues({}, finalResult), {
|
|
4859
|
-
paramMappings: result.paramMappings
|
|
4860
|
-
});
|
|
4854
|
+
return dialect === "sqlite" ? toSqliteParams(result.sql, result.params) : { sql: result.sql, params: [...result.params] };
|
|
4861
4855
|
}
|
|
4862
4856
|
function buildSQLWithCache(model, models, method, args, dialect) {
|
|
4863
4857
|
const cacheKey = canonicalizeQuery(model.name, method, args);
|
|
4864
|
-
const
|
|
4865
|
-
if (
|
|
4866
|
-
const
|
|
4867
|
-
return { sql:
|
|
4858
|
+
const cachedSql = queryCache.get(cacheKey);
|
|
4859
|
+
if (cachedSql) {
|
|
4860
|
+
const result2 = buildSQLFull(model, models, method, args, dialect);
|
|
4861
|
+
return { sql: cachedSql, params: result2.params };
|
|
4868
4862
|
}
|
|
4869
4863
|
const result = buildSQLFull(model, models, method, args, dialect);
|
|
4870
|
-
queryCache.set(cacheKey,
|
|
4871
|
-
|
|
4872
|
-
paramMappings: result.paramMappings
|
|
4873
|
-
});
|
|
4874
|
-
return { sql: result.sql, params: result.params };
|
|
4864
|
+
queryCache.set(cacheKey, result.sql);
|
|
4865
|
+
return result;
|
|
4875
4866
|
}
|
|
4876
4867
|
var ACCELERATED_METHODS = /* @__PURE__ */ new Set([
|
|
4877
4868
|
"findMany",
|