From e45805978e005605576ad4a27eaa689bd5bd2b1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20C=2E=20Marti=CC=81nez?= Date: Wed, 4 Dec 2024 11:17:31 +0100 Subject: [PATCH 01/19] Fix: PromisePoolCluster.of returns PromisePoolCluster instead of PoolNamespace (#3091) --- lib/pool_cluster.js | 9 +++++---- promise.js | 23 ++++++++++++++++++++++- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/lib/pool_cluster.js b/lib/pool_cluster.js index 92f53de668..2a049bbfd4 100644 --- a/lib/pool_cluster.js +++ b/lib/pool_cluster.js @@ -79,9 +79,9 @@ class PoolNamespace { /** * pool cluster execute - * @param {*} sql - * @param {*} values - * @param {*} cb + * @param {*} sql + * @param {*} values + * @param {*} cb */ execute(sql, values, cb) { if (typeof values === 'function') { @@ -280,4 +280,5 @@ class PoolCluster extends EventEmitter { } } -module.exports = PoolCluster; +exports.PoolNamespace = PoolNamespace; +exports.PoolCluster = PoolCluster; diff --git a/promise.js b/promise.js index a0216f5660..174405f6b9 100644 --- a/promise.js +++ b/promise.js @@ -55,6 +55,27 @@ function createPromisePool(opts) { return new PromisePool(corePool, thePromise); } +class PromisePoolNamespace { + + constructor(poolNamespace, thePromise) { + this.poolNamespace = poolNamespace; + this.Promise = thePromise || Promise; + } + + getConnection() { + const corePoolNamespace = this.poolNamespace; + return new this.Promise((resolve, reject) => { + corePoolNamespace.getConnection((err, coreConnection) => { + if (err) { + reject(err); + } else { + resolve(new PromisePoolConnection(coreConnection, this.Promise)); + } + }); + }); + } +} + class PromisePoolCluster extends EventEmitter { constructor(poolCluster, thePromise) { super(); @@ -109,7 +130,7 @@ class PromisePoolCluster extends EventEmitter { } of(pattern, selector) { - return new PromisePoolCluster( + return new PromisePoolNamespace( this.poolCluster.of(pattern, selector), this.Promise, ); From 86553f343c7cd747fe5cbfeac28c17669dbf180d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20C=2E=20Marti=CC=81nez?= Date: Wed, 4 Dec 2024 11:36:08 +0100 Subject: [PATCH 02/19] Fix: PromisePoolCluster.of returns PromisePoolCluster instead of PoolNamespace (#3091) --- lib/pool_cluster.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/pool_cluster.js b/lib/pool_cluster.js index 2a049bbfd4..a1c470b22d 100644 --- a/lib/pool_cluster.js +++ b/lib/pool_cluster.js @@ -280,5 +280,4 @@ class PoolCluster extends EventEmitter { } } -exports.PoolNamespace = PoolNamespace; -exports.PoolCluster = PoolCluster; +module.exports = PoolCluster; From 7c728ec35752fb38da66859263561bedf1e081cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20C=2E=20Marti=CC=81nez?= Date: Thu, 5 Dec 2024 21:59:31 +0100 Subject: [PATCH 03/19] Fix: PromisePoolCluster.of returns PromisePoolCluster instead of PoolNamespace (#3091) --- promise.js | 28 +++++++++++++++++++ .../test-promise-wrapper.test.mjs | 18 ++++++++++++ 2 files changed, 46 insertions(+) diff --git a/promise.js b/promise.js index 174405f6b9..014e825ef1 100644 --- a/promise.js +++ b/promise.js @@ -74,6 +74,34 @@ class PromisePoolNamespace { }); }); } + + query(sql, values) { + const corePoolNamespace = this.poolNamespace; + const localErr = new Error(); + if (typeof values === 'function') { + throw new Error( + 'Callback function is not available with promise clients.', + ); + } + return new this.Promise((resolve, reject) => { + const done = makeDoneCb(resolve, reject, localErr); + corePoolNamespace.query(sql, values, done); + }); + } + + execute(sql, values) { + const corePoolNamespace = this.poolNamespace; + const localErr = new Error(); + if (typeof values === 'function') { + throw new Error( + 'Callback function is not available with promise clients.', + ); + } + return new this.Promise((resolve, reject) => { + const done = makeDoneCb(resolve, reject, localErr); + corePoolNamespace.execute(sql, values, done); + }); + } } class PromisePoolCluster extends EventEmitter { diff --git a/test/esm/integration/pool-cluster/test-promise-wrapper.test.mjs b/test/esm/integration/pool-cluster/test-promise-wrapper.test.mjs index f19888369d..8b2151f57d 100644 --- a/test/esm/integration/pool-cluster/test-promise-wrapper.test.mjs +++ b/test/esm/integration/pool-cluster/test-promise-wrapper.test.mjs @@ -43,4 +43,22 @@ const { createPoolCluster } = require('../../../../promise.js'); poolCluster.poolCluster.emit('remove'); }); + + await test(async () => { + const poolCluster = createPoolCluster(); + poolCluster.add('MASTER', common.config); + + const poolNamespace = poolCluster.of('MASTER'); + + const connection = await poolNamespace.getConnection(); + + assert.ok(connection, 'should get connection'); + connection.release(); + + const result = await poolNamespace.query('SELECT 1 as a from dual where 1 = ?', [1]); + assert.equal(result[0]['a'], 1, 'should query successfully'); + + const result2 = await poolNamespace.execute('SELECT 1 as a from dual where 1 = ?', [1]); + assert.equal(result2[0]['a'], 1, 'should execute successfully'); + }); })(); From 8f27b4164eabc7fc6f5341ecb484ccc9f95b8548 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20C=2E=20Marti=CC=81nez?= Date: Fri, 6 Dec 2024 09:35:57 +0100 Subject: [PATCH 04/19] Fix: PromisePoolCluster.of returns PromisePoolCluster instead of PoolNamespace (#3091) --- .../test-promise-wrapper.test.mjs | 46 ++++--------------- 1 file changed, 8 insertions(+), 38 deletions(-) diff --git a/test/esm/integration/pool-cluster/test-promise-wrapper.test.mjs b/test/esm/integration/pool-cluster/test-promise-wrapper.test.mjs index 369149d28d..a788bb46b6 100644 --- a/test/esm/integration/pool-cluster/test-promise-wrapper.test.mjs +++ b/test/esm/integration/pool-cluster/test-promise-wrapper.test.mjs @@ -80,42 +80,6 @@ const { createPoolCluster } = require('../../../../promise.js'); poolCluster.poolCluster.emit('online'); }); - await test(async () => { - const poolCluster = createPoolCluster(); - - poolCluster.once('offline', async function () { - await new Promise((resolve) => { - assert.equal( - // eslint-disable-next-line no-invalid-this - this, - poolCluster, - 'should propagate offline event to promise wrapper', - ); - resolve(true); - }); - }); - - poolCluster.poolCluster.emit('offline'); - }); - - await test(async () => { - const poolCluster = createPoolCluster(); - - poolCluster.once('online', async function () { - await new Promise((resolve) => { - assert.equal( - // eslint-disable-next-line no-invalid-this - this, - poolCluster, - 'should propagate online event to promise wrapper', - ); - resolve(true); - }); - }); - - poolCluster.poolCluster.emit('online'); - }); - await test(async () => { const poolCluster = createPoolCluster(); poolCluster.add('MASTER', common.config); @@ -127,10 +91,16 @@ const { createPoolCluster } = require('../../../../promise.js'); assert.ok(connection, 'should get connection'); connection.release(); - const result = await poolNamespace.query('SELECT 1 as a from dual where 1 = ?', [1]); + const result = await poolNamespace.query( + 'SELECT 1 as a from dual where 1 = ?', + [1], + ); assert.equal(result[0]['a'], 1, 'should query successfully'); - const result2 = await poolNamespace.execute('SELECT 1 as a from dual where 1 = ?', [1]); + const result2 = await poolNamespace.execute( + 'SELECT 1 as a from dual where 1 = ?', + [1], + ); assert.equal(result2[0]['a'], 1, 'should execute successfully'); }); })(); From 9c0c2925195c91500c038c168a28dbcbf977da14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20C=2E=20Marti=CC=81nez?= Date: Tue, 10 Dec 2024 10:59:48 +0100 Subject: [PATCH 05/19] fix: PromisePoolCluster.of returns PromisePoolCluster instead of PoolNamespace (#3091) --- .../pool-cluster/test-promise-wrapper.test.mjs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/test/esm/integration/pool-cluster/test-promise-wrapper.test.mjs b/test/esm/integration/pool-cluster/test-promise-wrapper.test.mjs index a788bb46b6..b6177378c5 100644 --- a/test/esm/integration/pool-cluster/test-promise-wrapper.test.mjs +++ b/test/esm/integration/pool-cluster/test-promise-wrapper.test.mjs @@ -86,21 +86,25 @@ const { createPoolCluster } = require('../../../../promise.js'); const poolNamespace = poolCluster.of('MASTER'); + assert.equal(poolNamespace.poolNamespace, poolCluster.poolCluster.of('MASTER')); + const connection = await poolNamespace.getConnection(); assert.ok(connection, 'should get connection'); connection.release(); - const result = await poolNamespace.query( - 'SELECT 1 as a from dual where 1 = ?', + const [result] = await poolNamespace.query( + 'SELECT 1 as a where 1 = ?', [1], ); assert.equal(result[0]['a'], 1, 'should query successfully'); - const result2 = await poolNamespace.execute( - 'SELECT 1 as a from dual where 1 = ?', + const [result2] = await poolNamespace.execute( + 'SELECT 1 as a where 1 = ?', [1], ); assert.equal(result2[0]['a'], 1, 'should execute successfully'); + + poolCluster.end(); }); })(); From 6a00b0f4b620ae120060473e22fbf190637ae55a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20C=2E=20Marti=CC=81nez?= Date: Tue, 10 Dec 2024 20:33:25 +0100 Subject: [PATCH 06/19] fix: PromisePoolCluster.of returns PromisePoolCluster instead of PoolNamespace (#3091) --- .../test-promise-wrapper.test.mjs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/test/esm/integration/pool-cluster/test-promise-wrapper.test.mjs b/test/esm/integration/pool-cluster/test-promise-wrapper.test.mjs index b6177378c5..c103721b33 100644 --- a/test/esm/integration/pool-cluster/test-promise-wrapper.test.mjs +++ b/test/esm/integration/pool-cluster/test-promise-wrapper.test.mjs @@ -86,23 +86,24 @@ const { createPoolCluster } = require('../../../../promise.js'); const poolNamespace = poolCluster.of('MASTER'); - assert.equal(poolNamespace.poolNamespace, poolCluster.poolCluster.of('MASTER')); + assert.equal( + poolNamespace.poolNamespace, + poolCluster.poolCluster.of('MASTER'), + ); const connection = await poolNamespace.getConnection(); assert.ok(connection, 'should get connection'); connection.release(); - const [result] = await poolNamespace.query( - 'SELECT 1 as a where 1 = ?', - [1], - ); + const [result] = await poolNamespace.query('SELECT 1 as a where 1 = ?', [ + 1, + ]); assert.equal(result[0]['a'], 1, 'should query successfully'); - const [result2] = await poolNamespace.execute( - 'SELECT 1 as a where 1 = ?', - [1], - ); + const [result2] = await poolNamespace.execute('SELECT 1 as a where 1 = ?', [ + 1, + ]); assert.equal(result2[0]['a'], 1, 'should execute successfully'); poolCluster.end(); From 6ae2689b0a3bcf6e0b1d231ab0e74f3e6a834e7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20C=2E=20Marti=CC=81nez?= Date: Wed, 11 Dec 2024 08:25:36 +0100 Subject: [PATCH 07/19] fix: PromisePoolCluster.of returns PromisePoolCluster instead of PoolNamespace (#3091) --- .../pool-cluster/test-promise-wrapper.test.mjs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/test/esm/integration/pool-cluster/test-promise-wrapper.test.mjs b/test/esm/integration/pool-cluster/test-promise-wrapper.test.mjs index c103721b33..163f11bf7c 100644 --- a/test/esm/integration/pool-cluster/test-promise-wrapper.test.mjs +++ b/test/esm/integration/pool-cluster/test-promise-wrapper.test.mjs @@ -96,14 +96,16 @@ const { createPoolCluster } = require('../../../../promise.js'); assert.ok(connection, 'should get connection'); connection.release(); - const [result] = await poolNamespace.query('SELECT 1 as a where 1 = ?', [ - 1, - ]); + const [result] = await poolNamespace.query( + 'SELECT 1 as a from dual where 1 = ?', + [1], + ); assert.equal(result[0]['a'], 1, 'should query successfully'); - const [result2] = await poolNamespace.execute('SELECT 1 as a where 1 = ?', [ - 1, - ]); + const [result2] = await poolNamespace.execute( + 'SELECT 1 as a from dual where 1 = ?', + [1], + ); assert.equal(result2[0]['a'], 1, 'should execute successfully'); poolCluster.end(); From 6e5ccbbb0e74a24cead7fcf0d2e91e56b65fce19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20C=2E=20Marti=CC=81nez?= Date: Wed, 4 Dec 2024 11:17:31 +0100 Subject: [PATCH 08/19] Fix: PromisePoolCluster.of returns PromisePoolCluster instead of PoolNamespace (#3091) --- lib/pool_cluster.js | 3 ++- promise.js | 23 ++++++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/lib/pool_cluster.js b/lib/pool_cluster.js index 9edda501a2..eb2ab62d4a 100644 --- a/lib/pool_cluster.js +++ b/lib/pool_cluster.js @@ -362,4 +362,5 @@ class PoolCluster extends EventEmitter { } } -module.exports = PoolCluster; +exports.PoolNamespace = PoolNamespace; +exports.PoolCluster = PoolCluster; diff --git a/promise.js b/promise.js index 4010437fe9..61b2ed656e 100644 --- a/promise.js +++ b/promise.js @@ -55,6 +55,27 @@ function createPromisePool(opts) { return new PromisePool(corePool, thePromise); } +class PromisePoolNamespace { + + constructor(poolNamespace, thePromise) { + this.poolNamespace = poolNamespace; + this.Promise = thePromise || Promise; + } + + getConnection() { + const corePoolNamespace = this.poolNamespace; + return new this.Promise((resolve, reject) => { + corePoolNamespace.getConnection((err, coreConnection) => { + if (err) { + reject(err); + } else { + resolve(new PromisePoolConnection(coreConnection, this.Promise)); + } + }); + }); + } +} + class PromisePoolCluster extends EventEmitter { constructor(poolCluster, thePromise) { super(); @@ -109,7 +130,7 @@ class PromisePoolCluster extends EventEmitter { } of(pattern, selector) { - return new PromisePoolCluster( + return new PromisePoolNamespace( this.poolCluster.of(pattern, selector), this.Promise, ); From 393fbc0b78e3299b5329d710150b972a2488a606 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20C=2E=20Marti=CC=81nez?= Date: Wed, 4 Dec 2024 11:36:08 +0100 Subject: [PATCH 09/19] Fix: PromisePoolCluster.of returns PromisePoolCluster instead of PoolNamespace (#3091) --- lib/pool_cluster.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/pool_cluster.js b/lib/pool_cluster.js index eb2ab62d4a..9edda501a2 100644 --- a/lib/pool_cluster.js +++ b/lib/pool_cluster.js @@ -362,5 +362,4 @@ class PoolCluster extends EventEmitter { } } -exports.PoolNamespace = PoolNamespace; -exports.PoolCluster = PoolCluster; +module.exports = PoolCluster; From 5869a62a8c4db648ecce952d0d4a9cb632a88016 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20C=2E=20Marti=CC=81nez?= Date: Thu, 5 Dec 2024 21:59:31 +0100 Subject: [PATCH 10/19] Fix: PromisePoolCluster.of returns PromisePoolCluster instead of PoolNamespace (#3091) --- promise.js | 28 +++++++++++++++++++ .../test-promise-wrapper.test.mjs | 18 ++++++++++++ 2 files changed, 46 insertions(+) diff --git a/promise.js b/promise.js index 61b2ed656e..0e714ddf63 100644 --- a/promise.js +++ b/promise.js @@ -74,6 +74,34 @@ class PromisePoolNamespace { }); }); } + + query(sql, values) { + const corePoolNamespace = this.poolNamespace; + const localErr = new Error(); + if (typeof values === 'function') { + throw new Error( + 'Callback function is not available with promise clients.', + ); + } + return new this.Promise((resolve, reject) => { + const done = makeDoneCb(resolve, reject, localErr); + corePoolNamespace.query(sql, values, done); + }); + } + + execute(sql, values) { + const corePoolNamespace = this.poolNamespace; + const localErr = new Error(); + if (typeof values === 'function') { + throw new Error( + 'Callback function is not available with promise clients.', + ); + } + return new this.Promise((resolve, reject) => { + const done = makeDoneCb(resolve, reject, localErr); + corePoolNamespace.execute(sql, values, done); + }); + } } class PromisePoolCluster extends EventEmitter { diff --git a/test/esm/integration/pool-cluster/test-promise-wrapper.test.mjs b/test/esm/integration/pool-cluster/test-promise-wrapper.test.mjs index 00a56edde6..1b9bfea730 100644 --- a/test/esm/integration/pool-cluster/test-promise-wrapper.test.mjs +++ b/test/esm/integration/pool-cluster/test-promise-wrapper.test.mjs @@ -79,4 +79,22 @@ const { createPoolCluster } = require('../../../../promise.js'); poolCluster.poolCluster.emit('online'); }); + + await test(async () => { + const poolCluster = createPoolCluster(); + poolCluster.add('MASTER', common.config); + + const poolNamespace = poolCluster.of('MASTER'); + + const connection = await poolNamespace.getConnection(); + + assert.ok(connection, 'should get connection'); + connection.release(); + + const result = await poolNamespace.query('SELECT 1 as a from dual where 1 = ?', [1]); + assert.equal(result[0]['a'], 1, 'should query successfully'); + + const result2 = await poolNamespace.execute('SELECT 1 as a from dual where 1 = ?', [1]); + assert.equal(result2[0]['a'], 1, 'should execute successfully'); + }); })(); From 39b47c6410dbbb31c8329043d1ea1fc636039bae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20C=2E=20Marti=CC=81nez?= Date: Fri, 6 Dec 2024 09:35:57 +0100 Subject: [PATCH 11/19] Fix: PromisePoolCluster.of returns PromisePoolCluster instead of PoolNamespace (#3091) --- .../pool-cluster/test-promise-wrapper.test.mjs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/test/esm/integration/pool-cluster/test-promise-wrapper.test.mjs b/test/esm/integration/pool-cluster/test-promise-wrapper.test.mjs index 1b9bfea730..a788bb46b6 100644 --- a/test/esm/integration/pool-cluster/test-promise-wrapper.test.mjs +++ b/test/esm/integration/pool-cluster/test-promise-wrapper.test.mjs @@ -91,10 +91,16 @@ const { createPoolCluster } = require('../../../../promise.js'); assert.ok(connection, 'should get connection'); connection.release(); - const result = await poolNamespace.query('SELECT 1 as a from dual where 1 = ?', [1]); + const result = await poolNamespace.query( + 'SELECT 1 as a from dual where 1 = ?', + [1], + ); assert.equal(result[0]['a'], 1, 'should query successfully'); - const result2 = await poolNamespace.execute('SELECT 1 as a from dual where 1 = ?', [1]); + const result2 = await poolNamespace.execute( + 'SELECT 1 as a from dual where 1 = ?', + [1], + ); assert.equal(result2[0]['a'], 1, 'should execute successfully'); }); })(); From d5cba5ab4bec63fe3a9c827c5ba9131022f87180 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20C=2E=20Marti=CC=81nez?= Date: Tue, 10 Dec 2024 10:59:48 +0100 Subject: [PATCH 12/19] fix: PromisePoolCluster.of returns PromisePoolCluster instead of PoolNamespace (#3091) --- .../pool-cluster/test-promise-wrapper.test.mjs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/test/esm/integration/pool-cluster/test-promise-wrapper.test.mjs b/test/esm/integration/pool-cluster/test-promise-wrapper.test.mjs index a788bb46b6..b6177378c5 100644 --- a/test/esm/integration/pool-cluster/test-promise-wrapper.test.mjs +++ b/test/esm/integration/pool-cluster/test-promise-wrapper.test.mjs @@ -86,21 +86,25 @@ const { createPoolCluster } = require('../../../../promise.js'); const poolNamespace = poolCluster.of('MASTER'); + assert.equal(poolNamespace.poolNamespace, poolCluster.poolCluster.of('MASTER')); + const connection = await poolNamespace.getConnection(); assert.ok(connection, 'should get connection'); connection.release(); - const result = await poolNamespace.query( - 'SELECT 1 as a from dual where 1 = ?', + const [result] = await poolNamespace.query( + 'SELECT 1 as a where 1 = ?', [1], ); assert.equal(result[0]['a'], 1, 'should query successfully'); - const result2 = await poolNamespace.execute( - 'SELECT 1 as a from dual where 1 = ?', + const [result2] = await poolNamespace.execute( + 'SELECT 1 as a where 1 = ?', [1], ); assert.equal(result2[0]['a'], 1, 'should execute successfully'); + + poolCluster.end(); }); })(); From e20086c41e6d34e7ef18b6769558d00a8348c963 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20C=2E=20Marti=CC=81nez?= Date: Tue, 10 Dec 2024 20:33:25 +0100 Subject: [PATCH 13/19] fix: PromisePoolCluster.of returns PromisePoolCluster instead of PoolNamespace (#3091) --- .../test-promise-wrapper.test.mjs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/test/esm/integration/pool-cluster/test-promise-wrapper.test.mjs b/test/esm/integration/pool-cluster/test-promise-wrapper.test.mjs index b6177378c5..c103721b33 100644 --- a/test/esm/integration/pool-cluster/test-promise-wrapper.test.mjs +++ b/test/esm/integration/pool-cluster/test-promise-wrapper.test.mjs @@ -86,23 +86,24 @@ const { createPoolCluster } = require('../../../../promise.js'); const poolNamespace = poolCluster.of('MASTER'); - assert.equal(poolNamespace.poolNamespace, poolCluster.poolCluster.of('MASTER')); + assert.equal( + poolNamespace.poolNamespace, + poolCluster.poolCluster.of('MASTER'), + ); const connection = await poolNamespace.getConnection(); assert.ok(connection, 'should get connection'); connection.release(); - const [result] = await poolNamespace.query( - 'SELECT 1 as a where 1 = ?', - [1], - ); + const [result] = await poolNamespace.query('SELECT 1 as a where 1 = ?', [ + 1, + ]); assert.equal(result[0]['a'], 1, 'should query successfully'); - const [result2] = await poolNamespace.execute( - 'SELECT 1 as a where 1 = ?', - [1], - ); + const [result2] = await poolNamespace.execute('SELECT 1 as a where 1 = ?', [ + 1, + ]); assert.equal(result2[0]['a'], 1, 'should execute successfully'); poolCluster.end(); From ffb97bd54f859ce3cbe357bfb423eedca38e0e82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20C=2E=20Marti=CC=81nez?= Date: Wed, 11 Dec 2024 08:25:36 +0100 Subject: [PATCH 14/19] fix: PromisePoolCluster.of returns PromisePoolCluster instead of PoolNamespace (#3091) --- .../pool-cluster/test-promise-wrapper.test.mjs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/test/esm/integration/pool-cluster/test-promise-wrapper.test.mjs b/test/esm/integration/pool-cluster/test-promise-wrapper.test.mjs index c103721b33..163f11bf7c 100644 --- a/test/esm/integration/pool-cluster/test-promise-wrapper.test.mjs +++ b/test/esm/integration/pool-cluster/test-promise-wrapper.test.mjs @@ -96,14 +96,16 @@ const { createPoolCluster } = require('../../../../promise.js'); assert.ok(connection, 'should get connection'); connection.release(); - const [result] = await poolNamespace.query('SELECT 1 as a where 1 = ?', [ - 1, - ]); + const [result] = await poolNamespace.query( + 'SELECT 1 as a from dual where 1 = ?', + [1], + ); assert.equal(result[0]['a'], 1, 'should query successfully'); - const [result2] = await poolNamespace.execute('SELECT 1 as a where 1 = ?', [ - 1, - ]); + const [result2] = await poolNamespace.execute( + 'SELECT 1 as a from dual where 1 = ?', + [1], + ); assert.equal(result2[0]['a'], 1, 'should execute successfully'); poolCluster.end(); From 6b6eaf6277d10636b17a25aafa47d054e37fe2ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20C=2E=20Marti=CC=81nez?= Date: Wed, 4 Dec 2024 11:17:31 +0100 Subject: [PATCH 15/19] Fix: PromisePoolCluster.of returns PromisePoolCluster instead of PoolNamespace (#3091) --- lib/pool_cluster.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/pool_cluster.js b/lib/pool_cluster.js index 9edda501a2..eb2ab62d4a 100644 --- a/lib/pool_cluster.js +++ b/lib/pool_cluster.js @@ -362,4 +362,5 @@ class PoolCluster extends EventEmitter { } } -module.exports = PoolCluster; +exports.PoolNamespace = PoolNamespace; +exports.PoolCluster = PoolCluster; From 91f13a0d52751e6577066072782c3737b99863b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20C=2E=20Marti=CC=81nez?= Date: Wed, 4 Dec 2024 11:36:08 +0100 Subject: [PATCH 16/19] Fix: PromisePoolCluster.of returns PromisePoolCluster instead of PoolNamespace (#3091) --- lib/pool_cluster.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/pool_cluster.js b/lib/pool_cluster.js index eb2ab62d4a..9edda501a2 100644 --- a/lib/pool_cluster.js +++ b/lib/pool_cluster.js @@ -362,5 +362,4 @@ class PoolCluster extends EventEmitter { } } -exports.PoolNamespace = PoolNamespace; -exports.PoolCluster = PoolCluster; +module.exports = PoolCluster; From 1d4df1db104897595a160af40cc5456503383414 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20C=2E=20Marti=CC=81nez?= Date: Tue, 10 Dec 2024 10:59:48 +0100 Subject: [PATCH 17/19] fix: PromisePoolCluster.of returns PromisePoolCluster instead of PoolNamespace (#3091) --- test/esm/integration/pool-cluster/test-promise-wrapper.test.mjs | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/esm/integration/pool-cluster/test-promise-wrapper.test.mjs b/test/esm/integration/pool-cluster/test-promise-wrapper.test.mjs index 163f11bf7c..9cbbcca41b 100644 --- a/test/esm/integration/pool-cluster/test-promise-wrapper.test.mjs +++ b/test/esm/integration/pool-cluster/test-promise-wrapper.test.mjs @@ -107,7 +107,5 @@ const { createPoolCluster } = require('../../../../promise.js'); [1], ); assert.equal(result2[0]['a'], 1, 'should execute successfully'); - - poolCluster.end(); }); })(); From f979effaab868d66230173ef5cee21ed318ff428 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20C=2E=20Marti=CC=81nez?= Date: Tue, 10 Dec 2024 20:33:25 +0100 Subject: [PATCH 18/19] fix: PromisePoolCluster.of returns PromisePoolCluster instead of PoolNamespace (#3091) --- test/esm/integration/pool-cluster/test-promise-wrapper.test.mjs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/esm/integration/pool-cluster/test-promise-wrapper.test.mjs b/test/esm/integration/pool-cluster/test-promise-wrapper.test.mjs index 9cbbcca41b..163f11bf7c 100644 --- a/test/esm/integration/pool-cluster/test-promise-wrapper.test.mjs +++ b/test/esm/integration/pool-cluster/test-promise-wrapper.test.mjs @@ -107,5 +107,7 @@ const { createPoolCluster } = require('../../../../promise.js'); [1], ); assert.equal(result2[0]['a'], 1, 'should execute successfully'); + + poolCluster.end(); }); })(); From 15523059e4adac985088e1e06be322871bf4e558 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20C=2E=20Marti=CC=81nez?= Date: Wed, 5 Mar 2025 07:43:32 +0100 Subject: [PATCH 19/19] Refactor. --- lib/promise/pool_cluster.js | 55 +++++++++++++++++++++++++++++++++++++ promise.js | 50 +-------------------------------- 2 files changed, 56 insertions(+), 49 deletions(-) create mode 100644 lib/promise/pool_cluster.js diff --git a/lib/promise/pool_cluster.js b/lib/promise/pool_cluster.js new file mode 100644 index 0000000000..b81d872a1a --- /dev/null +++ b/lib/promise/pool_cluster.js @@ -0,0 +1,55 @@ +'use strict'; + +const PromisePoolConnection = require('./pool_connection'); +const makeDoneCb = require('./make_done_cb'); + +class PromisePoolNamespace { + + constructor(poolNamespace, thePromise) { + this.poolNamespace = poolNamespace; + this.Promise = thePromise || Promise; + } + + getConnection() { + const corePoolNamespace = this.poolNamespace; + return new this.Promise((resolve, reject) => { + corePoolNamespace.getConnection((err, coreConnection) => { + if (err) { + reject(err); + } else { + resolve(new PromisePoolConnection(coreConnection, this.Promise)); + } + }); + }); + } + + query(sql, values) { + const corePoolNamespace = this.poolNamespace; + const localErr = new Error(); + if (typeof values === 'function') { + throw new Error( + 'Callback function is not available with promise clients.', + ); + } + return new this.Promise((resolve, reject) => { + const done = makeDoneCb(resolve, reject, localErr); + corePoolNamespace.query(sql, values, done); + }); + } + + execute(sql, values) { + const corePoolNamespace = this.poolNamespace; + const localErr = new Error(); + if (typeof values === 'function') { + throw new Error( + 'Callback function is not available with promise clients.', + ); + } + return new this.Promise((resolve, reject) => { + const done = makeDoneCb(resolve, reject, localErr); + corePoolNamespace.execute(sql, values, done); + }); + } +} + +module.exports = PromisePoolNamespace; diff --git a/promise.js b/promise.js index 0e714ddf63..16c59eb82a 100644 --- a/promise.js +++ b/promise.js @@ -12,6 +12,7 @@ const PromisePool = require('./lib/promise/pool.js'); const makeDoneCb = require('./lib/promise/make_done_cb.js'); const PromisePoolConnection = require('./lib/promise/pool_connection.js'); const inheritEvents = require('./lib/promise/inherit_events.js'); +const PromisePoolNamespace = require('./lib/promise/pool_cluster'); function createConnectionPromise(opts) { const coreConnection = createConnection(opts); @@ -55,55 +56,6 @@ function createPromisePool(opts) { return new PromisePool(corePool, thePromise); } -class PromisePoolNamespace { - - constructor(poolNamespace, thePromise) { - this.poolNamespace = poolNamespace; - this.Promise = thePromise || Promise; - } - - getConnection() { - const corePoolNamespace = this.poolNamespace; - return new this.Promise((resolve, reject) => { - corePoolNamespace.getConnection((err, coreConnection) => { - if (err) { - reject(err); - } else { - resolve(new PromisePoolConnection(coreConnection, this.Promise)); - } - }); - }); - } - - query(sql, values) { - const corePoolNamespace = this.poolNamespace; - const localErr = new Error(); - if (typeof values === 'function') { - throw new Error( - 'Callback function is not available with promise clients.', - ); - } - return new this.Promise((resolve, reject) => { - const done = makeDoneCb(resolve, reject, localErr); - corePoolNamespace.query(sql, values, done); - }); - } - - execute(sql, values) { - const corePoolNamespace = this.poolNamespace; - const localErr = new Error(); - if (typeof values === 'function') { - throw new Error( - 'Callback function is not available with promise clients.', - ); - } - return new this.Promise((resolve, reject) => { - const done = makeDoneCb(resolve, reject, localErr); - corePoolNamespace.execute(sql, values, done); - }); - } -} - class PromisePoolCluster extends EventEmitter { constructor(poolCluster, thePromise) { super();