Result.fields should always be an array (#2060)

This fixes a subtle backwards incompatible change.  Added a test to prevent further regressions.  Closes #2056
This commit is contained in:
Brian C 2020-01-09 21:30:53 -06:00 committed by GitHub
parent 8eca181d20
commit 19308f9ceb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 1 deletions

View File

@ -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

View File

@ -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)
})
})