find() 等同于帆
find() with equal and like in sails
我想执行这样的查询,
select * from user where user.status = 'ban' and
user.status = 'new' and
user.username like 'fo%' // in code I will get this from req.param('user')
我知道怎么做了,
var username = req.param('user');
var status = req.param('status');
User.find().where({ status : [status, 'new'], username : username }).exec(function(err, users){
console.log(users);
});
但我不知道如何使用 "like" 作为用户名。
我该怎么办。
谢谢
var username = req.param('user');
var status = req.param('status');
User.find({
status: [status, 'new'],
username: {
'startsWith': username
}
}).exec(function(err, users) {
console.log(users);
});
试试看
作为参考,这里有一个 link 关于水线查询格式的文档
https://github.com/balderdashy/waterline-docs/blob/master/query-language.md
我想执行这样的查询,
select * from user where user.status = 'ban' and
user.status = 'new' and
user.username like 'fo%' // in code I will get this from req.param('user')
我知道怎么做了,
var username = req.param('user');
var status = req.param('status');
User.find().where({ status : [status, 'new'], username : username }).exec(function(err, users){
console.log(users);
});
但我不知道如何使用 "like" 作为用户名。
我该怎么办。 谢谢
var username = req.param('user');
var status = req.param('status');
User.find({
status: [status, 'new'],
username: {
'startsWith': username
}
}).exec(function(err, users) {
console.log(users);
});
试试看
作为参考,这里有一个 link 关于水线查询格式的文档 https://github.com/balderdashy/waterline-docs/blob/master/query-language.md