prisma-sql 1.13.0 → 1.15.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 +57 -14
- package/dist/generator.cjs.map +1 -1
- package/dist/generator.js +57 -14
- package/dist/generator.js.map +1 -1
- package/dist/index.cjs +5 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +5 -11
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
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.15.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",
|
|
@@ -118,7 +118,7 @@ var require_package = __commonJS({
|
|
|
118
118
|
author: "multipliedtwice <multipliedtwice@gmail.com>",
|
|
119
119
|
license: "MIT",
|
|
120
120
|
dependencies: {
|
|
121
|
-
"@dee-wan/schema-parser": "1.
|
|
121
|
+
"@dee-wan/schema-parser": "1.3.0",
|
|
122
122
|
"@prisma/generator-helper": "^7.2.0",
|
|
123
123
|
"@prisma/internals": "^7.2.0"
|
|
124
124
|
},
|
|
@@ -4185,14 +4185,6 @@ function safeAlias(input) {
|
|
|
4185
4185
|
}
|
|
4186
4186
|
return base;
|
|
4187
4187
|
}
|
|
4188
|
-
function isPrismaMethod(v) {
|
|
4189
|
-
return v === "findMany" || v === "findFirst" || v === "findUnique" || v === "aggregate" || v === "groupBy" || v === "count";
|
|
4190
|
-
}
|
|
4191
|
-
function getMethodFromProcessed(processed) {
|
|
4192
|
-
const maybe = processed == null ? void 0 : processed.method;
|
|
4193
|
-
if (isPrismaMethod(maybe)) return maybe;
|
|
4194
|
-
return "findMany";
|
|
4195
|
-
}
|
|
4196
4188
|
function buildSqlResult(args) {
|
|
4197
4189
|
const {
|
|
4198
4190
|
method,
|
|
@@ -4305,6 +4297,7 @@ function buildMainWhere(args) {
|
|
|
4305
4297
|
}
|
|
4306
4298
|
function buildAndNormalizeSql(args) {
|
|
4307
4299
|
const {
|
|
4300
|
+
method,
|
|
4308
4301
|
processed,
|
|
4309
4302
|
whereResult,
|
|
4310
4303
|
tableName,
|
|
@@ -4313,7 +4306,6 @@ function buildAndNormalizeSql(args) {
|
|
|
4313
4306
|
schemaModels,
|
|
4314
4307
|
dialect
|
|
4315
4308
|
} = args;
|
|
4316
|
-
const method = getMethodFromProcessed(processed);
|
|
4317
4309
|
const sqlResult = buildSqlResult({
|
|
4318
4310
|
method,
|
|
4319
4311
|
processed,
|
|
@@ -4335,7 +4327,7 @@ function finalizeDirective(args) {
|
|
|
4335
4327
|
validateSqlPositions(normalizedSql, normalizedMappings, getGlobalDialect());
|
|
4336
4328
|
const { staticParams, dynamicKeys } = buildParamsFromMappings(normalizedMappings);
|
|
4337
4329
|
return {
|
|
4338
|
-
|
|
4330
|
+
method: directive.method,
|
|
4339
4331
|
sql: normalizedSql,
|
|
4340
4332
|
staticParams,
|
|
4341
4333
|
dynamicKeys,
|
|
@@ -4355,7 +4347,9 @@ function generateSQL(directive) {
|
|
|
4355
4347
|
modelDef,
|
|
4356
4348
|
dialect
|
|
4357
4349
|
});
|
|
4350
|
+
const method = directive.method;
|
|
4358
4351
|
const normalized = buildAndNormalizeSql({
|
|
4352
|
+
method,
|
|
4359
4353
|
processed: query.processed,
|
|
4360
4354
|
whereResult,
|
|
4361
4355
|
tableName,
|
|
@@ -4396,7 +4390,7 @@ function generateClient(options) {
|
|
|
4396
4390
|
const modelQueries = queries.get(modelName);
|
|
4397
4391
|
for (const directive of result.directives) {
|
|
4398
4392
|
try {
|
|
4399
|
-
const method = directive.
|
|
4393
|
+
const method = directive.method;
|
|
4400
4394
|
const sqlDirective = generateSQL2(directive);
|
|
4401
4395
|
if (!modelQueries.has(method)) {
|
|
4402
4396
|
modelQueries.set(method, /* @__PURE__ */ new Map());
|
|
@@ -4460,9 +4454,58 @@ const QUERIES: Record<string, Record<string, Record<string, {
|
|
|
4460
4454
|
|
|
4461
4455
|
const DIALECT = ${JSON.stringify(dialect)}
|
|
4462
4456
|
|
|
4457
|
+
function isDynamicParam(key: string): boolean {
|
|
4458
|
+
// Common dynamic parameters that should be replaced with markers
|
|
4459
|
+
return key === 'skip' || key === 'take' || key === 'cursor'
|
|
4460
|
+
}
|
|
4461
|
+
|
|
4463
4462
|
function normalizeQuery(args: any): string {
|
|
4464
4463
|
if (!args) return '{}'
|
|
4465
|
-
|
|
4464
|
+
|
|
4465
|
+
// Clone and normalize the args
|
|
4466
|
+
const normalized = JSON.parse(JSON.stringify(args))
|
|
4467
|
+
|
|
4468
|
+
// Replace dynamic params with markers to match prebaked keys
|
|
4469
|
+
function replaceDynamicParams(obj: any): any {
|
|
4470
|
+
if (!obj || typeof obj !== 'object') return obj
|
|
4471
|
+
|
|
4472
|
+
if (Array.isArray(obj)) {
|
|
4473
|
+
return obj.map(replaceDynamicParams)
|
|
4474
|
+
}
|
|
4475
|
+
|
|
4476
|
+
const result: any = {}
|
|
4477
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
4478
|
+
// Replace top-level dynamic params with markers
|
|
4479
|
+
if (isDynamicParam(key)) {
|
|
4480
|
+
result[key] = \`__DYNAMIC_\${key}__\`
|
|
4481
|
+
} else {
|
|
4482
|
+
result[key] = replaceDynamicParams(value)
|
|
4483
|
+
}
|
|
4484
|
+
}
|
|
4485
|
+
return result
|
|
4486
|
+
}
|
|
4487
|
+
|
|
4488
|
+
const withMarkers = replaceDynamicParams(normalized)
|
|
4489
|
+
|
|
4490
|
+
// Remove empty objects to match prebaked keys
|
|
4491
|
+
function removeEmptyObjects(obj: any): any {
|
|
4492
|
+
if (!obj || typeof obj !== 'object' || Array.isArray(obj)) return obj
|
|
4493
|
+
|
|
4494
|
+
const result: any = {}
|
|
4495
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
4496
|
+
// Skip empty objects (but keep empty arrays)
|
|
4497
|
+
if (value && typeof value === 'object' && !Array.isArray(value) && Object.keys(value).length === 0) {
|
|
4498
|
+
continue
|
|
4499
|
+
}
|
|
4500
|
+
result[key] = removeEmptyObjects(value)
|
|
4501
|
+
}
|
|
4502
|
+
return result
|
|
4503
|
+
}
|
|
4504
|
+
|
|
4505
|
+
const cleaned = removeEmptyObjects(withMarkers)
|
|
4506
|
+
|
|
4507
|
+
// Sort keys recursively for deterministic matching
|
|
4508
|
+
return JSON.stringify(cleaned, (key, value) => {
|
|
4466
4509
|
if (value && typeof value === 'object' && !Array.isArray(value)) {
|
|
4467
4510
|
const sorted: Record<string, unknown> = {}
|
|
4468
4511
|
for (const k of Object.keys(value).sort()) {
|