Skip to content
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