gpt4 book ai didi

javascript - 书架.JS |如何在查询中使用 where 和 orWhere

转载 作者:可可西里 更新时间:2023-11-01 02:31:46 28 4
gpt4 key购买 nike

BookshelfJS 有以下使用“查询”的示例:

model
.query({where: {other_id: '5'}, orWhere: {key: 'value'}})
.fetch()
.then(function(model) {
...
});

是否可以执行以下操作:

var whereObj = {
'key1':'value1',
'key2':'value2'
};

model
.query({where: whereObj, orWhere: {key: 'value'}})
.fetch()
.then(function(model) {
...
});

最佳答案

对于更复杂的查询,你可以使用这个:

.query(function(qb) {
qb.select('*');
qb.where(function () {
this.where('attr1', 1);
this.where('attr2','in' , [1,2,3]);
});
qb.orWhere(function () {
this.where('attr1', 2);
this.where('attr2','in' , [4,5,6]);
});
})

关于javascript - 书架.JS |如何在查询中使用 where 和 orWhere,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32214978/

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