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: v7.0.1
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: v7.0.2
Choose a head ref
  • 5 commits
  • 5 files changed
  • 3 contributors

Commits on Jul 18, 2017

  1. remove unused variable

    test
    billouboq committed Jul 18, 2017
    Copy the full SHA
    5062f27 View commit details

Commits on Jul 19, 2017

  1. Merge pull request #1375 from billouboq/remove-unused-var

    remove unused variable
    brianc authored Jul 19, 2017
    Copy the full SHA
    d4bb51f View commit details

Commits on Jul 21, 2017

  1. Copy the full SHA
    66c6776 View commit details
  2. Update utils.js

    fixing invalid custom type check
    vitaly-t authored and brianc committed Jul 21, 2017
    Copy the full SHA
    40cc6aa View commit details
  3. Bump version

    brianc committed Jul 21, 2017
    Copy the full SHA
    c6ee200 View commit details
Showing with 42 additions and 9 deletions.
  1. +1 −1 lib/client.js
  2. +5 −6 lib/native/query.js
  3. +1 −1 lib/utils.js
  4. +1 −1 package.json
  5. +34 −0 test/integration/gh-issues/1382-tests.js
2 changes: 1 addition & 1 deletion lib/client.js
Original file line number Diff line number Diff line change
@@ -400,7 +400,7 @@ Client.prototype.end = function (cb) {
// if we have an active query we need to force a disconnect
// on the socket - otherwise a hung query could block end forever
this.connection.stream.destroy(new Error('Connection terminated by user'))
return
return cb ? cb() : Promise.resolve()
}
if (cb) {
this.connection.end()
11 changes: 5 additions & 6 deletions lib/native/query.js
Original file line number Diff line number Diff line change
@@ -50,21 +50,20 @@ var errorFieldMap = {
}

NativeQuery.prototype.handleError = function (err) {
var self = this
// copy pq error fields into the error object
var fields = self.native.pq.resultErrorFields()
var fields = this.native.pq.resultErrorFields()
if (fields) {
for (var key in fields) {
var normalizedFieldName = errorFieldMap[key] || key
err[normalizedFieldName] = fields[key]
}
}
if (self.callback) {
self.callback(err)
if (this.callback) {
this.callback(err)
} else {
self.emit('error', err)
this.emit('error', err)
}
self.state = 'error'
this.state = 'error'
}

NativeQuery.prototype.then = function (onSuccess, onFailure) {
2 changes: 1 addition & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
@@ -70,7 +70,7 @@ var prepareValue = function (val, seen) {
}

function prepareObject (val, seen) {
if (val.toPostgres && typeof val.toPostgres === 'function') {
if (val && typeof val.toPostgres === 'function') {
seen = seen || []
if (seen.indexOf(val) !== -1) {
throw new Error('circular reference detected while preparing "' + val + '" for query')
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": "7.0.1",
"version": "7.0.2",
"description": "PostgreSQL client - pure javascript & libpq with the same API",
"keywords": [
"postgres",
34 changes: 34 additions & 0 deletions test/integration/gh-issues/1382-tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"use strict"
var helper = require('./../test-helper')

const suite = new helper.Suite()

suite.test('calling end during active query should return a promise', (done) => {
const client = new helper.pg.Client()
let callCount = 0
// ensure both the query rejects and the end promise resolves
const after = () => {
if (++callCount > 1) {
done()
}
}
client.connect().then(() => {
client.query('SELECT NOW()').catch(after)
client.end().then(after)
})
})

suite.test('calling end during an active query should call end callback', (done) => {
const client = new helper.pg.Client()
let callCount = 0
// ensure both the query rejects and the end callback fires
const after = () => {
if (++callCount > 1) {
done()
}
}
client.connect().then(() => {
client.query('SELECT NOW()').catch(after)
client.end(after)
})
})