Skip to content

Commit 86f534d

Browse files
author
Kevin Delisle
authored
Merge pull request #296 from STRML/feature/pg7
Upgrade to pg@7.
2 parents f187f31 + d69b4b7 commit 86f534d

File tree

4 files changed

+11
-49
lines changed

4 files changed

+11
-49
lines changed

lib/postgresql.js

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -50,38 +50,6 @@ exports.initialize = function initializeDataSource(dataSource, callback) {
5050
}
5151
};
5252

53-
// there is a bug in the generic pool where it will not recreate
54-
// destroyed workers (even if there is waiting work to do) unless
55-
// there is a min specified. Make sure we keep some connections
56-
// SEE: https://github.com/coopernurse/node-pool/pull/186
57-
// SEE: https://github.com/brianc/node-pg-pool/issues/48
58-
// SEE: https://github.com/strongloop/loopback-connector-postgresql/issues/231
59-
function _ensureMinimum() {
60-
var i, diff, waiting;
61-
if (this._draining) return;
62-
waiting = this._waitingClients.size();
63-
if (this._factory.min > 0) { // we have positive specified minimum
64-
diff = this._factory.min - this._count;
65-
} else if (waiting > 0) { // we have no minimum, but we do have work to do
66-
diff = Math.min(waiting, this._factory.max - this._count);
67-
}
68-
for (i = 0; i < diff; i++) {
69-
this._createResource();
70-
}
71-
};
72-
function makePool(options) {
73-
var pg = new postgresql.Pool(options);
74-
// Monkey patch to ensure we always finish our work
75-
// - There is a bug where callbacks go uncalled if min is not set
76-
// - We might still not want a connection to *always* exist
77-
// - but we do want to create up to max connections if we have work
78-
// - still waiting
79-
// This should be safe till the version of pg-pool is upgraded
80-
// SEE: https://github.com/coopernurse/node-pool/pull/186
81-
pg.pool._ensureMinimum = _ensureMinimum;
82-
return pg;
83-
}
84-
8553
/**
8654
* PostgreSQL connector constructor
8755
*
@@ -110,7 +78,7 @@ function PostgreSQL(postgresql, settings) {
11078
this.clientConfig.connectionString = settings.url;
11179
}
11280
this.clientConfig.Promise = Promise;
113-
this.pg = makePool(this.clientConfig);
81+
this.pg = new postgresql.Pool(this.clientConfig);
11482

11583
this.settings = settings;
11684
debug('Settings %j', settings);

lib/transaction.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,7 @@ function mixinTransaction(PostgreSQL) {
7575
connection.autorelease(err);
7676
connection.autorelease = null;
7777
} else {
78-
var pool = this.pg;
79-
if (err) {
80-
pool.pool.destroy(connection);
81-
} else {
82-
pool.pool.release(connection);
83-
}
78+
connection.release();
8479
}
8580
};
8681
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"bluebird": "^3.4.6",
2525
"debug": "^2.1.1",
2626
"loopback-connector": "^4.2.2",
27-
"pg": "^6.0.0",
27+
"pg": "^7.0.0",
2828
"strong-globalize": "^2.6.2",
2929
"uuid": "^3.0.1"
3030
},

test/postgresql.initialization.test.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ function newConfig(withURL) {
1818
describe('initialization', function() {
1919
it('honours user-defined pg-pool settings', function() {
2020
var dataSource = new DataSource(connector, newConfig());
21-
var pool = dataSource.connector.pg.pool;
22-
pool._factory.max.should.not.equal(999);
21+
var pool = dataSource.connector.pg;
22+
pool.options.max.should.not.equal(999);
2323

2424
var settings = newConfig();
2525
settings.max = 999; // non-default value
2626
var dataSource = new DataSource(connector, settings);
27-
var pool = dataSource.connector.pg.pool;
28-
pool._factory.max.should.equal(999);
27+
var pool = dataSource.connector.pg;
28+
pool.options.max.should.equal(999);
2929
});
3030

3131
it('honours user-defined url settings', function() {
@@ -45,8 +45,8 @@ describe('initialization', function() {
4545
var urlOnly = {url: newConfig(true).url, max: 999};
4646

4747
var dataSource = new DataSource(connector, urlOnly);
48-
var pool = dataSource.connector.pg.pool;
49-
pool._factory.max.should.equal(999);
48+
var pool = dataSource.connector.pg;
49+
pool.options.max.should.equal(999);
5050

5151
var clientConfig = dataSource.connector.clientConfig;
5252
clientConfig.connectionString.should.equal(urlOnly.url);
@@ -57,9 +57,8 @@ describe('postgresql connector errors', function() {
5757
it('Should complete these 4 queries without dying', function(done) {
5858
var dataSource = getDataSource();
5959
var db = dataSource.connector;
60-
var pool = db.pg.pool;
61-
pool._factory.max = 5;
62-
pool._factory.min = null;
60+
var pool = db.pg;
61+
pool.options.max = 5;
6362
var errors = 0;
6463
var shouldGet = 0;
6564
function runErrorQuery() {

0 commit comments

Comments
 (0)