Reputation: 14189
I'm trying to do the following query in sequelize:
mysql> SELECT * FROM articles WHERE MATCH (title,body)
-> AGAINST ('+MySQL -YourSQL' IN BOOLEAN MODE);
this is my attempt:
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;
});
The problem is that I get an error because what I pass a string it contains single quotes and this is the error I got:
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
do you know which is the way to fix it?
Upvotes: 0
Views: 4133
Reputation: 544
What about this:
var rawQuery = 'SELECT * FROM users WHERE MATCH (email) AGAINST ("?*" IN BOOLEAN MODE)';
Upvotes: 0
Reputation: 11551
Try by escaping the quotes:
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;
});
Upvotes: 1