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.
@@ -70,7 +70,7 @@ var require_package = __commonJS({
70
70
  "package.json"(exports$1, module) {
71
71
  module.exports = {
72
72
  name: "prisma-sql",
73
- version: "1.80.2",
73
+ version: "1.80.4",
74
74
  description: "Convert Prisma queries to optimized SQL with type safety. 2-7x faster than Prisma Client.",
75
75
  main: "dist/index.cjs",
76
76
  module: "dist/index.js",
@@ -136,7 +136,7 @@ var require_package = __commonJS({
136
136
  author: "multipliedtwice <multipliedtwice@gmail.com>",
137
137
  license: "MIT",
138
138
  dependencies: {
139
- "@dee-wan/schema-parser": "1.4.0",
139
+ "@dee-wan/schema-parser": "1.5.0",
140
140
  "@prisma/generator-helper": "^7.4.1",
141
141
  "@prisma/internals": "^7.4.1",
142
142
  dotenv: "^17.3.1",
@@ -1103,7 +1103,7 @@ function normalizeField(field) {
1103
1103
  return field;
1104
1104
  }
1105
1105
  function getFieldIndices(model) {
1106
- var _a6;
1106
+ var _a6, _b;
1107
1107
  let cached = FIELD_INDICES_CACHE.get(model);
1108
1108
  if (cached) return cached;
1109
1109
  const scalarFields = /* @__PURE__ */ new Map();
@@ -1138,6 +1138,16 @@ function getFieldIndices(model) {
1138
1138
  quotedColumns.set(field.name, quote(columnName));
1139
1139
  }
1140
1140
  }
1141
+ if (pkFields.length === 0) {
1142
+ const compositePk = (_b = model.primaryKey) == null ? void 0 : _b.fields;
1143
+ if (Array.isArray(compositePk)) {
1144
+ for (const f of compositePk) {
1145
+ if (typeof f === "string" && scalarFields.has(f)) {
1146
+ pkFields.push(f);
1147
+ }
1148
+ }
1149
+ }
1150
+ }
1141
1151
  const scalarFieldSet = new Set(scalarNames);
1142
1152
  const relationFieldSet = new Set(relationNames);
1143
1153
  cached = Object.freeze({
@@ -1504,23 +1514,23 @@ function normalizeField2(field) {
1504
1514
  return field;
1505
1515
  }
1506
1516
  function getPrimaryKeyFields(model) {
1517
+ var _a6;
1507
1518
  const cached = getFieldIndices(model).pkFields;
1508
1519
  if (cached.length > 0) return [...cached];
1509
1520
  const idField = model.fields.find(
1510
1521
  (f) => f.name === "id" && !f.isRelation
1511
1522
  );
1512
1523
  if (idField) return ["id"];
1524
+ const compositePk = (_a6 = model.primaryKey) == null ? void 0 : _a6.fields;
1525
+ if (Array.isArray(compositePk) && compositePk.length > 0) {
1526
+ return compositePk.filter((f) => typeof f === "string");
1527
+ }
1513
1528
  throw new Error(
1514
- `Model ${model.name} has no primary key field. Models must have either fields with isId=true or a field named 'id'.`
1529
+ `Model ${model.name} has no primary key field. Models must have either fields with isId=true, a field named 'id', or a composite @@id.`
1515
1530
  );
1516
1531
  }
1517
1532
  function getPrimaryKeyField(model) {
1518
1533
  const fields = getPrimaryKeyFields(model);
1519
- if (fields.length !== 1) {
1520
- throw new Error(
1521
- `getPrimaryKeyField requires single-field PK, but ${model.name} has ${fields.length} fields`
1522
- );
1523
- }
1524
1534
  return fields[0];
1525
1535
  }
1526
1536
  function getFieldByName(model, fieldName) {
@@ -5463,6 +5473,7 @@ function extractNestedToOneRelations(relArgs, relModel, schemaByName) {
5463
5473
  if (isList) continue;
5464
5474
  const nestedModel = schemaByName.get(field.relatedModel);
5465
5475
  if (!nestedModel) continue;
5476
+ if (hasNestedRelationInArgs(entry.value, nestedModel)) continue;
5466
5477
  toOneRelations.push({
5467
5478
  name: entry.name,
5468
5479
  field,