pg 8.4.0 → 8.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/client.js +9 -0
- package/lib/connection-parameters.js +10 -0
- package/lib/connection.js +12 -6
- package/lib/index.js +0 -3
- package/lib/query.js +41 -35
- package/lib/utils.js +4 -3
- package/package.json +4 -4
package/lib/client.js
CHANGED
|
@@ -57,6 +57,15 @@ class Client extends EventEmitter {
|
|
|
57
57
|
this.processID = null
|
|
58
58
|
this.secretKey = null
|
|
59
59
|
this.ssl = this.connectionParameters.ssl || false
|
|
60
|
+
// As with Password, make SSL->Key (the private key) non-enumerable.
|
|
61
|
+
// It won't show up in stack traces
|
|
62
|
+
// or if the client is console.logged
|
|
63
|
+
if (this.ssl && this.ssl.key) {
|
|
64
|
+
Object.defineProperty(this.ssl, 'key', {
|
|
65
|
+
enumerable: false,
|
|
66
|
+
})
|
|
67
|
+
}
|
|
68
|
+
|
|
60
69
|
this._connectionTimeoutMillis = c.connectionTimeoutMillis || 0
|
|
61
70
|
}
|
|
62
71
|
|
|
@@ -80,10 +80,20 @@ class ConnectionParameters {
|
|
|
80
80
|
|
|
81
81
|
this.ssl = typeof config.ssl === 'undefined' ? readSSLConfigFromEnvironment() : config.ssl
|
|
82
82
|
|
|
83
|
+
if (typeof this.ssl === 'string') {
|
|
84
|
+
if (this.ssl === 'true') {
|
|
85
|
+
this.ssl = true
|
|
86
|
+
}
|
|
87
|
+
}
|
|
83
88
|
// support passing in ssl=no-verify via connection string
|
|
84
89
|
if (this.ssl === 'no-verify') {
|
|
85
90
|
this.ssl = { rejectUnauthorized: false }
|
|
86
91
|
}
|
|
92
|
+
if (this.ssl && this.ssl.key) {
|
|
93
|
+
Object.defineProperty(this.ssl, 'key', {
|
|
94
|
+
enumerable: false,
|
|
95
|
+
})
|
|
96
|
+
}
|
|
87
97
|
|
|
88
98
|
this.client_encoding = val('client_encoding', config)
|
|
89
99
|
this.replication = val('replication', config)
|
package/lib/connection.js
CHANGED
|
@@ -76,12 +76,18 @@ class Connection extends EventEmitter {
|
|
|
76
76
|
return self.emit('error', new Error('There was an error establishing an SSL connection'))
|
|
77
77
|
}
|
|
78
78
|
var tls = require('tls')
|
|
79
|
-
const options =
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
79
|
+
const options = {
|
|
80
|
+
socket: self.stream,
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (self.ssl !== true) {
|
|
84
|
+
Object.assign(options, self.ssl)
|
|
85
|
+
|
|
86
|
+
if ('key' in self.ssl) {
|
|
87
|
+
options.key = self.ssl.key
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
85
91
|
if (net.isIP(host) === 0) {
|
|
86
92
|
options.servername = host
|
|
87
93
|
}
|
package/lib/index.js
CHANGED
|
@@ -40,9 +40,6 @@ if (typeof process.env.NODE_PG_FORCE_NATIVE !== 'undefined') {
|
|
|
40
40
|
if (err.code !== 'MODULE_NOT_FOUND') {
|
|
41
41
|
throw err
|
|
42
42
|
}
|
|
43
|
-
/* eslint-disable no-console */
|
|
44
|
-
console.error(err.message)
|
|
45
|
-
/* eslint-enable no-console */
|
|
46
43
|
}
|
|
47
44
|
|
|
48
45
|
// overwrite module.exports.native so that getter is never called again
|
package/lib/query.js
CHANGED
|
@@ -96,39 +96,28 @@ class Query extends EventEmitter {
|
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
handleCommandComplete(msg,
|
|
99
|
+
handleCommandComplete(msg, connection) {
|
|
100
100
|
this._checkForMultirow()
|
|
101
101
|
this._result.addCommandComplete(msg)
|
|
102
102
|
// need to sync after each command complete of a prepared statement
|
|
103
|
-
if
|
|
104
|
-
|
|
103
|
+
// if we were using a row count which results in multiple calls to _getRows
|
|
104
|
+
if (this.rows) {
|
|
105
|
+
connection.sync()
|
|
105
106
|
}
|
|
106
107
|
}
|
|
107
108
|
|
|
108
109
|
// if a named prepared statement is created with empty query text
|
|
109
110
|
// the backend will send an emptyQuery message but *not* a command complete message
|
|
110
|
-
//
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
handleReadyForQuery(con) {
|
|
118
|
-
if (this._canceledDueToError) {
|
|
119
|
-
return this.handleError(this._canceledDueToError, con)
|
|
120
|
-
}
|
|
121
|
-
if (this.callback) {
|
|
122
|
-
this.callback(null, this._results)
|
|
111
|
+
// since we pipeline sync immediately after execute we don't need to do anything here
|
|
112
|
+
// unless we have rows specified, in which case we did not pipeline the intial sync call
|
|
113
|
+
handleEmptyQuery(connection) {
|
|
114
|
+
if (this.rows) {
|
|
115
|
+
connection.sync()
|
|
123
116
|
}
|
|
124
|
-
this.emit('end', this._results)
|
|
125
117
|
}
|
|
126
118
|
|
|
127
119
|
handleError(err, connection) {
|
|
128
120
|
// need to sync after error during a prepared statement
|
|
129
|
-
if (this.isPreparedStatement) {
|
|
130
|
-
connection.sync()
|
|
131
|
-
}
|
|
132
121
|
if (this._canceledDueToError) {
|
|
133
122
|
err = this._canceledDueToError
|
|
134
123
|
this._canceledDueToError = false
|
|
@@ -141,6 +130,16 @@ class Query extends EventEmitter {
|
|
|
141
130
|
this.emit('error', err)
|
|
142
131
|
}
|
|
143
132
|
|
|
133
|
+
handleReadyForQuery(con) {
|
|
134
|
+
if (this._canceledDueToError) {
|
|
135
|
+
return this.handleError(this._canceledDueToError, con)
|
|
136
|
+
}
|
|
137
|
+
if (this.callback) {
|
|
138
|
+
this.callback(null, this._results)
|
|
139
|
+
}
|
|
140
|
+
this.emit('end', this._results)
|
|
141
|
+
}
|
|
142
|
+
|
|
144
143
|
submit(connection) {
|
|
145
144
|
if (typeof this.text !== 'string' && typeof this.name !== 'string') {
|
|
146
145
|
return new Error('A query must have either text or a name. Supplying neither is unsupported.')
|
|
@@ -173,7 +172,14 @@ class Query extends EventEmitter {
|
|
|
173
172
|
portal: this.portal,
|
|
174
173
|
rows: rows,
|
|
175
174
|
})
|
|
176
|
-
|
|
175
|
+
// if we're not reading pages of rows send the sync command
|
|
176
|
+
// to indicate the pipeline is finished
|
|
177
|
+
if (!rows) {
|
|
178
|
+
connection.sync()
|
|
179
|
+
} else {
|
|
180
|
+
// otherwise flush the call out to read more rows
|
|
181
|
+
connection.flush()
|
|
182
|
+
}
|
|
177
183
|
}
|
|
178
184
|
|
|
179
185
|
// http://developer.postgresql.org/pgdocs/postgres/protocol-flow.html#PROTOCOL-FLOW-EXT-QUERY
|
|
@@ -191,22 +197,22 @@ class Query extends EventEmitter {
|
|
|
191
197
|
})
|
|
192
198
|
}
|
|
193
199
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
200
|
+
// because we're mapping user supplied values to
|
|
201
|
+
// postgres wire protocol compatible values it could
|
|
202
|
+
// throw an exception, so try/catch this section
|
|
203
|
+
try {
|
|
204
|
+
connection.bind({
|
|
205
|
+
portal: this.portal,
|
|
206
|
+
statement: this.name,
|
|
207
|
+
values: this.values,
|
|
208
|
+
binary: this.binary,
|
|
209
|
+
valueMapper: utils.prepareValue,
|
|
210
|
+
})
|
|
211
|
+
} catch (err) {
|
|
212
|
+
this.handleError(err, connection)
|
|
213
|
+
return
|
|
201
214
|
}
|
|
202
215
|
|
|
203
|
-
connection.bind({
|
|
204
|
-
portal: this.portal,
|
|
205
|
-
statement: this.name,
|
|
206
|
-
values: this.values,
|
|
207
|
-
binary: this.binary,
|
|
208
|
-
})
|
|
209
|
-
|
|
210
216
|
connection.describe({
|
|
211
217
|
type: 'P',
|
|
212
218
|
name: this.portal || '',
|
package/lib/utils.js
CHANGED
|
@@ -38,6 +38,10 @@ function arrayString(val) {
|
|
|
38
38
|
// note: you can override this function to provide your own conversion mechanism
|
|
39
39
|
// for complex types, etc...
|
|
40
40
|
var prepareValue = function (val, seen) {
|
|
41
|
+
// null and undefined are both null for postgres
|
|
42
|
+
if (val == null) {
|
|
43
|
+
return null
|
|
44
|
+
}
|
|
41
45
|
if (val instanceof Buffer) {
|
|
42
46
|
return val
|
|
43
47
|
}
|
|
@@ -58,9 +62,6 @@ var prepareValue = function (val, seen) {
|
|
|
58
62
|
if (Array.isArray(val)) {
|
|
59
63
|
return arrayString(val)
|
|
60
64
|
}
|
|
61
|
-
if (val === null || typeof val === 'undefined') {
|
|
62
|
-
return null
|
|
63
|
-
}
|
|
64
65
|
if (typeof val === 'object') {
|
|
65
66
|
return prepareObject(val, seen)
|
|
66
67
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pg",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.5.1",
|
|
4
4
|
"description": "PostgreSQL client - pure javascript & libpq with the same API",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"database",
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
"buffer-writer": "2.0.0",
|
|
23
23
|
"packet-reader": "1.0.0",
|
|
24
24
|
"pg-connection-string": "^2.4.0",
|
|
25
|
-
"pg-pool": "^3.2.
|
|
26
|
-
"pg-protocol": "^1.
|
|
25
|
+
"pg-pool": "^3.2.2",
|
|
26
|
+
"pg-protocol": "^1.4.0",
|
|
27
27
|
"pg-types": "^2.1.0",
|
|
28
28
|
"pgpass": "1.x"
|
|
29
29
|
},
|
|
@@ -52,5 +52,5 @@
|
|
|
52
52
|
"engines": {
|
|
53
53
|
"node": ">= 8.0.0"
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "0b9bb349dcb10f6473737001062082b65efc74be"
|
|
56
56
|
}
|