Skip to content

Commit

Permalink
Fix: PromisePoolCluster.of returns PromisePoolCluster instead of Pool…
Browse files Browse the repository at this point in the history
…Namespace (sidorares#3091)
  • Loading branch information
jcmartineztiempo committed Dec 5, 2024
1 parent 86553f3 commit 7c728ec
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
28 changes: 28 additions & 0 deletions promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
18 changes: 18 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 @@ -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');
});
})();

0 comments on commit 7c728ec

Please sign in to comment.