MCPcopy Create free account
hub / github.com/mikro-orm/mikro-orm / findAndCount

Method findAndCount

packages/core/src/EntityManager.ts:831–849  ·  view source on GitHub ↗
(
    entityName: EntityName<Entity>,
    where: FilterQuery<NoInfer<Entity>>,
    options: FindOptions<Entity, Hint, Fields, Excludes> = {},
  )

Source from the content-addressed store, hash-verified

829 ): Promise<[Loaded<Entity, Hint, Fields, Excludes>[], number]>;
830
831 async findAndCount<
832 Entity extends object,
833 Hint extends string = never,
834 Fields extends string = never,
835 Excludes extends string = never,
836 >(
837 entityName: EntityName<Entity>,
838 where: FilterQuery<NoInfer<Entity>>,
839 options: FindOptions<Entity, Hint, Fields, Excludes> = {},
840 ): Promise<[Loaded<Entity, Hint, Fields, Excludes>[], number]> {
841 const em = this.getContext(false);
842 await em.tryFlush(entityName, options);
843 options.flushMode = 'commit'; // do not try to auto flush again
844
845 return Promise.all([
846 em.find(entityName, where as any, options),
847 em.count(entityName, where, options as CountOptions<Entity, Hint>),
848 ]);
849 }
850
851 /**
852 * Calls `em.find()` and `em.count()` with the same arguments (where applicable) and returns the results as {@apilink Cursor} object.

Calls 4

getContextMethod · 0.95
tryFlushMethod · 0.80
findMethod · 0.65
countMethod · 0.65

Tested by

no test coverage detected