Hi,
I have been using sequelize for the past two months and haven't encountered any serious problems but I've been stuck with this one for quite some time now.
The code-snippet I am presenting here is a simplified version of what I am actually trying to do.
First approach:
var findUserByName = function(name,companyId) {
return models.sequelize.query('SELECT * FROM users WHERE firstName = ?',
{replacements: ['Simon']});
}
Error generated by this chunk of code:
Executing (default): SELECT * FROM users WHERE firstName = ?
{ [SequelizeDatabaseError: syntax error at end of input]
name: 'SequelizeDatabaseError',
message: 'syntax error at end of input',
Second approach:
var findUserByName = function(name,companyId) {
return models.sequelize.query('SELECT * FROM users WHERE firstName = :firstName',
{replacements: {firstName: 'Simon' }});
}
Error generated by this chunk of code:
Executing (default): SELECT * FROM users WHERE firstName = :firstName
{ [SequelizeDatabaseError: syntax error at or near ":"]
name: 'SequelizeDatabaseError',
message: 'syntax error at or near ":"',
Third approach:
var findUserByName = function(name,companyId) {
debugger;
return models.sequelize.query('SELECT * FROM users WHERE firstName=:name',}
Error generated by this chunk of code:
Executing (default): SELECT * FROM users WHERE firstName=:name
{ [SequelizeDatabaseError: syntax error at or near ":"]
name: 'SequelizeDatabaseError',
message: 'syntax error at or near ":"',
The error messages make me believe that the identifier (:firstName) or the question marks I am using in the queries are not being replaced by the values I am passing in the next argument of the query-operator. Can somebody confirm that this is the problem and tell me how to fix this. According to the docs this should work.
Kind regards,
Simon Van de Water