gpt4 book ai didi

javascript - 使用 Sequelize 将多个参数安全地发送到 IN 子句以进行原始查询

转载 作者:行者123 更新时间:2023-12-03 22:19:16 25 4
gpt4 key购买 nike

使用 Sequelize 我可以执行原始查询并安全地发送参数(感谢通过参数绑定(bind)数据库的参数:

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 } },
);

最佳答案

根据the documentation :

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 } },
);

关于javascript - 使用 Sequelize 将多个参数安全地发送到 IN 子句以进行原始查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64554295/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com