@mikro-orm/knex 5.8.11-dev.9 → 5.9.1-dev.0

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.
@@ -21,7 +21,6 @@ export declare abstract class AbstractSqlDriver<Connection extends AbstractSqlCo
21
21
  protected wrapVirtualExpressionInSubquery<T extends object>(meta: EntityMetadata<T>, expression: string, where: FilterQuery<T>, options: FindOptions<T, any>, type: QueryType): Promise<T[] | number>;
22
22
  mapResult<T extends object>(result: EntityData<T>, meta: EntityMetadata<T>, populate?: PopulateOptions<T>[], qb?: QueryBuilder<T>, map?: Dictionary): EntityData<T> | null;
23
23
  private mapJoinedProps;
24
- private appendToCollection;
25
24
  count<T extends object>(entityName: string, where: any, options?: CountOptions<T>): Promise<number>;
26
25
  nativeInsert<T extends object>(entityName: string, data: EntityDictionary<T>, options?: NativeInsertUpdateOptions<T>): Promise<QueryResult<T>>;
27
26
  nativeInsertMany<T extends object>(entityName: string, data: EntityDictionary<T>[], options?: NativeInsertUpdateManyOptions<T>): Promise<QueryResult<T>>;
@@ -186,7 +186,7 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
186
186
  });
187
187
  if ([core_1.ReferenceType.MANY_TO_MANY, core_1.ReferenceType.ONE_TO_MANY].includes(relation.reference)) {
188
188
  result[relation.name] = result[relation.name] || [];
189
- this.appendToCollection(meta2, result[relation.name], relationPojo);
189
+ result[relation.name].push(relationPojo);
190
190
  }
191
191
  else {
192
192
  result[relation.name] = relationPojo;
@@ -195,17 +195,6 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
195
195
  this.mapJoinedProps(relationPojo, meta2, populateChildren, qb, root, map, path);
196
196
  });
197
197
  }
198
- appendToCollection(meta, collection, relationPojo) {
199
- if (collection.length === 0) {
200
- return void collection.push(relationPojo);
201
- }
202
- const last = collection[collection.length - 1];
203
- const pk1 = core_1.Utils.getCompositeKeyHash(last, meta);
204
- const pk2 = core_1.Utils.getCompositeKeyHash(relationPojo, meta);
205
- if (pk1 !== pk2) {
206
- collection.push(relationPojo);
207
- }
208
- }
209
198
  async count(entityName, where, options = {}) {
210
199
  const meta = this.metadata.find(entityName);
211
200
  if (meta?.virtual) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/knex",
3
- "version": "5.8.11-dev.9",
3
+ "version": "5.9.1-dev.0",
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,12 +63,12 @@
63
63
  "sqlstring": "2.3.3"
64
64
  },
65
65
  "devDependencies": {
66
- "@mikro-orm/core": "^5.8.10"
66
+ "@mikro-orm/core": "^5.9.0"
67
67
  },
68
68
  "peerDependencies": {
69
- "@mikro-orm/core": "5.8.11-dev.9",
70
- "@mikro-orm/entity-generator": "5.8.11-dev.9",
71
- "@mikro-orm/migrations": "5.8.11-dev.9",
69
+ "@mikro-orm/core": "5.9.1-dev.0",
70
+ "@mikro-orm/entity-generator": "5.9.1-dev.0",
71
+ "@mikro-orm/migrations": "5.9.1-dev.0",
72
72
  "better-sqlite3": "*",
73
73
  "mssql": "*",
74
74
  "mysql": "*",
@@ -782,6 +782,8 @@ class QueryBuilder {
782
782
  getQueryBase() {
783
783
  const qb = this.getKnex();
784
784
  const schema = this.getSchema(this.mainAlias);
785
+ // Joined tables doesn't need to belong to the same schema as the main table
786
+ const joinSchema = this._schema ?? this.em?.schema ?? schema;
785
787
  if (schema) {
786
788
  qb.withSchema(schema);
787
789
  }
@@ -800,12 +802,12 @@ class QueryBuilder {
800
802
  else if (this.flags.has(core_1.QueryFlag.DISTINCT)) {
801
803
  qb.distinct();
802
804
  }
803
- this.helper.processJoins(qb, this._joins, schema);
805
+ this.helper.processJoins(qb, this._joins, joinSchema);
804
806
  break;
805
807
  case enums_1.QueryType.COUNT: {
806
808
  const m = this.flags.has(core_1.QueryFlag.DISTINCT) ? 'countDistinct' : 'count';
807
809
  qb[m]({ count: this._fields.map(f => this.helper.mapper(f, this.type)) });
808
- this.helper.processJoins(qb, this._joins, schema);
810
+ this.helper.processJoins(qb, this._joins, joinSchema);
809
811
  break;
810
812
  }
811
813
  case enums_1.QueryType.INSERT:
@@ -998,7 +1000,7 @@ class QueryBuilder {
998
1000
  getSchema(alias) {
999
1001
  const { metadata } = alias;
1000
1002
  const metaSchema = metadata?.schema && metadata.schema !== '*' ? metadata.schema : undefined;
1001
- return this._schema ?? metaSchema ?? this.em?.config.get('schema');
1003
+ return this._schema ?? metaSchema ?? this.em?.schema ?? this.em?.config.get('schema');
1002
1004
  }
1003
1005
  createAlias(entityName, aliasName, subQuery) {
1004
1006
  const metadata = this.metadata.find(entityName);
@@ -133,7 +133,7 @@ class QueryBuilderHelper {
133
133
  return {
134
134
  prop, type, cond, ownerAlias, alias,
135
135
  table: this.getTableName(prop.type),
136
- schema: this.driver.getSchemaName(prop.targetMeta),
136
+ schema: prop.targetMeta?.schema === '*' ? '*' : this.driver.getSchemaName(prop.targetMeta),
137
137
  joinColumns: prop.referencedColumnNames,
138
138
  primaryKeys: prop.fieldNames,
139
139
  };
@@ -150,7 +150,7 @@ class QueryBuilderHelper {
150
150
  primaryKeys: prop.referencedColumnNames,
151
151
  cond: {},
152
152
  table: pivotMeta.tableName,
153
- schema: this.driver.getSchemaName(pivotMeta),
153
+ schema: prop.targetMeta?.schema === '*' ? '*' : this.driver.getSchemaName(pivotMeta),
154
154
  path: path.endsWith('[pivot]') ? path : `${path}[pivot]`,
155
155
  },
156
156
  };
@@ -393,7 +393,11 @@ class QueryBuilderHelper {
393
393
  processObjectSubCondition(cond, key, qb, method, m, type) {
394
394
  // grouped condition for one field
395
395
  let value = cond[key];
396
- if (core_1.Utils.getObjectKeysSize(value) > 1) {
396
+ const size = core_1.Utils.getObjectKeysSize(value);
397
+ if (core_1.Utils.isPlainObject(value) && size === 0) {
398
+ return;
399
+ }
400
+ if (size > 1) {
397
401
  const subCondition = Object.entries(value).map(([subKey, subValue]) => ({ [key]: { [subKey]: subValue } }));
398
402
  return subCondition.forEach(sub => this.appendQueryCondition(type, sub, qb, '$and', method));
399
403
  }
@@ -402,6 +406,7 @@ class QueryBuilderHelper {
402
406
  }
403
407
  // operators
404
408
  const op = Object.keys(core_1.QueryOperator).find(op => op in value);
409
+ /* istanbul ignore next */
405
410
  if (!op) {
406
411
  throw new Error(`Invalid query condition: ${(0, util_1.inspect)(cond)}`);
407
412
  }