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