序列化查询。 Where 条件使用计算值
Sequelize query. Where condition using calculated values
通常的 mySQL 请求就是这样。
SELECT * from table WHERE (sec - duration) < 10
但是我没有在sequelize的文档中找到具体操作方法
谁能告诉我如何在 sequelize 查询中的 where 对象中执行此操作???请 ))
sec - duration < 10
等价于sec < 10 + duration
,或sec < SUM(10, duration)
。我们可以只使用 SQL SUM
函数和 sequelize.fn
:
Table.findAll({
where: {
sec:{
[Op.lt]: sequelize.fn('sum', 10, sequelize.col('duration'))
}
}
})
我找到了更合适的方案!!!
Table.findAll({
where: {
sec:{
[Op.lt]: sequelize.literal(duration + 10)
}
}
})
通常的 mySQL 请求就是这样。
SELECT * from table WHERE (sec - duration) < 10
但是我没有在sequelize的文档中找到具体操作方法
谁能告诉我如何在 sequelize 查询中的 where 对象中执行此操作???请 ))
sec - duration < 10
等价于sec < 10 + duration
,或sec < SUM(10, duration)
。我们可以只使用 SQL SUM
函数和 sequelize.fn
:
Table.findAll({
where: {
sec:{
[Op.lt]: sequelize.fn('sum', 10, sequelize.col('duration'))
}
}
})
我找到了更合适的方案!!!
Table.findAll({
where: {
sec:{
[Op.lt]: sequelize.literal(duration + 10)
}
}
})