【发布时间】:2020-10-03 21:44:20
【问题描述】:
我正在使用 NodeJS + TypeORM + PostgreSQL
我发现很难根据自己的要求生成查询。
我需要生成以下查询:
select * from clinics where status = 1 and (last_sync_date < x or last_sync_date is null)
这里 x 是当前日期 - 10 天。
我尝试了以下查询:
let now = Date();
now.setDate(now.getDate() - 10);
let clinics = await clinicRepo.find({
where: [
{ status: 1, last_sync_date: LessThan(now) },
{ last_sync_date: IsNull() }
]
});
但是结果是这样的:
select * from clinics where (status = 1 and last_sync_date < x) or last_sync_date is null;
我需要在上面的代码中更改什么?
我想使用 find 来加载关系。
【问题讨论】:
-
您可以将
status: 1添加到第二个 where 查询中,它应该可以工作 -
实际上,我正在动态生成上述内容,其中可能有任意数量的条件。
标签: node.js postgresql typeorm