Any one know how to custom select query on sequelize seeder
I have tried two ways, but no one work
First attempt
up: function(queryInterface, Sequelize) {
return queryInterface.sequelize.query(
'SELECT * FROM "Users" WHERE username = "admin"',
{ type: queryInterface.sequelize.QueryTypes.SELECT }
).then(function(users) {});
},
and then got error
SequelizeDatabaseError: column "admin" does not exist
I do not understand why admin is column here ???
Second attempt
return queryInterface.sequelize.query('SELECT * FROM "Users" WHERE username = :admin', {
replacement: {
admin: 'admin'
},
type: queryInterface.sequelize.QueryTypes.SELECT
}).then(function(users) {
});
Below error occurred
SequelizeDatabaseError: syntax error at or near ":"
Third attempt
return queryInterface.sequelize.query(
'SELECT * FROM "Users" WHERE username = ' admin '',
{type: queryInterface.sequelize.QueryTypes.SELECT})
.then(function(users) { })
Error:
SyntaxError: missing ) after argument list
UPDATED
Fourth attempt
return queryInterface.sequelize.query(
'SELECT * FROM Users WHERE username = "admin"',
{ type: queryInterface.sequelize.QueryTypes.SELECT }
).then(function(users) {});
Another error appear:
SequelizeDatabaseError: relation "Users" does not exist
queryInterface.sequelize.query('SELECT * FROM "Users"')
works without any error. I think the problem here is WHERE querying
It's driving me to crazy :)
Thank you for any help in advance!
"SELECT * FROM Users WHERE username = 'admin'"
– HandsetUsers
in quotes in the SQL statement? – MillimicronSequelizeDatabaseError: column "admin" does not exist
. Anyway, I have founded the solution when I read docs carefully. Let's me update the answer :) – Whorton