Merge pull request #2271 from aravindanve/master

Fix: use types configured on pg client in pg-query-stream
This commit is contained in:
Brian C 2020-07-15 13:01:39 -05:00 committed by GitHub
commit 3c176bdf86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 0 deletions

View File

@ -16,6 +16,9 @@ class PgQueryStream extends Readable {
this.handleReadyForQuery = this.cursor.handleReadyForQuery.bind(this.cursor)
this.handleError = this.cursor.handleError.bind(this.cursor)
this.handleEmptyQuery = this.cursor.handleEmptyQuery.bind(this.cursor)
// pg client sets types via _result property
this._result = this.cursor._result
}
submit(connection) {

View File

@ -0,0 +1,27 @@
var pg = require('pg')
var assert = require('assert')
var QueryStream = require('../')
describe('client options', function () {
it('uses custom types from client config', function (done) {
const types = {
getTypeParser: () => (string) => string,
}
var client = new pg.Client({ types })
client.connect()
var stream = new QueryStream('SELECT * FROM generate_series(0, 10) num')
var query = client.query(stream)
var result = []
query.on('data', (datum) => {
result.push(datum)
})
query.on('end', () => {
const expected = new Array(11).fill(0).map((_, i) => ({
num: i.toString(),
}))
assert.deepEqual(result, expected)
client.end()
done()
})
})
})