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