Skip to main content
Version: 4.5

Class: SqlEntityManager<D>#

knex.SqlEntityManager

inheritdoc

Type parameters#

NameTypeDefault
DAbstractSqlDriverAbstractSqlDriver

Hierarchy#

Constructors#

constructor#

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

Type parameters:#

NameTypeDefault
DAbstractSqlDriver<AbstractSqlConnection, D>AbstractSqlDriver<AbstractSqlConnection>

Parameters:#

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

Returns: EntityManager<D>

Inherited from: EntityManager

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

Properties#

config#

Readonly config: Configuration<IDatabaseDriver<Connection>>

Inherited from: EntityManager.config


id#

Readonly id: number

Inherited from: EntityManager.id

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


name#

Readonly name: string

Inherited from: EntityManager.name

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

Methods#

[custom]#

[custom](): string

Returns: string

Inherited from: EntityManager

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


addFilter#

addFilter<T1>(name: string, cond: FilterQuery<T1> | (args: Dictionary<any>) => FilterQuery<T1>, entityName?: EntityName<T1> | [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
condFilterQuery<T1> | (args: Dictionary<any>) => FilterQuery<T1>
entityName?EntityName<T1> | [EntityName<T1>]
enabled?boolean

Returns: void

Inherited from: EntityManager

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

addFilter<T1, T2>(name: string, cond: FilterQuery<T1 | 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
condFilterQuery<T1 | T2> | (args: Dictionary<any>) => FilterQuery<T1 | T2>
entityName?[EntityName<T1>, EntityName<T2>]
enabled?boolean

Returns: void

Inherited from: EntityManager

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

addFilter<T1, T2, T3>(name: string, cond: FilterQuery<T1 | T2 | 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
condFilterQuery<T1 | T2 | T3> | (args: Dictionary<any>) => FilterQuery<T1 | T2 | T3>
entityName?[EntityName<T1>, EntityName<T2>, EntityName<T3>]
enabled?boolean

Returns: void

Inherited from: EntityManager

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>

Inherited from: EntityManager

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


applyFilters#

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

internal

Type parameters:#

NameType
TAnyEntity<T>

Parameters:#

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

Returns: Promise<FilterQuery<T>>

Inherited from: EntityManager

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


assign#

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

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

Type parameters:#

NameType
TAnyEntity<T>

Parameters:#

NameType
entityT
dataEntityData<T>
optionsAssignOptions

Returns: T

Inherited from: EntityManager

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


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>

Inherited from: EntityManager

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


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

Inherited from: EntityManager

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


clear#

clear(): void

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

Returns: void

Inherited from: EntityManager

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


commit#

commit(): Promise<void>

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

Returns: Promise<void>

Inherited from: EntityManager

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


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

NameType
entityNameEntityName<T>
whereFilterQuery<T>
optionsCountOptions<T>

Returns: Promise<number>

Inherited from: EntityManager

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


create#

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

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

Type parameters:#

NameTypeDefault
TAnyEntity<T>-
Preadonly string[] | readonly keyof T[] | boolean | LoadStrategy | PopulateChildren<T>any

Parameters:#

NameType
entityNameEntityName<T>
dataEntityData<T>
optionsobject
options.managed?boolean

Returns: Loaded<T, P>

Inherited from: EntityManager

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


createQueryBuilder#

createQueryBuilder<T>(entityName: EntityName<T>, alias?: string, type?: read | write): QueryBuilder<T>

Creates a QueryBuilder instance

Type parameters:#

Name
T

Parameters:#

NameType
entityNameEntityName<T>
alias?string
type?read | write

Returns: QueryBuilder<T>

Defined in: packages/knex/src/SqlEntityManager.ts:15


execute#

execute<T>(queryOrKnex: string | QueryBuilder<any, any> | Raw<any>, params?: any[], method?: all | get | run): Promise<T>

Type parameters:#

NameTypeDefault
TQueryResult | EntityData<AnyEntity<any>> | EntityData<AnyEntity<any>>[]EntityData<AnyEntity<any>>[]

Parameters:#

NameTypeDefault value
queryOrKnexstring | QueryBuilder<any, any> | Raw<any>-
paramsany[]-
methodall | get | run'all'

Returns: Promise<T>

Defined in: packages/knex/src/SqlEntityManager.ts:27


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>-
Preadonly string[] | readonly keyof T[] | boolean | LoadStrategy | PopulateChildren<T>any

Parameters:#

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

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

Inherited from: EntityManager

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>-
Preadonly string[] | readonly keyof T[] | boolean | LoadStrategy | PopulateChildren<T>any

Parameters:#

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

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

Inherited from: EntityManager

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>-
Preadonly string[] | readonly keyof T[] | boolean | LoadStrategy | PopulateChildren<T>any

Parameters:#

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

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

Inherited from: EntityManager

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

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>-
Preadonly string[] | readonly keyof T[] | boolean | LoadStrategy | PopulateChildren<T>any

Parameters:#

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

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

Inherited from: EntityManager

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


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>-
Preadonly string[] | readonly keyof T[] | boolean | LoadStrategy | PopulateChildren<T>any

Parameters:#

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

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

Inherited from: EntityManager

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

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>-
Preadonly string[] | readonly keyof T[] | boolean | LoadStrategy | PopulateChildren<T>any

Parameters:#

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

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

Inherited from: EntityManager

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


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>-
Preadonly string[] | readonly keyof T[] | boolean | LoadStrategy | PopulateChildren<T>any

Parameters:#

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

Returns: Promise<Loaded<T, P>>

Inherited from: EntityManager

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

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>-
Preadonly string[] | readonly keyof T[] | boolean | LoadStrategy | PopulateChildren<T>any

Parameters:#

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

Returns: Promise<Loaded<T, P>>

Inherited from: EntityManager

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


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>

Inherited from: EntityManager

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


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]

Inherited from: EntityManager

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


getComparator#

getComparator(): EntityComparator

Gets the EntityComparator.

Returns: EntityComparator

Inherited from: EntityManager

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


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

Inherited from: EntityManager

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

Inherited from: EntityManager

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


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

Inherited from: EntityManager

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


getEntityFactory#

getEntityFactory(): EntityFactory

Gets the EntityFactory used by the EntityManager.

Returns: EntityFactory

Inherited from: EntityManager

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


getEventManager#

getEventManager(): EventManager

Returns: EventManager

Inherited from: EntityManager

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


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

Inherited from: EntityManager

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


getKnex#

getKnex(type?: read | write): Knex<any, unknown[]>

Returns configured knex instance.

Parameters:#

NameType
type?read | write

Returns: Knex<any, unknown[]>

Defined in: packages/knex/src/SqlEntityManager.ts:23


getMetadata#

getMetadata(): MetadataStorage

Gets the MetadataStorage.

Returns: MetadataStorage

Inherited from: EntityManager

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


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

Inherited from: EntityManager

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>

Inherited from: EntityManager

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

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

Inherited from: EntityManager

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

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

Inherited from: EntityManager

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

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>

Inherited from: EntityManager

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


getRepository#

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

Type parameters:#

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

Parameters:#

NameType
entityNameEntityName<T>

Returns: GetRepository<T, U>

Overrides: EntityManager

Defined in: packages/knex/src/SqlEntityManager.ts:31


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

Inherited from: EntityManager

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


getUnitOfWork#

getUnitOfWork(): UnitOfWork

Gets the UnitOfWork used by the EntityManager to coordinate operations.

Returns: UnitOfWork

Inherited from: EntityManager

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


getValidator#

getValidator(): EntityValidator

Gets EntityValidator instance

Returns: EntityValidator

Inherited from: EntityManager

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


isInTransaction#

isInTransaction(): boolean

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

Returns: boolean

Inherited from: EntityManager

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


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>

Inherited from: EntityManager

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


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

Inherited from: EntityManager

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


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

Inherited from: EntityManager

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

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

Inherited from: EntityManager

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


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

NameType
entityNameEntityName<T>
whereFilterQuery<T>
optionsDeleteOptions<T>

Returns: Promise<number>

Inherited from: EntityManager

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


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

Inherited from: EntityManager

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

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

Inherited from: EntityManager

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


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

NameType
entityNameEntityName<T>
whereFilterQuery<T>
dataEntityData<T>
optionsUpdateOptions<T>

Returns: Promise<number>

Inherited from: EntityManager

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


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>

Inherited from: EntityManager

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


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>

Inherited from: EntityManager

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


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

Inherited from: EntityManager

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


populate#

populate<T, P>(entities: T, populate: P, where?: FilterQuery<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?FilterQuery<T>
orderBy?QueryOrderMap
refresh?boolean
validate?boolean

Returns: Promise<Loaded<T, P>>

Inherited from: EntityManager

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

populate<T, P>(entities: T[], populate: P, where?: FilterQuery<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?FilterQuery<T>
orderBy?QueryOrderMap
refresh?boolean
validate?boolean

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

Inherited from: EntityManager

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

populate<T, P>(entities: T | T[], populate: P, where?: FilterQuery<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?FilterQuery<T>
orderBy?QueryOrderMap
refresh?boolean
validate?boolean

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

Inherited from: EntityManager

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


processWhere#

ProtectedprocessWhere<T>(entityName: string, where: FilterQuery<T>, options: FindOptions<T, readonly string[] | readonly keyof T[] | boolean | LoadStrategy | PopulateChildren<T>>, type: read | update | delete): Promise<FilterQuery<T>>

Type parameters:#

NameType
TAnyEntity<T>

Parameters:#

NameType
entityNamestring
whereFilterQuery<T>
optionsFindOptions<T, readonly string[] | readonly keyof T[] | boolean | LoadStrategy | PopulateChildren<T>>
typeread | update | delete

Returns: Promise<FilterQuery<T>>

Inherited from: EntityManager

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>

Inherited from: EntityManager

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


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>

Inherited from: EntityManager

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


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

Inherited from: EntityManager

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


resetTransactionContext#

resetTransactionContext(): void

Resets the transaction context.

Returns: void

Inherited from: EntityManager

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


rollback#

rollback(): Promise<void>

Rollbacks the transaction bound to this EntityManager.

Returns: Promise<void>

Inherited from: EntityManager

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


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

Inherited from: EntityManager

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


setTransactionContext#

setTransactionContext(ctx: any): void

Sets the transaction context.

Parameters:#

NameType
ctxany

Returns: void

Inherited from: EntityManager

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


storeCache#

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

internal

Parameters:#

NameType
configundefined | number | boolean | [string, number]
keyobject
key.keystring
dataunknown

Returns: Promise<void>

Inherited from: EntityManager

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


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

NameType
cb(em: D[typeof EntityManagerType]) => Promise<T>
ctxany

Returns: Promise<T>

Inherited from: EntityManager

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


tryCache#

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

Inherited from: EntityManager

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

Last updated on by renovate[bot]