@mikro-orm/knex 6.5.3-dev.9 → 6.5.4-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.
@@ -56,7 +56,7 @@ export declare abstract class AbstractSqlDriver<Connection extends AbstractSqlCo
56
56
  strategy?: Options['loadStrategy'];
57
57
  populateWhere?: FindOptions<any>['populateWhere'];
58
58
  populateFilter?: FindOptions<any>['populateFilter'];
59
- }, parentTableAlias?: string, parentJoinPath?: string, count?: boolean): Field<T>[];
59
+ }, parentTableAlias?: string, parentJoinPath?: string): Field<T>[];
60
60
  /**
61
61
  * @internal
62
62
  */
@@ -77,5 +77,5 @@ export declare abstract class AbstractSqlDriver<Connection extends AbstractSqlCo
77
77
  protected normalizeFields<T extends object>(fields: Field<T>[], prefix?: string): string[];
78
78
  protected processField<T extends object>(meta: EntityMetadata<T>, prop: EntityProperty<T> | undefined, field: string, ret: Field<T>[], populate: PopulateOptions<T>[], joinedProps: PopulateOptions<T>[], qb: QueryBuilder<T, any, any, any>): void;
79
79
  protected isPopulated<T extends object>(meta: EntityMetadata<T>, prop: EntityProperty<T>, hint: PopulateOptions<T>, name?: string): boolean;
80
- protected buildFields<T extends object>(meta: EntityMetadata<T>, populate: PopulateOptions<T>[], joinedProps: PopulateOptions<T>[], qb: QueryBuilder<T, any, any, any>, alias: string, options: Pick<FindOptions<T, any, any, any>, 'strategy' | 'fields' | 'exclude'>, count?: boolean): Field<T>[];
80
+ protected buildFields<T extends object>(meta: EntityMetadata<T>, populate: PopulateOptions<T>[], joinedProps: PopulateOptions<T>[], qb: QueryBuilder<T, any, any, any>, alias: string, options: Pick<FindOptions<T, any, any, any>, 'strategy' | 'fields' | 'exclude'>): Field<T>[];
81
81
  }
@@ -313,15 +313,20 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
313
313
  });
314
314
  }
315
315
  async count(entityName, where, options = {}) {
316
- const meta = this.metadata.find(entityName);
317
- if (meta?.virtual) {
316
+ const meta = this.metadata.get(entityName);
317
+ if (meta.virtual) {
318
318
  return this.countVirtual(entityName, where, options);
319
319
  }
320
- const joinedProps = meta ? this.joinedProps(meta, options.populate ?? []) : [];
321
- const populateWhere = meta ? this.buildPopulateWhere(meta, joinedProps, options) : undefined;
322
- const populate = options.populate ?? [];
323
- const qb = this.createQueryBuilder(entityName, options.ctx, options.connectionType, false, options.logging)
324
- .indexHint(options.indexHint)
320
+ options = { populate: [], ...options };
321
+ const populate = options.populate;
322
+ const joinedProps = this.joinedProps(meta, populate, options);
323
+ const qb = this.createQueryBuilder(entityName, options.ctx, options.connectionType, false, options.logging);
324
+ const populateWhere = this.buildPopulateWhere(meta, joinedProps, options);
325
+ if (meta && !core_1.Utils.isEmpty(populate)) {
326
+ this.buildFields(meta, populate, joinedProps, qb, qb.alias, options);
327
+ }
328
+ qb.__populateWhere = options._populateWhere;
329
+ qb.indexHint(options.indexHint)
325
330
  .comment(options.comments)
326
331
  .hintComment(options.hintComments)
327
332
  .groupBy(options.groupBy)
@@ -329,9 +334,6 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
329
334
  .populate(populate, joinedProps.length > 0 ? populateWhere : undefined, joinedProps.length > 0 ? options.populateFilter : undefined)
330
335
  .withSchema(this.getSchemaName(meta, options))
331
336
  .where(where);
332
- if (meta && !core_1.Utils.isEmpty(populate)) {
333
- this.buildFields(meta, populate, joinedProps, qb, qb.alias, options, true);
334
- }
335
337
  if (options.em) {
336
338
  await qb.applyJoinedFilters(options.em, options.filters);
337
339
  }
@@ -915,7 +917,7 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
915
917
  }
916
918
  return res;
917
919
  }
918
- getFieldsForJoinedLoad(qb, meta, explicitFields, exclude, populate = [], options, parentTableAlias, parentJoinPath, count) {
920
+ getFieldsForJoinedLoad(qb, meta, explicitFields, exclude, populate = [], options, parentTableAlias, parentJoinPath) {
919
921
  const fields = [];
920
922
  const joinedProps = this.joinedProps(meta, populate, options);
921
923
  const shouldHaveColumn = (meta, prop, populate, fields) => {
@@ -942,9 +944,6 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
942
944
  if (ref && !hint.filter && (prop.kind === core_1.ReferenceKind.MANY_TO_ONE || (prop.kind === core_1.ReferenceKind.ONE_TO_ONE && prop.owner))) {
943
945
  continue;
944
946
  }
945
- if (count && (!options?.populateFilter || !options.populateFilter[prop.name])) {
946
- continue;
947
- }
948
947
  const meta2 = this.metadata.find(prop.type);
949
948
  const pivotRefJoin = prop.kind === core_1.ReferenceKind.MANY_TO_MANY && ref;
950
949
  const tableAlias = qb.getNextAlias(prop.name);
@@ -966,7 +965,7 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
966
965
  fields.push(...prop.joinColumns.map(col => qb.helper.mapper(`${tableAlias}.${col}`, qb.type, undefined, `${tableAlias}__${col}`)), ...prop.inverseJoinColumns.map(col => qb.helper.mapper(`${tableAlias}.${col}`, qb.type, undefined, `${tableAlias}__${col}`)));
967
966
  }
968
967
  if (prop.kind === core_1.ReferenceKind.ONE_TO_MANY && ref) {
969
- fields.push(...this.getFieldsForJoinedLoad(qb, meta2, prop.referencedColumnNames, undefined, hint.children, options, tableAlias, path, count));
968
+ fields.push(...this.getFieldsForJoinedLoad(qb, meta2, prop.referencedColumnNames, undefined, hint.children, options, tableAlias, path));
970
969
  }
971
970
  const childExplicitFields = explicitFields?.filter(f => core_1.Utils.isPlainObject(f)).map(o => o[prop.name])[0] || [];
972
971
  explicitFields?.forEach(f => {
@@ -976,7 +975,7 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
976
975
  });
977
976
  const childExclude = exclude ? core_1.Utils.extractChildElements(exclude, prop.name) : exclude;
978
977
  if (!ref && !prop.mapToPk) {
979
- fields.push(...this.getFieldsForJoinedLoad(qb, meta2, childExplicitFields.length === 0 ? undefined : childExplicitFields, childExclude, hint.children, options, tableAlias, path, count));
978
+ fields.push(...this.getFieldsForJoinedLoad(qb, meta2, childExplicitFields.length === 0 ? undefined : childExplicitFields, childExclude, hint.children, options, tableAlias, path));
980
979
  }
981
980
  else if (hint.filter || prop.mapToPk || (ref && [core_1.ReferenceKind.MANY_TO_ONE, core_1.ReferenceKind.ONE_TO_ONE].includes(prop.kind))) {
982
981
  fields.push(...prop.referencedColumnNames.map(col => qb.helper.mapper(`${tableAlias}.${col}`, qb.type, undefined, `${tableAlias}__${col}`)));
@@ -1244,7 +1243,7 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
1244
1243
  }
1245
1244
  return false;
1246
1245
  }
1247
- buildFields(meta, populate, joinedProps, qb, alias, options, count = false) {
1246
+ buildFields(meta, populate, joinedProps, qb, alias, options) {
1248
1247
  const lazyProps = meta.props.filter(prop => prop.lazy && !populate.some(p => this.isPopulated(meta, prop, p)));
1249
1248
  const hasLazyFormulas = meta.props.some(p => p.lazy && p.formula);
1250
1249
  const requiresSQLConversion = meta.props.some(p => p.customType?.convertToJSValueSQL && p.persist !== false);
@@ -1305,7 +1304,7 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
1305
1304
  }
1306
1305
  // add joined relations after the root entity fields
1307
1306
  if (joinedProps.length > 0) {
1308
- ret.push(...this.getFieldsForJoinedLoad(qb, meta, options.fields, options.exclude, populate, options, alias, undefined, count));
1307
+ ret.push(...this.getFieldsForJoinedLoad(qb, meta, options.fields, options.exclude, populate, options, alias));
1309
1308
  }
1310
1309
  return core_1.Utils.unique(ret);
1311
1310
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/knex",
3
- "version": "6.5.3-dev.9",
3
+ "version": "6.5.4-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,10 +63,10 @@
63
63
  "sqlstring": "2.3.3"
64
64
  },
65
65
  "devDependencies": {
66
- "@mikro-orm/core": "^6.5.2"
66
+ "@mikro-orm/core": "^6.5.3"
67
67
  },
68
68
  "peerDependencies": {
69
- "@mikro-orm/core": "6.5.3-dev.9",
69
+ "@mikro-orm/core": "6.5.4-dev.0",
70
70
  "better-sqlite3": "*",
71
71
  "libsql": "*",
72
72
  "mariadb": "*"