@mikro-orm/knex 6.6.5 → 6.6.6-dev.1

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.6.5",
3
+ "version": "6.6.6-dev.1",
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",
@@ -66,7 +66,7 @@
66
66
  "@mikro-orm/core": "^6.6.5"
67
67
  },
68
68
  "peerDependencies": {
69
- "@mikro-orm/core": "^6.0.0",
69
+ "@mikro-orm/core": "6.6.6-dev.1",
70
70
  "better-sqlite3": "*",
71
71
  "libsql": "*",
72
72
  "mariadb": "*"
@@ -290,7 +290,7 @@ export declare class QueryBuilder<Entity extends object = AnyEntity, RootAlias e
290
290
  getLoggerContext<T extends Dictionary & LoggingOptions = Dictionary>(): T;
291
291
  private fromVirtual;
292
292
  private joinReference;
293
- protected prepareFields<T, U extends string | Knex.Raw>(fields: Field<T>[], type?: 'where' | 'groupBy' | 'sub-query'): U[];
293
+ protected prepareFields<T, U extends string | Knex.Raw>(fields: Field<T>[], type?: 'where' | 'groupBy' | 'sub-query', schema?: string): U[];
294
294
  private init;
295
295
  private getQueryBase;
296
296
  private applyDiscriminatorCondition;
@@ -553,10 +553,11 @@ class QueryBuilder {
553
553
  this._query = {};
554
554
  this.finalize();
555
555
  const qb = this.getQueryBase(processVirtualEntity);
556
+ const schema = this.getSchema(this.mainAlias);
556
557
  const type = this.type ?? enums_1.QueryType.SELECT;
557
558
  qb.__raw = true; // tag it as there is now way to check via `instanceof`
558
559
  core_1.Utils.runIfNotEmpty(() => this.helper.appendQueryCondition(type, this._cond, qb), this._cond && !this._onConflict);
559
- core_1.Utils.runIfNotEmpty(() => qb.groupBy(this.prepareFields(this._groupBy, 'groupBy')), this._groupBy);
560
+ core_1.Utils.runIfNotEmpty(() => qb.groupBy(this.prepareFields(this._groupBy, 'groupBy', schema)), this._groupBy);
560
561
  core_1.Utils.runIfNotEmpty(() => this.helper.appendQueryCondition(type, this._having, qb, undefined, 'having'), this._having);
561
562
  core_1.Utils.runIfNotEmpty(() => {
562
563
  const queryOrder = this.helper.getQueryOrder(type, this._orderBy, this._populateMap);
@@ -991,13 +992,10 @@ class QueryBuilder {
991
992
  }
992
993
  return { prop, key: aliasedName };
993
994
  }
994
- prepareFields(fields, type = 'where') {
995
+ prepareFields(fields, type = 'where', schema) {
995
996
  const ret = [];
996
997
  const getFieldName = (name) => {
997
- if (type === 'groupBy') {
998
- return this.helper.mapper(name, this.type, undefined, null);
999
- }
1000
- return this.helper.mapper(name, this.type);
998
+ return this.helper.mapper(name, this.type, undefined, type === 'groupBy' ? null : undefined, schema);
1001
999
  };
1002
1000
  fields.forEach(field => {
1003
1001
  const rawField = core_1.RawQueryFragment.getKnownFragment(field);
@@ -1104,9 +1102,9 @@ class QueryBuilder {
1104
1102
  }
1105
1103
  switch (this.type) {
1106
1104
  case enums_1.QueryType.SELECT:
1107
- qb.select(this.prepareFields(this._fields));
1105
+ qb.select(this.prepareFields(this._fields, 'where', schema));
1108
1106
  if (this._distinctOn) {
1109
- qb.distinctOn(this.prepareFields(this._distinctOn));
1107
+ qb.distinctOn(this.prepareFields(this._distinctOn, 'where', schema));
1110
1108
  }
1111
1109
  else if (this.flags.has(core_1.QueryFlag.DISTINCT)) {
1112
1110
  qb.distinct();
@@ -1115,7 +1113,7 @@ class QueryBuilder {
1115
1113
  break;
1116
1114
  case enums_1.QueryType.COUNT: {
1117
1115
  const m = this.flags.has(core_1.QueryFlag.DISTINCT) ? 'countDistinct' : 'count';
1118
- qb[m]({ count: this._fields.map(f => this.helper.mapper(f, this.type)) });
1116
+ qb[m]({ count: this._fields.map(f => this.helper.mapper(f, this.type, undefined, undefined, schema)) });
1119
1117
  this.helper.processJoins(qb, this._joins, joinSchema);
1120
1118
  break;
1121
1119
  }
@@ -1328,7 +1326,8 @@ class QueryBuilder {
1328
1326
  });
1329
1327
  }
1330
1328
  wrapPaginateSubQuery(meta) {
1331
- const pks = this.prepareFields(meta.primaryKeys, 'sub-query');
1329
+ const schema = this.getSchema(this.mainAlias);
1330
+ const pks = this.prepareFields(meta.primaryKeys, 'sub-query', schema);
1332
1331
  const subQuery = this.clone(['_orderBy', '_fields', 'lockMode', 'lockTableAliases']).select(pks).groupBy(pks).limit(this._limit);
1333
1332
  // revert the on conditions added via populateWhere, we want to apply those only once
1334
1333
  for (const join of Object.values(subQuery._joins)) {