Last active
August 11, 2024 16:56
-
-
Save paulodutra/5036a8d951c586e5eab5db27157bc754 to your computer and use it in GitHub Desktop.
Database Dynamic module nestjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { DynamicModule, Module } from '@nestjs/common'; | |
import { MysqlModule } from './mysql/mysql.module'; | |
import { InMemoryModule } from './in-memory/in-memory.module'; | |
@Module({ | |
imports: [MysqlModule, InMemoryModule], | |
}) | |
export class DatabaseModule { | |
static forRoot(): DynamicModule { | |
const isTestEnv = process.env.NODE_ENV === 'test'; | |
const moduleImports = isTestEnv ? [InMemoryModule] : [MysqlModule]; | |
console.log(moduleImports, isTestEnv); | |
return { | |
module: DatabaseModule, | |
imports: moduleImports, | |
exports: moduleImports, | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment