Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use class-extends to wrap Pool #1541

Merged
merged 4 commits into from Jan 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 5 additions & 12 deletions packages/pg/lib/index.js
Expand Up @@ -7,25 +7,18 @@
* README.md file in the root directory of this source tree.
*/

var util = require('util')
var Client = require('./client')
var defaults = require('./defaults')
var Connection = require('./connection')
var Pool = require('pg-pool')
const checkConstructor = require('./compat/check-constructor')

const poolFactory = (Client) => {
var BoundPool = function (options) {
// eslint-disable-next-line no-eval
checkConstructor('pg.Pool', 'PG-POOL-NEW', () => eval('new.target'))

var config = Object.assign({ Client: Client }, options)
return new Pool(config)
return class BoundPool extends Pool {
constructor (options) {
var config = Object.assign({ Client: Client }, options)
super(config)
}
}

util.inherits(BoundPool, Pool)

return BoundPool
}

var PG = function (clientConstructor) {
Expand Down
25 changes: 25 additions & 0 deletions packages/pg/test/integration/gh-issues/1542-tests.js
@@ -0,0 +1,25 @@

"use strict"
const helper = require('./../test-helper')
const assert = require('assert')

const suite = new helper.Suite()

suite.testAsync('BoundPool can be subclassed', async () => {
const Pool = helper.pg.Pool;
class SubPool extends Pool {

}
const subPool = new SubPool()
const client = await subPool.connect()
client.release()
await subPool.end()
assert(subPool instanceof helper.pg.Pool)
})

suite.test('calling pg.Pool without new throws', () => {
const Pool = helper.pg.Pool;
assert.throws(() => {
const pool = Pool()
})
})