mirror of
https://github.com/brianc/node-postgres.git
synced 2026-01-18 15:55:05 +00:00
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:
parent
1d89029ba7
commit
51fb7db8fa
3
index.js
3
index.js
@ -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 () { }
|
||||
|
||||
@ -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()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user