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