使用 Sequelize 将多个参数安全地发送到 IN 子句以进行原始查询
Send multiples params securely to IN clause with Sequelize for raw query
使用 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 } },
);
Array replacements will automatically be handled, the following query searches for projects where the status matches an array of values
所以这实际上应该有效:
const baz = [1, 2, 3];
sequelize.query(
'select * from foo where bar IN (:baz)',
{ replacements: { baz } },
);
使用 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 } },
);
Array replacements will automatically be handled, the following query searches for projects where the status matches an array of values
所以这实际上应该有效:
const baz = [1, 2, 3];
sequelize.query(
'select * from foo where bar IN (:baz)',
{ replacements: { baz } },
);