@mikro-orm/knex 6.1.12-dev.8 → 6.1.12

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/knex",
3
- "version": "6.1.12-dev.8",
3
+ "version": "6.1.12",
4
4
  "description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.",
5
5
  "main": "index.js",
6
6
  "module": "index.mjs",
@@ -63,9 +63,9 @@
63
63
  "sqlstring": "2.3.3"
64
64
  },
65
65
  "devDependencies": {
66
- "@mikro-orm/core": "^6.1.11"
66
+ "@mikro-orm/core": "^6.1.12"
67
67
  },
68
68
  "peerDependencies": {
69
- "@mikro-orm/core": "6.1.12-dev.8"
69
+ "@mikro-orm/core": "^6.0.0"
70
70
  }
71
71
  }
@@ -52,6 +52,9 @@ class ObjectCriteriaNode extends CriteriaNode_1.CriteriaNode {
52
52
  [core_1.Utils.getPrimaryKeyHash(primaryKeys)]: { [op]: sub.getKnexQuery() },
53
53
  });
54
54
  }
55
+ if ($and.length === 1) {
56
+ return $and[0];
57
+ }
55
58
  return { $and };
56
59
  }
57
60
  alias = this.autoJoin(qb, ownerAlias);
@@ -155,15 +158,18 @@ class ObjectCriteriaNode extends CriteriaNode_1.CriteriaNode {
155
158
  }
156
159
  }
157
160
  inlineCondition(key, o, value) {
158
- if (key in o) {
159
- const $and = o.$and ?? [];
160
- $and.push({ [key]: o[key] }, { [key]: value });
161
- delete o[key];
162
- o.$and = $and;
163
- }
164
- else {
161
+ if (!(key in o)) {
165
162
  o[key] = value;
163
+ return;
164
+ }
165
+ if (key === '$and') {
166
+ o.$and.push({ [key]: value });
167
+ return;
166
168
  }
169
+ const $and = o.$and ?? [];
170
+ $and.push({ [key]: o[key] }, { [key]: value });
171
+ delete o[key];
172
+ o.$and = $and;
167
173
  }
168
174
  shouldAutoJoin(qb, nestedAlias) {
169
175
  if (!this.prop || !this.parent) {
@@ -465,7 +465,7 @@ class DatabaseTable {
465
465
  }
466
466
  getForeignKeyDeclaration(fk, namingStrategy, schemaHelper, fkIndex, nullable, propNameBase) {
467
467
  const prop = this.getPropertyName(namingStrategy, propNameBase, fk);
468
- const kind = (fkIndex.unique && !fkIndex.primary) ? this.getReferenceKind(fk, fkIndex) : this.getReferenceKind(fk);
468
+ const kind = (fkIndex?.unique && !fkIndex.primary) ? this.getReferenceKind(fk, fkIndex) : this.getReferenceKind(fk);
469
469
  const type = this.getPropertyTypeForForeignKey(namingStrategy, fk);
470
470
  const fkOptions = {};
471
471
  fkOptions.fieldNames = fk.columnNames;
@@ -497,9 +497,9 @@ class DatabaseTable {
497
497
  kind,
498
498
  ...columnOptions,
499
499
  nullable,
500
- primary: fkIndex.primary || !fk.columnNames.some(columnName => !this.getPrimaryKey()?.columnNames.includes(columnName)),
501
- index: !fkIndex.unique ? fkIndex.keyName : undefined,
502
- unique: (fkIndex.unique && !fkIndex.primary) ? fkIndex.keyName : undefined,
500
+ primary: fkIndex?.primary || !fk.columnNames.some(columnName => !this.getPrimaryKey()?.columnNames.includes(columnName)),
501
+ index: !fkIndex?.unique ? fkIndex?.keyName : undefined,
502
+ unique: (fkIndex?.unique && !fkIndex.primary) ? fkIndex.keyName : undefined,
503
503
  ...fkOptions,
504
504
  };
505
505
  }
@@ -187,8 +187,12 @@ class SchemaHelper {
187
187
  mapForeignKeys(fks, tableName, schemaName) {
188
188
  return fks.reduce((ret, fk) => {
189
189
  if (ret[fk.constraint_name]) {
190
- ret[fk.constraint_name].columnNames.push(fk.column_name);
191
- ret[fk.constraint_name].referencedColumnNames.push(fk.referenced_column_name);
190
+ if (!ret[fk.constraint_name].columnNames.includes(fk.column_name)) {
191
+ ret[fk.constraint_name].columnNames.push(fk.column_name);
192
+ }
193
+ if (!ret[fk.constraint_name].referencedColumnNames.includes(fk.referenced_column_name)) {
194
+ ret[fk.constraint_name].referencedColumnNames.push(fk.referenced_column_name);
195
+ }
192
196
  }
193
197
  else {
194
198
  ret[fk.constraint_name] = {