我正在使用 nestjs-typeorm 并希望根据一些参考过滤掉嵌套数据。该代码首先加载整个数据库,然后过滤所需的结果。如何在不加载整个数据库表的情况下过滤掉所需的数据,使其更高效、更快速?
服务.ts
public async uploadedFiles(fileReferenceParams: ReferenceFilterParams): Promise<UploadedFilesEntity[]> {
try {
const manager = getManager();
const trees = await manager.getTreeRepository(UploadedFilesEntity).findTrees();
this.uploadedFilesRepository.createQueryBuilder()
const rootFiles = trees.filter(tree => ( tree.isDeleted==false||null && tree.referenceID == fileReferenceParams.referenceID && tree.referenceType == fileReferenceParams.referenceType));
return rootFiles;
} catch (error) {
return error;
}
}