Skip to content

Commit 70a2b56

Browse files
committed
Merge branch 'master' into queued-query-errors
2 parents a55da8a + 83ede28 commit 70a2b56

15 files changed

+205
-72
lines changed

Diff for: .travis.yml

+15-9
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,34 @@ env:
88

99
matrix:
1010
include:
11+
- node_js: "lts/boron"
12+
addons:
13+
postgresql: "9.6"
1114
- node_js: "lts/argon"
1215
addons:
1316
postgresql: "9.6"
14-
- node_js: "lts/boron"
17+
- node_js: "9"
18+
addons:
19+
postgresql: "9.6"
20+
- node_js: "10"
21+
addons:
22+
postgresql: "9.6"
23+
- node_js: "lts/carbon"
1524
addons:
1625
postgresql: "9.1"
1726
dist: precise
18-
- node_js: "lts/boron"
27+
- node_js: "lts/carbon"
1928
addons:
2029
postgresql: "9.2"
21-
- node_js: "lts/boron"
30+
- node_js: "lts/carbon"
2231
addons:
2332
postgresql: "9.3"
24-
- node_js: "lts/boron"
33+
- node_js: "lts/carbon"
2534
addons:
2635
postgresql: "9.4"
27-
- node_js: "lts/boron"
36+
- node_js: "lts/carbon"
2837
addons:
2938
postgresql: "9.5"
30-
- node_js: "lts/boron"
31-
addons:
32-
postgresql: "9.6"
33-
- node_js: "8"
39+
- node_js: "lts/carbon"
3440
addons:
3541
postgresql: "9.6"

Diff for: CHANGELOG.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ var pg = require('pg')
6666
6767
var pool = new pg.Pool()
6868
69-
// your friendly neighboorhood pool interface, without the singleton
69+
// your friendly neighborhood pool interface, without the singleton
7070
pool.connect(function(err, client, done) {
7171
// ...
7272
})
@@ -113,7 +113,7 @@ client.query('SELECT $1::text as name', ['brianc'])
113113
- Add option to parse JS date objects in query parameters as [UTC](https://github.com/brianc/node-postgres/pull/943)
114114

115115
### v4.4.0
116-
- Warn to `stderr` if a named query exceeds 63 characters which is the max lenght supported by postgres.
116+
- Warn to `stderr` if a named query exceeds 63 characters which is the max length supported by postgres.
117117

118118
### v4.3.0
119119
- Unpin `pg-types` semver. Allow it to float against `[email protected]`.

Diff for: LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2010 - 2017 Brian Carlson
3+
Copyright (c) 2010 - 2018 Brian Carlson
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

Diff for: README.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<span class="badge-npmversion"><a href="https://npmjs.org/package/pg" title="View this project on NPM"><img src="https://img.shields.io/npm/v/pg.svg" alt="NPM version" /></a></span>
66
<span class="badge-npmdownloads"><a href="https://npmjs.org/package/pg" title="View this project on NPM"><img src="https://img.shields.io/npm/dm/pg.svg" alt="NPM downloads" /></a></span>
77

8-
Non-blocking PostgreSQL client for node.js. Pure JavaScript and optional native libpq bindings.
8+
Non-blocking PostgreSQL client for Node.js. Pure JavaScript and optional native libpq bindings.
99

1010
## Install
1111

@@ -19,9 +19,9 @@ $ npm install pg
1919

2020
### Features
2121

22-
* Pure JavaScript client and native libpq bindings share _the same api_
22+
* Pure JavaScript client and native libpq bindings share _the same API_
2323
* Connection pooling
24-
* Extensible js<->postgresql data-type coercion
24+
* Extensible JS<->PostgreSQL data-type coercion
2525
* Supported PostgreSQL features
2626
* Parameterized queries
2727
* Named statements with query plan caching
@@ -35,18 +35,18 @@ The entire list can be found on our [wiki](https://github.com/brianc/node-postgr
3535

3636
## Support
3737

38-
node-postgres is free software. If you encounter a bug with the library please open an issue on the [github repo](https://github.com/brianc/node-postgres). If you have questions unanswered by the documentation please open an issue pointing out how the documentation was unclear & I will do my best to make it better!
38+
node-postgres is free software. If you encounter a bug with the library please open an issue on the [GitHub repo](https://github.com/brianc/node-postgres). If you have questions unanswered by the documentation please open an issue pointing out how the documentation was unclear & I will do my best to make it better!
3939

4040
When you open an issue please provide:
41-
- version of node
42-
- version of postgres
41+
- version of Node
42+
- version of Postgres
4343
- smallest possible snippet of code to reproduce the problem
4444

4545
You can also follow me [@briancarlson](https://twitter.com/briancarlson) if that's your thing. I try to always announce noteworthy changes & developments with node-postgres on Twitter.
4646

4747
### Professional Support
4848

49-
I offer professional support for node-postgres. I provide implementation, training, and many years of expertise on how to build applications with node, express, PostgreSQL, and react/redux. Please contact me at [[email protected]](mailto:[email protected]) to discuss how I can help your company be more successful!
49+
I offer professional support for node-postgres. I provide implementation, training, and many years of expertise on how to build applications with Node, Express, PostgreSQL, and React/Redux. Please contact me at [[email protected]](mailto:[email protected]) to discuss how I can help your company be more successful!
5050

5151
### Sponsorship :star:
5252

@@ -63,11 +63,11 @@ I will __happily__ accept your pull request if it:
6363

6464
## Troubleshooting and FAQ
6565

66-
The causes and solutions to common errors can be found among the [Frequently Asked Questions(FAQ)](https://github.com/brianc/node-postgres/wiki/FAQ)
66+
The causes and solutions to common errors can be found among the [Frequently Asked Questions (FAQ)](https://github.com/brianc/node-postgres/wiki/FAQ)
6767

6868
## License
6969

70-
Copyright (c) 2010-2017 Brian Carlson ([email protected])
70+
Copyright (c) 2010-2018 Brian Carlson ([email protected])
7171

7272
Permission is hereby granted, free of charge, to any person obtaining a copy
7373
of this software and associated documentation files (the "Software"), to deal

Diff for: SPONSORS.md

+2
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ node-postgres is made possible by the helpful contributors from the community we
1010
- Rein Petersen
1111
- Arnaud Benhamdine [@abenhamdine](https://twitter.com/abenhamdine)
1212
- Matthew Welke
13+
- Matthew Weber
14+
- Benjie Gillam

Diff for: lib/connection.js

+19-12
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ var BINARY_MODE = 1
1919
var Connection = function (config) {
2020
EventEmitter.call(this)
2121
config = config || {}
22-
this.stream = config.stream || new net.Stream()
22+
this.stream = config.stream || new net.Socket()
2323
this._keepAlive = config.keepAlive
2424
this.lastBuffer = false
2525
this.lastOffset = 0
@@ -62,14 +62,15 @@ Connection.prototype.connect = function (port, host) {
6262
self.emit('connect')
6363
})
6464

65-
this.stream.on('error', function (error) {
65+
const reportStreamError = function (error) {
6666
// don't raise ECONNRESET errors - they can & should be ignored
6767
// during disconnect
6868
if (self._ending && error.code === 'ECONNRESET') {
6969
return
7070
}
7171
self.emit('error', error)
72-
})
72+
}
73+
this.stream.on('error', reportStreamError)
7374

7475
this.stream.on('close', function () {
7576
self.emit('end')
@@ -81,13 +82,19 @@ Connection.prototype.connect = function (port, host) {
8182

8283
this.stream.once('data', function (buffer) {
8384
var responseCode = buffer.toString('utf8')
84-
if (responseCode !== 'S') {
85-
return self.emit('error', new Error('The server does not support SSL connections'))
85+
switch (responseCode) {
86+
case 'N': // Server does not support SSL connections
87+
return self.emit('error', new Error('The server does not support SSL connections'))
88+
case 'S': // Server supports SSL connections, continue with a secure connection
89+
break
90+
default: // Any other response byte, including 'E' (ErrorResponse) indicating a server error
91+
return self.emit('error', new Error('There was an error establishing an SSL connection'))
8692
}
8793
var tls = require('tls')
8894
self.stream = tls.connect({
8995
socket: self.stream,
9096
servername: host,
97+
checkServerIdentity: self.ssl.checkServerIdentity,
9198
rejectUnauthorized: self.ssl.rejectUnauthorized,
9299
ca: self.ssl.ca,
93100
pfx: self.ssl.pfx,
@@ -97,11 +104,9 @@ Connection.prototype.connect = function (port, host) {
97104
NPNProtocols: self.ssl.NPNProtocols
98105
})
99106
self.attachListeners(self.stream)
100-
self.emit('sslconnect')
107+
self.stream.on('error', reportStreamError)
101108

102-
self.stream.on('error', function (error) {
103-
self.emit('error', error)
104-
})
109+
self.emit('sslconnect')
105110
})
106111
}
107112

@@ -311,7 +316,9 @@ Connection.prototype.end = function () {
311316
// 0x58 = 'X'
312317
this.writer.add(emptyBuffer)
313318
this._ending = true
314-
return this.stream.write(END_BUFFER)
319+
return this.stream.write(END_BUFFER, () => {
320+
this.stream.end()
321+
})
315322
}
316323

317324
Connection.prototype.close = function (msg, more) {
@@ -619,13 +626,13 @@ Connection.prototype.parsed = function (buffer, length) {
619626
}
620627

621628
Connection.prototype.parseInt32 = function (buffer) {
622-
var value = buffer.readInt32BE(this.offset, true)
629+
var value = buffer.readInt32BE(this.offset)
623630
this.offset += 4
624631
return value
625632
}
626633

627634
Connection.prototype.parseInt16 = function (buffer) {
628-
var value = buffer.readInt16BE(this.offset, true)
635+
var value = buffer.readInt16BE(this.offset)
629636
this.offset += 2
630637
return value
631638
}

Diff for: lib/query.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ Query.prototype.handlePortalSuspended = function (connection) {
170170

171171
Query.prototype._getRows = function (connection, rows) {
172172
connection.execute({
173-
portal: this.portalName,
173+
portal: this.portal,
174174
rows: rows
175175
}, true)
176176
connection.flush()
@@ -196,15 +196,15 @@ Query.prototype.prepare = function (connection) {
196196

197197
// http://developer.postgresql.org/pgdocs/postgres/protocol-flow.html#PROTOCOL-FLOW-EXT-QUERY
198198
connection.bind({
199-
portal: self.portalName,
199+
portal: self.portal,
200200
statement: self.name,
201201
values: self.values,
202202
binary: self.binary
203203
}, true)
204204

205205
connection.describe({
206206
type: 'P',
207-
name: self.portalName || ''
207+
name: self.portal || ''
208208
}, true)
209209

210210
this._getRows(connection, this.rows)

Diff for: lib/result.js

+11-24
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
*/
99

1010
var types = require('pg-types')
11-
var escape = require('js-string-escape')
1211

1312
// result object returned from query
1413
// in the 'end' event and also
@@ -65,29 +64,24 @@ Result.prototype._parseRowAsArray = function (rowData) {
6564
return row
6665
}
6766

68-
// rowData is an array of text or binary values
69-
// this turns the row into a JavaScript object
7067
Result.prototype.parseRow = function (rowData) {
71-
return new this.RowCtor(this._parsers, rowData)
68+
var row = {}
69+
for (var i = 0, len = rowData.length; i < len; i++) {
70+
var rawValue = rowData[i]
71+
var field = this.fields[i].name
72+
if (rawValue !== null) {
73+
row[field] = this._parsers[i](rawValue)
74+
} else {
75+
row[field] = null
76+
}
77+
}
78+
return row
7279
}
7380

7481
Result.prototype.addRow = function (row) {
7582
this.rows.push(row)
7683
}
7784

78-
var inlineParser = function (fieldName, i) {
79-
return "\nthis['" +
80-
// fields containing single quotes will break
81-
// the evaluated javascript unless they are escaped
82-
// see https://github.com/brianc/node-postgres/issues/507
83-
// Addendum: However, we need to make sure to replace all
84-
// occurences of apostrophes, not just the first one.
85-
// See https://github.com/brianc/node-postgres/issues/934
86-
escape(fieldName) +
87-
"'] = " +
88-
'rowData[' + i + '] == null ? null : parsers[' + i + '](rowData[' + i + ']);'
89-
}
90-
9185
Result.prototype.addFields = function (fieldDescriptions) {
9286
// clears field definitions
9387
// multiple query statements in 1 action can result in multiple sets
@@ -97,18 +91,11 @@ Result.prototype.addFields = function (fieldDescriptions) {
9791
this.fields = []
9892
this._parsers = []
9993
}
100-
var ctorBody = ''
10194
for (var i = 0; i < fieldDescriptions.length; i++) {
10295
var desc = fieldDescriptions[i]
10396
this.fields.push(desc)
10497
var parser = this._getTypeParser(desc.dataTypeID, desc.format || 'text')
10598
this._parsers.push(parser)
106-
// this is some craziness to compile the row result parsing
107-
// results in ~60% speedup on large query result sets
108-
ctorBody += inlineParser(desc.name, i)
109-
}
110-
if (!this.rowAsArray) {
111-
this.RowCtor = Function('parsers', 'rowData', ctorBody)
11299
}
113100
}
114101

Diff for: package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pg",
3-
"version": "7.4.0",
3+
"version": "7.4.2",
44
"description": "PostgreSQL client - pure javascript & libpq with the same API",
55
"keywords": [
66
"database",
@@ -20,7 +20,6 @@
2020
"main": "./lib",
2121
"dependencies": {
2222
"buffer-writer": "1.0.1",
23-
"js-string-escape": "1.0.1",
2423
"packet-reader": "0.3.1",
2524
"pg-connection-string": "0.1.3",
2625
"pg-pool": "~2.0.3",

Diff for: test/integration/client/network-partition-tests.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Server.prototype.start = function (cb) {
2222
this.socket.on('data', function (data) {
2323
// deny request for SSL
2424
if (data.length == 8) {
25-
this.socket.write(new Buffer('N', 'utf8'))
25+
this.socket.write(Buffer.from('N', 'utf8'))
2626
// consider all authentication requests as good
2727
} else if (!data[0]) {
2828
this.socket.write(buffers.authenticationOk())
@@ -46,7 +46,7 @@ Server.prototype.start = function (cb) {
4646
}
4747

4848
Server.prototype.drop = function () {
49-
this.socket.end()
49+
this.socket.destroy()
5050
}
5151

5252
Server.prototype.close = function (cb) {

0 commit comments

Comments
 (0)