-
Notifications
You must be signed in to change notification settings - Fork 1
/
typeorm-config.service.ts
30 lines (28 loc) · 1014 Bytes
/
typeorm-config.service.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { TypeOrmModuleOptions, TypeOrmOptionsFactory } from '@nestjs/typeorm';
@Injectable()
export class TypeOrmConfigService implements TypeOrmOptionsFactory {
constructor(private 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'),
password: this.configService.get('DB_PASSWORD'),
database: this.configService.get('DB_NAME'),
synchronize: true,
dropSchema: true,
keepConnectionAlive: true,
autoLoadEntities: true,
logging: false,
entities: [__dirname + '../**/*.entity{.ts,.js}'],
cli: {
entitiesDir: 'src',
migrationsDir: '../database/migrations',
subscribersDir: 'subscriber',
},
} as TypeOrmModuleOptions;
}
}