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/index.cjs CHANGED
@@ -4592,12 +4592,12 @@ function resolveCountSelect(countSelectRaw, model) {
4592
4592
  return null;
4593
4593
  }
4594
4594
  function buildIncludeColumns(spec) {
4595
- var _a3, _b;
4595
+ var _a3, _b, _c, _d, _e;
4596
4596
  const { select, includes, dialect, model, schemas, from, params } = spec;
4597
4597
  const baseSelect = (select != null ? select : "").trim();
4598
4598
  let countCols = "";
4599
4599
  let countJoins = [];
4600
- const countSelectRaw = (_b = (_a3 = spec.args) == null ? void 0 : _a3.select) == null ? void 0 : _b[COUNT_SELECT_KEY];
4600
+ 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];
4601
4601
  if (countSelectRaw) {
4602
4602
  const resolvedCountSelect = resolveCountSelect(countSelectRaw, model);
4603
4603
  if (resolvedCountSelect && Object.keys(resolvedCountSelect).length > 0) {
@@ -4732,7 +4732,7 @@ function extractIncludeSpec(args) {
4732
4732
  const includeSpec = {};
4733
4733
  if (args.include && isPlainObject(args.include)) {
4734
4734
  for (const [key, value] of Object.entries(args.include)) {
4735
- if (value !== false) {
4735
+ if (value !== false && key !== COUNT_SELECT_KEY) {
4736
4736
  includeSpec[key] = value;
4737
4737
  }
4738
4738
  }
@@ -5151,14 +5151,18 @@ function buildNestedToOneJoins(relations, baseAlias, baseModel, aliasGen, dialec
5151
5151
  }
5152
5152
  return { joins, aliasMap };
5153
5153
  }
5154
- function buildNestedToOneSelects(relations, aliasMap) {
5154
+ function buildNestedToOneSelects(relations, aliasMap, dialect) {
5155
5155
  const selects = [];
5156
5156
  for (const rel of relations) {
5157
5157
  const relAlias = aliasMap.get(rel.name);
5158
5158
  if (!relAlias) continue;
5159
5159
  const relSelect = buildRelationSelect(rel.args, rel.model, relAlias);
5160
5160
  if (!relSelect || relSelect.trim().length === 0) continue;
5161
- selects.push(`${sqlStringLiteral(rel.name)}, ${relSelect}`);
5161
+ const jsonExpr = jsonBuildObject(relSelect, dialect);
5162
+ const pkField = getPrimaryKeyField(rel.model);
5163
+ const pkCol = `${relAlias}.${quoteColumn(rel.model, pkField)}`;
5164
+ const nullSafeExpr = `CASE WHEN ${pkCol} IS NOT NULL THEN ${jsonExpr} ELSE NULL END`;
5165
+ selects.push(`${sqlStringLiteral(rel.name)}, ${nullSafeExpr}`);
5162
5166
  }
5163
5167
  return selects;
5164
5168
  }
@@ -5236,7 +5240,11 @@ function buildSelectWithNestedIncludes(relArgs, relModel, relAlias, ctx) {
5236
5240
  ctx.dialect
5237
5241
  );
5238
5242
  const baseSelect = buildRelationSelect(relArgs, relModel, relAlias);
5239
- const nestedSelects = buildNestedToOneSelects(nestedToOnes, aliasMap);
5243
+ const nestedSelects = buildNestedToOneSelects(
5244
+ nestedToOnes,
5245
+ aliasMap,
5246
+ ctx.dialect
5247
+ );
5240
5248
  const allParts = [];
5241
5249
  if (baseSelect && baseSelect.trim().length > 0) {
5242
5250
  allParts.push(baseSelect);