Clone options in Pool constructor (fixes #4) (#5)

This commit is contained in:
ikokostya 2016-06-23 00:34:17 +03:00 committed by Brian C
parent d21ed42fc6
commit cc20f8b747
3 changed files with 15 additions and 2 deletions

View File

@ -2,10 +2,11 @@ var genericPool = require('generic-pool')
var util = require('util')
var EventEmitter = require('events').EventEmitter
var debug = require('debug')
var objectAssign = require('object-assign')
var Pool = module.exports = function (options, Client) {
EventEmitter.call(this)
this.options = options || {}
this.options = objectAssign({}, options)
this.log = this.options.log || debug('pg:pool')
this.Client = this.options.Client || Client || require('pg').Client
this.Promise = this.options.Promise || Promise

View File

@ -37,6 +37,7 @@
},
"dependencies": {
"debug": "^2.2.0",
"generic-pool": "2.4.2"
"generic-pool": "2.4.2",
"object-assign": "4.1.0"
}
}

View File

@ -51,6 +51,17 @@ describe('pool', function () {
})
})
})
it('should not change given options', function (done) {
var options = { max: 10 }
var pool = new Pool(options)
pool.connect(function (err, client, release) {
release()
if (err) return done(err)
expect(options).to.eql({ max: 10 })
pool.end(done)
})
})
})
describe('with promises', function () {