I'm building up nodejs api by using async await.So my controller every function is async which receives a promise by model. For query i have used the sequelize package for interacting with the database. for using sequelize async query behaviour i choose the bluebird plugin for promisfy.
Promise.promisifyAll(sequelize)
In my model i have write a method which return data but when i call the sequelize.query it will return the data but when i write sequelize.queryAsync it should not return the data. The function is exist when i print the sequelize object. I want to know how to get the queryAsync data.
LeadModel.getActiveRecords = function () {
return new Promise(async (resolve, reject) => {
try {
let output = await LeadModel.sequelize.queryAsync("SELECT * FROM some_tbl where status = '1'")
// This below query is working fine without queryAsync
//let output = await LeadModel.sequelize.query("SELECT * FROM some_tbl where status = '1'")
resolve(output)
} catch (e) {
reject(e)
}d
})
}
In the controller i'm using this way.
LeadController.getlead = async function(req, res) {
try {
let datanew = await LeadModel.getActiveRecords();
console.log(datanew);
} catch (e) {
throw e;
}
}
Can you please help me out why the sequelize is not return async query result.