Skip to content

Commit f85f77c

Browse files
committed
Deprecate Client's internal query queue
1 parent d80d883 commit f85f77c

File tree

4 files changed

+25
-11
lines changed

4 files changed

+25
-11
lines changed

packages/pg-cursor/test/close.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ describe('close', function () {
1616
it('can close a finished cursor without a callback', function (done) {
1717
const cursor = new Cursor(text)
1818
this.client.query(cursor)
19-
this.client.query('SELECT NOW()', done)
2019
cursor.read(100, function (err) {
2120
assert.ifError(err)
2221
cursor.close()
2322
})
23+
this.client.once('drain', done)
2424
})
2525

2626
it('can close a finished cursor a promise', function (done) {
@@ -37,11 +37,11 @@ describe('close', function () {
3737
it('closes cursor early', function (done) {
3838
const cursor = new Cursor(text)
3939
this.client.query(cursor)
40-
this.client.query('SELECT NOW()', done)
4140
cursor.read(25, function (err) {
4241
assert.ifError(err)
4342
cursor.close()
4443
})
44+
this.client.once('drain', done)
4545
})
4646

4747
it('works with callback style', function (done) {

packages/pg/lib/client.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use strict'
2-
31
const EventEmitter = require('events').EventEmitter
42
const utils = require('./utils')
53
const nodeUtils = require('util')
@@ -14,23 +12,28 @@ const crypto = require('./crypto/utils')
1412

1513
const activeQueryDeprecationNotice = nodeUtils.deprecate(
1614
() => {},
17-
'Client.activeQuery is deprecated and will be removed in a future version.'
15+
'Client.activeQuery is deprecated and will be removed in pg@9.0'
1816
)
1917

2018
const queryQueueDeprecationNotice = nodeUtils.deprecate(
2119
() => {},
22-
'Client.queryQueue is deprecated and will be removed in a future version.'
20+
'Client.queryQueue is deprecated and will be removed in pg@9.0.'
2321
)
2422

2523
const pgPassDeprecationNotice = nodeUtils.deprecate(
2624
() => {},
27-
'pgpass support is deprecated and will be removed in a future version. ' +
25+
'pgpass support is deprecated and will be removed in pg@9.0. ' +
2826
'You can provide an async function as the password property to the Client/Pool constructor that returns a password instead. Within this funciton you can call the pgpass module in your own code.'
2927
)
3028

3129
const byoPromiseDeprecationNotice = nodeUtils.deprecate(
3230
() => {},
33-
'Passing a custom Promise implementation to the Client/Pool constructor is deprecated and will be removed in a future version.'
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.'
3437
)
3538

3639
class Client extends EventEmitter {
@@ -680,6 +683,9 @@ class Client extends EventEmitter {
680683
return result
681684
}
682685

686+
if (this._queryQueue.length > 0) {
687+
queryQueueLengthDeprecationNotice()
688+
}
683689
this._queryQueue.push(query)
684690
this._pulseQueryQueue()
685691
return result

packages/pg/lib/native/client.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
'use strict'
2-
1+
const nodeUtils = require('util')
32
// eslint-disable-next-line
43
var Native
54
// eslint-disable-next-line no-useless-catch
@@ -16,6 +15,11 @@ const ConnectionParameters = require('../connection-parameters')
1615

1716
const NativeQuery = require('./query')
1817

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+
1923
const Client = (module.exports = function (config) {
2024
EventEmitter.call(this)
2125
config = config || {}
@@ -230,6 +234,10 @@ Client.prototype.query = function (config, values, callback) {
230234
return result
231235
}
232236

237+
if (this._queryQueue.length > 0) {
238+
queryQueueLengthDeprecationNotice()
239+
}
240+
233241
this._queryQueue.push(query)
234242
this._pulseQueryQueue()
235243
return result

packages/pg/test/integration/client/results-as-array-tests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const conInfo = helper.config
1111
suite.test('returns results as array', function () {
1212
const client = new Client(conInfo)
1313
const checkRow = function (row) {
14-
assert(util.isArray(row), 'row should be an array')
14+
assert(Array.isArray(row), 'row should be an array')
1515
assert.equal(row.length, 4)
1616
assert.equal(row[0].getFullYear(), new Date().getFullYear())
1717
assert.strictEqual(row[1], 1)

0 commit comments

Comments
 (0)