prisma-sql 1.80.2 → 1.80.4
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 +20 -9
- package/dist/generator.cjs.map +1 -1
- package/dist/generator.js +20 -9
- package/dist/generator.js.map +1 -1
- package/dist/index.cjs +18 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +18 -7
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1038,7 +1038,7 @@ function normalizeField(field) {
|
|
|
1038
1038
|
return field;
|
|
1039
1039
|
}
|
|
1040
1040
|
function getFieldIndices(model) {
|
|
1041
|
-
var _a6;
|
|
1041
|
+
var _a6, _b;
|
|
1042
1042
|
let cached = FIELD_INDICES_CACHE.get(model);
|
|
1043
1043
|
if (cached) return cached;
|
|
1044
1044
|
const scalarFields = /* @__PURE__ */ new Map();
|
|
@@ -1073,6 +1073,16 @@ function getFieldIndices(model) {
|
|
|
1073
1073
|
quotedColumns.set(field.name, quote(columnName));
|
|
1074
1074
|
}
|
|
1075
1075
|
}
|
|
1076
|
+
if (pkFields.length === 0) {
|
|
1077
|
+
const compositePk = (_b = model.primaryKey) == null ? void 0 : _b.fields;
|
|
1078
|
+
if (Array.isArray(compositePk)) {
|
|
1079
|
+
for (const f of compositePk) {
|
|
1080
|
+
if (typeof f === "string" && scalarFields.has(f)) {
|
|
1081
|
+
pkFields.push(f);
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1076
1086
|
const scalarFieldSet = new Set(scalarNames);
|
|
1077
1087
|
const relationFieldSet = new Set(relationNames);
|
|
1078
1088
|
cached = Object.freeze({
|
|
@@ -1462,23 +1472,23 @@ function normalizeField2(field) {
|
|
|
1462
1472
|
return field;
|
|
1463
1473
|
}
|
|
1464
1474
|
function getPrimaryKeyFields(model) {
|
|
1475
|
+
var _a6;
|
|
1465
1476
|
const cached = getFieldIndices(model).pkFields;
|
|
1466
1477
|
if (cached.length > 0) return [...cached];
|
|
1467
1478
|
const idField = model.fields.find(
|
|
1468
1479
|
(f) => f.name === "id" && !f.isRelation
|
|
1469
1480
|
);
|
|
1470
1481
|
if (idField) return ["id"];
|
|
1482
|
+
const compositePk = (_a6 = model.primaryKey) == null ? void 0 : _a6.fields;
|
|
1483
|
+
if (Array.isArray(compositePk) && compositePk.length > 0) {
|
|
1484
|
+
return compositePk.filter((f) => typeof f === "string");
|
|
1485
|
+
}
|
|
1471
1486
|
throw new Error(
|
|
1472
|
-
`Model ${model.name} has no primary key field. Models must have either fields with isId=true
|
|
1487
|
+
`Model ${model.name} has no primary key field. Models must have either fields with isId=true, a field named 'id', or a composite @@id.`
|
|
1473
1488
|
);
|
|
1474
1489
|
}
|
|
1475
1490
|
function getPrimaryKeyField(model) {
|
|
1476
1491
|
const fields = getPrimaryKeyFields(model);
|
|
1477
|
-
if (fields.length !== 1) {
|
|
1478
|
-
throw new Error(
|
|
1479
|
-
`getPrimaryKeyField requires single-field PK, but ${model.name} has ${fields.length} fields`
|
|
1480
|
-
);
|
|
1481
|
-
}
|
|
1482
1492
|
return fields[0];
|
|
1483
1493
|
}
|
|
1484
1494
|
function getFieldByName(model, fieldName) {
|
|
@@ -5489,6 +5499,7 @@ function extractNestedToOneRelations(relArgs, relModel, schemaByName) {
|
|
|
5489
5499
|
if (isList) continue;
|
|
5490
5500
|
const nestedModel = schemaByName.get(field.relatedModel);
|
|
5491
5501
|
if (!nestedModel) continue;
|
|
5502
|
+
if (hasNestedRelationInArgs(entry.value, nestedModel)) continue;
|
|
5492
5503
|
toOneRelations.push({
|
|
5493
5504
|
name: entry.name,
|
|
5494
5505
|
field,
|