UNPKG

@nestjs/typeorm

Version:

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

33 lines (32 loc) 1.49 kB
import { Logger } from '@nestjs/common'; /** * Tracks active data source names at runtime in order to prevent multiple * data sources from being registered under the same name. Registering two * data sources with the same name is unsupported by TypeORM — the second * registration silently overrides the first — which is a common source * of hard-to-debug configuration issues. */ export class DataSourceNameRegistry { static logger = new Logger(DataSourceNameRegistry.name); static registeredNames = new Set(); static register(dataSourceName) { if (this.registeredNames.has(dataSourceName)) { // Commented out to avoid throwing an exception as it caused regressions in test suites. // throw new DuplicateDataSourceException(dataSourceName); this.logger.warn(`A data source with the ${dataSourceName} name is already registered. ` + `Multiple data sources must be registered with unique names; otherwise, ` + `they will override each other. Please assign a unique "name" property ` + `to each TypeOrmModule.forRoot()/forRootAsync() registration.`); } this.registeredNames.add(dataSourceName); } static unregister(dataSourceName) { this.registeredNames.delete(dataSourceName); } static has(dataSourceName) { return this.registeredNames.has(dataSourceName); } static clear() { this.registeredNames.clear(); } }