@mikro-orm/knex 5.8.11-dev.7 → 5.8.11-dev.9

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": "5.8.11-dev.7",
3
+ "version": "5.8.11-dev.9",
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,9 +66,9 @@
66
66
  "@mikro-orm/core": "^5.8.10"
67
67
  },
68
68
  "peerDependencies": {
69
- "@mikro-orm/core": "5.8.11-dev.7",
70
- "@mikro-orm/entity-generator": "5.8.11-dev.7",
71
- "@mikro-orm/migrations": "5.8.11-dev.7",
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",
72
72
  "better-sqlite3": "*",
73
73
  "mssql": "*",
74
74
  "mysql": "*",
@@ -473,7 +473,8 @@ class QueryBuilder {
473
473
  if (cached?.data) {
474
474
  return cached.data;
475
475
  }
476
- const type = this.connectionType || (method === 'run' ? 'write' : 'read');
476
+ const write = method === 'run' || !this.platform.getConfig().get('preferReadReplicas');
477
+ const type = this.connectionType || (write ? 'write' : 'read');
477
478
  const res = await this.driver.getConnection(type).execute(query.sql, query.bindings, method, this.context);
478
479
  const meta = this.mainAlias.metadata;
479
480
  if (!options.mapResults || !meta) {
@@ -689,6 +690,12 @@ class QueryBuilder {
689
690
  }
690
691
  prepareFields(fields, type = 'where') {
691
692
  const ret = [];
693
+ const getFieldName = (name) => {
694
+ if (type === 'groupBy') {
695
+ return this.helper.mapper(name, this.type, undefined, null);
696
+ }
697
+ return this.helper.mapper(name, this.type);
698
+ };
692
699
  fields.forEach(field => {
693
700
  if (!core_1.Utils.isString(field)) {
694
701
  return ret.push(field);
@@ -705,19 +712,18 @@ class QueryBuilder {
705
712
  }
706
713
  if (prop?.embedded) {
707
714
  const name = this._aliases[a] ? `${a}.${prop.fieldNames[0]}` : prop.fieldNames[0];
708
- const fieldName = this.helper.mapper(name, this.type);
709
- ret.push(fieldName);
715
+ ret.push(getFieldName(name));
710
716
  return;
711
717
  }
712
718
  if (prop?.reference === core_1.ReferenceType.EMBEDDED) {
713
719
  if (prop.object) {
714
- ret.push(this.helper.mapper(prop.fieldNames[0], this.type));
720
+ ret.push(getFieldName(prop.fieldNames[0]));
715
721
  }
716
722
  else {
717
723
  const nest = (prop) => {
718
724
  for (const childProp of Object.values(prop.embeddedProps)) {
719
725
  if (childProp.fieldNames) {
720
- ret.push(this.helper.mapper(childProp.fieldNames[0], this.type));
726
+ ret.push(getFieldName(childProp.fieldNames[0]));
721
727
  }
722
728
  else {
723
729
  nest(childProp);
@@ -729,10 +735,10 @@ class QueryBuilder {
729
735
  return;
730
736
  }
731
737
  if (prop && prop.fieldNames.length > 1) {
732
- ret.push(...prop.fieldNames.map(f => this.helper.mapper(f, this.type)));
738
+ ret.push(...prop.fieldNames.map(f => getFieldName(f)));
733
739
  return;
734
740
  }
735
- ret.push(this.helper.mapper(field, this.type));
741
+ ret.push(getFieldName(field));
736
742
  });
737
743
  const meta = this.mainAlias.metadata;
738
744
  /* istanbul ignore next */