UnitOfWork
Index
Constructors
Methods
- cancelOrphanRemoval
- clear
- clearActionsQueue
- commit
- computeChangeSet
- computeChangeSets
- getById
- getByKey
- getChangeSetPersister
- getChangeSets
- getCollectionUpdates
- getExtraUpdates
- getIdentityMap
- getOriginalEntityData
- getOrphanRemoveStack
- getPersistStack
- getRemoveStack
- lock
- merge
- persist
- recomputeSingleChangeSet
- remove
- scheduleExtraUpdate
- scheduleOrphanRemoval
- shouldAutoFlush
- storeByKey
- tryGetById
- unsetIdentity
Constructors
constructor
Parameters
Returns UnitOfWork
Methods
cancelOrphanRemoval
Parameters
entity: Partial<any>
optionalvisited: Set<Partial<any>>
Returns void
clear
Returns void
clearActionsQueue
Clears the queue of entity types that triggered auto-flush detection.
Returns void
commit
Flushes all pending changes to the database within a transaction.
Returns Promise<void>
computeChangeSet
Computes and registers a change set for the given entity.
Parameters
entity: T
optionaltype: ChangeSetType
Returns void
computeChangeSets
Returns void
getById
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.Parameters
entityName: EntityName<T>
id: (T extends { [PrimaryKeyProp]?: PK } ? PK extends undefined ? Omit<T<T>, typeof PrimaryKeyProp> : PK extends keyof T<T> ? ReadonlyPrimary<UnwrapPrimary<T<T>[PK<PK>]>> : PK extends keyof T<T>[] ? ReadonlyPrimary<PrimaryPropToType<T<T>, PK<PK>>> : PK : T extends { _id?: PK } ? string | ReadonlyPrimary<PK> : T extends { id?: PK } ? ReadonlyPrimary<PK> : T extends { uuid?: PK } ? ReadonlyPrimary<PK> : T) | (T extends { [PrimaryKeyProp]?: PK } ? PK extends undefined ? Omit<T<T>, typeof PrimaryKeyProp> : PK extends keyof T<T> ? ReadonlyPrimary<UnwrapPrimary<T<T>[PK<PK>]>> : PK extends keyof T<T>[] ? ReadonlyPrimary<PrimaryPropToType<T<T>, PK<PK>>> : PK : T extends { _id?: PK } ? string | ReadonlyPrimary<PK> : T extends { id?: PK } ? ReadonlyPrimary<PK> : T extends { uuid?: PK } ? ReadonlyPrimary<PK> : T)[]
optionalschema: string
optionalconvertCustomTypes: boolean
Returns undefined | T
getByKey
Returns entity from the identity map by an alternate key (non-PK property).
Parameters
entityName: EntityName<T>
key: string
value: unknown
optionalschema: string
optionalconvertCustomTypes: boolean
If true, the value is in database format and will be converted to JS format for lookup. If false (default), the value is assumed to be in JS format already.
Returns undefined | T
getChangeSetPersister
Returns ChangeSetPersister
getChangeSets
Returns all computed change sets for the current flush.
Returns ChangeSet<Partial<any>>[]
getCollectionUpdates
Returns all M:N collections that need synchronization.
Returns Collection<Partial<any>, object>[]
getExtraUpdates
Returns extra updates needed for relations that could not be resolved in the initial pass.
Returns Set<[Partial<any>, string | string[], Partial<any> | Collection<any, object> | Partial<any>[] | Reference<any>, undefined | ChangeSet<any>, ChangeSetType]>
getIdentityMap
Returns map of all managed entities.
Returns IdentityMap
getOriginalEntityData
Returns stored snapshot of entity state that is used for change set computation.
Parameters
entity: T
Returns undefined | EntityData<T>
getOrphanRemoveStack
Returns Set<Partial<any>>
getPersistStack
Returns the set of entities scheduled for persistence.
Returns Set<Partial<any>>
getRemoveStack
Returns the set of entities scheduled for removal.
Returns Set<Partial<any>>
lock
Parameters
entity: T
options: LockOptions
Returns Promise<void>
merge
Merges an entity into the identity map, taking a snapshot of its current state.
Parameters
entity: T
optionalvisited: Set<Partial<any>>
Returns void
persist
Marks an entity for persistence, cascading to related entities.
Parameters
entity: T
optionalvisited: Set<Partial<any>>
options: { cascade?: boolean; checkRemoveStack?: boolean } = {}
optionalcascade: boolean
optionalcheckRemoveStack: boolean
Returns void
recomputeSingleChangeSet
Recomputes and merges the change set for an already-tracked entity.
Parameters
entity: T
Returns void
remove
Marks an entity for removal, cascading to related entities.
Parameters
entity: T
optionalvisited: Set<Partial<any>>
options: { cascade?: boolean } = {}
optionalcascade: boolean
Returns void
scheduleExtraUpdate
Parameters
changeSet: ChangeSet<T>
props: EntityProperty<T, any>[]
Returns void
scheduleOrphanRemoval
Parameters
optionalentity: Partial<any>
optionalvisited: Set<Partial<any>>
Returns void
shouldAutoFlush
Checks whether an auto-flush is needed before querying the given entity type.
Parameters
meta: EntityMetadata<T, EntityCtor<T>>
Returns boolean
storeByKey
Stores an entity in the identity map under an alternate key (non-PK property). Also sets the property value on the entity.
Parameters
entity: T
key: string
value: unknown
optionalschema: string
optionalconvertCustomTypes: boolean
If true, the value is in database format and will be converted to JS format. If false (default), the value is assumed to be in JS format already.
Returns void
tryGetById
Attempts to extract a primary key from the where condition and look up the entity in the identity map.
Parameters
entityName: EntityName<T>
where: FilterQuery<T>
optionalschema: string
strict: boolean = true
Returns null | T
unsetIdentity
Parameters
entity: Partial<any>
Returns void
Implements the Unit of Work pattern: tracks entity changes, computes change sets, and flushes them to the database.