如何从ApplicationContext获取实体的存储库
const ctx = await NestFactory.createApplicationContext(AppModule)
const repository = ctx.get<Repository<UserEntity>>(Repository);
// Error: Nest cannot find given element (it does not exist in current context)
答案 0 :(得分:0)
想通了
import ...
import { UserEntity } from './user.entity';
import { getRepositoryToken } from '@nestjs/typeorm';
const ctx = await NestFactory.createApplicationContext(AppModule)
const repository: Repository<UserEntity> = ctx.get(getRepositoryToken(UserEntity));