pg 8.17.2 → 8.19.0
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 +64 -18
- package/lib/native/client.js +20 -5
- package/package.json +5 -5
package/lib/client.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
1
|
const EventEmitter = require('events').EventEmitter
|
|
4
2
|
const utils = require('./utils')
|
|
5
3
|
const nodeUtils = require('util')
|
|
@@ -14,23 +12,28 @@ const crypto = require('./crypto/utils')
|
|
|
14
12
|
|
|
15
13
|
const activeQueryDeprecationNotice = nodeUtils.deprecate(
|
|
16
14
|
() => {},
|
|
17
|
-
'Client.activeQuery is deprecated and will be removed in
|
|
15
|
+
'Client.activeQuery is deprecated and will be removed in pg@9.0'
|
|
18
16
|
)
|
|
19
17
|
|
|
20
18
|
const queryQueueDeprecationNotice = nodeUtils.deprecate(
|
|
21
19
|
() => {},
|
|
22
|
-
'Client.queryQueue is deprecated and will be removed in
|
|
20
|
+
'Client.queryQueue is deprecated and will be removed in pg@9.0.'
|
|
23
21
|
)
|
|
24
22
|
|
|
25
23
|
const pgPassDeprecationNotice = nodeUtils.deprecate(
|
|
26
24
|
() => {},
|
|
27
|
-
'pgpass support is deprecated and will be removed in
|
|
28
|
-
'You can provide an async function as the password property to the Client/Pool constructor that returns a password instead. Within this
|
|
25
|
+
'pgpass support is deprecated and will be removed in pg@9.0. ' +
|
|
26
|
+
'You can provide an async function as the password property to the Client/Pool constructor that returns a password instead. Within this function you can call the pgpass module in your own code.'
|
|
29
27
|
)
|
|
30
28
|
|
|
31
29
|
const byoPromiseDeprecationNotice = nodeUtils.deprecate(
|
|
32
30
|
() => {},
|
|
33
|
-
'Passing a custom Promise implementation to the Client/Pool constructor is deprecated and will be removed in
|
|
31
|
+
'Passing a custom Promise implementation to the Client/Pool constructor is deprecated and will be removed in pg@9.0.'
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
const queryQueueLengthDeprecationNotice = nodeUtils.deprecate(
|
|
35
|
+
() => {},
|
|
36
|
+
'Calling client.query() when the client is already executing a query is deprecated and will be removed in pg@9.0. Use asycn/await or an external async flow control mechanism instead.'
|
|
34
37
|
)
|
|
35
38
|
|
|
36
39
|
class Client extends EventEmitter {
|
|
@@ -213,7 +216,7 @@ class Client extends EventEmitter {
|
|
|
213
216
|
if (error) {
|
|
214
217
|
reject(error)
|
|
215
218
|
} else {
|
|
216
|
-
resolve()
|
|
219
|
+
resolve(this)
|
|
217
220
|
}
|
|
218
221
|
})
|
|
219
222
|
})
|
|
@@ -249,7 +252,7 @@ class Client extends EventEmitter {
|
|
|
249
252
|
if (typeof this.password === 'function') {
|
|
250
253
|
this._Promise
|
|
251
254
|
.resolve()
|
|
252
|
-
.then(() => this.password())
|
|
255
|
+
.then(() => this.password(this.connectionParameters))
|
|
253
256
|
.then((pass) => {
|
|
254
257
|
if (pass !== undefined) {
|
|
255
258
|
if (typeof pass !== 'string') {
|
|
@@ -407,23 +410,47 @@ class Client extends EventEmitter {
|
|
|
407
410
|
}
|
|
408
411
|
|
|
409
412
|
_handleRowDescription(msg) {
|
|
413
|
+
const activeQuery = this._getActiveQuery()
|
|
414
|
+
if (activeQuery == null) {
|
|
415
|
+
const error = new Error('Received unexpected rowDescription message from backend.')
|
|
416
|
+
this._handleErrorEvent(error)
|
|
417
|
+
return
|
|
418
|
+
}
|
|
410
419
|
// delegate rowDescription to active query
|
|
411
|
-
|
|
420
|
+
activeQuery.handleRowDescription(msg)
|
|
412
421
|
}
|
|
413
422
|
|
|
414
423
|
_handleDataRow(msg) {
|
|
424
|
+
const activeQuery = this._getActiveQuery()
|
|
425
|
+
if (activeQuery == null) {
|
|
426
|
+
const error = new Error('Received unexpected dataRow message from backend.')
|
|
427
|
+
this._handleErrorEvent(error)
|
|
428
|
+
return
|
|
429
|
+
}
|
|
415
430
|
// delegate dataRow to active query
|
|
416
|
-
|
|
431
|
+
activeQuery.handleDataRow(msg)
|
|
417
432
|
}
|
|
418
433
|
|
|
419
434
|
_handlePortalSuspended(msg) {
|
|
435
|
+
const activeQuery = this._getActiveQuery()
|
|
436
|
+
if (activeQuery == null) {
|
|
437
|
+
const error = new Error('Received unexpected portalSuspended message from backend.')
|
|
438
|
+
this._handleErrorEvent(error)
|
|
439
|
+
return
|
|
440
|
+
}
|
|
420
441
|
// delegate portalSuspended to active query
|
|
421
|
-
|
|
442
|
+
activeQuery.handlePortalSuspended(this.connection)
|
|
422
443
|
}
|
|
423
444
|
|
|
424
445
|
_handleEmptyQuery(msg) {
|
|
446
|
+
const activeQuery = this._getActiveQuery()
|
|
447
|
+
if (activeQuery == null) {
|
|
448
|
+
const error = new Error('Received unexpected emptyQuery message from backend.')
|
|
449
|
+
this._handleErrorEvent(error)
|
|
450
|
+
return
|
|
451
|
+
}
|
|
425
452
|
// delegate emptyQuery to active query
|
|
426
|
-
|
|
453
|
+
activeQuery.handleEmptyQuery(this.connection)
|
|
427
454
|
}
|
|
428
455
|
|
|
429
456
|
_handleCommandComplete(msg) {
|
|
@@ -453,11 +480,23 @@ class Client extends EventEmitter {
|
|
|
453
480
|
}
|
|
454
481
|
|
|
455
482
|
_handleCopyInResponse(msg) {
|
|
456
|
-
this._getActiveQuery()
|
|
483
|
+
const activeQuery = this._getActiveQuery()
|
|
484
|
+
if (activeQuery == null) {
|
|
485
|
+
const error = new Error('Received unexpected copyInResponse message from backend.')
|
|
486
|
+
this._handleErrorEvent(error)
|
|
487
|
+
return
|
|
488
|
+
}
|
|
489
|
+
activeQuery.handleCopyInResponse(this.connection)
|
|
457
490
|
}
|
|
458
491
|
|
|
459
492
|
_handleCopyData(msg) {
|
|
460
|
-
this._getActiveQuery()
|
|
493
|
+
const activeQuery = this._getActiveQuery()
|
|
494
|
+
if (activeQuery == null) {
|
|
495
|
+
const error = new Error('Received unexpected copyData message from backend.')
|
|
496
|
+
this._handleErrorEvent(error)
|
|
497
|
+
return
|
|
498
|
+
}
|
|
499
|
+
activeQuery.handleCopyData(msg, this.connection)
|
|
461
500
|
}
|
|
462
501
|
|
|
463
502
|
_handleNotification(msg) {
|
|
@@ -573,8 +612,12 @@ class Client extends EventEmitter {
|
|
|
573
612
|
} else if (typeof config.submit === 'function') {
|
|
574
613
|
readTimeout = config.query_timeout || this.connectionParameters.query_timeout
|
|
575
614
|
result = query = config
|
|
576
|
-
if (
|
|
577
|
-
|
|
615
|
+
if (!query.callback) {
|
|
616
|
+
if (typeof values === 'function') {
|
|
617
|
+
query.callback = values
|
|
618
|
+
} else if (callback) {
|
|
619
|
+
query.callback = callback
|
|
620
|
+
}
|
|
578
621
|
}
|
|
579
622
|
} else {
|
|
580
623
|
readTimeout = config.query_timeout || this.connectionParameters.query_timeout
|
|
@@ -592,7 +635,7 @@ class Client extends EventEmitter {
|
|
|
592
635
|
}
|
|
593
636
|
|
|
594
637
|
if (readTimeout) {
|
|
595
|
-
queryCallback = query.callback
|
|
638
|
+
queryCallback = query.callback || (() => {})
|
|
596
639
|
|
|
597
640
|
readTimeoutTimer = setTimeout(() => {
|
|
598
641
|
const error = new Error('Query read timeout')
|
|
@@ -644,6 +687,9 @@ class Client extends EventEmitter {
|
|
|
644
687
|
return result
|
|
645
688
|
}
|
|
646
689
|
|
|
690
|
+
if (this._queryQueue.length > 0) {
|
|
691
|
+
queryQueueLengthDeprecationNotice()
|
|
692
|
+
}
|
|
647
693
|
this._queryQueue.push(query)
|
|
648
694
|
this._pulseQueryQueue()
|
|
649
695
|
return result
|
package/lib/native/client.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
const nodeUtils = require('util')
|
|
3
2
|
// eslint-disable-next-line
|
|
4
3
|
var Native
|
|
5
4
|
// eslint-disable-next-line no-useless-catch
|
|
@@ -16,6 +15,11 @@ const ConnectionParameters = require('../connection-parameters')
|
|
|
16
15
|
|
|
17
16
|
const NativeQuery = require('./query')
|
|
18
17
|
|
|
18
|
+
const queryQueueLengthDeprecationNotice = nodeUtils.deprecate(
|
|
19
|
+
() => {},
|
|
20
|
+
'Calling client.query() when the client is already executing a query is deprecated and will be removed in pg@9.0. Use asycn/await or an external async flow control mechanism instead.'
|
|
21
|
+
)
|
|
22
|
+
|
|
19
23
|
const Client = (module.exports = function (config) {
|
|
20
24
|
EventEmitter.call(this)
|
|
21
25
|
config = config || {}
|
|
@@ -119,7 +123,7 @@ Client.prototype._connect = function (cb) {
|
|
|
119
123
|
self.emit('connect')
|
|
120
124
|
self._pulseQueryQueue(true)
|
|
121
125
|
|
|
122
|
-
cb()
|
|
126
|
+
cb(null, this)
|
|
123
127
|
})
|
|
124
128
|
})
|
|
125
129
|
}
|
|
@@ -135,7 +139,7 @@ Client.prototype.connect = function (callback) {
|
|
|
135
139
|
if (error) {
|
|
136
140
|
reject(error)
|
|
137
141
|
} else {
|
|
138
|
-
resolve()
|
|
142
|
+
resolve(this)
|
|
139
143
|
}
|
|
140
144
|
})
|
|
141
145
|
})
|
|
@@ -184,7 +188,7 @@ Client.prototype.query = function (config, values, callback) {
|
|
|
184
188
|
}
|
|
185
189
|
|
|
186
190
|
if (readTimeout) {
|
|
187
|
-
queryCallback = query.callback
|
|
191
|
+
queryCallback = query.callback || (() => {})
|
|
188
192
|
|
|
189
193
|
readTimeoutTimer = setTimeout(() => {
|
|
190
194
|
const error = new Error('Query read timeout')
|
|
@@ -230,6 +234,10 @@ Client.prototype.query = function (config, values, callback) {
|
|
|
230
234
|
return result
|
|
231
235
|
}
|
|
232
236
|
|
|
237
|
+
if (this._queryQueue.length > 0) {
|
|
238
|
+
queryQueueLengthDeprecationNotice()
|
|
239
|
+
}
|
|
240
|
+
|
|
233
241
|
this._queryQueue.push(query)
|
|
234
242
|
this._pulseQueryQueue()
|
|
235
243
|
return result
|
|
@@ -250,7 +258,10 @@ Client.prototype.end = function (cb) {
|
|
|
250
258
|
cb = (err) => (err ? reject(err) : resolve())
|
|
251
259
|
})
|
|
252
260
|
}
|
|
261
|
+
|
|
253
262
|
this.native.end(function () {
|
|
263
|
+
self._connected = false
|
|
264
|
+
|
|
254
265
|
self._errorAllQueries(new Error('Connection terminated'))
|
|
255
266
|
|
|
256
267
|
process.nextTick(() => {
|
|
@@ -306,3 +317,7 @@ Client.prototype.setTypeParser = function (oid, format, parseFn) {
|
|
|
306
317
|
Client.prototype.getTypeParser = function (oid, format) {
|
|
307
318
|
return this._types.getTypeParser(oid, format)
|
|
308
319
|
}
|
|
320
|
+
|
|
321
|
+
Client.prototype.isConnected = function () {
|
|
322
|
+
return this._connected
|
|
323
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pg",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.19.0",
|
|
4
4
|
"description": "PostgreSQL client - pure javascript & libpq with the same API",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"database",
|
|
@@ -32,9 +32,9 @@
|
|
|
32
32
|
"./lib/*.js": "./lib/*.js"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"pg-connection-string": "^2.
|
|
36
|
-
"pg-pool": "^3.
|
|
37
|
-
"pg-protocol": "^1.
|
|
35
|
+
"pg-connection-string": "^2.11.0",
|
|
36
|
+
"pg-pool": "^3.12.0",
|
|
37
|
+
"pg-protocol": "^1.12.0",
|
|
38
38
|
"pg-types": "2.2.0",
|
|
39
39
|
"pgpass": "1.0.5"
|
|
40
40
|
},
|
|
@@ -72,5 +72,5 @@
|
|
|
72
72
|
"engines": {
|
|
73
73
|
"node": ">= 16.0.0"
|
|
74
74
|
},
|
|
75
|
-
"gitHead": "
|
|
75
|
+
"gitHead": "f2d7d1146cc87024a5fa503dce13c59ff5196d26"
|
|
76
76
|
}
|