prisma-sql 1.42.0 → 1.44.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 +26 -15
- package/dist/generator.cjs.map +1 -1
- package/dist/generator.js +26 -15
- package/dist/generator.js.map +1 -1
- package/dist/index.cjs +12 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +12 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/generator.cjs
CHANGED
|
@@ -56,7 +56,7 @@ var require_package = __commonJS({
|
|
|
56
56
|
"package.json"(exports$1, module) {
|
|
57
57
|
module.exports = {
|
|
58
58
|
name: "prisma-sql",
|
|
59
|
-
version: "1.
|
|
59
|
+
version: "1.44.0",
|
|
60
60
|
description: "Convert Prisma queries to optimized SQL with type safety. 2-7x faster than Prisma Client.",
|
|
61
61
|
main: "dist/index.cjs",
|
|
62
62
|
module: "dist/index.js",
|
|
@@ -3377,6 +3377,9 @@ function buildRelationCountSql(countSelect, model, schemas, parentAlias, _params
|
|
|
3377
3377
|
|
|
3378
3378
|
// src/builder/select/assembly.ts
|
|
3379
3379
|
var SIMPLE_SELECT_RE_CACHE = /* @__PURE__ */ new Map();
|
|
3380
|
+
function normalizeFinalParams(params) {
|
|
3381
|
+
return params.map(normalizeValue);
|
|
3382
|
+
}
|
|
3380
3383
|
function joinNonEmpty(parts, sep) {
|
|
3381
3384
|
return parts.filter((s) => s.trim().length > 0).join(sep);
|
|
3382
3385
|
}
|
|
@@ -3403,8 +3406,8 @@ function finalizeSql(sql, params) {
|
|
|
3403
3406
|
validateParamConsistency(sql, snapshot.params);
|
|
3404
3407
|
return Object.freeze({
|
|
3405
3408
|
sql,
|
|
3406
|
-
params: snapshot.params,
|
|
3407
|
-
paramMappings: snapshot.mappings
|
|
3409
|
+
params: normalizeFinalParams(snapshot.params),
|
|
3410
|
+
paramMappings: Object.freeze(snapshot.mappings)
|
|
3408
3411
|
});
|
|
3409
3412
|
}
|
|
3410
3413
|
function parseSimpleScalarSelect(select, alias) {
|
|
@@ -3898,6 +3901,9 @@ var COMPARISON_OPS = {
|
|
|
3898
3901
|
[Ops.LT]: "<",
|
|
3899
3902
|
[Ops.LTE]: "<="
|
|
3900
3903
|
};
|
|
3904
|
+
function normalizeFinalParams2(params) {
|
|
3905
|
+
return params.map(normalizeValue);
|
|
3906
|
+
}
|
|
3901
3907
|
function getModelFieldMap(model) {
|
|
3902
3908
|
const cached = MODEL_FIELD_CACHE.get(model);
|
|
3903
3909
|
if (cached) return cached;
|
|
@@ -4254,7 +4260,7 @@ function buildAggregateSql(args, whereResult, tableName, alias, model) {
|
|
|
4254
4260
|
validateParamConsistency(sql, whereResult.params);
|
|
4255
4261
|
return Object.freeze({
|
|
4256
4262
|
sql,
|
|
4257
|
-
params: Object.freeze([...whereResult.params]),
|
|
4263
|
+
params: Object.freeze(normalizeFinalParams2([...whereResult.params])),
|
|
4258
4264
|
paramMappings: Object.freeze([...whereResult.paramMappings])
|
|
4259
4265
|
});
|
|
4260
4266
|
}
|
|
@@ -4325,9 +4331,10 @@ function buildGroupBySql(args, whereResult, tableName, alias, model, dialect) {
|
|
|
4325
4331
|
const snapshot = params.snapshot();
|
|
4326
4332
|
validateSelectQuery(sql);
|
|
4327
4333
|
validateParamConsistency(sql, [...whereResult.params, ...snapshot.params]);
|
|
4334
|
+
const mergedParams = [...whereResult.params, ...snapshot.params];
|
|
4328
4335
|
return Object.freeze({
|
|
4329
4336
|
sql,
|
|
4330
|
-
params: Object.freeze(
|
|
4337
|
+
params: Object.freeze(normalizeFinalParams2(mergedParams)),
|
|
4331
4338
|
paramMappings: Object.freeze([
|
|
4332
4339
|
...whereResult.paramMappings,
|
|
4333
4340
|
...snapshot.mappings
|
|
@@ -4366,7 +4373,7 @@ function buildCountSql(whereResult, tableName, alias, skip, dialect) {
|
|
|
4366
4373
|
validateParamConsistency(sql, mergedParams);
|
|
4367
4374
|
return Object.freeze({
|
|
4368
4375
|
sql,
|
|
4369
|
-
params: Object.freeze(mergedParams),
|
|
4376
|
+
params: Object.freeze(normalizeFinalParams2(mergedParams)),
|
|
4370
4377
|
paramMappings: Object.freeze([
|
|
4371
4378
|
...whereResult.paramMappings,
|
|
4372
4379
|
...snapshot.mappings
|
|
@@ -4677,6 +4684,18 @@ function generateCode(models, queries, dialect, datamodel) {
|
|
|
4677
4684
|
return `// Generated by @prisma-sql/generator - DO NOT EDIT
|
|
4678
4685
|
import { buildSQL, transformQueryResults, type PrismaMethod, type Model } from 'prisma-sql'
|
|
4679
4686
|
|
|
4687
|
+
function normalizeValue(value: unknown): unknown {
|
|
4688
|
+
if (value instanceof Date) {
|
|
4689
|
+
return value.toISOString()
|
|
4690
|
+
}
|
|
4691
|
+
|
|
4692
|
+
if (Array.isArray(value)) {
|
|
4693
|
+
return value.map(normalizeValue)
|
|
4694
|
+
}
|
|
4695
|
+
|
|
4696
|
+
return value
|
|
4697
|
+
}
|
|
4698
|
+
|
|
4680
4699
|
export const MODELS: Model[] = ${JSON.stringify(cleanModels, null, 2)}
|
|
4681
4700
|
|
|
4682
4701
|
const ENUM_MAPPINGS: Record<string, Record<string, string>> = ${JSON.stringify(mappings, null, 2)}
|
|
@@ -4706,7 +4725,6 @@ function transformEnumInValue(value: unknown, enumType: string | undefined): unk
|
|
|
4706
4725
|
return value
|
|
4707
4726
|
}
|
|
4708
4727
|
|
|
4709
|
-
// Handle array of enum values
|
|
4710
4728
|
if (Array.isArray(value)) {
|
|
4711
4729
|
return value.map(v => {
|
|
4712
4730
|
if (typeof v === 'string' && mapping[v] !== undefined) {
|
|
@@ -4716,7 +4734,6 @@ function transformEnumInValue(value: unknown, enumType: string | undefined): unk
|
|
|
4716
4734
|
})
|
|
4717
4735
|
}
|
|
4718
4736
|
|
|
4719
|
-
// Handle single enum value
|
|
4720
4737
|
if (typeof value === 'string' && mapping[value] !== undefined) {
|
|
4721
4738
|
return mapping[value]
|
|
4722
4739
|
}
|
|
@@ -4740,24 +4757,19 @@ function transformEnumValues(modelName: string, obj: any, currentPath: string[]
|
|
|
4740
4757
|
for (const [key, value] of Object.entries(obj)) {
|
|
4741
4758
|
const newPath = [...currentPath, key]
|
|
4742
4759
|
|
|
4743
|
-
// Check if current key is an enum field at root level
|
|
4744
4760
|
const enumType = modelFields[key]
|
|
4745
4761
|
|
|
4746
4762
|
if (enumType) {
|
|
4747
|
-
// This is an enum field - check if value is direct or has operators
|
|
4748
4763
|
if (value && typeof value === 'object' && !Array.isArray(value)) {
|
|
4749
|
-
// Has operators like { equals: "ACTIVE" }, { in: ["ACTIVE"] }, etc.
|
|
4750
4764
|
const transformedOperators: any = {}
|
|
4751
4765
|
for (const [op, opValue] of Object.entries(value)) {
|
|
4752
4766
|
transformedOperators[op] = transformEnumInValue(opValue, enumType)
|
|
4753
4767
|
}
|
|
4754
4768
|
transformed[key] = transformedOperators
|
|
4755
4769
|
} else {
|
|
4756
|
-
// Direct value like { status: "ACTIVE" }
|
|
4757
4770
|
transformed[key] = transformEnumInValue(value, enumType)
|
|
4758
4771
|
}
|
|
4759
4772
|
} else if (typeof value === 'object' && value !== null) {
|
|
4760
|
-
// Recursively transform nested objects (relations, logical operators, etc)
|
|
4761
4773
|
transformed[key] = transformEnumValues(modelName, value, newPath)
|
|
4762
4774
|
} else {
|
|
4763
4775
|
transformed[key] = value
|
|
@@ -4833,7 +4845,7 @@ function extractDynamicParams(args: any, dynamicKeys: string[]): unknown[] {
|
|
|
4833
4845
|
throw new Error(\`Missing required parameter: \${key}\`)
|
|
4834
4846
|
}
|
|
4835
4847
|
|
|
4836
|
-
params.push(value)
|
|
4848
|
+
params.push(normalizeValue(value))
|
|
4837
4849
|
}
|
|
4838
4850
|
|
|
4839
4851
|
return params
|
|
@@ -4884,7 +4896,6 @@ export function speedExtension(config: {
|
|
|
4884
4896
|
const modelName = this?.name || this?.$name
|
|
4885
4897
|
const startTime = Date.now()
|
|
4886
4898
|
|
|
4887
|
-
// Transform enum values before processing
|
|
4888
4899
|
const transformedArgs = transformEnumValues(modelName, args || {})
|
|
4889
4900
|
|
|
4890
4901
|
const queryKey = normalizeQuery(transformedArgs)
|