@mikro-orm/knex 6.4.8 → 6.4.9-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.
@@ -13,12 +13,12 @@ export declare abstract class AbstractSqlDriver<Connection extends AbstractSqlCo
13
13
  protected constructor(config: Configuration, platform: Platform, connection: Constructor<Connection>, connector: string[]);
14
14
  getPlatform(): Platform;
15
15
  createEntityManager<D extends IDatabaseDriver = IDatabaseDriver>(useContext?: boolean): D[typeof EntityManagerType];
16
- find<T extends object, P extends string = never, F extends string = PopulatePath.ALL, E extends string = never>(entityName: string, where: FilterQuery<T>, options?: FindOptions<T, P, F, E>): Promise<EntityData<T>[]>;
17
- findOne<T extends object, P extends string = never, F extends string = PopulatePath.ALL, E extends string = never>(entityName: string, where: FilterQuery<T>, options?: FindOneOptions<T, P, F, E>): Promise<EntityData<T> | null>;
16
+ find<T extends object, P extends string = never, F extends string = PopulatePath.ALL, E extends string = never>(entityName: string, where: ObjectQuery<T>, options?: FindOptions<T, P, F, E>): Promise<EntityData<T>[]>;
17
+ findOne<T extends object, P extends string = never, F extends string = PopulatePath.ALL, E extends string = never>(entityName: string, where: ObjectQuery<T>, options?: FindOneOptions<T, P, F, E>): Promise<EntityData<T> | null>;
18
18
  protected hasToManyJoins<T extends object>(hint: PopulateOptions<T>, meta: EntityMetadata<T>): boolean;
19
- findVirtual<T extends object>(entityName: string, where: FilterQuery<T>, options: FindOptions<T, any, any, any>): Promise<EntityData<T>[]>;
20
- countVirtual<T extends object>(entityName: string, where: FilterQuery<T>, options: CountOptions<T, any>): Promise<number>;
21
- protected findFromVirtual<T extends object>(entityName: string, where: FilterQuery<T>, options: FindOptions<T, any> | CountOptions<T, any>, type: QueryType): Promise<EntityData<T>[] | number>;
19
+ findVirtual<T extends object>(entityName: string, where: ObjectQuery<T>, options: FindOptions<T, any, any, any>): Promise<EntityData<T>[]>;
20
+ countVirtual<T extends object>(entityName: string, where: ObjectQuery<T>, options: CountOptions<T, any>): Promise<number>;
21
+ protected findFromVirtual<T extends object>(entityName: string, where: ObjectQuery<T>, options: FindOptions<T, any> | CountOptions<T, any>, type: QueryType): Promise<EntityData<T>[] | number>;
22
22
  protected wrapVirtualExpressionInSubquery<T extends object>(meta: EntityMetadata<T>, expression: string, where: FilterQuery<T>, options: FindOptions<T, any>, type: QueryType): Promise<T[] | number>;
23
23
  mapResult<T extends object>(result: EntityData<T>, meta: EntityMetadata<T>, populate?: PopulateOptions<T>[], qb?: QueryBuilder<T, any, any, any>, map?: Dictionary): EntityData<T> | null;
24
24
  private mapJoinedProps;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/knex",
3
- "version": "6.4.8",
3
+ "version": "6.4.9-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.4.8"
67
67
  },
68
68
  "peerDependencies": {
69
- "@mikro-orm/core": "^6.0.0",
69
+ "@mikro-orm/core": "6.4.9-dev.1",
70
70
  "better-sqlite3": "*",
71
71
  "libsql": "*",
72
72
  "mariadb": "*"
@@ -698,16 +698,28 @@ class DatabaseTable {
698
698
  }
699
699
  addIndex(meta, index, type) {
700
700
  const properties = core_1.Utils.unique(core_1.Utils.flatten(core_1.Utils.asArray(index.properties).map(prop => {
701
- const root = prop.replace(/\..+$/, '');
701
+ const parts = prop.split('.');
702
+ const root = parts[0];
702
703
  if (meta.properties[prop]) {
703
704
  if (meta.properties[prop].embeddedPath) {
704
705
  return [meta.properties[prop].embeddedPath.join('.')];
705
706
  }
706
707
  return meta.properties[prop].fieldNames;
707
708
  }
709
+ const rootProp = meta.properties[root];
710
+ // inline embedded property index, we need to find the field name of the child property
711
+ if (rootProp?.embeddable && !rootProp.object && parts.length > 1) {
712
+ const expand = (p, i) => {
713
+ if (parts.length === i) {
714
+ return p.fieldNames[0];
715
+ }
716
+ return expand(p.embeddedProps[parts[i]], i + 1);
717
+ };
718
+ return [expand(rootProp, 1)];
719
+ }
708
720
  // json index, we need to rename the column only
709
- if (meta.properties[root]) {
710
- return [prop.replace(root, meta.properties[root].fieldNames[0])];
721
+ if (rootProp) {
722
+ return [prop.replace(root, rootProp.fieldNames[0])];
711
723
  }
712
724
  /* istanbul ignore next */
713
725
  return [prop];