prisma-sql 1.72.0 → 1.74.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.js CHANGED
@@ -2312,7 +2312,7 @@ var require_package = __commonJS({
2312
2312
  "package.json"(exports$1, module) {
2313
2313
  module.exports = {
2314
2314
  name: "prisma-sql",
2315
- version: "1.72.0",
2315
+ version: "1.74.0",
2316
2316
  description: "Convert Prisma queries to optimized SQL with type safety. 2-7x faster than Prisma Client.",
2317
2317
  main: "dist/index.cjs",
2318
2318
  module: "dist/index.js",
@@ -6869,12 +6869,12 @@ function resolveCountSelect(countSelectRaw, model) {
6869
6869
  return null;
6870
6870
  }
6871
6871
  function buildIncludeColumns(spec) {
6872
- var _a3, _b;
6872
+ var _a3, _b, _c, _d, _e;
6873
6873
  const { select: select2, includes, dialect, model, schemas, from, params } = spec;
6874
6874
  const baseSelect = (select2 != null ? select2 : "").trim();
6875
6875
  let countCols = "";
6876
6876
  let countJoins = [];
6877
- const countSelectRaw = (_b = (_a3 = spec.args) == null ? void 0 : _a3.select) == null ? void 0 : _b[COUNT_SELECT_KEY];
6877
+ const countSelectRaw = (_e = (_b = (_a3 = spec.args) == null ? void 0 : _a3.select) == null ? void 0 : _b[COUNT_SELECT_KEY]) != null ? _e : (_d = (_c = spec.args) == null ? void 0 : _c.include) == null ? void 0 : _d[COUNT_SELECT_KEY];
6878
6878
  if (countSelectRaw) {
6879
6879
  const resolvedCountSelect = resolveCountSelect(countSelectRaw, model);
6880
6880
  if (resolvedCountSelect && Object.keys(resolvedCountSelect).length > 0) {
@@ -7009,7 +7009,7 @@ function extractIncludeSpec(args) {
7009
7009
  const includeSpec = {};
7010
7010
  if (args.include && isPlainObject(args.include)) {
7011
7011
  for (const [key, value] of Object.entries(args.include)) {
7012
- if (value !== false) {
7012
+ if (value !== false && key !== COUNT_SELECT_KEY) {
7013
7013
  includeSpec[key] = value;
7014
7014
  }
7015
7015
  }
@@ -7428,14 +7428,18 @@ function buildNestedToOneJoins(relations, baseAlias, baseModel, aliasGen, dialec
7428
7428
  }
7429
7429
  return { joins, aliasMap };
7430
7430
  }
7431
- function buildNestedToOneSelects(relations, aliasMap) {
7431
+ function buildNestedToOneSelects(relations, aliasMap, dialect) {
7432
7432
  const selects = [];
7433
7433
  for (const rel of relations) {
7434
7434
  const relAlias = aliasMap.get(rel.name);
7435
7435
  if (!relAlias) continue;
7436
7436
  const relSelect = buildRelationSelect(rel.args, rel.model, relAlias);
7437
7437
  if (!relSelect || relSelect.trim().length === 0) continue;
7438
- selects.push(`${sqlStringLiteral(rel.name)}, ${relSelect}`);
7438
+ const jsonExpr = jsonBuildObject(relSelect, dialect);
7439
+ const pkField = getPrimaryKeyField(rel.model);
7440
+ const pkCol = `${relAlias}.${quoteColumn(rel.model, pkField)}`;
7441
+ const nullSafeExpr = `CASE WHEN ${pkCol} IS NOT NULL THEN ${jsonExpr} ELSE NULL END`;
7442
+ selects.push(`${sqlStringLiteral(rel.name)}, ${nullSafeExpr}`);
7439
7443
  }
7440
7444
  return selects;
7441
7445
  }
@@ -7513,7 +7517,11 @@ function buildSelectWithNestedIncludes(relArgs, relModel, relAlias, ctx) {
7513
7517
  ctx.dialect
7514
7518
  );
7515
7519
  const baseSelect = buildRelationSelect(relArgs, relModel, relAlias);
7516
- const nestedSelects = buildNestedToOneSelects(nestedToOnes, aliasMap);
7520
+ const nestedSelects = buildNestedToOneSelects(
7521
+ nestedToOnes,
7522
+ aliasMap,
7523
+ ctx.dialect
7524
+ );
7517
7525
  const allParts = [];
7518
7526
  if (baseSelect && baseSelect.trim().length > 0) {
7519
7527
  allParts.push(baseSelect);