Skip to content

fix count() promise error "this.resolve is not a function" #69

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 16 additions & 17 deletions drivers/mysql/query_exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,24 @@ class QueryExec extends QueryBuilder {
const sql = this._count(table);
this.reset_query(sql);

const handler = (err, row) => {
if (!err) {
if (typeof callback !== "function") {
this.resolve(row[0].numrows);
return;
}
cb(err, row[0].numrows);
}
else {
if (typeof callback !== "function") {
this.reject(err);
return;
const handler = (resolve, reject) => {
this._exec(sql, (err, row) => {
if ((!cb || typeof cb !== 'function') && (typeof resolve === 'function' && typeof reject === 'function')) {
if(err) return reject(new Error(err));
return resolve(row[0].numrows);
} else if (cb && typeof cb === 'function') {
return cb(err,row[0].numrows);
} else {
throw ERRORS.NO_VALID_RESULTS_HANDLER;
}
cb(err, row);
}
});

}
if (!cb || cb !== 'function') {
return new Promise(handler);
} else {
handler();
}

if (typeof cb !== "function") return new WrapperPromise(sql, this._exec.bind(this), handler).promisify();
this._exec(sql, handler);
}

get(table, cb, conn) {
Expand Down