Version: 4.3

Class: EntityManager<D>

The EntityManager is the central access point to ORM functionality. It is a facade to all different ORM subsystems such as UnitOfWork, Query Language and Repository API.

Type parameters

NameTypeDefault
DIDatabaseDriverIDatabaseDriver

Hierarchy

  • EntityManager

Constructors

constructor

+ new EntityManager(config: Configuration, driver: D, metadata: MetadataStorage, useContext?: boolean, eventManager?: EventManager): EntityManager

Defined in packages/core/src/EntityManager.ts:33

Parameters:

NameTypeDefault value
configConfiguration-
driverD-
metadataMetadataStorage-
useContextbooleantrue
eventManagerEventManagernew EventManager(config.get('subscribers'))

Returns: EntityManager

Properties

comparator

Private Readonly comparator: EntityComparator = new EntityComparator(this.metadata, this.driver.getPlatform())

Defined in packages/core/src/EntityManager.ts:27


config

Readonly config: Configuration

Defined in packages/core/src/EntityManager.ts:35


driver

Private Readonly driver: D

Defined in packages/core/src/EntityManager.ts:36


entityFactory

Private Readonly entityFactory: EntityFactory = new EntityFactory(this.unitOfWork, this)

Defined in packages/core/src/EntityManager.ts:29


entityLoader

Private Readonly entityLoader: EntityLoader = new EntityLoader(this)

Defined in packages/core/src/EntityManager.ts:26


eventManager

Private Readonly eventManager: EventManager

Defined in packages/core/src/EntityManager.ts:39


filterParams

Private filterParams: Dictionary<Dictionary>

Defined in packages/core/src/EntityManager.ts:32


filters

Private filters: Dictionary<FilterDef<any>>

Defined in packages/core/src/EntityManager.ts:31


id

Readonly id: number = EntityManager.counter++

Defined in packages/core/src/EntityManager.ts:22


metadata

Private Readonly metadata: MetadataStorage

Defined in packages/core/src/EntityManager.ts:37


name

Readonly name: string = this.config.get('contextName')

Defined in packages/core/src/EntityManager.ts:23


repositoryMap

Private Readonly repositoryMap: Dictionary<EntityRepository<AnyEntity>>

Defined in packages/core/src/EntityManager.ts:25


resultCache

Private Readonly resultCache: CacheAdapter = this.config.getResultCacheAdapter()

Defined in packages/core/src/EntityManager.ts:30


transactionContext

Private Optional transactionContext: Transaction

Defined in packages/core/src/EntityManager.ts:33


unitOfWork

Private Readonly unitOfWork: any = new UnitOfWork(this)

Defined in packages/core/src/EntityManager.ts:28


useContext

Private Readonly useContext: boolean

Defined in packages/core/src/EntityManager.ts:38


validator

Private Readonly validator: EntityValidator = new EntityValidator(this.config.get('strict'))

Defined in packages/core/src/EntityManager.ts:24


counter

Static Private counter: number = 1

Defined in packages/core/src/EntityManager.ts:21

Methods

[inspect.custom]

[inspect.custom](): string

Defined in packages/core/src/EntityManager.ts:907

Returns: string


addFilter

addFilter<T1>(name: string, cond: FilterQuery<T1> | (args: Dictionary) => FilterQuery<T1>, entityName?: EntityName<T1> | [EntityName<T1>], enabled?: boolean): void

Defined in packages/core/src/EntityManager.ts:137

Registers global filter to this entity manager. Global filters are enabled by default (unless disabled via last parameter).

Type parameters:

NameType
T1AnyEntity<T1>

Parameters:

NameType
namestring
condFilterQuery<T1> | (args: Dictionary) => FilterQuery<T1>
entityName?EntityName<T1> | [EntityName<T1>]
enabled?boolean

Returns: void

addFilter<T1, T2>(name: string, cond: FilterQuery<T1 | T2> | (args: Dictionary) => FilterQuery<T1 | T2>, entityName?: [EntityName<T1>, EntityName<T2>], enabled?: boolean): void

Defined in packages/core/src/EntityManager.ts:142

Registers global filter to this entity manager. Global filters are enabled by default (unless disabled via last parameter).

Type parameters:

NameType
T1AnyEntity<T1>
T2AnyEntity<T2>

Parameters:

NameType
namestring
condFilterQuery<T1 | T2> | (args: Dictionary) => FilterQuery<T1 | T2>
entityName?[EntityName<T1>, EntityName<T2>]
enabled?boolean

Returns: void

addFilter<T1, T2, T3>(name: string, cond: FilterQuery<T1 | T2 | T3> | (args: Dictionary) => FilterQuery<T1 | T2 | T3>, entityName?: [EntityName<T1>, EntityName<T2>, EntityName<T3>], enabled?: boolean): void

Defined in packages/core/src/EntityManager.ts:147

Registers global filter to this entity manager. Global filters are enabled by default (unless disabled via last parameter).

Type parameters:

NameType
T1AnyEntity<T1>
T2AnyEntity<T2>
T3AnyEntity<T3>

Parameters:

NameType
namestring
condFilterQuery<T1 | T2 | T3> | (args: Dictionary) => FilterQuery<T1 | T2 | T3>
entityName?[EntityName<T1>, EntityName<T2>, EntityName<T3>]
enabled?boolean

Returns: void


applyFilters

ProtectedapplyFilters<T>(entityName: string, where: FilterQuery<T>, options: Dictionary<boolean | Dictionary> | string[] | boolean, type: "read" | "update" | "delete"): Promise<FilterQuery<T>>

Defined in packages/core/src/EntityManager.ts:177

Type parameters:

NameType
TAnyEntity<T>

Parameters:

NameType
entityNamestring
whereFilterQuery<T>
optionsDictionary<boolean | Dictionary> | string[] | boolean
type"read" | "update" | "delete"

Returns: Promise<FilterQuery<T>>


assign

assign<T>(entity: T, data: EntityData<T>, options?: AssignOptions): T

Defined in packages/core/src/EntityManager.ts:498

Shortcut for wrap(entity).assign(data, { em })

Type parameters:

NameType
TAnyEntity<T>

Parameters:

NameTypeDefault value
entityT-
dataEntityData<T>-
optionsAssignOptions{}

Returns: T


begin

begin(ctx?: Transaction): Promise<void>

Defined in packages/core/src/EntityManager.ts:345

Starts new transaction bound to this EntityManager. Use ctx parameter to provide the parent when nesting transactions.

Parameters:

NameType
ctx?Transaction

Returns: Promise<void>


canPopulate

canPopulate<T>(entityName: EntityName<T>, property: string): boolean

Defined in packages/core/src/EntityManager.ts:665

Checks whether given property can be populated on the entity.

Type parameters:

NameType
TAnyEntity<T>

Parameters:

NameType
entityNameEntityName<T>
propertystring

Returns: boolean


checkLockRequirements

PrivatecheckLockRequirements(mode: LockMode | undefined, meta: EntityMetadata): void

Defined in packages/core/src/EntityManager.ts:796

Parameters:

NameType
modeLockMode | undefined
metaEntityMetadata

Returns: void


clear

clear(): void

Defined in packages/core/src/EntityManager.ts:658

Clears the EntityManager. All entities that are currently managed by this EntityManager become detached.

Returns: void


commit

commit(): Promise<void>

Defined in packages/core/src/EntityManager.ts:352

Commits the transaction bound to this EntityManager. Flushes before doing the actual commit query.

Returns: Promise<void>


count

count<T>(entityName: EntityName<T>, where?: FilterQuery<T>, options?: CountOptions<T>): Promise<number>

Defined in packages/core/src/EntityManager.ts:548

Returns total number of entities matching your where query.

Type parameters:

NameType
TAnyEntity<T>

Parameters:

NameTypeDefault value
entityNameEntityName<T>-
whereFilterQuery<T>{}
optionsCountOptions<T>{}

Returns: Promise<number>


create

create<T, P>(entityName: EntityName<T>, data: EntityData<T>, options?: { managed?: boolean }): New<T, P>

Defined in packages/core/src/EntityManager.ts:491

Creates new instance of given entity and populates it with given data

Type parameters:

NameTypeDefault
TAnyEntity<T>-
PPopulate<T>any

Parameters:

NameTypeDefault value
entityNameEntityName<T>-
dataEntityData<T>-
options{ managed?: boolean }{}

Returns: New<T, P>


find

find<T, P>(entityName: EntityName<T>, where: FilterQuery<T>, options?: FindOptions<T, P>): Promise<Loaded<T, P>[]>

Defined in packages/core/src/EntityManager.ts:88

Finds all entities matching your where query. You can pass additional options via the options parameter.

Type parameters:

NameTypeDefault
TAnyEntity<T>-
PPopulate<T>any

Parameters:

NameType
entityNameEntityName<T>
whereFilterQuery<T>
options?FindOptions<T, P>

Returns: Promise<Loaded<T, P>[]>

find<T, P>(entityName: EntityName<T>, where: FilterQuery<T>, populate?: P, orderBy?: QueryOrderMap, limit?: number, offset?: number): Promise<Loaded<T, P>[]>

Defined in packages/core/src/EntityManager.ts:93

Finds all entities matching your where query.

Type parameters:

NameTypeDefault
TAnyEntity<T>-
PPopulate<T>any

Parameters:

NameType
entityNameEntityName<T>
whereFilterQuery<T>
populate?P
orderBy?QueryOrderMap
limit?number
offset?number

Returns: Promise<Loaded<T, P>[]>


findAndCount

findAndCount<T, P>(entityName: EntityName<T>, where: FilterQuery<T>, options?: FindOptions<T, P>): Promise<[Loaded<T, P>[], number]>

Defined in packages/core/src/EntityManager.ts:220

Calls em.find() and em.count() with the same arguments (where applicable) and returns the results as tuple where first element is the array of entities and the second is the count.

Type parameters:

NameTypeDefault
TAnyEntity<T>-
PPopulate<T>any

Parameters:

NameType
entityNameEntityName<T>
whereFilterQuery<T>
options?FindOptions<T, P>

Returns: Promise<[Loaded<T, P>[], number]>

findAndCount<T, P>(entityName: EntityName<T>, where: FilterQuery<T>, populate?: P, orderBy?: QueryOrderMap, limit?: number, offset?: number): Promise<[Loaded<T, P>[], number]>

Defined in packages/core/src/EntityManager.ts:226

Calls em.find() and em.count() with the same arguments (where applicable) and returns the results as tuple where first element is the array of entities and the second is the count.

Type parameters:

NameTypeDefault
TAnyEntity<T>-
PPopulate<T>any

Parameters:

NameType
entityNameEntityName<T>
whereFilterQuery<T>
populate?P
orderBy?QueryOrderMap
limit?number
offset?number

Returns: Promise<[Loaded<T, P>[], number]>


findOne

findOne<T, P>(entityName: EntityName<T>, where: FilterQuery<T>, options?: FindOneOptions<T, P>): Promise<Loaded<T, P> | null>

Defined in packages/core/src/EntityManager.ts:245

Finds first entity matching your where query.

Type parameters:

NameTypeDefault
TAnyEntity<T>-
PPopulate<T>any

Parameters:

NameType
entityNameEntityName<T>
whereFilterQuery<T>
options?FindOneOptions<T, P>

Returns: Promise<Loaded<T, P> | null>

findOne<T, P>(entityName: EntityName<T>, where: FilterQuery<T>, populate?: P, orderBy?: QueryOrderMap): Promise<Loaded<T, P> | null>

Defined in packages/core/src/EntityManager.ts:250

Finds first entity matching your where query.

Type parameters:

NameTypeDefault
TAnyEntity<T>-
PPopulate<T>any

Parameters:

NameType
entityNameEntityName<T>
whereFilterQuery<T>
populate?P
orderBy?QueryOrderMap

Returns: Promise<Loaded<T, P> | null>


findOneOrFail

findOneOrFail<T, P>(entityName: EntityName<T>, where: FilterQuery<T>, options?: FindOneOrFailOptions<T, P>): Promise<Loaded<T, P>>

Defined in packages/core/src/EntityManager.ts:298

Finds first entity matching your where query. If nothing found, it will throw an error. You can override the factory for creating this method via options.failHandler locally or via Configuration.findOneOrFailHandler globally.

Type parameters:

NameTypeDefault
TAnyEntity<T>-
PPopulate<T>any

Parameters:

NameType
entityNameEntityName<T>
whereFilterQuery<T>
options?FindOneOrFailOptions<T, P>

Returns: Promise<Loaded<T, P>>

findOneOrFail<T, P>(entityName: EntityName<T>, where: FilterQuery<T>, populate?: P, orderBy?: QueryOrderMap): Promise<Loaded<T, P>>

Defined in packages/core/src/EntityManager.ts:305

Finds first entity matching your where query. If nothing found, it will throw an error. You can override the factory for creating this method via options.failHandler locally or via Configuration.findOneOrFailHandler globally.

Type parameters:

NameTypeDefault
TAnyEntity<T>-
PPopulate<T>any

Parameters:

NameType
entityNameEntityName<T>
whereFilterQuery<T>
populate?P
orderBy?QueryOrderMap

Returns: Promise<Loaded<T, P>>


flush

flush(): Promise<void>

Defined in packages/core/src/EntityManager.ts:651

Flushes all changes to objects that have been queued up to now to the database. This effectively synchronizes the in-memory state of managed objects with the database.

Returns: Promise<void>


fork

fork(clear?: boolean, useContext?: boolean): D[typeof EntityManagerType]

Defined in packages/core/src/EntityManager.ts:722

Returns new EntityManager instance with its own identity map

Parameters:

NameTypeDefault valueDescription
clearbooleantruedo we want clear identity map? defaults to true
useContextbooleanfalseuse request context? should be used only for top level request scope EM, defaults to false

Returns: D[typeof EntityManagerType]


getComparator

getComparator(): EntityComparator

Defined in packages/core/src/EntityManager.ts:792

Gets the EntityComparator.

Returns: EntityComparator


getConnection

getConnection(type?: "read" | "write"): ReturnType<D["getConnection"]>

Defined in packages/core/src/EntityManager.ts:52

Gets the Connection instance, by default returns write connection

Parameters:

NameType
type?"read" | "write"

Returns: ReturnType<D["getConnection"]>


getContext

getContext(): EntityManager

Defined in packages/core/src/EntityManager.ts:753

Gets the EntityManager based on current transaction/request context.

Returns: EntityManager


getDriver

getDriver(): D

Defined in packages/core/src/EntityManager.ts:45

Gets the Driver instance used by this EntityManager. Driver is singleton, for one MikroORM instance, only one driver is created.

Returns: D


getEntityFactory

getEntityFactory(): EntityFactory

Defined in packages/core/src/EntityManager.ts:746

Gets the EntityFactory used by the EntityManager.

Returns: EntityFactory


getEventManager

getEventManager(): EventManager

Defined in packages/core/src/EntityManager.ts:764

Returns: EventManager


getFilterParams

getFilterParams<T>(name: string): T

Defined in packages/core/src/EntityManager.ts:173

Returns filter parameters for given filter set in this context.

Type parameters:

NameTypeDefault
TDictionaryDictionary

Parameters:

NameType
namestring

Returns: T


getMetadata

getMetadata(): MetadataStorage

Defined in packages/core/src/EntityManager.ts:785

Gets the MetadataStorage.

Returns: MetadataStorage


getPlatform

getPlatform(): ReturnType<D["getPlatform"]>

Defined in packages/core/src/EntityManager.ts:59

Gets the platform instance. Just like the driver, platform is singleton, one for a MikroORM instance.

Returns: ReturnType<D["getPlatform"]>


getReference

getReference<T, PK>(entityName: EntityName<T>, id: Primary<T>, wrapped: true, convertCustomTypes?: boolean): IdentifiedReference<T, PK>

Defined in packages/core/src/EntityManager.ts:505

Gets a reference to the entity identified by the given type and identifier without actually loading it, if the entity is not yet loaded

Type parameters:

NameType
TAnyEntity<T>
PKkeyof T

Parameters:

NameType
entityNameEntityName<T>
idPrimary<T>
wrappedtrue
convertCustomTypes?boolean

Returns: IdentifiedReference<T, PK>

getReference<T>(entityName: EntityName<T>, id: Primary<T> | Primary<T>[]): T

Defined in packages/core/src/EntityManager.ts:510

Gets a reference to the entity identified by the given type and identifier without actually loading it, if the entity is not yet loaded

Type parameters:

NameType
TAnyEntity<T>

Parameters:

NameType
entityNameEntityName<T>
idPrimary<T> | Primary<T>[]

Returns: T

getReference<T>(entityName: EntityName<T>, id: Primary<T>, wrapped: false, convertCustomTypes?: boolean): T

Defined in packages/core/src/EntityManager.ts:515

Gets a reference to the entity identified by the given type and identifier without actually loading it, if the entity is not yet loaded

Type parameters:

NameType
TAnyEntity<T>

Parameters:

NameType
entityNameEntityName<T>
idPrimary<T>
wrappedfalse
convertCustomTypes?boolean

Returns: T

getReference<T>(entityName: EntityName<T>, id: Primary<T>, wrapped?: boolean, convertCustomTypes?: boolean): T | Reference<T>

Defined in packages/core/src/EntityManager.ts:520

Gets a reference to the entity identified by the given type and identifier without actually loading it, if the entity is not yet loaded

Type parameters:

NameType
TAnyEntity<T>

Parameters:

NameType
entityNameEntityName<T>
idPrimary<T>
wrapped?boolean
convertCustomTypes?boolean

Returns: T | Reference<T>


getRepository

getRepository<T, U>(entityName: EntityName<T>): GetRepository<T, U>

Defined in packages/core/src/EntityManager.ts:66

Gets repository for given entity. You can pass either string name or entity class reference.

Type parameters:

NameTypeDefault
TAnyEntity<T>-
UEntityRepository<T>EntityRepository\<T>

Parameters:

NameType
entityNameEntityName<T>

Returns: GetRepository<T, U>


getTransactionContext

getTransactionContext<T>(): T | undefined

Defined in packages/core/src/EntityManager.ts:778

Gets the transaction context (driver dependent object used to make sure queries are executed on same connection).

Type parameters:

NameTypeDefault
TTransactionTransaction

Returns: T | undefined


getUnitOfWork

getUnitOfWork(): UnitOfWork

Defined in packages/core/src/EntityManager.ts:739

Gets the UnitOfWork used by the EntityManager to coordinate operations.

Returns: UnitOfWork


getValidator

getValidator(): EntityValidator

Defined in packages/core/src/EntityManager.ts:81

Gets EntityValidator instance

Returns: EntityValidator


isInTransaction

isInTransaction(): boolean

Defined in packages/core/src/EntityManager.ts:771

Checks whether this EntityManager is currently operating inside a database transaction.

Returns: boolean


lock

lock(entity: AnyEntity, lockMode: LockMode, lockVersion?: number | Date): Promise<void>

Defined in packages/core/src/EntityManager.ts:369

Runs your callback wrapped inside a database transaction.

Parameters:

NameType
entityAnyEntity
lockModeLockMode
lockVersion?number | Date

Returns: Promise<void>


lockAndPopulate

PrivatelockAndPopulate<T, P>(entityName: string, entity: T, where: FilterQuery<T>, options: FindOneOptions<T>): Promise<Loaded<T, P>>

Defined in packages/core/src/EntityManager.ts:810

Type parameters:

NameTypeDefault
TAnyEntity<T>-
PPopulate<T>any

Parameters:

NameType
entityNamestring
entityT
whereFilterQuery<T>
optionsFindOneOptions<T>

Returns: Promise<Loaded<T, P>>


map

map<T>(entityName: EntityName<T>, result: EntityData<T>): T

Defined in packages/core/src/EntityManager.ts:434

Maps raw database result to an entity and merges it to this EntityManager.

Type parameters:

NameType
TAnyEntity<T>

Parameters:

NameType
entityNameEntityName<T>
resultEntityData<T>

Returns: T


merge

merge<T>(entity: T, refresh?: boolean): T

Defined in packages/core/src/EntityManager.ts:453

Merges given entity to this EntityManager so it becomes managed. You can force refreshing of existing entities via second parameter. By default it will return already loaded entities without modifying them.

Type parameters:

NameType
TAnyEntity<T>

Parameters:

NameType
entityT
refresh?boolean

Returns: T

merge<T>(entityName: EntityName<T>, data: EntityData<T>, refresh?: boolean, convertCustomTypes?: boolean): T

Defined in packages/core/src/EntityManager.ts:459

Merges given entity to this EntityManager so it becomes managed. You can force refreshing of existing entities via second parameter. By default it will return already loaded entities without modifying them.

Type parameters:

NameType
TAnyEntity<T>

Parameters:

NameType
entityNameEntityName<T>
dataEntityData<T>
refresh?boolean
convertCustomTypes?boolean

Returns: T


nativeDelete

nativeDelete<T>(entityName: EntityName<T>, where: FilterQuery<T>, options?: DeleteOptions<T>): Promise<number>

Defined in packages/core/src/EntityManager.ts:421

Fires native delete query. Calling this has no side effects on the context (identity map).

Type parameters:

NameType
TAnyEntity<T>

Parameters:

NameTypeDefault value
entityNameEntityName<T>-
whereFilterQuery<T>-
optionsDeleteOptions<T>{}

Returns: Promise<number>


nativeInsert

nativeInsert<T>(entity: T): Promise<Primary<T>>

Defined in packages/core/src/EntityManager.ts:376

Fires native insert query. Calling this has no side effects on the context (identity map).

Type parameters:

NameType
TAnyEntity<T>

Parameters:

NameType
entityT

Returns: Promise<Primary<T>>

nativeInsert<T>(entityName: EntityName<T>, data: EntityData<T>): Promise<Primary<T>>

Defined in packages/core/src/EntityManager.ts:381

Fires native insert query. Calling this has no side effects on the context (identity map).

Type parameters:

NameType
TAnyEntity<T>

Parameters:

NameType
entityNameEntityName<T>
dataEntityData<T>

Returns: Promise<Primary<T>>


nativeUpdate

nativeUpdate<T>(entityName: EntityName<T>, where: FilterQuery<T>, data: EntityData<T>, options?: UpdateOptions<T>): Promise<number>

Defined in packages/core/src/EntityManager.ts:406

Fires native update query. Calling this has no side effects on the context (identity map).

Type parameters:

NameType
TAnyEntity<T>

Parameters:

NameTypeDefault value
entityNameEntityName<T>-
whereFilterQuery<T>-
dataEntityData<T>-
optionsUpdateOptions<T>{}

Returns: Promise<number>


persist

persist(entity: AnyEntity | Reference<AnyEntity> | (AnyEntity | Reference<AnyEntity>)[]): this

Defined in packages/core/src/EntityManager.ts:570

Tells the EntityManager to make an instance managed and persistent. The entity will be entered into the database at or before transaction commit or as a result of the flush operation.

Parameters:

NameType
entityAnyEntity | Reference<AnyEntity> | (AnyEntity | Reference<AnyEntity>)[]

Returns: this


persistAndFlush

persistAndFlush(entity: AnyEntity | Reference<AnyEntity> | (AnyEntity | Reference<AnyEntity>)[]): Promise<void>

Defined in packages/core/src/EntityManager.ts:595

Persists your entity immediately, flushing all not yet persisted changes to the database too. Equivalent to em.persist(e).flush().

Parameters:

NameType
entityAnyEntity | Reference<AnyEntity> | (AnyEntity | Reference<AnyEntity>)[]

Returns: Promise<void>


persistLater

persistLater(entity: AnyEntity | AnyEntity[]): void

Defined in packages/core/src/EntityManager.ts:605

Tells the EntityManager to make an instance managed and persistent. The entity will be entered into the database at or before transaction commit or as a result of the flush operation.

deprecated use persist()

Parameters:

NameType
entityAnyEntity | AnyEntity[]

Returns: void


populate

populate<T, P>(entities: T, populate: P, where?: FilterQuery<T>, orderBy?: QueryOrderMap, refresh?: boolean, validate?: boolean): Promise<Loaded<T, P>>

Defined in packages/core/src/EntityManager.ts:685

Loads specified relations in batch. This will execute one query for each relation, that will populate it on all of the specified entities.

Type parameters:

NameType
TAnyEntity<T>
Pstring | keyof T | Populate<T>

Parameters:

NameType
entitiesT
populateP
where?FilterQuery<T>
orderBy?QueryOrderMap
refresh?boolean
validate?boolean

Returns: Promise<Loaded<T, P>>

populate<T, P>(entities: T[], populate: P, where?: FilterQuery<T>, orderBy?: QueryOrderMap, refresh?: boolean, validate?: boolean): Promise<Loaded<T, P>[]>

Defined in packages/core/src/EntityManager.ts:690

Loads specified relations in batch. This will execute one query for each relation, that will populate it on all of the specified entities.

Type parameters:

NameType
TAnyEntity<T>
Pstring | keyof T | Populate<T>

Parameters:

NameType
entitiesT[]
populateP
where?FilterQuery<T>
orderBy?QueryOrderMap
refresh?boolean
validate?boolean

Returns: Promise<Loaded<T, P>[]>

populate<T, P>(entities: T | T[], populate: P, where?: FilterQuery<T>, orderBy?: QueryOrderMap, refresh?: boolean, validate?: boolean): Promise<Loaded<T, P> | Loaded<T, P>[]>

Defined in packages/core/src/EntityManager.ts:695

Loads specified relations in batch. This will execute one query for each relation, that will populate it on all of the specified entities.

Type parameters:

NameType
TAnyEntity<T>
Pstring | keyof T | Populate<T>

Parameters:

NameType
entitiesT | T[]
populateP
where?FilterQuery<T>
orderBy?QueryOrderMap
refresh?boolean
validate?boolean

Returns: Promise<Loaded<T, P> | Loaded<T, P>[]>


preparePopulate

PrivatepreparePopulate<T>(entityName: string, populate?: Populate<T>, strategy?: LoadStrategy): PopulateOptions<T>[]

Defined in packages/core/src/EntityManager.ts:821

Type parameters:

NameType
TAnyEntity<T>

Parameters:

NameType
entityNamestring
populate?Populate<T>
strategy?LoadStrategy

Returns: PopulateOptions<T>[]


preparePopulateObject

PrivatepreparePopulateObject<T>(meta: EntityMetadata<T>, populate: PopulateMap<T>, strategy?: LoadStrategy): PopulateOptions<T>[]

Defined in packages/core/src/EntityManager.ts:850

Type parameters:

NameType
TAnyEntity<T>

Parameters:

NameType
metaEntityMetadata<T>
populatePopulateMap<T>
strategy?LoadStrategy

Returns: PopulateOptions<T>[]


remove

remove<T>(entity: T | Reference<T> | (T | Reference<T>)[]): this

Defined in packages/core/src/EntityManager.ts:615

Marks entity for removal. A removed entity will be removed from the database at or before transaction commit or as a result of the flush operation.

To remove entities by condition, use em.nativeDelete().

Type parameters:

NameType
TAnyEntity<T>

Parameters:

NameType
entityT | Reference<T> | (T | Reference<T>)[]

Returns: this


removeAndFlush

removeAndFlush(entity: AnyEntity | Reference<AnyEntity>): Promise<void>

Defined in packages/core/src/EntityManager.ts:633

Removes an entity instance immediately, flushing all not yet persisted changes to the database too. Equivalent to em.remove(e).flush()

Parameters:

NameType
entityAnyEntity | Reference<AnyEntity>

Returns: Promise<void>


removeLater

removeLater(entity: AnyEntity): void

Defined in packages/core/src/EntityManager.ts:643

Marks entity for removal. A removed entity will be removed from the database at or before transaction commit or as a result of the flush operation.

deprecated use remove()

Parameters:

NameType
entityAnyEntity

Returns: void


rollback

rollback(): Promise<void>

Defined in packages/core/src/EntityManager.ts:361

Rollbacks the transaction bound to this EntityManager.

Returns: Promise<void>


setFilterParams

setFilterParams(name: string, args: Dictionary): void

Defined in packages/core/src/EntityManager.ts:166

Sets filter parameter values globally inside context defined by this entity manager. If you want to set shared value for all contexts, be sure to use the root entity manager.

Parameters:

NameType
namestring
argsDictionary

Returns: void


storeCache

storeCache(config: boolean | number | [string, number] | undefined, key: { key: string }, data: unknown | () => unknown): Promise<void>

Defined in packages/core/src/EntityManager.ts:899

internal

Parameters:

NameType
configboolean | number | [string, number] | undefined
key{ key: string }
dataunknown | () => unknown

Returns: Promise<void>


transactional

transactional<T>(cb: (em: D[typeof EntityManagerType]) => Promise<T>, ctx?: any): Promise<T>

Defined in packages/core/src/EntityManager.ts:328

Runs your callback wrapped inside a database transaction.

Type parameters:

Name
T

Parameters:

NameTypeDefault value
cb(em: D[typeof EntityManagerType]) => Promise<T>-
ctxanythis.transactionContext

Returns: Promise<T>


tryCache

tryCache<T, R>(entityName: string, config: boolean | number | [string, number] | undefined, key: unknown, refresh?: boolean, merge?: boolean): Promise<{ data?: R ; key: string } | undefined>

Defined in packages/core/src/EntityManager.ts:871

internal

Type parameters:

Name
T
R

Parameters:

NameType
entityNamestring
configboolean | number | [string, number] | undefined
keyunknown
refresh?boolean
merge?boolean

Returns: Promise<{ data?: R ; key: string } | undefined>

Last updated on by Martin Adámek