Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/pg-cursor/test/close.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ describe('close', function () {
it('can close a finished cursor without a callback', function (done) {
const cursor = new Cursor(text)
this.client.query(cursor)
this.client.query('SELECT NOW()', done)
cursor.read(100, function (err) {
assert.ifError(err)
cursor.close()
})
this.client.once('drain', done)
})

it('can close a finished cursor a promise', function (done) {
Expand All @@ -37,11 +37,11 @@ describe('close', function () {
it('closes cursor early', function (done) {
const cursor = new Cursor(text)
this.client.query(cursor)
this.client.query('SELECT NOW()', done)
cursor.read(25, function (err) {
assert.ifError(err)
cursor.close()
})
this.client.once('drain', done)
})

it('works with callback style', function (done) {
Expand Down
18 changes: 12 additions & 6 deletions packages/pg/lib/client.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict'

const EventEmitter = require('events').EventEmitter
const utils = require('./utils')
const nodeUtils = require('util')
Expand All @@ -14,23 +12,28 @@ const crypto = require('./crypto/utils')

const activeQueryDeprecationNotice = nodeUtils.deprecate(
() => {},
'Client.activeQuery is deprecated and will be removed in a future version.'
'Client.activeQuery is deprecated and will be removed in pg@9.0'
)

const queryQueueDeprecationNotice = nodeUtils.deprecate(
() => {},
'Client.queryQueue is deprecated and will be removed in a future version.'
'Client.queryQueue is deprecated and will be removed in pg@9.0.'
)

const pgPassDeprecationNotice = nodeUtils.deprecate(
() => {},
'pgpass support is deprecated and will be removed in a future version. ' +
'pgpass support is deprecated and will be removed in pg@9.0. ' +
'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.'
)

const byoPromiseDeprecationNotice = nodeUtils.deprecate(
() => {},
'Passing a custom Promise implementation to the Client/Pool constructor is deprecated and will be removed in a future version.'
'Passing a custom Promise implementation to the Client/Pool constructor is deprecated and will be removed in pg@9.0.'
)

const queryQueueLengthDeprecationNotice = nodeUtils.deprecate(
() => {},
'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.'
)

class Client extends EventEmitter {
Expand Down Expand Up @@ -680,6 +683,9 @@ class Client extends EventEmitter {
return result
}

if (this._queryQueue.length > 0) {
queryQueueLengthDeprecationNotice()
}
this._queryQueue.push(query)
this._pulseQueryQueue()
return result
Expand Down
12 changes: 10 additions & 2 deletions packages/pg/lib/native/client.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
'use strict'

const nodeUtils = require('util')
// eslint-disable-next-line
var Native
// eslint-disable-next-line no-useless-catch
Expand All @@ -16,6 +15,11 @@ const ConnectionParameters = require('../connection-parameters')

const NativeQuery = require('./query')

const queryQueueLengthDeprecationNotice = nodeUtils.deprecate(
() => {},
'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.'
)

const Client = (module.exports = function (config) {
EventEmitter.call(this)
config = config || {}
Expand Down Expand Up @@ -230,6 +234,10 @@ Client.prototype.query = function (config, values, callback) {
return result
}

if (this._queryQueue.length > 0) {
queryQueueLengthDeprecationNotice()
}

this._queryQueue.push(query)
this._pulseQueryQueue()
return result
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
'use strict'
const util = require('util')
const helper = require('./test-helper')
const assert = require('assert')
const suite = new helper.Suite()
Expand All @@ -11,7 +10,7 @@ const conInfo = helper.config
suite.test('returns results as array', function () {
const client = new Client(conInfo)
const checkRow = function (row) {
assert(util.isArray(row), 'row should be an array')
assert(Array.isArray(row), 'row should be an array')
assert.equal(row.length, 4)
assert.equal(row[0].getFullYear(), new Date().getFullYear())
assert.strictEqual(row[1], 1)
Expand Down