Trần Viết Sơn
fix: refactor, add entities
c114c72
raw
history blame
973 Bytes
import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { TypeOrmModuleOptions, TypeOrmOptionsFactory } from '@nestjs/typeorm';
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
@Injectable()
export class DatabaseConfigService implements TypeOrmOptionsFactory {
constructor(private readonly configService: ConfigService) {}
createTypeOrmOptions(): TypeOrmModuleOptions {
return {
type: 'postgres',
host: this.configService.get('db.host'),
port: this.configService.get('db.port'),
username: this.configService.get('db.user_name'),
database: this.configService.get('db.name'),
password: this.configService.get('db.password'),
entities: [path.join(__dirname, '../**/*.entity{.ts,.js}')],
maxQueryExecutionTime: this.configService.get('db.slow_limit'),
};
}
}