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, );