【发布时间】:2018-12-13 15:13:43
【问题描述】:
我正在尝试使用 sequelize 构建我的查询,在 where 子句中我需要从我的前端给出条件值,所以我这样做了:
getResults(req) {
return parm
.findAll({
attributes: [
sequelize.literal('DISTINCT "id"')
],
where : {
name: req.query.parm.replace(/"/g, '').split(',')
} ,
raw: true
});
}
它正在工作! 但现在我需要编写一个包含 where 子句的子查询: 像这样:
SELECT tab1.name FROM
(SELECT name FROM "MYTABLE"
WHERE id = (value from the front-end) AND name IN (values from front-end)
) as tab1
这是我尝试过的:
getTest(req) {
if (req.query.parm != null) {
return parm .sequelize.query('SELECT id FROM "table_base" where id = $mid ); ',
{ type: sequelize.QueryTypes.SELECT ,
bind: { mid: [req.query.parm.replace(/"/g, '').split(',')] }} );
}
},
我尝试使用原始查询并测试了绑定参数,但是当我执行此测试查询时出现此错误:
Executing (default): SELECT id FROM "table_base" where id = $1 );
【问题讨论】:
标签: javascript node.js reactjs sequelize.js backend