Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: brianc/node-postgres
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v6.3.0
Choose a base ref
...
head repository: brianc/node-postgres
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v6.3.1
Choose a head ref
  • 3 commits
  • 7 files changed
  • 1 contributor

Commits on Jun 20, 2017

  1. Fix over-eager deprecation warnings (#1333)

    * WIP
    
    * Remove console.log messages
    brianc authored Jun 20, 2017
    Copy the full SHA
    842803c View commit details
  2. Copy the full SHA
    e446934 View commit details
  3. Bump version

    brianc committed Jun 20, 2017
    Copy the full SHA
    afe2498 View commit details
Showing with 56 additions and 13 deletions.
  1. +4 −2 lib/native/index.js
  2. +15 −5 lib/native/query.js
  3. +12 −2 lib/query.js
  4. +1 −1 lib/utils.js
  5. +1 −1 package.json
  6. +23 −0 test/integration/client/deprecation-tests.js
  7. +0 −2 test/test-helper.js
6 changes: 4 additions & 2 deletions lib/native/index.js
Original file line number Diff line number Diff line change
@@ -209,9 +209,11 @@ Client.prototype._pulseQueryQueue = function(initialConnection) {
this._activeQuery = query;
query.submit(this);
var self = this;
query.once('_done', function() {
var pulseOnDone = function() {
self._pulseQueryQueue();
});
query.removeListener('_done', pulseOnDone);
};
query._on('_done', pulseOnDone);
};

//attempt to cancel an in-progress query
20 changes: 15 additions & 5 deletions lib/native/query.js
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ var NativeQuery = module.exports = function(config, values, callback) {
//this has almost no meaning because libpq
//reads all rows into memory befor returning any
this._emitRowEvents = false;
this.on('newListener', function(event) {
this._on('newListener', function(event) {
if(event === 'row') this._emitRowEvents = true;
}.bind(this));
};
@@ -42,18 +42,28 @@ NativeQuery._once = NativeQuery.once;


NativeQuery.prototype.then = function(onSuccess, onFailure) {
return this.promise().then(onSuccess, onFailure);
return this._getPromise().then(onSuccess, onFailure);
};

NativeQuery.prototype.catch = function(callback) {
return this.promise().catch(callback);
return this._getPromise().catch(callback);
};

NativeQuery.prototype._getPromise = function() {
if (this._promise) return this._promise;
this._promise = new Promise(function(resolve, reject) {
this._once('end', resolve);
this._once('error', reject);
var onEnd = function (result) {
this.removeListener('error', onError);
this.removeListener('end', onEnd);
resolve(result);
};
var onError = function (err) {
this.removeListener('error', onError);
this.removeListener('end', onEnd);
reject(err);
};
this._on('end', onEnd);
this._on('error', onError);
}.bind(this));
return this._promise;
};
14 changes: 12 additions & 2 deletions lib/query.js
Original file line number Diff line number Diff line change
@@ -57,8 +57,18 @@ Query.prototype.catch = function(callback) {
Query.prototype._getPromise = function () {
if (this._promise) return this._promise;
this._promise = new Promise(function(resolve, reject) {
this._once('end', resolve);
this._once('error', reject);
var onEnd = function (result) {
this.removeListener('error', onError);
this.removeListener('end', onEnd);
resolve(result);
};
var onError = function (err) {
this.removeListener('error', onError);
this.removeListener('end', onEnd);
reject(err);
};
this._on('end', onEnd);
this._on('error', onError);
}.bind(this));
return this._promise;
};
2 changes: 1 addition & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
@@ -139,7 +139,7 @@ function normalizeQueryConfig (config, values, callback) {
return config;
}

var queryEventEmitterOverloadDeprecationMessage = 'Using the automatically created return value from client.query as an event emitter is deprecated. Please see the upgrade guide at https://node-postgres.com/guides/upgrading';
var queryEventEmitterOverloadDeprecationMessage = 'Using the automatically created return value from client.query as an event emitter is deprecated and will be removed in pg@7.0. Please see the upgrade guide at https://node-postgres.com/guides/upgrading';

var deprecateEventEmitter = function(Emitter) {
var Result = function () {
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pg",
"version": "6.3.0",
"version": "6.3.1",
"description": "PostgreSQL client - pure javascript & libpq with the same API",
"keywords": [
"postgres",
23 changes: 23 additions & 0 deletions test/integration/client/deprecation-tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
var helper = require('./test-helper')

process.on('warning', function (warning) {
console.log(warning)
throw new Error('Should not emit deprecation warning')
})

var client = new helper.pg.Client()

client.connect(function (err) {
if (err) throw err
client.query('SELECT NOW()')
.then(function (res) {
client.query('SELECT NOW()', function () {
client.end(function () {
})
})
}).catch(function (err) {
setImmediate(function () {
throw err
})
})
})
2 changes: 0 additions & 2 deletions test/test-helper.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
//make assert a global...
assert = require('assert');

process.noDeprecation = true

//support for node@0.10.x
if (typeof Promise == 'undefined') {
global.Promise = require('promise-polyfill')