使用Sequelize,我可以安全地执行原始查询和发送参数(感谢通过参数绑定数据库的参数:
const baz = 1;
sequelize.query(
'select * from foo where bar=:baz',
{ replacements: { baz } },
);
是否有类似的方法来寻址IN
(具有多个值(?
const baz = [1, 2, 3];
sequelize.query(
'select * from foo where bar IN (:baz)',
{ replacements: { baz } },
);
根据文档:
将自动处理数组替换,下面的查询将搜索状态与值数组匹配的项目
所以这实际上应该有效:
const baz = [1, 2, 3];
sequelize.query(
'select * from foo where bar IN (:baz)',
{ replacements: { baz } },
);