-
Notifications
You must be signed in to change notification settings - Fork 0
/
ormconfig.ts
42 lines (38 loc) · 1.44 KB
/
ormconfig.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
31
32
33
34
35
36
37
38
39
40
41
42
import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { TypeOrmModuleOptions, TypeOrmOptionsFactory } from '@nestjs/typeorm';
// const typeOrmConfig: TypeOrmModuleOptions = {
// type: 'mysql',
// host: process.env.DB_HOST,
// port: parseInt(process.env.DB_PORT),
// username: process.env.DB_USERNAME,
// password: process.env.DB_PASSWORD,
// database: process.env.DB_DATABASE,
// autoLoadEntities: true,
// synchronize: false,
// logging: true,
// entities: ['dist/src/entities/**/*{.js,.ts}'],
// migrations: ['dist/migration/**/*{.js,.ts}'],
// subscribers: ['dist/subscribers/**/*{.js,.ts}'],
// };
// export default typeOrmConfig;
@Injectable()
export class TypeOrmConfigService implements TypeOrmOptionsFactory {
constructor(private configService: ConfigService) {}
createTypeOrmOptions(): TypeOrmModuleOptions {
return {
type: 'mysql',
host: this.configService.get('DB_HOST'),
port: parseInt(this.configService.get('DB_PORT')),
username: this.configService.get('DB_USERNAME'),
password: this.configService.get('DB_PASSWORD'),
database: this.configService.get('DB_DATABASE'),
synchronize: false,
autoLoadEntities: true,
logging: true,
entities: ['dist/src/entities/**/*{.js,.ts}'],
migrations: ['dist/migration/**/*{.js,.ts}'],
subscribers: ['dist/subscribers/**/*{.js,.ts}'],
} as TypeOrmModuleOptions;
}
}