Skip to main content
Version: 4.4

Class: EntityManager<D>#

core.EntityManager

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#

Constructors#

constructor#

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

Type parameters:#

NameTypeDefault
DIDatabaseDriver<Connection, D>IDatabaseDriver<Connection\>

Parameters:#

NameTypeDefault value
configConfiguration<IDatabaseDriver<Connection>>-
driverD-
metadataMetadataStorage-
useContextbooleantrue
eventManagerEventManager...

Returns: EntityManager<D>

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

Properties#

comparator#

Private Readonly comparator: EntityComparator

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


config#

Readonly config: Configuration<IDatabaseDriver<Connection>>


entityFactory#

Private Readonly entityFactory: EntityFactory

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


entityLoader#

Private Readonly entityLoader: EntityLoader

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


filterParams#

Private filterParams: Dictionary<Dictionary<any>>

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

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


name#

Readonly name: string

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


repositoryMap#

Private Readonly repositoryMap: Dictionary<EntityRepository<AnyEntity<any>>>

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


resultCache#

Private Readonly resultCache: CacheAdapter

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


transactionContext#

Private Optional transactionContext: any

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


unitOfWork#

Private Readonly unitOfWork: any

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


validator#

Private Readonly validator: EntityValidator

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


counter#

Private Static counter: number= 1

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

Methods#

__@custom@36825#

__@custom@36825(): string

Returns: string

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


addFilter#

addFilter<T1>(name: string, cond: { __@PrimaryKeyType@41543?: any } | NonNullable<Query<T1>> | (args: Dictionary<any>) => FilterQuery<T1>, entityName?: string | EntityClass<T1> | EntitySchema<T1, any> | [EntityName<T1>], enabled?: boolean): void

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
cond{ __@PrimaryKeyType@41543?: any } | NonNullable<Query<T1>> | (args: Dictionary<any>) => FilterQuery<T1>
entityName?string | EntityClass<T1> | EntitySchema<T1, any> | [EntityName<T1>]
enabled?boolean

Returns: void

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

addFilter<T1, T2>(name: string, cond: { __@PrimaryKeyType@41543?: any } | NonNullable<Query<T1>> | NonNullable<Query<T2>> | (args: Dictionary<any>) => FilterQuery<T1 | T2>, entityName?: [EntityName<T1>, EntityName<T2>], enabled?: boolean): void

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
cond{ __@PrimaryKeyType@41543?: any } | NonNullable<Query<T1>> | NonNullable<Query<T2>> | (args: Dictionary<any>) => FilterQuery<T1 | T2>
entityName?[EntityName<T1>, EntityName<T2>]
enabled?boolean

Returns: void

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

addFilter<T1, T2, T3>(name: string, cond: { __@PrimaryKeyType@41543?: any } | NonNullable<Query<T1>> | NonNullable<Query<T2>> | NonNullable<Query<T3>> | (args: Dictionary<any>) => FilterQuery<T1 | T2 | T3>, entityName?: [EntityName<T1>, EntityName<T2>, EntityName<T3>], enabled?: boolean): void

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
cond{ __@PrimaryKeyType@41543?: any } | NonNullable<Query<T1>> | NonNullable<Query<T2>> | NonNullable<Query<T3>> | (args: Dictionary<any>) => FilterQuery<T1 | T2 | T3>
entityName?[EntityName<T1>, EntityName<T2>, EntityName<T3>]
enabled?boolean

Returns: void

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


applyDiscriminatorCondition#

ProtectedapplyDiscriminatorCondition<T>(entityName: string, where: FilterQuery<T>): FilterQuery<T>

Type parameters:#

NameType
TAnyEntity<T>

Parameters:#

NameType
entityNamestring
whereFilterQuery<T>

Returns: FilterQuery<T>

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


applyFilters#

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

Type parameters:#

NameType
TAnyEntity<T>

Parameters:#

NameType
entityNamestring
whereFilterQuery<T>
optionsboolean | string[] | Dictionary<boolean | Dictionary<any>>
typeread | update | delete

Returns: Promise<FilterQuery<T>>

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


assign#

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

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

Type parameters:#

NameType
TAnyEntity<T>

Parameters:#

NameTypeDefault value
entityT-
dataEntityData<T>-
optionsAssignOptions...

Returns: T

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


begin#

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

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

Parameters:#

NameType
ctx?any

Returns: Promise<void>

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


canPopulate#

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

Checks whether given property can be populated on the entity.

Type parameters:#

NameType
TAnyEntity<T>

Parameters:#

NameType
entityNameEntityName<T>
propertystring

Returns: boolean

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


checkLockRequirements#

PrivatecheckLockRequirements(mode: undefined | NONE | OPTIMISTIC | PESSIMISTIC_READ | PESSIMISTIC_WRITE, meta: EntityMetadata<any>): void

Parameters:#

NameType
modeundefined | NONE | OPTIMISTIC | PESSIMISTIC_READ | PESSIMISTIC_WRITE
metaEntityMetadata<any>

Returns: void

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


clear#

clear(): void

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

Returns: void

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


commit#

commit(): Promise<void>

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

Returns: Promise<void>

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


count#

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

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>

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


create#

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

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?: undefined | boolean }...

Returns: Loaded<T, P>

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


find#

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

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>[]>

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

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

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>[]>

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


findAndCount#

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

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]>

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

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

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]>

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


findOne#

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

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<null | Loaded<T, P>>

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

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

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<null | Loaded<T, P>>

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


findOneOrFail#

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

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>>

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

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

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>>

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


flush#

flush(): Promise<void>

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>

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


fork#

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

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]

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


getComparator#

getComparator(): EntityComparator

Gets the EntityComparator.

Returns: EntityComparator

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


getConnection#

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

Gets the Connection instance, by default returns write connection

Parameters:#

NameType
type?read | write

Returns: ReturnType<D[getConnection]>

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


getContext#

getContext(): EntityManager<IDatabaseDriver<Connection>>

Gets the EntityManager based on current transaction/request context.

Returns: EntityManager<IDatabaseDriver<Connection>>

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


getDriver#

getDriver(): D

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

Returns: D

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


getEntityFactory#

getEntityFactory(): EntityFactory

Gets the EntityFactory used by the EntityManager.

Returns: EntityFactory

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


getEventManager#

getEventManager(): EventManager

Returns: EventManager

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


getFilterParams#

getFilterParams<T>(name: string): T

Returns filter parameters for given filter set in this context.

Type parameters:#

NameTypeDefault
TDictionary<any>Dictionary<any\>

Parameters:#

NameType
namestring

Returns: T

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


getMetadata#

getMetadata(): MetadataStorage

Gets the MetadataStorage.

Returns: MetadataStorage

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


getPlatform#

getPlatform(): ReturnType<D[getPlatform]>

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

Returns: ReturnType<D[getPlatform]>

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


getReference#

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

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>
PKstring | number | symbol

Parameters:#

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

Returns: IdentifiedReference<T, PK>

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

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

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

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

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

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

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

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

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>

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


getRepository#

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

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

Type parameters:#

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

Parameters:#

NameType
entityNameEntityName<T>

Returns: GetRepository<T, U>

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


getTransactionContext#

getTransactionContext<T>(): undefined | T

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

Type parameters:#

NameTypeDefault
Tunknownany

Returns: undefined | T

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


getUnitOfWork#

getUnitOfWork(): UnitOfWork

Gets the UnitOfWork used by the EntityManager to coordinate operations.

Returns: UnitOfWork

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


getValidator#

getValidator(): EntityValidator

Gets EntityValidator instance

Returns: EntityValidator

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


isInTransaction#

isInTransaction(): boolean

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

Returns: boolean

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


lock#

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

Runs your callback wrapped inside a database transaction.

Parameters:#

NameType
entityAnyEntity<any>
lockModeLockMode
lockVersion?number | Date

Returns: Promise<void>

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


lockAndPopulate#

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

Type parameters:#

NameTypeDefault
TAnyEntity<T>-
PPopulate<T>any

Parameters:#

NameType
entityNamestring
entityT
whereFilterQuery<T>
optionsFindOneOptions<T, Populate<T>>

Returns: Promise<Loaded<T, P>>

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


map#

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

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

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


merge#

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

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

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

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

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

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


nativeDelete#

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

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>

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


nativeInsert#

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

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>>

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

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

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>>

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


nativeUpdate#

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

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>

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


persist#

persist(entity: AnyEntity<any> | Reference<AnyEntity<any>> | (AnyEntity<any> | Reference<AnyEntity<any>>)[]): EntityManager<D>

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<any> | Reference<AnyEntity<any>> | (AnyEntity<any> | Reference<AnyEntity<any>>)[]

Returns: EntityManager<D>

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


persistAndFlush#

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

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

Parameters:#

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

Returns: Promise<void>

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


persistLater#

persistLater(entity: AnyEntity<any> | AnyEntity<any>[]): void

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<any> | AnyEntity<any>[]

Returns: void

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


populate#

populate<T, P>(entities: T, populate: P, where?: { __@PrimaryKeyType@41543?: any } | NonNullable<Query<T>>, orderBy?: QueryOrderMap, refresh?: boolean, validate?: boolean): Promise<Loaded<T, P>>

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 | number | boolean | symbol | readonly string[] | readonly keyof T[] | PopulateChildren<T>

Parameters:#

NameType
entitiesT
populateP
where?{ __@PrimaryKeyType@41543?: any } | NonNullable<Query<T>>
orderBy?QueryOrderMap
refresh?boolean
validate?boolean

Returns: Promise<Loaded<T, P>>

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

populate<T, P>(entities: T[], populate: P, where?: { __@PrimaryKeyType@41543?: any } | NonNullable<Query<T>>, orderBy?: QueryOrderMap, refresh?: boolean, validate?: boolean): Promise<Loaded<T, P>[]>

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 | number | boolean | symbol | readonly string[] | readonly keyof T[] | PopulateChildren<T>

Parameters:#

NameType
entitiesT[]
populateP
where?{ __@PrimaryKeyType@41543?: any } | NonNullable<Query<T>>
orderBy?QueryOrderMap
refresh?boolean
validate?boolean

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

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

populate<T, P>(entities: T | T[], populate: P, where?: { __@PrimaryKeyType@41543?: any } | NonNullable<Query<T>>, orderBy?: QueryOrderMap, refresh?: boolean, validate?: boolean): Promise<Loaded<T, P> | Loaded<T, P>[]>

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 | number | boolean | symbol | readonly string[] | readonly keyof T[] | PopulateChildren<T>

Parameters:#

NameType
entitiesT | T[]
populateP
where?{ __@PrimaryKeyType@41543?: any } | NonNullable<Query<T>>
orderBy?QueryOrderMap
refresh?boolean
validate?boolean

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

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


preparePopulate#

PrivatepreparePopulate<T>(entityName: string, populate?: boolean | readonly string[] | SELECT_IN | JOINED | readonly keyof T[] | PopulateChildren<T>, strategy?: SELECT_IN | JOINED): PopulateOptions<T>[]

Type parameters:#

NameType
TAnyEntity<T>

Parameters:#

NameType
entityNamestring
populate?boolean | readonly string[] | SELECT_IN | JOINED | readonly keyof T[] | PopulateChildren<T>
strategy?SELECT_IN | JOINED

Returns: PopulateOptions<T>[]

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


preparePopulateObject#

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

Type parameters:#

NameType
TAnyEntity<T>

Parameters:#

NameType
metaEntityMetadata<T>
populatePopulateMap<T>
strategy?SELECT_IN | JOINED

Returns: PopulateOptions<T>[]

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


processWhere#

ProtectedprocessWhere<T>(entityName: string, where: FilterQuery<T>, options: FindOptions<T, Populate<T>>, type: read | update | delete): Promise<FilterQuery<T>>

Type parameters:#

NameType
TAnyEntity<T>

Parameters:#

NameType
entityNamestring
whereFilterQuery<T>
optionsFindOptions<T, Populate<T>>
typeread | update | delete

Returns: Promise<FilterQuery<T>>

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


remove#

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

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: EntityManager<D>

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


removeAndFlush#

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

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

Parameters:#

NameType
entityAnyEntity<any> | Reference<AnyEntity<any>>

Returns: Promise<void>

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


removeLater#

removeLater(entity: AnyEntity<any>): void

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<any>

Returns: void

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


rollback#

rollback(): Promise<void>

Rollbacks the transaction bound to this EntityManager.

Returns: Promise<void>

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


setFilterParams#

setFilterParams(name: string, args: Dictionary<any>): void

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<any>

Returns: void

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


storeCache#

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

internal

Parameters:#

NameType
configundefined | number | boolean | [string, number]
key{ key: string }
dataunknown

Returns: Promise<void>

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


transactional#

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

Runs your callback wrapped inside a database transaction.

Type parameters:#

Name
T

Parameters:#

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

Returns: Promise<T>

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


tryCache#

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

internal

Type parameters:#

Name
T
R

Parameters:#

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

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

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

Last updated on by renovate[bot]