init
This commit is contained in:
30
costly-api/src/database/database.module.ts
Normal file
30
costly-api/src/database/database.module.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { ConfigModule, ConfigService } from '@nestjs/config';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { GroupEntity } from '../groups/persistence/group.entity';
|
||||
|
||||
const ENTITY = [GroupEntity]
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
|
||||
TypeOrmModule.forRootAsync({
|
||||
imports: [ConfigModule],
|
||||
inject: [ConfigService],
|
||||
useFactory: (configService: ConfigService) => ({
|
||||
type: 'mysql',
|
||||
host: configService.get('DATABASE_HOST') || 'localhost',
|
||||
port: parseInt(configService.get('DATABASE_PORT') || '0'),
|
||||
username: configService.get('DATABASE_USER'),
|
||||
password: configService.get('DATABASE_PASSWORD'),
|
||||
database: configService.get('DATABASE_NAME'),
|
||||
entities: ENTITY,
|
||||
synchronize: true,
|
||||
})
|
||||
})
|
||||
],
|
||||
providers: [ConfigService,],
|
||||
exports: [TypeOrmModule]
|
||||
|
||||
})
|
||||
export class DatabaseModule {}
|
||||
Reference in New Issue
Block a user