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

Function getEntityManager

packages/decorators/src/utils.ts:23–45  ·  view source on GitHub ↗
(caller: { orm?: MikroORM; em?: EntityManager }, context: unknown)

Source from the content-addressed store, hash-verified

21 ) => MaybePromise<MikroORM | EntityManager | EntityRepository<any> | { getEntityManager(): EntityManager }>);
22
23function getEntityManager(caller: { orm?: MikroORM; em?: EntityManager }, context: unknown): EntityManager | undefined {
24 if (context instanceof EntityManager) {
25 return context;
26 }
27
28 if (context instanceof EntityRepository) {
29 return context.getEntityManager();
30 }
31
32 if (context instanceof MikroORM) {
33 return context.em;
34 }
35
36 if (caller.em instanceof EntityManager) {
37 return caller.em;
38 }
39
40 if (caller.orm instanceof MikroORM) {
41 return caller.orm.em;
42 }
43
44 return undefined;
45}
46
47/**
48 * Find `EntityManager` in provided context, or else in instance's `orm` or `em` properties.

Callers 1

resolveContextProviderFunction · 0.70

Calls 1

getEntityManagerMethod · 0.45

Tested by

no test coverage detected