@mikro-orm/core
Version:
TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.
122 lines (121 loc) • 4.93 kB
TypeScript
import type { AnyEntity, EntityData, EntityMetadata, EntityProperty, FilterQuery, Primary } from '../typings';
import { Collection, Reference } from '../entity';
import { ChangeSet, ChangeSetType } from './ChangeSet';
import { ChangeSetPersister } from './ChangeSetPersister';
import type { EntityManager } from '../EntityManager';
import { IdentityMap } from './IdentityMap';
import type { LockOptions } from '../drivers/IDatabaseDriver';
export declare class UnitOfWork {
private readonly em;
/** map of references to managed entities */
private readonly identityMap;
private readonly persistStack;
private readonly removeStack;
private readonly orphanRemoveStack;
private readonly changeSets;
private readonly collectionUpdates;
private readonly extraUpdates;
private readonly metadata;
private readonly platform;
private readonly eventManager;
private readonly comparator;
private readonly changeSetComputer;
private readonly changeSetPersister;
private readonly queuedActions;
private readonly loadedEntities;
private readonly flushQueue;
private working;
constructor(em: EntityManager);
merge<T extends object>(entity: T, visited?: Set<AnyEntity>): void;
/**
* @internal
*/
register<T extends object>(entity: T, data?: EntityData<T>, options?: RegisterOptions): T;
/**
* @internal
*/
dispatchOnLoadEvent(): Promise<void>;
/**
* 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`.
*/
getById<T extends object>(entityName: string, id: Primary<T> | Primary<T>[], schema?: string, convertCustomTypes?: boolean): T | undefined;
tryGetById<T extends object>(entityName: string, where: FilterQuery<T>, schema?: string, strict?: boolean): T | null;
/**
* Returns map of all managed entities.
*/
getIdentityMap(): IdentityMap;
/**
* Returns stored snapshot of entity state that is used for change set computation.
*/
getOriginalEntityData<T extends object>(entity: T): EntityData<T> | undefined;
getPersistStack(): Set<AnyEntity>;
getRemoveStack(): Set<AnyEntity>;
getChangeSets(): ChangeSet<AnyEntity>[];
getCollectionUpdates(): Collection<AnyEntity>[];
getExtraUpdates(): Set<[AnyEntity, string | string[], (AnyEntity | AnyEntity[] | Reference<any> | Collection<any>), ChangeSet<any> | undefined, ChangeSetType]>;
shouldAutoFlush<T extends object>(meta: EntityMetadata<T>): boolean;
clearActionsQueue(): void;
computeChangeSet<T extends object>(entity: T, type?: ChangeSetType): void;
recomputeSingleChangeSet<T extends object>(entity: T): void;
persist<T extends object>(entity: T, visited?: Set<AnyEntity>, options?: {
checkRemoveStack?: boolean;
cascade?: boolean;
}): void;
remove<T extends object>(entity: T, visited?: Set<AnyEntity>, options?: {
cascade?: boolean;
}): void;
commit(): Promise<void>;
private doCommit;
lock<T extends object>(entity: T, options: LockOptions): Promise<void>;
clear(): void;
unsetIdentity(entity: AnyEntity): void;
computeChangeSets(): void;
scheduleExtraUpdate<T extends object>(changeSet: ChangeSet<T>, props: EntityProperty<T>[]): void;
scheduleOrphanRemoval(entity?: AnyEntity, visited?: Set<AnyEntity>): void;
cancelOrphanRemoval(entity: AnyEntity, visited?: Set<AnyEntity>): void;
getOrphanRemoveStack(): Set<AnyEntity>;
getChangeSetPersister(): ChangeSetPersister;
private findNewEntities;
/**
* Returns `true` when the change set should be skipped as it will be empty after the extra update.
*/
private checkUniqueProps;
private expandUniqueProps;
private initIdentifier;
private processReference;
private processToOneReference;
private processToManyReference;
private runHooks;
private postCommitCleanup;
private cascade;
private cascadeReference;
private isCollectionSelfReferenced;
private shouldCascade;
private lockPessimistic;
private lockOptimistic;
private fixMissingReference;
private persistToDatabase;
private commitCreateChangeSets;
private findExtraUpdates;
private findEarlyUpdates;
private commitUpdateChangeSets;
private commitDeleteChangeSets;
private commitExtraUpdates;
private commitCollectionUpdates;
private filterCollectionUpdates;
/**
* Orders change sets so FK constrains are maintained, ensures stable order (needed for node < 11)
*/
private getChangeSetGroups;
private getCommitOrder;
private resetTransaction;
/**
* Takes snapshots of all processed collections
*/
private takeCollectionSnapshots;
}
export interface RegisterOptions {
refresh?: boolean;
newEntity?: boolean;
loaded?: boolean;
}