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.4.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: v7.4.1
Choose a head ref
  • 10 commits
  • 17 files changed
  • 4 contributors

Commits on Nov 17, 2017

  1. Specify collation when relied on in tests

    Fixes #189.
    charmander authored and brianc committed Nov 17, 2017
    Copy the full SHA
    0b80aba View commit details
  2. Make tests compatible with PostgreSQL 10

    PostgreSQL 10 reports its version as only `major.minor`, so it can’t be parsed with semver. The `server_version_num` setting is a major version followed by a four-digit minor version since version 10, and was a three-digit major version followed by a two-digit minor version before that.
    charmander authored and brianc committed Nov 17, 2017
    Copy the full SHA
    9870c86 View commit details

Commits on Dec 6, 2017

  1. Update SPONSORS.md

    brianc authored Dec 6, 2017
    Copy the full SHA
    56633a5 View commit details
  2. Update SPONSORS.md

    brianc authored Dec 6, 2017
    Copy the full SHA
    6c723b2 View commit details

Commits on Jan 2, 2018

  1. Update license date

    benhc123 authored and charmander committed Jan 2, 2018
    Copy the full SHA
    1e48733 View commit details

Commits on Jan 3, 2018

  1. License date in README

    benhc123 authored and charmander committed Jan 3, 2018
    Copy the full SHA
    c9ca1da View commit details

Commits on Jan 5, 2018

  1. Copy the full SHA
    4cf67b2 View commit details
  2. Copy the full SHA
    70a8ee1 View commit details
  3. Copy the full SHA
    9825e7c View commit details
  4. Bump version

    brianc committed Jan 5, 2018
    Copy the full SHA
    a664983 View commit details
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2010 - 2017 Brian Carlson
Copyright (c) 2010 - 2018 Brian Carlson

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -67,7 +67,7 @@ The causes and solutions to common errors can be found among the [Frequently Ask

## License

Copyright (c) 2010-2017 Brian Carlson (brian.m.carlson@gmail.com)
Copyright (c) 2010-2018 Brian Carlson (brian.m.carlson@gmail.com)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
2 changes: 2 additions & 0 deletions SPONSORS.md
Original file line number Diff line number Diff line change
@@ -10,3 +10,5 @@ node-postgres is made possible by the helpful contributors from the community we
- Rein Petersen
- Arnaud Benhamdine [@abenhamdine](https://twitter.com/abenhamdine)
- Matthew Welke
- Matthew Weber
- Benjie Gillam
11 changes: 5 additions & 6 deletions lib/connection.js
Original file line number Diff line number Diff line change
@@ -62,14 +62,15 @@ Connection.prototype.connect = function (port, host) {
self.emit('connect')
})

this.stream.on('error', function (error) {
const reportStreamError = function (error) {
// don't raise ECONNRESET errors - they can & should be ignored
// during disconnect
if (self._ending && error.code === 'ECONNRESET') {
return
}
self.emit('error', error)
})
}
this.stream.on('error', reportStreamError)

this.stream.on('close', function () {
self.emit('end')
@@ -97,11 +98,9 @@ Connection.prototype.connect = function (port, host) {
NPNProtocols: self.ssl.NPNProtocols
})
self.attachListeners(self.stream)
self.emit('sslconnect')
self.stream.on('error', reportStreamError)

self.stream.on('error', function (error) {
self.emit('error', error)
})
self.emit('sslconnect')
})
}

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.4.0",
"version": "7.4.1",
"description": "PostgreSQL client - pure javascript & libpq with the same API",
"keywords": [
"database",
2 changes: 1 addition & 1 deletion test/integration/client/api-tests.js
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ suite.test('callback API', done => {
client.query(config)
client.query('INSERT INTO peep(name) VALUES ($1)', ['aaron'])

client.query('SELECT * FROM peep ORDER BY name', (err, res) => {
client.query('SELECT * FROM peep ORDER BY name COLLATE "C"', (err, res) => {
assert(!err)
assert.equal(res.rowCount, 3)
assert.deepEqual(res.rows, [
2 changes: 1 addition & 1 deletion test/integration/client/json-type-parsing-tests.js
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ var assert = require('assert')

const pool = new helper.pg.Pool()
pool.connect(assert.success(function (client, done) {
helper.versionGTE(client, '9.2.0', assert.success(function (jsonSupported) {
helper.versionGTE(client, 90200, assert.success(function (jsonSupported) {
if (!jsonSupported) {
console.log('skip json test on older versions of postgres')
done()
4 changes: 2 additions & 2 deletions test/integration/client/prepared-statement-tests.js
Original file line number Diff line number Diff line change
@@ -122,7 +122,7 @@ var suite = new helper.Suite()
suite.test('with small row count', function (done) {
var query = client.query(new Query({
name: 'get names',
text: 'SELECT name FROM zoom ORDER BY name',
text: 'SELECT name FROM zoom ORDER BY name COLLATE "C"',
rows: 1
}, done))

@@ -132,7 +132,7 @@ var suite = new helper.Suite()
suite.test('with large row count', function (done) {
var query = client.query(new Query({
name: 'get names',
text: 'SELECT name FROM zoom ORDER BY name',
text: 'SELECT name FROM zoom ORDER BY name COLLATE "C"',
rows: 1000
}, done))
checkForResults(query)
Original file line number Diff line number Diff line change
@@ -44,7 +44,7 @@ function killIdleQuery (targetQuery, cb) {
var pidColName = 'procpid'
var queryColName = 'current_query'
client2.connect(assert.success(function () {
helper.versionGTE(client2, '9.2.0', assert.success(function (isGreater) {
helper.versionGTE(client2, 90200, assert.success(function (isGreater) {
if (isGreater) {
pidColName = 'pid'
queryColName = 'query'
6 changes: 3 additions & 3 deletions test/integration/client/query-error-handling-tests.js
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ test('error during query execution', function() {
var sleepQuery = new Query(queryText);
var pidColName = 'procpid'
var queryColName = 'current_query';
helper.versionGTE(client, '9.2.0', assert.success(function(isGreater) {
helper.versionGTE(client, 90200, assert.success(function(isGreater) {
if(isGreater) {
pidColName = 'pid';
queryColName = 'query';
@@ -48,7 +48,7 @@ if (helper.config.native) {
test('9.3 column error fields', function() {
var client = new Client(helper.args);
client.connect(assert.success(function() {
helper.versionGTE(client, '9.3.0', assert.success(function(isGreater) {
helper.versionGTE(client, 90300, assert.success(function(isGreater) {
if(!isGreater) {
return client.end();
}
@@ -68,7 +68,7 @@ test('9.3 column error fields', function() {
test('9.3 constraint error fields', function() {
var client = new Client(helper.args);
client.connect(assert.success(function() {
helper.versionGTE(client, '9.3.0', assert.success(function(isGreater) {
helper.versionGTE(client, 90300, assert.success(function(isGreater) {
if(!isGreater) {
console.log('skip 9.3 error field on older versions of postgres');
return client.end();
2 changes: 1 addition & 1 deletion test/integration/client/result-metadata-tests.js
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ new helper.Suite().test('should return insert metadata', function () {
pool.connect(assert.calls(function (err, client, done) {
assert(!err)

helper.versionGTE(client, '9.0.0', assert.success(function (hasRowCount) {
helper.versionGTE(client, 90000, assert.success(function (hasRowCount) {
client.query('CREATE TEMP TABLE zugzug(name varchar(10))', assert.calls(function (err, result) {
assert(!err)
assert.equal(result.oid, null)
4 changes: 2 additions & 2 deletions test/integration/client/simple-query-tests.js
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ var Query = helper.pg.Query
test('simple query interface', function () {
var client = helper.client()

var query = client.query(new Query('select name from person order by name'))
var query = client.query(new Query('select name from person order by name collate "C"'))

client.on('drain', client.end.bind(client))

@@ -43,7 +43,7 @@ test('prepared statements do not mutate params', function () {

var params = [1]

var query = client.query(new Query('select name from person where $1 = 1 order by name', params))
var query = client.query(new Query('select name from person where $1 = 1 order by name collate "C"', params))

assert.deepEqual(params, [1])

2 changes: 1 addition & 1 deletion test/integration/connection-pool/error-tests.js
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ suite.test('errors emitted on pool', (cb) => {
pool.connect(assert.success(function (client2, done2) {
client2.id = 2
var pidColName = 'procpid'
helper.versionGTE(client2, '9.2.0', assert.success(function (isGreater) {
helper.versionGTE(client2, 90200, assert.success(function (isGreater) {
var killIdleQuery = 'SELECT pid, (SELECT pg_terminate_backend(pid)) AS killed FROM pg_stat_activity WHERE state = $1'
var params = ['idle']
if (!isGreater) {
9 changes: 4 additions & 5 deletions test/integration/test-helper.js
Original file line number Diff line number Diff line change
@@ -14,12 +14,11 @@ helper.client = function (cb) {
return client
}

var semver = require('semver')
helper.versionGTE = function (client, versionString, callback) {
client.query('SELECT version()', assert.calls(function (err, result) {
helper.versionGTE = function (client, testVersion, callback) {
client.query('SHOW server_version_num', assert.calls(function (err, result) {
if (err) return callback(err)
var version = result.rows[0].version.split(' ')[1]
return callback(null, semver.gte(version, versionString))
var version = parseInt(result.rows[0].server_version_num, 10)
return callback(null, version >= testVersion)
}))
}

2 changes: 1 addition & 1 deletion test/native/evented-api-tests.js
Original file line number Diff line number Diff line change
@@ -64,7 +64,7 @@ test('parameterized queries', function () {

test('multiple parameters', function () {
var client = setupClient()
var q = client.query(new Query('SELECT name FROM boom WHERE name = $1 or name = $2 ORDER BY name', ['Aaron', 'Brian']))
var q = client.query(new Query('SELECT name FROM boom WHERE name = $1 or name = $2 ORDER BY name COLLATE "C"', ['Aaron', 'Brian']))
assert.emits(q, 'row', function (row) {
assert.equal(row.name, 'Aaron')
assert.emits(q, 'row', function (row) {
37 changes: 34 additions & 3 deletions test/unit/connection/error-tests.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,62 @@
'use strict'
var helper = require(__dirname + '/test-helper')
var Connection = require(__dirname + '/../../../lib/connection')
test('connection emits stream errors', function () {
var net = require('net')

const suite = new helper.Suite()

suite.test('connection emits stream errors', function (done) {
var con = new Connection({stream: new MemoryStream()})
assert.emits(con, 'error', function (err) {
assert.equal(err.message, 'OMG!')
done()
})
con.connect()
con.stream.emit('error', new Error('OMG!'))
})

test('connection emits ECONNRESET errors during normal operation', function () {
suite.test('connection emits ECONNRESET errors during normal operation', function (done) {
var con = new Connection({stream: new MemoryStream()})
con.connect()
assert.emits(con, 'error', function (err) {
assert.equal(err.code, 'ECONNRESET')
done()
})
var e = new Error('Connection Reset')
e.code = 'ECONNRESET'
con.stream.emit('error', e)
})

test('connection does not emit ECONNRESET errors during disconnect', function () {
suite.test('connection does not emit ECONNRESET errors during disconnect', function (done) {
var con = new Connection({stream: new MemoryStream()})
con.connect()
var e = new Error('Connection Reset')
e.code = 'ECONNRESET'
con.end()
con.stream.emit('error', e)
done()
})


suite.test('connection does not emit ECONNRESET errors during disconnect also when using SSL', function (done) {
// our fake postgres server, which just responds with 'S' to start SSL
var socket
var server = net.createServer(function (c) {
socket = c
c.once('data', function (data) {
c.write(Buffer.from('S'))
})
})

server.listen(7778, function () {
var con = new Connection({ssl: true})
con.connect(7778, 'localhost')
assert.emits(con, 'sslconnect', function () {
con.end()
socket.destroy()
server.close()
done()
})
con.requestSsl()
})
})
2 changes: 1 addition & 1 deletion test/unit/connection/test-helper.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
'use strict'
require(__dirname + '/../test-helper')
module.exports = require(__dirname + '/../test-helper')