Last active
August 11, 2024 17:06
-
-
Save paulodutra/7305e81ccfefb5f63b22a15e5b4d9b33 to your computer and use it in GitHub Desktop.
InMemory Database module with providers and exports
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 { Module } from '@nestjs/common'; | |
import { TypeOrmModule, TypeOrmModuleOptions } from '@nestjs/typeorm'; | |
import { ConfigModule, ConfigService } from '@nestjs/config'; | |
import { inMemoryDatabaseConfig } from '@/main/config/database/in-memory-database.config'; | |
import { TaskRepository } from '@/infrastructure/database/repositories/task.repository'; | |
import { TaskSeedService } from '@/infrastructure/database/seeds/task-seed-service'; | |
import { Task } from '@/infrastructure/database/entities/task.entity'; | |
@Module({ | |
imports: [ | |
ConfigModule.forRoot({ | |
isGlobal: true, | |
load: [inMemoryDatabaseConfig], | |
}), | |
TypeOrmModule.forRootAsync({ | |
inject: [ConfigService], | |
useFactory: (configService: ConfigService): TypeOrmModuleOptions => | |
configService.get<TypeOrmModuleOptions>('database.inMemory'), | |
}), | |
TypeOrmModule.forFeature([Task]), | |
], | |
providers: [TaskRepository, TaskSeedService], | |
exports: [TaskRepository, TaskSeedService], | |
}) | |
export class InMemoryModule {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment