Sequelize:WHERE LIKE子句中的Concat字段 [英] Sequelize: Concat fields in WHERE LIKE clause
本文介绍了Sequelize:WHERE LIKE子句中的Concat字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在为我正在工作的node.js项目使用续集ORM.我有一个查询,我需要对多列的合并结果执行类似的操作.
I am using the sequelize ORM for a node.js project I am working on. One query I have, I need to perform a like operation on the concatenated result of multiple columns.
例如,如下所示:
选择*从人所在的地方(CONCAT(名字,',姓")),例如%John Do%".
SELECT * FROM People WHERE (CONCAT(firstname, ' ', lastname)) LIKE '%John Do%'.
我正在使用以下语法,并且想知道这是否有可能,而不必诉诸于RAW查询(这在我的解决方案中无处可寻).
I am using the following syntax and would like to know if this is possible without having to resort to using RAW queries (which is nowhere else in my solution).
var criteria = {
include: [
occupation
],
where: {
is_active: 1
},
nest: false
};
db.people.findAll(criteria, {}).then(function(people) {
success(people);
}).catch(function(err) {
error(err);
});
有什么想法吗?
推荐答案
您将需要这样的内容
var criteria = {
where: Sequelize.where(Sequelize.fn("concat", Sequelize.col("firstname"), Sequelize.col("lastname")), {
like: '%John Do%'
})
}
注意:未经测试
这篇关于Sequelize:WHERE LIKE子句中的Concat字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文