0
I am trying to return the value of a query using Sequelize but it always comes as Undefined. I imagine it is due to being an asynchronous function.
const { Sequelize, sequelize } = require('../../config/database');
// Classe para realizar manipulação dos usuarios no banco
class UserDAO{
// Consultar registros no banco pelas credenciais passadas pelo controller
userQuery(userCredentials){
sequelize.query(`SELECT * FROM usuarios WHERE login='${userCredentials.user}' AND senha='${userCredentials.pass}'`).then((result) => {
return result;
}).catch((err) => {
console.log(err);
});
}
}
module.exports = UserDAO;
The Userdao class is instantiated in another file and the userQuery() function is called by passing an object as argument. I need the userQuery() function to return the then() value of the sequelize.query().
try to give a console.log(result) and put here what appears in your log
– Teuuz1994
Within the sequelize.query() function it shows the object that is returned by the query (how it should happen). That is, everything works perfectly well within the function, however when I try to externalize it somehow it gets Undefined.
– Robert Ferreira