import {Injectable} from '@nestjs/common'; import {TypeOrmModuleOptions, TypeOrmOptionsFactory} from '@nestjs/typeorm'; import {DatabaseModuleConfig} from './database.module'; @Injectable() export class TypeOrmSQLConfigService implements TypeOrmOptionsFactory { protected TAG: string = `[${TypeOrmSQLConfigService}]`; public static SQL_CONNECTION_NAME: string = 'postgres'; constructor(private readonly config: DatabaseModuleConfig) { } createTypeOrmOptions(): TypeOrmModuleOptions { return { name: TypeOrmSQLConfigService.SQL_CONNECTION_NAME, type: 'postgres', synchronize: false, logging: true, host: this.config.host, port: this.config.port, username: this.config.username, password: this.config.password, database: this.config.database, entities: [__dirname + '/../**/*.entity{.ts,.js}'], migrations: [this.config.migrationsFullPath + '/*{.ts,.js}'], cli: { migrationsDir: this.config.migrationsFullPath, }, } as TypeOrmModuleOptions; } }