gpt4 book ai didi

sequelize.js - 如何在 sequelize 中使用多个 $or

转载 作者:行者123 更新时间:2023-12-03 22:26:54 27 4
gpt4 key购买 nike

我正在写一个需要多个“或”语句的查询。

这是我的 whereClause:

{
date_added: {
'$lte': '2019-04-18', '$gte': '2019-04-11'
},
'$or': [
{ id: [Array], secondary_id:[Array] }
],
'$and': [
{ third_id: [Array], fourth_id:[Array] }
],///make it into $or
}

使得语句从哪里改变
WHERE ("date_added" <= '2019-04-18' AND "date_added" >= '2019-04-11') 
AND ("id" IN ('10') or "secondary_id" in ('11'))
AND ("third_id" IN ('12') and "fourth_id" in ('13'))

进入
WHERE ("date_added" <= '2019-04-18' AND "date_added" >= '2019-04-11') 
AND ("id" IN ('10') or "secondary_id" in ('11'))
AND ("third_id" IN ('12') OR "fourth_id" in ('13'))

另一种说法是我如何使用 sequelize 来做(A 或 B)和(C 或 D)

最佳答案

您应该在示例中使用 Sequelize operator symbols 而不是字符串值,它们已被弃用。要在 SQL 中重新创建查询,您需要执行以下操作:

const Op = Sequelize.Op

where: {
date_added: {
[Op.between]: ['2019-04-18', '2019-04-11'],
},
id: {
[Op.in]: arrayOfIds,
}
[Op.or]: [
{
channel_type: {
[Op.like]: {
[Op.any]: ['facebook', 'instagram'],
},
},
},
],
}

SQL
WHERE date_added BETWEEN '2019-04-18' AND '2019-04-11'
AND id IN (... your id array)
AND (
channel_type LIKE 'facebook'
OR channel_type LIKE 'instagram'
)

关于sequelize.js - 如何在 sequelize 中使用多个 $or,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55755261/

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