Skip to main content
Version: 4.5

Class: UnitOfWork#

core.UnitOfWork

Constructors#

constructor#

+ new UnitOfWork(em: EntityManager<IDatabaseDriver<Connection>>): UnitOfWork

Parameters:#

NameType
emEntityManager<IDatabaseDriver<Connection>>

Returns: UnitOfWork

Defined in: packages/core/src/unit-of-work/UnitOfWork.ts:32

Properties#

changeSetComputer#

Private Readonly changeSetComputer: ChangeSetComputer

Defined in: packages/core/src/unit-of-work/UnitOfWork.ts:30


changeSetPersister#

Private Readonly changeSetPersister: ChangeSetPersister

Defined in: packages/core/src/unit-of-work/UnitOfWork.ts:31


changeSets#

Private Readonly changeSets: Map<AnyEntity<any>, ChangeSet<AnyEntity<any>>>

Defined in: packages/core/src/unit-of-work/UnitOfWork.ts:23


collectionUpdates#

Private Readonly collectionUpdates: Set<Collection<AnyEntity<any>, unknown>>

Defined in: packages/core/src/unit-of-work/UnitOfWork.ts:24


comparator#

Private Readonly comparator: EntityComparator

Defined in: packages/core/src/unit-of-work/UnitOfWork.ts:29


eventManager#

Private Readonly eventManager: EventManager

Defined in: packages/core/src/unit-of-work/UnitOfWork.ts:28


extraUpdates#

Private Readonly extraUpdates: Set<[AnyEntity<any>, string, Reference<any> | AnyEntity<any> | Collection<any, unknown>]>

Defined in: packages/core/src/unit-of-work/UnitOfWork.ts:25


identityMap#

Private Readonly identityMap: IdentityMap

map of references to managed entities

Defined in: packages/core/src/unit-of-work/UnitOfWork.ts:18


metadata#

Private Readonly metadata: MetadataStorage

Defined in: packages/core/src/unit-of-work/UnitOfWork.ts:26


orphanRemoveStack#

Private Readonly orphanRemoveStack: Set<AnyEntity<any>>

Defined in: packages/core/src/unit-of-work/UnitOfWork.ts:22


persistStack#

Private Readonly persistStack: Set<AnyEntity<any>>

Defined in: packages/core/src/unit-of-work/UnitOfWork.ts:20


platform#

Private Readonly platform: Platform

Defined in: packages/core/src/unit-of-work/UnitOfWork.ts:27


removeStack#

Private Readonly removeStack: Set<AnyEntity<any>>

Defined in: packages/core/src/unit-of-work/UnitOfWork.ts:21


working#

Private working: boolean= false

Defined in: packages/core/src/unit-of-work/UnitOfWork.ts:32

Methods#

cancelOrphanRemoval#

cancelOrphanRemoval(entity: AnyEntity<any>): void

Parameters:#

NameType
entityAnyEntity<any>

Returns: void

Defined in: packages/core/src/unit-of-work/UnitOfWork.ts:323


cascade#

Privatecascade<T>(entity: T, type: Cascade, visited: WeakSet<AnyEntity<any>>, options?: { checkRemoveStack?: boolean }): void

Type parameters:#

NameType
TAnyEntity<T>

Parameters:#

NameType
entityT
typeCascade
visitedWeakSet<AnyEntity<any>>
optionsobject
options.checkRemoveStack?boolean

Returns: void

Defined in: packages/core/src/unit-of-work/UnitOfWork.ts:459


cascadeReference#

PrivatecascadeReference<T>(entity: T, prop: EntityProperty<T>, type: Cascade, visited: WeakSet<AnyEntity<any>>, options: { checkRemoveStack?: boolean }): void

Type parameters:#

NameType
TAnyEntity<T>

Parameters:#

NameType
entityT
propEntityProperty<T>
typeCascade
visitedWeakSet<AnyEntity<any>>
optionsobject
options.checkRemoveStack?boolean

Returns: void

Defined in: packages/core/src/unit-of-work/UnitOfWork.ts:477


checkOrphanRemoval#

PrivatecheckOrphanRemoval<T>(changeSet: ChangeSet<T>): void

Type parameters:#

NameType
TAnyEntity<T>

Parameters:#

NameType
changeSetChangeSet<T>

Returns: void

Defined in: packages/core/src/unit-of-work/UnitOfWork.ts:370


checkUniqueProps#

PrivatecheckUniqueProps<T>(changeSet: ChangeSet<T>): boolean

Type parameters:#

NameType
TAnyEntity<T>

Parameters:#

NameType
changeSetChangeSet<T>

Returns: boolean

Defined in: packages/core/src/unit-of-work/UnitOfWork.ts:355


clear#

clear(): void

Returns: void

Defined in: packages/core/src/unit-of-work/UnitOfWork.ts:270


commit#

commit(): Promise<void>

Returns: Promise<void>

Defined in: packages/core/src/unit-of-work/UnitOfWork.ts:216


commitCreateChangeSets#

PrivatecommitCreateChangeSets<T>(changeSets: ChangeSet<T>[], ctx?: any): Promise<void>

Type parameters:#

NameType
TAnyEntity<T>

Parameters:#

NameType
changeSetsChangeSet<T>[]
ctx?any

Returns: Promise<void>

Defined in: packages/core/src/unit-of-work/UnitOfWork.ts:613


commitDeleteChangeSets#

PrivatecommitDeleteChangeSets<T>(changeSets: ChangeSet<T>[], ctx?: any): Promise<void>

Type parameters:#

NameType
TAnyEntity<T>

Parameters:#

NameType
changeSetsChangeSet<T>[]
ctx?any

Returns: Promise<void>

Defined in: packages/core/src/unit-of-work/UnitOfWork.ts:668


commitUpdateChangeSets#

PrivatecommitUpdateChangeSets<T>(changeSets: ChangeSet<T>[], ctx?: any, batched?: boolean): Promise<void>

Type parameters:#

NameType
TAnyEntity<T>

Parameters:#

NameTypeDefault value
changeSetsChangeSet<T>[]-
ctx?any-
batchedbooleantrue

Returns: Promise<void>

Defined in: packages/core/src/unit-of-work/UnitOfWork.ts:651


computeChangeSet#

computeChangeSet<T>(entity: T): void

Type parameters:#

NameType
TAnyEntity<T>

Parameters:#

NameType
entityT

Returns: void

Defined in: packages/core/src/unit-of-work/UnitOfWork.ts:158


computeChangeSets#

computeChangeSets(): void

Returns: void

Defined in: packages/core/src/unit-of-work/UnitOfWork.ts:287


findExtraUpdates#

PrivatefindExtraUpdates<T>(changeSet: ChangeSet<T>, props: EntityProperty<T>[]): void

Type parameters:#

NameType
TAnyEntity<T>

Parameters:#

NameType
changeSetChangeSet<T>
propsEntityProperty<T>[]

Returns: void

Defined in: packages/core/src/unit-of-work/UnitOfWork.ts:636


findNewEntities#

PrivatefindNewEntities<T>(entity: T, visited?: WeakSet<AnyEntity<any>>): void

Type parameters:#

NameType
TAnyEntity<T>

Parameters:#

NameType
entityT
visitedWeakSet<AnyEntity<any>>

Returns: void

Defined in: packages/core/src/unit-of-work/UnitOfWork.ts:327


fixMissingReference#

PrivatefixMissingReference<T>(entity: T, prop: EntityProperty<T>): void

Type parameters:#

NameType
TAnyEntity<T>

Parameters:#

NameType
entityT
propEntityProperty<T>

Returns: void

Defined in: packages/core/src/unit-of-work/UnitOfWork.ts:553


getById#

getById<T>(entityName: string, id: Primary<T> | Primary<T>[]): undefined | T

Returns entity from the identity map. For composite keys, you need to pass an array of PKs in the same order as they are defined in meta.primaryKeys.

Type parameters:#

NameType
TAnyEntity<T>

Parameters:#

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

Returns: undefined | T

Defined in: packages/core/src/unit-of-work/UnitOfWork.ts:87


getChangeSetGroups#

PrivategetChangeSetGroups(): object

Orders change sets so FK constrains are maintained, ensures stable order (needed for node < 11)

Returns: object

NameType
create
delete
update

Defined in: packages/core/src/unit-of-work/UnitOfWork.ts:688


getChangeSets#

getChangeSets(): ChangeSet<AnyEntity<any>>[]

Returns: ChangeSet<AnyEntity<any>>[]

Defined in: packages/core/src/unit-of-work/UnitOfWork.ts:146


getCollectionUpdates#

getCollectionUpdates(): Collection<AnyEntity<any>, unknown>[]

Returns: Collection<AnyEntity<any>, unknown>[]

Defined in: packages/core/src/unit-of-work/UnitOfWork.ts:150


getCommitOrder#

PrivategetCommitOrder(): string[]

Returns: string[]

Defined in: packages/core/src/unit-of-work/UnitOfWork.ts:704


getExtraUpdates#

getExtraUpdates(): Set<[AnyEntity<any>, string, Reference<any> | AnyEntity<any> | Collection<any, unknown>]>

Returns: Set<[AnyEntity<any>, string, Reference<any> | AnyEntity<any> | Collection<any, unknown>]>

Defined in: packages/core/src/unit-of-work/UnitOfWork.ts:154


getIdentityMap#

getIdentityMap(): IdentityMap

Returns map of all managed entities.

Returns: IdentityMap

Defined in: packages/core/src/unit-of-work/UnitOfWork.ts:111


getOriginalEntityData#

getOriginalEntityData<T>(): AnyEntity<any>[]

deprecated use uow.getOriginalEntityData(entity)

Type parameters:#

NameType
TAnyEntity<T>

Returns: AnyEntity<any>[]

Defined in: packages/core/src/unit-of-work/UnitOfWork.ts:118

getOriginalEntityData<T>(entity: T): undefined | EntityData<T>

Returns stored snapshot of entity state that is used for change set computation.

Type parameters:#

NameType
TAnyEntity<T>

Parameters:#

NameType
entityT

Returns: undefined | EntityData<T>

Defined in: packages/core/src/unit-of-work/UnitOfWork.ts:123


getPersistStack#

getPersistStack(): Set<AnyEntity<any>>

Returns: Set<AnyEntity<any>>

Defined in: packages/core/src/unit-of-work/UnitOfWork.ts:138


getRemoveStack#

getRemoveStack(): Set<AnyEntity<any>>

Returns: Set<AnyEntity<any>>

Defined in: packages/core/src/unit-of-work/UnitOfWork.ts:142


initIdentifier#

PrivateinitIdentifier<T>(entity: T): void

Type parameters:#

NameType
TAnyEntity<T>

Parameters:#

NameType
entityT

Returns: void

Defined in: packages/core/src/unit-of-work/UnitOfWork.ts:385


isCollectionSelfReferenced#

PrivateisCollectionSelfReferenced(collection: Collection<AnyEntity<any>, unknown>, visited: WeakSet<AnyEntity<any>>): boolean

Parameters:#

NameType
collectionCollection<AnyEntity<any>, unknown>
visitedWeakSet<AnyEntity<any>>

Returns: boolean

Defined in: packages/core/src/unit-of-work/UnitOfWork.ts:505


lock#

lock<T>(entity: T, mode: LockMode, version?: number | Date): Promise<void>

Type parameters:#

NameType
TAnyEntity<T>

Parameters:#

NameType
entityT
modeLockMode
version?number | Date

Returns: Promise<void>

Defined in: packages/core/src/unit-of-work/UnitOfWork.ts:256


lockOptimistic#

PrivatelockOptimistic<T>(entity: T, meta: EntityMetadata<T>, version: number | Date): Promise<void>

Type parameters:#

NameType
TAnyEntity<T>

Parameters:#

NameType
entityT
metaEntityMetadata<T>
versionnumber | Date

Returns: Promise<void>

Defined in: packages/core/src/unit-of-work/UnitOfWork.ts:531


lockPessimistic#

PrivatelockPessimistic<T>(entity: T, mode: LockMode): Promise<void>

Type parameters:#

NameType
TAnyEntity<T>

Parameters:#

NameType
entityT
modeLockMode

Returns: Promise<void>

Defined in: packages/core/src/unit-of-work/UnitOfWork.ts:523


merge#

merge<T>(entity: T, visited?: WeakSet<AnyEntity<any>>): void

Type parameters:#

NameType
TAnyEntity<T>

Parameters:#

NameType
entityT
visited?WeakSet<AnyEntity<any>>

Returns: void

Defined in: packages/core/src/unit-of-work/UnitOfWork.ts:36


persist#

persist<T>(entity: T, visited?: WeakSet<AnyEntity<any>>, checkRemoveStack?: boolean): void

Type parameters:#

NameType
TAnyEntity<T>

Parameters:#

NameTypeDefault value
entityT-
visitedWeakSet<AnyEntity<any>>-
checkRemoveStackbooleanfalse

Returns: void

Defined in: packages/core/src/unit-of-work/UnitOfWork.ts:189


persistToDatabase#

PrivatepersistToDatabase(groups: { create: ; delete: ; update: }, tx?: any): Promise<void>

Parameters:#

NameType
groupsobject
groups.create-
groups.delete-
groups.update-
tx?any

Returns: Promise<void>

Defined in: packages/core/src/unit-of-work/UnitOfWork.ts:569


postCommitCleanup#

PrivatepostCommitCleanup(): void

Returns: void

Defined in: packages/core/src/unit-of-work/UnitOfWork.ts:449


processReference#

PrivateprocessReference<T>(parent: T, prop: EntityProperty<T>, reference: any, visited: WeakSet<AnyEntity<any>>): void

Type parameters:#

NameType
TAnyEntity<T>

Parameters:#

NameType
parentT
propEntityProperty<T>
referenceany
visitedWeakSet<AnyEntity<any>>

Returns: void

Defined in: packages/core/src/unit-of-work/UnitOfWork.ts:395


processToManyReference#

PrivateprocessToManyReference<T>(reference: Collection<AnyEntity<any>, unknown>, visited: WeakSet<AnyEntity<any>>, parent: T, prop: EntityProperty<T>): void

Type parameters:#

NameType
TAnyEntity<T>

Parameters:#

NameType
referenceCollection<AnyEntity<any>, unknown>
visitedWeakSet<AnyEntity<any>>
parentT
propEntityProperty<T>

Returns: void

Defined in: packages/core/src/unit-of-work/UnitOfWork.ts:413


processToOneReference#

PrivateprocessToOneReference<T>(reference: any, visited: WeakSet<AnyEntity<any>>): void

Type parameters:#

NameType
TAnyEntity<T>

Parameters:#

NameType
referenceany
visitedWeakSet<AnyEntity<any>>

Returns: void

Defined in: packages/core/src/unit-of-work/UnitOfWork.ts:407


recomputeSingleChangeSet#

recomputeSingleChangeSet<T>(entity: T): void

Type parameters:#

NameType
TAnyEntity<T>

Parameters:#

NameType
entityT

Returns: void

Defined in: packages/core/src/unit-of-work/UnitOfWork.ts:172


registerManaged#

registerManaged<T>(entity: T, data?: EntityData<T>, refresh?: boolean, newEntity?: boolean): T

internal

Type parameters:#

NameType
TAnyEntity<T>

Parameters:#

NameType
entityT
data?EntityData<T>
refresh?boolean
newEntity?boolean

Returns: T

Defined in: packages/core/src/unit-of-work/UnitOfWork.ts:66


remove#

remove(entity: AnyEntity<any>, visited?: WeakSet<AnyEntity<any>>): void

Parameters:#

NameType
entityAnyEntity<any>
visitedWeakSet<AnyEntity<any>>

Returns: void

Defined in: packages/core/src/unit-of-work/UnitOfWork.ts:203


runHooks#

PrivaterunHooks<T>(type: EventType, changeSet: ChangeSet<T>, sync?: boolean): Promise<unknown>

Type parameters:#

NameType
TAnyEntity<T>

Parameters:#

NameTypeDefault value
typeEventType-
changeSetChangeSet<T>-
syncbooleanfalse

Returns: Promise<unknown>

Defined in: packages/core/src/unit-of-work/UnitOfWork.ts:426


scheduleExtraUpdate#

scheduleExtraUpdate<T>(changeSet: ChangeSet<T>, prop: EntityProperty<T>): void

Type parameters:#

Name
T

Parameters:#

NameType
changeSetChangeSet<T>
propEntityProperty<T>

Returns: void

Defined in: packages/core/src/unit-of-work/UnitOfWork.ts:311


scheduleOrphanRemoval#

scheduleOrphanRemoval(entity?: AnyEntity<any>): void

Parameters:#

NameType
entity?AnyEntity<any>

Returns: void

Defined in: packages/core/src/unit-of-work/UnitOfWork.ts:317


shouldCascade#

PrivateshouldCascade(prop: EntityProperty<any>, type: Cascade): boolean

Parameters:#

NameType
propEntityProperty<any>
typeCascade

Returns: boolean

Defined in: packages/core/src/unit-of-work/UnitOfWork.ts:510


tryGetById#

tryGetById<T>(entityName: string, where: FilterQuery<T>, strict?: boolean): null | T

Type parameters:#

NameType
TAnyEntity<T>

Parameters:#

NameTypeDefault value
entityNamestring-
whereFilterQuery<T>-
strictbooleantrue

Returns: null | T

Defined in: packages/core/src/unit-of-work/UnitOfWork.ts:98


unsetIdentity#

unsetIdentity(entity: AnyEntity<any>): void

Parameters:#

NameType
entityAnyEntity<any>

Returns: void

Defined in: packages/core/src/unit-of-work/UnitOfWork.ts:275

Last updated on by Renovate Bot