UNPKG

@nestjs/typeorm

Version:

Nest - modern, fast, powerful node.js web framework (@typeorm)

32 lines (31 loc) 972 B
export class EntitiesMetadataStorage { static storage = new Map(); static addEntitiesByDataSource(dataSource, entities) { const dataSourceToken = typeof dataSource === 'string' ? dataSource : dataSource.name; if (!dataSourceToken) { return; } let collection = this.storage.get(dataSourceToken); if (!collection) { collection = []; this.storage.set(dataSourceToken, collection); } entities.forEach((entity) => { if (collection.includes(entity)) { return; } collection.push(entity); }); } static getEntitiesByDataSource(dataSource) { const dataSourceToken = typeof dataSource === 'string' ? dataSource : dataSource.name; if (!dataSourceToken) { return []; } return this.storage.get(dataSourceToken) || []; } }