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
3 changes: 3 additions & 0 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,9 @@ Client.prototype.query = function (config, values, callback) {
}

this.queryQueue.push(query)
process.nextTick(() => {
this.emit('query', query)
})
this._pulseQueryQueue()
return result
}
Expand Down
3 changes: 3 additions & 0 deletions lib/native/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@ Client.prototype.query = function (config, values, callback) {
}

this._queryQueue.push(query)
process.nextTick(() => {
this.emit('query', query)
})
this._pulseQueryQueue()
return result
}
Expand Down
36 changes: 36 additions & 0 deletions test/integration/client/api-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,3 +247,39 @@ suite.test('null and undefined are both inserted as NULL', function (done) {
})
)
})

suite.test('"query" event fired on query called', function (done) {
const pool = new pg.Pool()
pool.connect(
assert.calls(function (err, client, release) {
assert(!err)
const queryText = 'SELECT 1'
client.query(queryText, () => {
pool.end(done)
release()
})
assert.emits(client, 'query', function (query) {
assert(query instanceof pg.Query)
assert.equal(query.text, queryText)
})
})
)
})

suite.test('Check that client query event fired before query events', function (done) {
const pool = new pg.Pool()
pool.connect(
assert.calls(function (err, client, release) {
assert(!err)
const queryText = 'SELECT 1'
client.query(queryText, () => {
pool.end(done)
release()
})
client.once('query', query => {
assert.emits(query, 'row')
assert.emits(query, 'end')
})
})
)
})