gpt4 book ai didi

javascript - 删除sequelize中的单引号原始查询

转载 作者:行者123 更新时间:2023-11-29 12:02:38 25 4
gpt4 key购买 nike

我正在尝试在sequelize中执行以下查询:

mysql> SELECT * FROM articles WHERE MATCH (title,body)
-> AGAINST ('+MySQL -YourSQL' IN BOOLEAN MODE);

这是我的尝试:

var rawQuery = "SELECT * FROM users WHERE MATCH (email) AGAINST ('?*' IN BOOLEAN MODE)";

return sequelize.query(rawQuery, {
replacements: [text],
type: sequelize.QueryTypes.SELECT
}).then(function(user) {
return user;
});

问题是我收到错误,因为我传递的字符串包含单引号,这就是我收到的错误:

Executing (default): SELECT * FROM users WHERE MATCH (email) AGAINST (''test'*' IN BOOLEAN MODE)
Unhandled rejection SequelizeDatabaseError: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'test'*' IN BOOLEAN MODE)' at line 1

你知道修复它的方法吗?

最佳答案

尝试转义引号:

var rawQuery = "SELECT * FROM users WHERE MATCH (email) AGAINST (\"?*\" IN BOOLEAN MODE)";

return sequelize.query(rawQuery, {
replacements: [text],
type: sequelize.QueryTypes.SELECT
}).then(function(user) {
return user;
});

关于javascript - 删除sequelize中的单引号原始查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32113720/

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