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