mirror of
https://github.com/brianc/node-postgres.git
synced 2025-12-08 20:16:25 +00:00
Merge pull request #2271 from aravindanve/master
Fix: use types configured on pg client in pg-query-stream
This commit is contained in:
commit
3c176bdf86
@ -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) {
|
||||
|
||||
27
packages/pg-query-stream/test/client-options.js
Normal file
27
packages/pg-query-stream/test/client-options.js
Normal 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()
|
||||
})
|
||||
})
|
||||
})
|
||||
Loading…
x
Reference in New Issue
Block a user