gpt4 book ai didi

javascript - Typeor find with and & or where block

转载 作者:行者123 更新时间:2023-12-05 02:53:47 24 4
gpt4 key购买 nike

我正在尝试在 typeorm 中构建以下查询。

SELECT * from Department where
type = 'Employee' and
((from_date BETWEEN '2013-01-03'AND '2013-01-09') OR
(to_date BETWEEN '2013-01-03' AND '2013-01-09') OR
(from_date <= '2013-01-03' AND to_date >= '2013-01-09'))

下面是我的 typeorm 等价物。

connection.find(Department, {
where: [
{ fromDate: Between(filter.fromDate, filter.toDate) },
{ toDate: Between(filter.fromDate, filter.toDate) },
{
fromDate: LessThanOrEqual(filter.fromDate),
toDate: MoreThanOrEqual(filter.toDate),
},
],
andWhere: { type: 'Employee' },
});

但不知何故我得到了错误的输出数量。好像 andWhere 不起作用。提前致谢

最佳答案

let qb = this.repository.createQueryBuilder("department");

qb.where("department.type= :type", {type: "Employee"});
qb.andWhere("((department.from_date BETWEEN '2013-01-03'AND '2013-01-09') OR
(department.to_date BETWEEN '2013-01-03' AND '2013-01-09') OR
(department.from_date <= '2013-01-03' AND department.to_date >= '2013-01-09'))");

关于javascript - Typeor find with and & or where block ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62004119/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com