Skip to content

Commit cc20f8b

Browse files
ikokostyabrianc
authored andcommitted
Clone options in Pool constructor (fixes #4) (#5)
1 parent d21ed42 commit cc20f8b

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ var genericPool = require('generic-pool')
22
var util = require('util')
33
var EventEmitter = require('events').EventEmitter
44
var debug = require('debug')
5+
var objectAssign = require('object-assign')
56

67
var Pool = module.exports = function (options, Client) {
78
EventEmitter.call(this)
8-
this.options = options || {}
9+
this.options = objectAssign({}, options)
910
this.log = this.options.log || debug('pg:pool')
1011
this.Client = this.options.Client || Client || require('pg').Client
1112
this.Promise = this.options.Promise || Promise

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
},
3838
"dependencies": {
3939
"debug": "^2.2.0",
40-
"generic-pool": "2.4.2"
40+
"generic-pool": "2.4.2",
41+
"object-assign": "4.1.0"
4142
}
4243
}

test/index.js

+11
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,17 @@ describe('pool', function () {
5151
})
5252
})
5353
})
54+
55+
it('should not change given options', function (done) {
56+
var options = { max: 10 }
57+
var pool = new Pool(options)
58+
pool.connect(function (err, client, release) {
59+
release()
60+
if (err) return done(err)
61+
expect(options).to.eql({ max: 10 })
62+
pool.end(done)
63+
})
64+
})
5465
})
5566

5667
describe('with promises', function () {

0 commit comments

Comments
 (0)