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

fix: PromisePoolCluster.of returns PromisePoolCluster instead of PoolNamespace #3261

Merged
merged 27 commits into from
Mar 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
e458059
Fix: PromisePoolCluster.of returns PromisePoolCluster instead of Pool…
jcmartineztiempo Dec 4, 2024
86553f3
Fix: PromisePoolCluster.of returns PromisePoolCluster instead of Pool…
jcmartineztiempo Dec 4, 2024
7c728ec
Fix: PromisePoolCluster.of returns PromisePoolCluster instead of Pool…
jcmartineztiempo Dec 5, 2024
d39eb82
Merge remote-tracking branch 'upstream/master' into hotfix/fix_3091
jcmartineztiempo Dec 5, 2024
8f27b41
Fix: PromisePoolCluster.of returns PromisePoolCluster instead of Pool…
jcmartineztiempo Dec 6, 2024
e91ee6a
Merge remote-tracking branch 'upstream/master' into hotfix/fix_3091
jcmartineztiempo Dec 6, 2024
2d1a3be
Merge remote-tracking branch 'upstream/master' into hotfix/fix_3091
jcmartineztiempo Dec 10, 2024
9c0c292
fix: PromisePoolCluster.of returns PromisePoolCluster instead of Pool…
jcmartineztiempo Dec 10, 2024
6a00b0f
fix: PromisePoolCluster.of returns PromisePoolCluster instead of Pool…
jcmartineztiempo Dec 10, 2024
526cb33
Merge remote-tracking branch 'upstream/master' into hotfix/fix_3091
jcmartineztiempo Dec 10, 2024
6ae2689
fix: PromisePoolCluster.of returns PromisePoolCluster instead of Pool…
jcmartineztiempo Dec 11, 2024
6e5ccbb
Fix: PromisePoolCluster.of returns PromisePoolCluster instead of Pool…
jcmartineztiempo Dec 4, 2024
393fbc0
Fix: PromisePoolCluster.of returns PromisePoolCluster instead of Pool…
jcmartineztiempo Dec 4, 2024
5869a62
Fix: PromisePoolCluster.of returns PromisePoolCluster instead of Pool…
jcmartineztiempo Dec 5, 2024
39b47c6
Fix: PromisePoolCluster.of returns PromisePoolCluster instead of Pool…
jcmartineztiempo Dec 6, 2024
d5cba5a
fix: PromisePoolCluster.of returns PromisePoolCluster instead of Pool…
jcmartineztiempo Dec 10, 2024
e20086c
fix: PromisePoolCluster.of returns PromisePoolCluster instead of Pool…
jcmartineztiempo Dec 10, 2024
ffb97bd
fix: PromisePoolCluster.of returns PromisePoolCluster instead of Pool…
jcmartineztiempo Dec 11, 2024
1f5d034
Merge branch 'hotfix/fix_3091' of github.com:jcmartineztiempo/node-my…
jcmartineztiempo Feb 26, 2025
6b6eaf6
Fix: PromisePoolCluster.of returns PromisePoolCluster instead of Pool…
jcmartineztiempo Dec 4, 2024
91f13a0
Fix: PromisePoolCluster.of returns PromisePoolCluster instead of Pool…
jcmartineztiempo Dec 4, 2024
1d4df1d
fix: PromisePoolCluster.of returns PromisePoolCluster instead of Pool…
jcmartineztiempo Dec 10, 2024
f979eff
fix: PromisePoolCluster.of returns PromisePoolCluster instead of Pool…
jcmartineztiempo Dec 10, 2024
28dfb1a
Merge branch 'hotfix/fix_3091' of github.com:jcmartineztiempo/node-my…
jcmartineztiempo Feb 26, 2025
ae330a0
Merge branch 'master' into hotfix/fix_3091
jcmartineztiempo Mar 3, 2025
4d774b0
Merge branch 'master' into hotfix/fix_3091
wellwelwel Mar 4, 2025
1552305
Refactor.
jcmartineztiempo Mar 5, 2025
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
55 changes: 55 additions & 0 deletions lib/promise/pool_cluster.js
Original file line number Diff line number Diff line change
@@ -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);

Check warning on line 18 in lib/promise/pool_cluster.js

View check run for this annotation

Codecov / codecov/patch

lib/promise/pool_cluster.js#L18

Added line #L18 was not covered by tests
} 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.',
);
}

Check warning on line 33 in lib/promise/pool_cluster.js

View check run for this annotation

Codecov / codecov/patch

lib/promise/pool_cluster.js#L30-L33

Added lines #L30 - L33 were not covered by tests
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.',
);
}

Check warning on line 47 in lib/promise/pool_cluster.js

View check run for this annotation

Codecov / codecov/patch

lib/promise/pool_cluster.js#L44-L47

Added lines #L44 - L47 were not covered by tests
return new this.Promise((resolve, reject) => {
const done = makeDoneCb(resolve, reject, localErr);
corePoolNamespace.execute(sql, values, done);
});
}
}

module.exports = PromisePoolNamespace;
3 changes: 2 additions & 1 deletion promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -109,7 +110,7 @@ class PromisePoolCluster extends EventEmitter {
}

of(pattern, selector) {
return new PromisePoolCluster(
return new PromisePoolNamespace(
this.poolCluster.of(pattern, selector),
this.Promise,
);
Expand Down
31 changes: 31 additions & 0 deletions test/esm/integration/pool-cluster/test-promise-wrapper.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,35 @@ 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');

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 = ?',
[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');

poolCluster.end();
});
})();
Loading