const countUser = await Users.count();
console.log(countUser);
Trying to get a count in a database. Th above returns a validity error. The count() is
btw here count() is Sequelize Model.count() method is used to generate and execute a SELECT COUNT SQL query to your connected database
Wrapped it in an async/await like this
async function getUsers() {
const countUser = await Users.count()
return countUser;
}
and it returns as
Promise { <pending> }
Executing (default): SELECT count(*) AS `count` FROM `users` AS `users`;
and then, wrapped it in another async/await as a promise chain since i thought this might work but no
async function getUsers() {
const countUser = await Users.count()
return countUser;
}
async function logUsers() {
const userlog = await getUsers()
console.log(userlog)
}
console.log(logUsers())
returns same pending error thus the values be undefined.
Any way around this?
Thanks!