for root async, config module global
This commit is contained in:
@@ -3,11 +3,33 @@ import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { AlumnosController } from './alumnos.controller';
|
||||
import { AlumnosService } from './alumnos.service';
|
||||
import { RegistroAlumno } from './entities/registro-alumno.entity';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
TypeOrmModule.forFeature([RegistroAlumno], 'alumnosConnection'),
|
||||
TypeOrmModule.forRoot({
|
||||
|
||||
|
||||
TypeOrmModule.forRootAsync({
|
||||
name: 'alumnosConnection',
|
||||
useFactory: (configService: ConfigService) => ({
|
||||
type: 'mysql',
|
||||
host: configService.get<string>('ALUMNOS_DB_HOST'),
|
||||
port: Number(configService.get<number>('ALUMNOS_DB_PORT')),
|
||||
username: configService.get<string>('ALUMNOS_DB_USERNAME'),
|
||||
password: configService.get<string>('ALUMNOS_DB_PASSWORD'),
|
||||
database: configService.get<string>('ALUMNOS_DB_DATABASE'),
|
||||
entities: [RegistroAlumno],
|
||||
synchronize: false,
|
||||
retryAttempts: 10,
|
||||
retryDelay: 3000,
|
||||
connectTimeout: 30000,
|
||||
}),
|
||||
inject: [ConfigService],
|
||||
}),
|
||||
|
||||
|
||||
/* TypeOrmModule.forRoot({
|
||||
name: 'alumnosConnection',
|
||||
type: 'mysql',
|
||||
host: process.env.ALUMNOS_DB_HOST ,
|
||||
@@ -17,7 +39,12 @@ import { RegistroAlumno } from './entities/registro-alumno.entity';
|
||||
database: process.env.ALUMNOS_DB_DATABASE ,
|
||||
entities: [RegistroAlumno],
|
||||
synchronize: false,
|
||||
}),
|
||||
|
||||
retryAttempts: 10, // Intentos para reconectar
|
||||
retryDelay: 3000, // Tiempo entre reintentos
|
||||
connectTimeout: 30000, // Timeout de conexión (30 segundos) │ │
|
||||
|
||||
}), */
|
||||
],
|
||||
controllers: [AlumnosController],
|
||||
providers: [AlumnosService],
|
||||
|
||||
+3
-1
@@ -29,7 +29,9 @@ import { AlumnosModule } from './alumnos/alumnos.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
ConfigModule.forRoot(),
|
||||
ConfigModule.forRoot({
|
||||
isGlobal: true,
|
||||
}),
|
||||
TypeOrmModule.forRoot({
|
||||
|
||||
type: 'mysql',
|
||||
|
||||
Reference in New Issue
Block a user