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