Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When I run Model.count, code throw TypeError: callback is not a function # #111

Open
leeqiang opened this issue Apr 17, 2019 · 2 comments
Open

Comments

@leeqiang
Copy link

My Code

await Model.count()

Error (I add some log)

// jugglingdb-mysql/lib/mysql.js:505
MySQL.prototype.count = function count(model, callback, where) {
    console.log(model, callback, where) // here 
    var self = this;
    var query = 'SELECT count(*) as cnt FROM ' +
        this.tableEscaped(model);
    if(where){
        query += ' where ' + this._buildWhere(model, where);
    }
    this.queryOne(query, function (err, res) {
        if (err) return callback(err);
        callback(err, res && res.cnt);
    });
};

Screenshot

image

@leeqiang
Copy link
Author

@1602 Is this a bug?? The callback is where and the where is callback?

@1602
Copy link
Contributor

1602 commented Apr 18, 2019

@leeqiang looks like a bug indeed. I believe it happens because order of parameters isn't right, usually callback is the last argument and it seems like jugglingdb core expects it. Reasons behind that are unknown, looks like a really old technical debt (perhaps it is hard to address because this interface shaded by many drivers).

As a workaround you could try supplying empty where object in count call: Model.count({}).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants