我试图返回数字结果,但我似乎无法这样做。
如果我用 return c;
替换 return 1;
我能够检索静态值。如何正确返回结果?
exports.count = function(user) {
Project.count({ where: leader: user' }).then(c => {
console.log("There are " + c + " projects with an id greater than 25.")
})
return c;
};
最佳答案
您不能像您的代码一样返回 c
。
我认为你应该 return Project.count({ your_query })
。
你可以使用 Promise
(我看着你的代码并认为它是 Promise
)和 then
或者你创建的 exports.count
是异步函数,你可以像你的代码一样返回。
它看起来像:my_module.js
:
exports.count = function(user) {
return Project.count({ 'your_query' })
};
any_file.js
:let myModule = require('./your_module');
//define user
myModule .count(user)
.then(c => {
console.log("There are " + c + " projects with an id greater than 25.");
});
关于node.js - Sequelize .count() 无法返回结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51116299/