Support function-like construction (plus test) (#23)

* Support function-like construction

Remove the necessity of using `new` in front of the `Pool`, i.e. allow it to be used as a regular function. This is following https://github.com/brianc/node-postgres/issues/1077

* add Pool factory test
This commit is contained in:
Cody Greene 2016-08-05 14:21:51 -07:00 committed by Brian C
parent 1d89029ba7
commit 51fb7db8fa
2 changed files with 9 additions and 0 deletions

View File

@ -4,6 +4,9 @@ var EventEmitter = require('events').EventEmitter
var objectAssign = require('object-assign')
var Pool = module.exports = function (options, Client) {
if (!(this instanceof Pool)) {
return new Pool(options, Client)
}
EventEmitter.call(this)
this.options = objectAssign({}, options)
this.log = this.options.log || function () { }

View File

@ -12,6 +12,12 @@ if (typeof global.Promise === 'undefined') {
}
describe('pool', function () {
it('can be used as a factory function', function () {
var pool = Pool()
expect(pool instanceof Pool).to.be.ok()
expect(typeof pool.connect).to.be('function')
})
describe('with callbacks', function () {
it('works totally unconfigured', function (done) {
var pool = new Pool()