From 5533e3451fad09f2f485d69d4b9d75eb54f5dd1e Mon Sep 17 00:00:00 2001 From: UserGhost411 <39980239+UserGhost411@users.noreply.github.com> Date: Mon, 15 May 2023 01:04:08 +0700 Subject: [PATCH 1/2] Update query_exec.js fix count promise error "this.resolve is not a function" --- drivers/mysql/query_exec.js | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/drivers/mysql/query_exec.js b/drivers/mysql/query_exec.js index a6c23f1..fb5c2bd 100755 --- a/drivers/mysql/query_exec.js +++ b/drivers/mysql/query_exec.js @@ -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?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) { From 611dd515e34dc62a27dd7d5396d89ee38fd1151a Mon Sep 17 00:00:00 2001 From: UserGhost411 <39980239+UserGhost411@users.noreply.github.com> Date: Mon, 15 May 2023 01:07:45 +0700 Subject: [PATCH 2/2] Update query_exec.js adjusting the return value of the callback function according to the documentation --- drivers/mysql/query_exec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/mysql/query_exec.js b/drivers/mysql/query_exec.js index fb5c2bd..caa5c3c 100755 --- a/drivers/mysql/query_exec.js +++ b/drivers/mysql/query_exec.js @@ -59,7 +59,7 @@ class QueryExec extends QueryBuilder { if(err) return reject(new Error(err)); return resolve(row[0].numrows); } else if (cb && typeof cb === 'function') { - return cb(err?err:row[0].numrows); + return cb(err,row[0].numrows); } else { throw ERRORS.NO_VALID_RESULTS_HANDLER; }