Skip to content

Commit

Permalink
Result.fields should always be an array (#2060)
Browse files Browse the repository at this point in the history
This fixes a subtle backwards incompatible change.  Added a test to prevent further regressions.  Closes #2056
  • Loading branch information
brianc authored Jan 10, 2020
1 parent 8eca181 commit 19308f9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/pg/lib/result.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var Result = function (rowMode, types) {
this.rowCount = null
this.oid = null
this.rows = []
this.fields = undefined
this.fields = []
this._parsers = undefined
this._types = types
this.RowCtor = null
Expand Down
22 changes: 22 additions & 0 deletions packages/pg/test/integration/gh-issues/2056-tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

"use strict"
var helper = require('./../test-helper')
var assert = require('assert')

const suite = new helper.Suite()

suite.test('All queries should return a result array', (done) => {
const client = new helper.pg.Client()
client.connect()
const promises = []
promises.push(client.query('CREATE TEMP TABLE foo(bar TEXT)'))
promises.push(client.query('INSERT INTO foo(bar) VALUES($1)', ['qux']))
promises.push(client.query('SELECT * FROM foo WHERE bar = $1', ['foo']))
Promise.all(promises).then(results => {
results.forEach(res => {
assert(Array.isArray(res.fields))
assert(Array.isArray(res.rows))
})
client.end(done)
})
})

0 comments on commit 19308f9

Please sign in to comment.