Skip to content

Commit 3c176bd

Browse files
authored
Merge pull request brianc#2271 from aravindanve/master
Fix: use types configured on pg client in pg-query-stream
2 parents d7b22b3 + 5404823 commit 3c176bd

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

packages/pg-query-stream/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ class PgQueryStream extends Readable {
1616
this.handleReadyForQuery = this.cursor.handleReadyForQuery.bind(this.cursor)
1717
this.handleError = this.cursor.handleError.bind(this.cursor)
1818
this.handleEmptyQuery = this.cursor.handleEmptyQuery.bind(this.cursor)
19+
20+
// pg client sets types via _result property
21+
this._result = this.cursor._result
1922
}
2023

2124
submit(connection) {
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
var pg = require('pg')
2+
var assert = require('assert')
3+
var QueryStream = require('../')
4+
5+
describe('client options', function () {
6+
it('uses custom types from client config', function (done) {
7+
const types = {
8+
getTypeParser: () => (string) => string,
9+
}
10+
var client = new pg.Client({ types })
11+
client.connect()
12+
var stream = new QueryStream('SELECT * FROM generate_series(0, 10) num')
13+
var query = client.query(stream)
14+
var result = []
15+
query.on('data', (datum) => {
16+
result.push(datum)
17+
})
18+
query.on('end', () => {
19+
const expected = new Array(11).fill(0).map((_, i) => ({
20+
num: i.toString(),
21+
}))
22+
assert.deepEqual(result, expected)
23+
client.end()
24+
done()
25+
})
26+
})
27+
})

0 commit comments

Comments
 (0)