Skip to content

Commit 92fc34e

Browse files
authored
Merge pull request #143 from strongloop/feature/upgrade-to-pg-v6
Upgrade to pg 6.0.0
2 parents 1a25101 + e124a21 commit 92fc34e

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

lib/postgresql.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function PostgreSQL(postgresql, settings) {
6969
// this.settings = settings;
7070
this.constructor.super_.call(this, 'postgresql', settings);
7171
this.clientConfig = settings.url || settings;
72-
this.pg = postgresql;
72+
this.pg = new postgresql.Pool(this.clientConfig);
7373
this.settings = settings;
7474
if (settings.debug) {
7575
debug('Settings %j', settings);
@@ -95,7 +95,7 @@ PostgreSQL.prototype.getDefaultSchemaName = function() {
9595
*/
9696
PostgreSQL.prototype.connect = function(callback) {
9797
var self = this;
98-
self.pg.connect(self.clientConfig, function(err, client, done) {
98+
self.pg.connect(function(err, client, done) {
9999
self.client = client;
100100
process.nextTick(done);
101101
callback && callback(err, client);
@@ -130,9 +130,12 @@ PostgreSQL.prototype.executeSQL = function(sql, params, options, callback) {
130130
self.debug(err);
131131
}
132132
if (self.settings.debug && data) self.debug("%j", data);
133-
process.nextTick(function() {
134-
done(err);
135-
});
133+
if (done) {
134+
process.nextTick(function() {
135+
// Release the connection in next tick
136+
done(err);
137+
});
138+
}
136139
var result = null;
137140
if (data) {
138141
switch (data.command) {
@@ -152,10 +155,10 @@ PostgreSQL.prototype.executeSQL = function(sql, params, options, callback) {
152155
if (transaction && transaction.connection &&
153156
transaction.connector === this) {
154157
debug('Execute SQL within a transaction');
155-
executeWithConnection(transaction.connection,
156-
transaction.connection.release);
158+
// Do not release the connection
159+
executeWithConnection(transaction.connection, null);
157160
} else {
158-
self.pg.connect(self.clientConfig, function(err, connection, done) {
161+
self.pg.connect(function(err, connection, done) {
159162
if (err) return callback(err);
160163
executeWithConnection(connection, done);
161164
});

lib/transaction.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@ function mixinTransaction(PostgreSQL) {
1919
*/
2020
PostgreSQL.prototype.beginTransaction = function(isolationLevel, cb) {
2121
debug('Begin a transaction with isolation level: %s', isolationLevel);
22-
this.pg.connect(this.clientConfig, function(err, connection, done) {
22+
this.pg.connect(function(err, connection, done) {
2323
if (err) return cb(err);
2424
connection.query('BEGIN TRANSACTION ISOLATION LEVEL ' + isolationLevel,
2525
function(err) {
2626
if (err) return cb(err);
27-
connection.release = done;
2827
cb(null, connection);
2928
});
3029
});

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
},
1616
"dependencies": {
1717
"async": "^0.9.0",
18-
"pg": "^4.2.0",
1918
"debug": "^2.1.1",
20-
"loopback-connector": "^2.1.0"
19+
"loopback-connector": "^2.1.0",
20+
"pg": "^6.0.0"
2121
},
2222
"devDependencies": {
2323
"bluebird": "^2.9.12",

0 commit comments

Comments
 (0)