prisma-sql 1.4.0 → 1.6.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.js +84 -45
- package/dist/index.js +96 -26
- package/dist/index.js.map +1 -1
- package/dist/{index.cjs → index.mjs} +70 -39
- package/dist/index.mjs.map +1 -0
- package/package.json +1 -1
- package/dist/generator.cjs +0 -4657
- package/dist/generator.cjs.map +0 -1
- package/dist/generator.d.mts +0 -2
- package/dist/generator.d.ts +0 -2
- package/dist/generator.js.map +0 -1
- package/dist/index.cjs.map +0 -1
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var schemaParser = require('@dee-wan/schema-parser');
|
|
4
|
-
|
|
5
1
|
var __defProp = Object.defineProperty;
|
|
6
2
|
var __defProps = Object.defineProperties;
|
|
7
3
|
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
@@ -357,6 +353,7 @@ var Wildcards = Object.freeze({
|
|
|
357
353
|
[Ops.ENDS_WITH]: (v) => `%${v}`
|
|
358
354
|
});
|
|
359
355
|
var REGEX_CACHE = {
|
|
356
|
+
PARAM_PLACEHOLDER: /\$(\d+)/g,
|
|
360
357
|
VALID_IDENTIFIER: /^[a-z_][a-z0-9_]*$/
|
|
361
358
|
};
|
|
362
359
|
var LIMITS = Object.freeze({
|
|
@@ -661,7 +658,7 @@ function validateMappingsAgainstPlaceholders(mappings, placeholders, max, dialec
|
|
|
661
658
|
const mappingIndices = /* @__PURE__ */ new Set();
|
|
662
659
|
for (const mapping of mappings) {
|
|
663
660
|
validateMappingIndex(mapping, max);
|
|
664
|
-
ensureUniqueMappingIndex(mappingIndices, mapping.index);
|
|
661
|
+
ensureUniqueMappingIndex(mappingIndices, mapping.index, dialect);
|
|
665
662
|
ensureMappingIndexExistsInSql(placeholders, mapping.index);
|
|
666
663
|
validateMappingValueShape(mapping);
|
|
667
664
|
}
|
|
@@ -851,6 +848,9 @@ function joinCondition(field, parentAlias, childAlias) {
|
|
|
851
848
|
function getModelByName(schemas, name) {
|
|
852
849
|
return schemas.find((m) => m.name === name);
|
|
853
850
|
}
|
|
851
|
+
|
|
852
|
+
// src/builder/where/operators-scalar.ts
|
|
853
|
+
import { isDynamicParameter } from "@dee-wan/schema-parser";
|
|
854
854
|
function buildNotComposite(expr, val, params, dialect, buildOp, separator) {
|
|
855
855
|
const entries = Object.entries(val).filter(
|
|
856
856
|
([k, v]) => k !== "mode" && v !== void 0
|
|
@@ -879,7 +879,7 @@ function buildScalarOperator(expr, op, val, params, mode, fieldType, dialect) {
|
|
|
879
879
|
}
|
|
880
880
|
if (op === Ops.EQUALS && mode === Modes.INSENSITIVE && isNotNullish(dialect)) {
|
|
881
881
|
const placeholder = params.addAuto(val);
|
|
882
|
-
return caseInsensitiveEquals(expr, placeholder);
|
|
882
|
+
return caseInsensitiveEquals(expr, placeholder, dialect);
|
|
883
883
|
}
|
|
884
884
|
const STRING_LIKE_OPS = /* @__PURE__ */ new Set([
|
|
885
885
|
Ops.CONTAINS,
|
|
@@ -950,7 +950,7 @@ function buildDynamicLikePattern(op, placeholder, dialect) {
|
|
|
950
950
|
}
|
|
951
951
|
function handleLikeOperator(expr, op, val, params, mode, dialect) {
|
|
952
952
|
if (val === void 0) return "";
|
|
953
|
-
if (
|
|
953
|
+
if (isDynamicParameter(val)) {
|
|
954
954
|
const placeholder2 = params.addAuto(val);
|
|
955
955
|
const patternExpr = buildDynamicLikePattern(op, placeholder2, dialect);
|
|
956
956
|
if (mode === Modes.INSENSITIVE) {
|
|
@@ -966,7 +966,7 @@ function handleLikeOperator(expr, op, val, params, mode, dialect) {
|
|
|
966
966
|
}
|
|
967
967
|
function handleInOperator(expr, op, val, params, dialect) {
|
|
968
968
|
if (val === void 0) return "";
|
|
969
|
-
if (
|
|
969
|
+
if (isDynamicParameter(val)) {
|
|
970
970
|
const placeholder2 = params.addAuto(val);
|
|
971
971
|
return op === Ops.IN ? inArray(expr, placeholder2, dialect) : notInArray(expr, placeholder2, dialect);
|
|
972
972
|
}
|
|
@@ -999,8 +999,11 @@ function handleComparisonOperator(expr, op, val, params) {
|
|
|
999
999
|
const placeholder = params.addAuto(val);
|
|
1000
1000
|
return `${expr} ${sqlOp} ${placeholder}`;
|
|
1001
1001
|
}
|
|
1002
|
+
|
|
1003
|
+
// src/builder/where/operators-array.ts
|
|
1004
|
+
import { isDynamicParameter as isDynamicParameter2 } from "@dee-wan/schema-parser";
|
|
1002
1005
|
function buildArrayParam(val, params, dialect) {
|
|
1003
|
-
if (
|
|
1006
|
+
if (isDynamicParameter2(val)) {
|
|
1004
1007
|
return params.addAuto(val);
|
|
1005
1008
|
}
|
|
1006
1009
|
if (!Array.isArray(val)) {
|
|
@@ -1074,7 +1077,7 @@ function handleArrayHas(expr, val, params, cast, dialect) {
|
|
|
1074
1077
|
value: val
|
|
1075
1078
|
});
|
|
1076
1079
|
}
|
|
1077
|
-
if (!
|
|
1080
|
+
if (!isDynamicParameter2(val) && Array.isArray(val)) {
|
|
1078
1081
|
throw createError(`has requires scalar value (single element), not array`, {
|
|
1079
1082
|
operator: Ops.HAS,
|
|
1080
1083
|
value: val
|
|
@@ -1091,7 +1094,7 @@ function handleArrayHas(expr, val, params, cast, dialect) {
|
|
|
1091
1094
|
}
|
|
1092
1095
|
function handleArrayHasSome(expr, val, params, cast, dialect) {
|
|
1093
1096
|
if (val === void 0) return "";
|
|
1094
|
-
if (
|
|
1097
|
+
if (isDynamicParameter2(val)) {
|
|
1095
1098
|
const placeholder2 = params.addAuto(val);
|
|
1096
1099
|
return arrayOverlaps(expr, placeholder2, cast, dialect);
|
|
1097
1100
|
}
|
|
@@ -1763,6 +1766,12 @@ function createAliasGenerator(maxAliases = 1e4) {
|
|
|
1763
1766
|
}
|
|
1764
1767
|
};
|
|
1765
1768
|
}
|
|
1769
|
+
|
|
1770
|
+
// src/builder/shared/param-store.ts
|
|
1771
|
+
import {
|
|
1772
|
+
extractDynamicName,
|
|
1773
|
+
isDynamicParameter as isDynamicParameter3
|
|
1774
|
+
} from "@dee-wan/schema-parser";
|
|
1766
1775
|
var MAX_PARAM_INDEX = Number.MAX_SAFE_INTEGER - 1e3;
|
|
1767
1776
|
function assertSameLength(params, mappings) {
|
|
1768
1777
|
if (params.length !== mappings.length) {
|
|
@@ -1893,8 +1902,8 @@ function createStoreInternal(startIndex, initialParams = [], initialMappings = [
|
|
|
1893
1902
|
return dynamicName === void 0 ? addStatic(value) : addDynamic(dynamicName);
|
|
1894
1903
|
}
|
|
1895
1904
|
function addAuto(value) {
|
|
1896
|
-
if (
|
|
1897
|
-
const dynamicName =
|
|
1905
|
+
if (isDynamicParameter3(value)) {
|
|
1906
|
+
const dynamicName = extractDynamicName(value);
|
|
1898
1907
|
return add(void 0, dynamicName);
|
|
1899
1908
|
}
|
|
1900
1909
|
return add(value);
|
|
@@ -1983,10 +1992,13 @@ function buildWhereClause(where, options) {
|
|
|
1983
1992
|
}
|
|
1984
1993
|
return publicResult;
|
|
1985
1994
|
}
|
|
1995
|
+
|
|
1996
|
+
// src/builder/shared/int-like.ts
|
|
1997
|
+
import { isDynamicParameter as isDynamicParameter4 } from "@dee-wan/schema-parser";
|
|
1986
1998
|
function normalizeIntLike(name, v, opts = {}) {
|
|
1987
1999
|
var _a, _b;
|
|
1988
2000
|
if (!isNotNullish(v)) return void 0;
|
|
1989
|
-
if (
|
|
2001
|
+
if (isDynamicParameter4(v)) return v;
|
|
1990
2002
|
if (typeof v !== "number" || !Number.isFinite(v) || !Number.isInteger(v)) {
|
|
1991
2003
|
throw new Error(`${name} must be an integer`);
|
|
1992
2004
|
}
|
|
@@ -2003,6 +2015,9 @@ function normalizeIntLike(name, v, opts = {}) {
|
|
|
2003
2015
|
}
|
|
2004
2016
|
return v;
|
|
2005
2017
|
}
|
|
2018
|
+
|
|
2019
|
+
// src/builder/shared/dynamic-params.ts
|
|
2020
|
+
import { extractDynamicName as extractDynamicName2, isDynamicParameter as isDynamicParameter5 } from "@dee-wan/schema-parser";
|
|
2006
2021
|
function scopeName(scope, dynamicName) {
|
|
2007
2022
|
const s = String(scope).trim();
|
|
2008
2023
|
const dn = String(dynamicName).trim();
|
|
@@ -2010,13 +2025,16 @@ function scopeName(scope, dynamicName) {
|
|
|
2010
2025
|
return `${s}:${dn}`;
|
|
2011
2026
|
}
|
|
2012
2027
|
function addAutoScoped(params, value, scope) {
|
|
2013
|
-
if (
|
|
2014
|
-
const dn =
|
|
2028
|
+
if (isDynamicParameter5(value)) {
|
|
2029
|
+
const dn = extractDynamicName2(value);
|
|
2015
2030
|
return params.add(void 0, scopeName(scope, dn));
|
|
2016
2031
|
}
|
|
2017
2032
|
return params.add(value);
|
|
2018
2033
|
}
|
|
2019
2034
|
|
|
2035
|
+
// src/builder/pagination.ts
|
|
2036
|
+
import { isDynamicParameter as isDynamicParameter6 } from "@dee-wan/schema-parser";
|
|
2037
|
+
|
|
2020
2038
|
// src/builder/shared/order-by-utils.ts
|
|
2021
2039
|
var flipNulls = (v) => {
|
|
2022
2040
|
const s = String(v).toLowerCase();
|
|
@@ -2152,7 +2170,7 @@ function normalizeFiniteInteger(name, v) {
|
|
|
2152
2170
|
return v;
|
|
2153
2171
|
}
|
|
2154
2172
|
function normalizeNonNegativeInt(name, v) {
|
|
2155
|
-
if (
|
|
2173
|
+
if (isDynamicParameter6(v)) return v;
|
|
2156
2174
|
const n = normalizeFiniteInteger(name, v);
|
|
2157
2175
|
if (n < 0) {
|
|
2158
2176
|
throw new Error(`${name} must be >= 0`);
|
|
@@ -2166,7 +2184,7 @@ function hasNonNullishProp(v, key) {
|
|
|
2166
2184
|
return isPlainObject(v) && key in v && isNotNullish(v[key]);
|
|
2167
2185
|
}
|
|
2168
2186
|
function normalizeIntegerOrDynamic(name, v) {
|
|
2169
|
-
if (
|
|
2187
|
+
if (isDynamicParameter6(v)) return v;
|
|
2170
2188
|
return normalizeFiniteInteger(name, v);
|
|
2171
2189
|
}
|
|
2172
2190
|
function readSkipTake(relArgs) {
|
|
@@ -2399,6 +2417,9 @@ function getPaginationParams(method, args) {
|
|
|
2399
2417
|
return {};
|
|
2400
2418
|
}
|
|
2401
2419
|
|
|
2420
|
+
// src/builder/select/assembly.ts
|
|
2421
|
+
import { isDynamicParameter as isDynamicParameter7 } from "@dee-wan/schema-parser";
|
|
2422
|
+
|
|
2402
2423
|
// src/builder/select/fields.ts
|
|
2403
2424
|
function toSelectEntries(select) {
|
|
2404
2425
|
const out = [];
|
|
@@ -3234,7 +3255,7 @@ function appendPagination(sql, spec) {
|
|
|
3234
3255
|
const isFindUniqueOrFirst = method === "findUnique" || method === "findFirst";
|
|
3235
3256
|
if (isFindUniqueOrFirst) {
|
|
3236
3257
|
const parts2 = [sql, SQL_TEMPLATES.LIMIT, "1"];
|
|
3237
|
-
const hasSkip = isNotNullish(pagination.skip) && (
|
|
3258
|
+
const hasSkip = isNotNullish(pagination.skip) && (isDynamicParameter7(pagination.skip) || typeof pagination.skip === "number" && pagination.skip > 0) && method === "findFirst";
|
|
3238
3259
|
if (hasSkip) {
|
|
3239
3260
|
const placeholder = addAutoScoped(
|
|
3240
3261
|
params,
|
|
@@ -3467,7 +3488,7 @@ function normalizeArgsForNegativeTake(method, args) {
|
|
|
3467
3488
|
}
|
|
3468
3489
|
function normalizeArgsForDialect(dialect, args, model) {
|
|
3469
3490
|
if (dialect !== "postgres") return args;
|
|
3470
|
-
return applyPostgresDistinctOrderBy(args);
|
|
3491
|
+
return applyPostgresDistinctOrderBy(args, model);
|
|
3471
3492
|
}
|
|
3472
3493
|
function buildCursorClauseIfAny(input) {
|
|
3473
3494
|
const { cursor, orderBy, tableName, alias, params, dialect } = input;
|
|
@@ -3546,7 +3567,9 @@ function buildSelectSql(input) {
|
|
|
3546
3567
|
const argsForSql = normalizeArgsForNegativeTake(method, args);
|
|
3547
3568
|
const normalizedArgs = normalizeArgsForDialect(
|
|
3548
3569
|
dialectToUse,
|
|
3549
|
-
argsForSql
|
|
3570
|
+
argsForSql,
|
|
3571
|
+
model
|
|
3572
|
+
);
|
|
3550
3573
|
validateDistinct(model, normalizedArgs.distinct);
|
|
3551
3574
|
validateOrderBy(model, normalizedArgs.orderBy);
|
|
3552
3575
|
validateCursor(model, normalizedArgs.cursor);
|
|
@@ -3562,6 +3585,9 @@ function buildSelectSql(input) {
|
|
|
3562
3585
|
});
|
|
3563
3586
|
return constructFinalSql(spec);
|
|
3564
3587
|
}
|
|
3588
|
+
|
|
3589
|
+
// src/builder/aggregates.ts
|
|
3590
|
+
import { isDynamicParameter as isDynamicParameter8 } from "@dee-wan/schema-parser";
|
|
3565
3591
|
var MODEL_FIELD_CACHE = /* @__PURE__ */ new WeakMap();
|
|
3566
3592
|
var NUMERIC_TYPES = /* @__PURE__ */ new Set(["Int", "Float", "Decimal", "BigInt"]);
|
|
3567
3593
|
var AGGREGATES = [
|
|
@@ -3656,7 +3682,7 @@ function buildNullComparison(expr, op) {
|
|
|
3656
3682
|
throw new Error(`Operator '${op}' doesn't support null in HAVING`);
|
|
3657
3683
|
}
|
|
3658
3684
|
function buildInComparison(expr, op, val, params, dialect) {
|
|
3659
|
-
if (
|
|
3685
|
+
if (isDynamicParameter8(val)) {
|
|
3660
3686
|
const placeholder2 = addHavingParam(params, op, val);
|
|
3661
3687
|
return op === Ops.IN ? inArray(expr, placeholder2, dialect) : notInArray(expr, placeholder2, dialect);
|
|
3662
3688
|
}
|
|
@@ -4054,7 +4080,7 @@ function buildCountSql(whereResult, tableName, alias, skip, dialect) {
|
|
|
4054
4080
|
});
|
|
4055
4081
|
}
|
|
4056
4082
|
function applyCountSkip(subSelect, normalizedSkip, params, dialect) {
|
|
4057
|
-
const shouldApply =
|
|
4083
|
+
const shouldApply = isDynamicParameter8(normalizedSkip) || typeof normalizedSkip === "number" && normalizedSkip > 0;
|
|
4058
4084
|
if (!shouldApply) return subSelect;
|
|
4059
4085
|
const placeholder = addAutoScoped(params, normalizedSkip, "count.skip");
|
|
4060
4086
|
if (dialect === "sqlite") {
|
|
@@ -4062,6 +4088,11 @@ function applyCountSkip(subSelect, normalizedSkip, params, dialect) {
|
|
|
4062
4088
|
}
|
|
4063
4089
|
return `${subSelect} ${SQL_TEMPLATES.OFFSET} ${placeholder}`;
|
|
4064
4090
|
}
|
|
4091
|
+
|
|
4092
|
+
// src/sql-generator.ts
|
|
4093
|
+
import {
|
|
4094
|
+
convertDMMFToModels
|
|
4095
|
+
} from "@dee-wan/schema-parser";
|
|
4065
4096
|
function safeAlias(input) {
|
|
4066
4097
|
const raw = String(input).toLowerCase();
|
|
4067
4098
|
const cleaned = raw.replace(/[^a-z0-9_]/g, "_");
|
|
@@ -4163,7 +4194,7 @@ function buildParamsFromMappings(mappings) {
|
|
|
4163
4194
|
}
|
|
4164
4195
|
function resolveModelContext(directive) {
|
|
4165
4196
|
const { model, datamodel } = directive.context;
|
|
4166
|
-
const schemaModels =
|
|
4197
|
+
const schemaModels = convertDMMFToModels(datamodel);
|
|
4167
4198
|
const modelDef = getModelByName(schemaModels, model.name);
|
|
4168
4199
|
if (!modelDef) throw new Error(`Model ${model.name} not found in schema`);
|
|
4169
4200
|
return { schemaModels, modelDef };
|
|
@@ -4296,6 +4327,9 @@ function transformQueryResults(method, results) {
|
|
|
4296
4327
|
const transformer = RESULT_TRANSFORMERS[method];
|
|
4297
4328
|
return transformer ? transformer(results) : results;
|
|
4298
4329
|
}
|
|
4330
|
+
|
|
4331
|
+
// src/index.ts
|
|
4332
|
+
import { convertDMMFToModels as convertDMMFToModels2 } from "@dee-wan/schema-parser";
|
|
4299
4333
|
var ACCELERATED_METHODS = /* @__PURE__ */ new Set([
|
|
4300
4334
|
"findMany",
|
|
4301
4335
|
"findFirst",
|
|
@@ -4622,18 +4656,15 @@ function generateSQLByModel(directives) {
|
|
|
4622
4656
|
}
|
|
4623
4657
|
return byModel;
|
|
4624
4658
|
}
|
|
4625
|
-
|
|
4626
|
-
|
|
4627
|
-
|
|
4628
|
-
|
|
4629
|
-
|
|
4630
|
-
|
|
4631
|
-
|
|
4632
|
-
|
|
4633
|
-
|
|
4634
|
-
|
|
4635
|
-
|
|
4636
|
-
|
|
4637
|
-
exports.speedExtension = speedExtension;
|
|
4638
|
-
//# sourceMappingURL=index.cjs.map
|
|
4639
|
-
//# sourceMappingURL=index.cjs.map
|
|
4659
|
+
export {
|
|
4660
|
+
convertDMMFToModels2 as convertDMMFToModels,
|
|
4661
|
+
createPrismaSQL,
|
|
4662
|
+
createToSQL,
|
|
4663
|
+
generateAllSQL,
|
|
4664
|
+
generateSQL2 as generateSQL,
|
|
4665
|
+
generateSQLByModel,
|
|
4666
|
+
getGlobalDialect,
|
|
4667
|
+
setGlobalDialect,
|
|
4668
|
+
speedExtension
|
|
4669
|
+
};
|
|
4670
|
+
//# sourceMappingURL=index.mjs.map
|