序列化.count()无法返回结果

时间:2018-06-30 15:41:05

标签: node.js sequelize.js

我正在尝试返回数字结果,但似乎无法这样做。

如果我将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;
};

1 个答案:

答案 0 :(得分:1)

您不能像代码一样返回c。 我认为您应该return Project.count({ your_query })。 而且您可以将PromisePromise一起使用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."); });

Food