gpt4 book ai didi

node.js - Sequelize OR 条件对象

转载 作者:IT老高 更新时间:2023-10-28 21:52:37 26 4
gpt4 key购买 nike

通过创建这样的对象

var condition=
{
where:
{
LastName:"Doe",
FirstName:["John","Jane"],
Age:{
gt:18
}
}
}

并传入

Student.findAll(condition)
.success(function(students){

})

它可以像这样漂亮地生成 SQL

"SELECT * FROM Student WHERE LastName='Doe' AND FirstName in ("John","Jane") AND Age>18"

但是,这都是'AND'条件,我如何通过创建条件对象来生成'OR'条件?

最佳答案

现在好像有别的格式了

where: {
LastName: "Doe",
$or: [
{
FirstName:
{
$eq: "John"
}
},
{
FirstName:
{
$eq: "Jane"
}
},
{
Age:
{
$gt: 18
}
}
]
}

会生成

WHERE LastName='Doe' AND (FirstName = 'John' OR FirstName = 'Jane' OR Age > 18)

查看文档:http://docs.sequelizejs.com/en/latest/docs/querying/#where

关于node.js - Sequelize OR 条件对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20695062/

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