如何从 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)
弄清楚了
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));
| 归档时间: | 
 | 
| 查看次数: | 1040 次 | 
| 最近记录: |