Version: 4.3

Class: RequestContext

For node 14 and above it is suggested to use AsyncLocalStorage instead,

see https://mikro-orm.io/docs/async-local-storage/

Hierarchy

  • RequestContext

Constructors

constructor

+ new RequestContext(map: Map<string, EntityManager>): RequestContext

Defined in packages/core/src/utils/RequestContext.ts:14

Parameters:

NameType
mapMap<string, EntityManager>

Returns: RequestContext

Properties

id

Readonly id: number = RequestContext.counter++

Defined in packages/core/src/utils/RequestContext.ts:14


map

Readonly map: Map<string, EntityManager>

Defined in packages/core/src/utils/RequestContext.ts:16


counter

Static Private counter: number = 1

Defined in packages/core/src/utils/RequestContext.ts:13

Accessors

em

• get em(): EntityManager | undefined

Defined in packages/core/src/utils/RequestContext.ts:21

Returns default EntityManager.

Returns: EntityManager | undefined

Methods

create

Staticcreate(em: EntityManager | EntityManager[], next: (...args: any[]) => void): void

Defined in packages/core/src/utils/RequestContext.ts:28

Creates new RequestContext instance and runs the code inside its domain.

Parameters:

NameType
emEntityManager | EntityManager[]
next(...args: any[]) => void

Returns: void


createAsync

StaticcreateAsync(em: EntityManager | EntityManager[], next: (...args: any[]) => Promise<void>): Promise<void>

Defined in packages/core/src/utils/RequestContext.ts:37

Creates new RequestContext instance and runs the code inside its domain. Async variant, when the next handler needs to be awaited (like in Koa).

Parameters:

NameType
emEntityManager | EntityManager[]
next(...args: any[]) => Promise<void>

Returns: Promise<void>


createDomain

Static PrivatecreateDomain(em: EntityManager | EntityManager[]): ORMDomain

Defined in packages/core/src/utils/RequestContext.ts:60

Parameters:

NameType
emEntityManager | EntityManager[]

Returns: ORMDomain


currentRequestContext

StaticcurrentRequestContext(): RequestContext | undefined

Defined in packages/core/src/utils/RequestContext.ts:47

Returns current RequestContext (if available).

Returns: RequestContext | undefined


getEntityManager

StaticgetEntityManager(name?: string): EntityManager | undefined

Defined in packages/core/src/utils/RequestContext.ts:55

Returns current EntityManager (if available).

Parameters:

NameTypeDefault value
namestring"default"

Returns: EntityManager | undefined

Last updated on by Martin Adámek