prisma-sql 1.75.11 → 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.
@@ -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.75.11",
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",
@@ -146,7 +146,6 @@ var require_package = __commonJS({
146
146
  "@faker-js/faker": "^10.2.0",
147
147
  "@prisma/adapter-better-sqlite3": "^7.4.0",
148
148
  "@prisma/adapter-pg": "^7.4.0",
149
- "@prisma/client": "7.4.0",
150
149
  "@semantic-release/changelog": "^6.0.3",
151
150
  "@semantic-release/git": "^10.0.1",
152
151
  "@types/better-sqlite3": "^7.6.13",
@@ -155,11 +154,12 @@ var require_package = __commonJS({
155
154
  "better-sqlite3": "^12.6.2",
156
155
  "drizzle-kit": "^0.31.8",
157
156
  "drizzle-orm": "^0.45.1",
158
- prisma: "7.4.0",
159
157
  tsup: "^8.5.1",
160
158
  tsx: "^4.21.0",
161
159
  typescript: "^5.9.3",
162
- vitest: "^4.0.18"
160
+ vitest: "^4.0.18",
161
+ "@prisma/client": "7.4.0",
162
+ prisma: "7.4.0"
163
163
  },
164
164
  engines: {
165
165
  node: ">=16.0.0"
@@ -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 { includeSpec, model, schemas, method, takeValue, canFlatJoin, debug } = params;
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) {
@@ -7856,6 +7900,8 @@ function generateExtension(runtimeImportPath) {
7856
7900
  postgresClient: postgres,
7857
7901
  })
7858
7902
 
7903
+ const originalTransaction = prisma.$transaction.bind(prisma)
7904
+
7859
7905
  interface ModelContext {
7860
7906
  name?: string
7861
7907
  $name?: string
@@ -8260,9 +8306,15 @@ function generateExtension(runtimeImportPath) {
8260
8306
  }
8261
8307
 
8262
8308
  async function transaction(
8263
- queries: TransactionQuery[] | any[],
8309
+ queriesOrFn: TransactionQuery[] | any[] | ((...args: any[]) => Promise<any>),
8264
8310
  options?: TransactionOptions,
8265
8311
  ): Promise<unknown[]> {
8312
+ if (typeof queriesOrFn === 'function') {
8313
+ return originalTransaction(queriesOrFn, options)
8314
+ }
8315
+
8316
+ const queries = queriesOrFn
8317
+
8266
8318
  if (!queries || queries.length === 0) {
8267
8319
  return []
8268
8320
  }