import { Injectable } from '@nestjs/common'; import { ConfigService } from '@nestjs/config'; import { TypeOrmModuleOptions, TypeOrmOptionsFactory } from '@nestjs/typeorm'; // @Injectable() // export class MySqlConfiguration implements TypeOrmOptionsFactory { // constructor(private configService: ConfigService) {} // // createTypeOrmOptions(): TypeOrmModuleOptions { // return { // type: 'mysql', // host: this.configService.get('DB_HOST') || '13.234.25.234', // port: parseInt(this.configService.get('DB_PORT') || '3306', 10), // username: this.configService.get('DB_USER') || 'root', // password: this.configService.get('DB_PASS') || 'Rezolut@123', // database: this.configService.get('DB_NAME') || 'core', // entities: [__dirname + '/../module/**/*.entity.{ts,js}'], // synchronize: false, // autoLoadEntities: true, // poolSize: 5, // }; // } // } @Injectable() export class PostgresConfiguration implements TypeOrmOptionsFactory { constructor(private configService: ConfigService) {} createTypeOrmOptions(): TypeOrmModuleOptions { return { type: 'postgres', host: this.configService.get('DB_HOST') || '127.0.0.1', port: parseInt(this.configService.get('DB_PORT') || '5432', 10), username: this.configService.get('DB_USER') || 'postgres', password: this.configService.get('DB_PASS') || 'postgres', database: this.configService.get('DB_NAME') || 'core', schema: this.configService.get('DB_SCHEMA') || 'package', entities: [__dirname + '/../module/**/*.entity.{ts,js}'], synchronize: false, autoLoadEntities: true, // Configure pg pool size via `extra.max` (pg uses node-postgres pool) extra: { max: parseInt(this.configService.get('PG_POOL_MAX') || '5', 10), searchPath: this.configService.get('DB_SCHEMA') || 'package', }, }; } }