UNPKG

quaerateum

Version:

Simple 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 JS.

29 lines (20 loc) 879 B
import { EntityClass, EntityClassGroup, EntityMetadata, IEntityType } from '../decorators'; import { Configuration, Utils } from '../utils'; import { MetadataStorage } from './MetadataStorage'; export abstract class MetadataProvider { constructor(protected readonly config: Configuration) { } abstract async loadEntityMetadata(meta: EntityMetadata, name: string): Promise<void>; loadFromCache(meta: EntityMetadata, cache: EntityMetadata): void { Utils.merge(meta, cache); } prepare<T extends IEntityType<T>>(entity: EntityClass<T> | EntityClassGroup<T>): EntityClass<T> { // save path to entity from schema if ('entity' in entity && 'schema' in entity) { const schema = entity.schema; const meta = MetadataStorage.getMetadata(entity.entity.name); meta.path = schema.path; return entity.entity; } return entity; } }