UNPKG

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

36 lines (35 loc) 1.58 kB
import type { AnyEntity, EntityMetadata } from '../typings.js'; /** @internal Stores managed entity instances keyed by their primary key hash, ensuring each row is loaded once. */ export declare class IdentityMap { #private; constructor(defaultSchema?: string); /** Stores an entity in the identity map under its primary key hash. */ store<T>(item: T): void; /** * Stores an entity under an alternate key (non-PK property). * This allows looking up entities by unique properties that are not the primary key. */ storeByKey<T>(item: T, key: string, value: string, schema?: string): void; /** Removes an entity and its alternate key entries from the identity map. */ delete<T>(item: T): void; /** Retrieves an entity by its hash key from the identity map. */ getByHash<T>(meta: EntityMetadata<T>, hash: string): T | undefined; /** Returns (or creates) the per-entity-class store within the identity map. */ getStore<T>(meta: EntityMetadata<T>): Map<string, T>; clear(): void; /** Returns all entities currently in the identity map. */ values(): AnyEntity[]; [Symbol.iterator](): IterableIterator<AnyEntity>; /** Returns all hash keys currently in the identity map. */ keys(): string[]; /** * For back compatibility only. */ get<T>(hash: string): T | undefined; private getPkHash; /** * Creates a hash for an alternate key lookup. * Format: `[key]value` or `schema:[key]value` */ getKeyHash(key: string, value: string, schema?: string): string; }