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
7 changes: 5 additions & 2 deletions packages/pg-native/lib/build-result.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ class Result {
}

consumeCommand(pq) {
this.command = pq.cmdStatus().split(' ')[0]
this.rowCount = parseInt(pq.cmdTuples(), 10)
// null when there is none, as pg reports it: BEGIN has no row count, an empty query no command
const status = pq.cmdStatus()
this.command = status ? status.split(' ')[0] : null
const tuples = pq.cmdTuples()
this.rowCount = tuples ? parseInt(tuples, 10) : null
}

consumeFields(pq) {
Expand Down
18 changes: 18 additions & 0 deletions packages/pg-native/test/empty-query.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,22 @@ describe('empty query', () => {
client.end(done)
})
})

// what pg reports too: a command without a row count and an empty query without a command
// are null, not NaN and an empty string
it('reports no row count and no command as null', (done) => {
const client = new Client()
client.connectSync()
client.query('BEGIN', (err, rows, res) => {
assert(!err)
assert.strictEqual(res.command, 'BEGIN')
assert.strictEqual(res.rowCount, null)
client.query('', (err, rows, res) => {
assert(!err)
assert.strictEqual(res.command, null)
assert.strictEqual(res.rowCount, null)
client.end(done)
})
})
})
})
Loading