NestJS - Database with TypeORM
Which of the following is the correct way to import and configure TypeORM for PostgreSQL in a NestJS module?
Aimport { TypeOrmModule } from '@nestjs/typeorm';
@Module({
imports: [TypeOrmModule.forRoot({
type: 'sqlite',
database: ':memory:',
entities: [User],
synchronize: false,
})],
})
Bimport { TypeOrmModule } from '@nestjs/typeorm';
@Module({
imports: [TypeOrmModule.forFeature({
type: 'postgres',
host: 'localhost',
port: 5432,
username: 'user',
password: 'pass',
database: 'testdb',
entities: [User],
synchronize: true,
})],
})
Cimport { TypeOrmModule } from '@nestjs/typeorm';
@Module({
imports: [TypeOrmModule.forRootAsync({
useFactory: () => ({
type: 'mysql',
host: 'localhost',
port: 3306,
username: 'user',
password: 'pass',
database: 'testdb',
entities: [User],
synchronize: true,
}),
})],
})
Dimport { TypeOrmModule } from '@nestjs/typeorm';
@Module({
imports: [TypeOrmModule.forRoot({
type: 'postgres',
host: 'localhost',
port: 5432,
username: 'user',
password: 'pass',
database: 'testdb',
entities: [User],
synchronize: true,
})],
})
