Skip to main content
Version: 4.5

Class: RequestContext#

core.RequestContext

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

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

Constructors#

constructor#

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

Parameters:#

NameType
mapMap<string, EntityManager<IDatabaseDriver<Connection>>>

Returns: RequestContext

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

Properties#

id#

Readonly id: number

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


map#

Readonly map: Map<string, EntityManager<IDatabaseDriver<Connection>>>


counter#

Private Static counter: number= 1

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

Accessors#

em#

• get em(): undefined | EntityManager<IDatabaseDriver<Connection>>

Returns default EntityManager.

Returns: undefined | EntityManager<IDatabaseDriver<Connection>>

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

Methods#

create#

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

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

Parameters:#

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

Returns: void

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


createAsync#

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

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<IDatabaseDriver<Connection>> | EntityManager<IDatabaseDriver<Connection>>[]
next(...args: any[]) => Promise<void>

Returns: Promise<void>

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


createDomain#

Private StaticcreateDomain(em: EntityManager<IDatabaseDriver<Connection>> | EntityManager<IDatabaseDriver<Connection>>[]): ORMDomain

Parameters:#

NameType
emEntityManager<IDatabaseDriver<Connection>> | EntityManager<IDatabaseDriver<Connection>>[]

Returns: ORMDomain

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


currentRequestContext#

StaticcurrentRequestContext(): undefined | RequestContext

Returns current RequestContext (if available).

Returns: undefined | RequestContext

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


getEntityManager#

StaticgetEntityManager(name?: string): undefined | EntityManager<IDatabaseDriver<Connection>>

Returns current EntityManager (if available).

Parameters:#

NameTypeDefault value
namestring'default'

Returns: undefined | EntityManager<IDatabaseDriver<Connection>>

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

Last updated on by Renovate Bot