32 lines
1.1 KiB
TypeScript
32 lines
1.1 KiB
TypeScript
import { Module } from '@nestjs/common';
|
|
import { ConfigModule, ConfigService } from '@nestjs/config';
|
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
|
import { GroupEntity } from '../groups/persistence/group.entity';
|
|
import { GroupEventEntity } from 'src/groups/persistence/group-event.entity';
|
|
|
|
const ENTITY = [GroupEntity, GroupEventEntity]
|
|
|
|
@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: (configService.get('DATABASE_SYNC')||'').toLowerCase() == 'true',
|
|
})
|
|
})
|
|
],
|
|
providers: [ConfigService,],
|
|
exports: [TypeOrmModule]
|
|
|
|
})
|
|
export class DatabaseModule {}
|