mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-11 15:48:09 +00:00
41 lines
1.7 KiB
TypeScript
41 lines
1.7 KiB
TypeScript
import { Module } from '@nestjs/common';
|
|
import { ConfigModule, ConfigService } from '@nestjs/config';
|
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
|
import { SnakeNamingStrategy } from './strategies';
|
|
import { UserEntity } from '../modules/user/entities/user.entity';
|
|
import { UserSessionEntity } from '../modules/session/entities/session.entity';
|
|
import { UserOtpEntity } from '../modules/user-otp/entities';
|
|
import { HomeEntity } from '../modules/home/entities';
|
|
|
|
@Module({
|
|
imports: [
|
|
TypeOrmModule.forRootAsync({
|
|
imports: [ConfigModule],
|
|
inject: [ConfigService],
|
|
useFactory: (configService: ConfigService) => ({
|
|
name: 'default',
|
|
type: 'postgres',
|
|
host: configService.get('DB_HOST'),
|
|
port: configService.get('DB_PORT'),
|
|
username: configService.get('DB_USER'),
|
|
password: configService.get('DB_PASSWORD'),
|
|
database: configService.get('DB_NAME'),
|
|
entities: [UserEntity, UserSessionEntity, UserOtpEntity, HomeEntity],
|
|
namingStrategy: new SnakeNamingStrategy(),
|
|
synchronize: Boolean(JSON.parse(configService.get('DB_SYNC'))),
|
|
logging: true,
|
|
extra: {
|
|
charset: 'utf8mb4',
|
|
max: 20, // set pool max size
|
|
idleTimeoutMillis: 5000, // close idle clients after 5 second
|
|
connectionTimeoutMillis: 11_000, // return an error after 11 second if connection could not be established
|
|
maxUses: 7500, // close (and replace) a connection after it has been used 7500 times (see below for discussion)
|
|
},
|
|
continuationLocalStorage: true,
|
|
ssl: Boolean(JSON.parse(configService.get('DB_SSL'))),
|
|
}),
|
|
}),
|
|
],
|
|
})
|
|
export class DatabaseModule {}
|