prisma-sql 1.75.12 → 1.76.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 +49 -5
- package/dist/generator.cjs.map +1 -1
- package/dist/generator.js +49 -5
- package/dist/generator.js.map +1 -1
- package/dist/index.cjs +51 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +51 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/generator.js
CHANGED
|
@@ -68,7 +68,7 @@ var require_package = __commonJS({
|
|
|
68
68
|
"package.json"(exports$1, module) {
|
|
69
69
|
module.exports = {
|
|
70
70
|
name: "prisma-sql",
|
|
71
|
-
version: "1.
|
|
71
|
+
version: "1.76.0",
|
|
72
72
|
description: "Convert Prisma queries to optimized SQL with type safety. 2-7x faster than Prisma Client.",
|
|
73
73
|
main: "dist/index.cjs",
|
|
74
74
|
module: "dist/index.js",
|
|
@@ -2359,11 +2359,14 @@ var SINGLE_PARENT_MAX_FLAT_JOIN_DEPTH = 1;
|
|
|
2359
2359
|
function getFanOut(modelName, relName) {
|
|
2360
2360
|
return DEFAULT_FAN;
|
|
2361
2361
|
}
|
|
2362
|
+
var DYNAMIC_TAKE_ESTIMATE = 10;
|
|
2362
2363
|
function readTake(relArgs) {
|
|
2363
2364
|
if (!isPlainObject(relArgs)) return Infinity;
|
|
2364
2365
|
const obj = relArgs;
|
|
2365
2366
|
if ("take" in obj && typeof obj.take === "number" && obj.take > 0)
|
|
2366
2367
|
return obj.take;
|
|
2368
|
+
if ("take" in obj && obj.take != null && isDynamicParameter(obj.take))
|
|
2369
|
+
return DYNAMIC_TAKE_ESTIMATE;
|
|
2367
2370
|
return Infinity;
|
|
2368
2371
|
}
|
|
2369
2372
|
function hasWhereClause(relArgs) {
|
|
@@ -2377,7 +2380,7 @@ function isListField(field) {
|
|
|
2377
2380
|
function hasPaginationArgs(value) {
|
|
2378
2381
|
if (!isPlainObject(value)) return false;
|
|
2379
2382
|
const obj = value;
|
|
2380
|
-
return "take" in obj && obj.take != null || "skip" in obj && typeof obj.skip === "number" && obj.skip > 0;
|
|
2383
|
+
return "take" in obj && obj.take != null || "skip" in obj && obj.skip != null && (typeof obj.skip === "number" && obj.skip > 0 || isDynamicParameter(obj.skip));
|
|
2381
2384
|
}
|
|
2382
2385
|
function buildCostTree(includeSpec, model, schemas, depth = 0) {
|
|
2383
2386
|
if (depth > LIMITS.MAX_INCLUDE_DEPTH) return [];
|
|
@@ -2499,7 +2502,16 @@ function hasChildPaginationAnywhere(includeSpec, model, schemas, depth = 0) {
|
|
|
2499
2502
|
return false;
|
|
2500
2503
|
}
|
|
2501
2504
|
function pickIncludeStrategy(params) {
|
|
2502
|
-
const {
|
|
2505
|
+
const {
|
|
2506
|
+
includeSpec,
|
|
2507
|
+
model,
|
|
2508
|
+
schemas,
|
|
2509
|
+
method,
|
|
2510
|
+
takeValue,
|
|
2511
|
+
canFlatJoin,
|
|
2512
|
+
hasChildPagination,
|
|
2513
|
+
debug
|
|
2514
|
+
} = params;
|
|
2503
2515
|
if (Object.keys(includeSpec).length === 0) return "where-in";
|
|
2504
2516
|
if (canFlatJoin && hasOnlyToOneRelations(includeSpec, model)) {
|
|
2505
2517
|
if (debug)
|
|
@@ -2519,6 +2531,35 @@ function pickIncludeStrategy(params) {
|
|
|
2519
2531
|
}
|
|
2520
2532
|
const costTree = buildCostTree(includeSpec, model, schemas);
|
|
2521
2533
|
const treeDepth = maxDepthFromTree(costTree);
|
|
2534
|
+
if (hasChildPagination && treeDepth >= 2) {
|
|
2535
|
+
if (debug)
|
|
2536
|
+
console.log(
|
|
2537
|
+
` [strategy] ${model.name}: childPagination + depth=${treeDepth} \u2265 2 \u2192 fallback`
|
|
2538
|
+
);
|
|
2539
|
+
return "fallback";
|
|
2540
|
+
}
|
|
2541
|
+
if (hasChildPagination && treeDepth === 1) {
|
|
2542
|
+
if (anyChildHasWhere(costTree)) {
|
|
2543
|
+
if (debug)
|
|
2544
|
+
console.log(
|
|
2545
|
+
` [strategy] ${model.name}: childPagination + depth=1 + childWhere \u2192 where-in`
|
|
2546
|
+
);
|
|
2547
|
+
return "where-in";
|
|
2548
|
+
}
|
|
2549
|
+
const hasSelectNarrowing = isPlainObject(params.args) && isPlainObject(params.args.select);
|
|
2550
|
+
if (hasSelectNarrowing) {
|
|
2551
|
+
if (debug)
|
|
2552
|
+
console.log(
|
|
2553
|
+
` [strategy] ${model.name}: childPagination + depth=1 + selectNarrowing \u2192 fallback`
|
|
2554
|
+
);
|
|
2555
|
+
return "fallback";
|
|
2556
|
+
}
|
|
2557
|
+
if (debug)
|
|
2558
|
+
console.log(
|
|
2559
|
+
` [strategy] ${model.name}: childPagination + depth=1 \u2192 where-in`
|
|
2560
|
+
);
|
|
2561
|
+
return "where-in";
|
|
2562
|
+
}
|
|
2522
2563
|
if (treeDepth === 1 && anyChildHasWhere(costTree)) {
|
|
2523
2564
|
if (debug)
|
|
2524
2565
|
console.log(` [strategy] ${model.name}: depth-1 + childWhere \u2192 where-in`);
|
|
@@ -4863,14 +4904,17 @@ function constructFinalSql(spec) {
|
|
|
4863
4904
|
if (dialect === "postgres" && hasIncludes) {
|
|
4864
4905
|
const canFlatJoin = canUseFlatJoinForAll(includeSpec, model, schemas);
|
|
4865
4906
|
canUseLateralJoin(includeSpec, model, schemas);
|
|
4866
|
-
hasChildPaginationAnywhere(includeSpec, model, schemas);
|
|
4907
|
+
const hasChildPag = hasChildPaginationAnywhere(includeSpec, model, schemas);
|
|
4867
4908
|
const strategy = pickIncludeStrategy({
|
|
4868
4909
|
includeSpec,
|
|
4869
4910
|
model,
|
|
4870
4911
|
schemas,
|
|
4871
4912
|
method,
|
|
4913
|
+
args,
|
|
4872
4914
|
takeValue,
|
|
4873
|
-
canFlatJoin
|
|
4915
|
+
canFlatJoin,
|
|
4916
|
+
hasChildPagination: hasChildPag
|
|
4917
|
+
});
|
|
4874
4918
|
if (strategy === "flat-join") {
|
|
4875
4919
|
const flatResult = buildFlatJoinSql(spec);
|
|
4876
4920
|
if (flatResult.sql) {
|