Pass options to cursor (#65)

* Bump version of pg-cursor

This includes fixes in pg-cursor@2.0.1.  I've relaxed semver a touch so I don't have to release a new version here just for patch changes to pg-cursor.

* Pass options to pg-cursor

fixes #55
This commit is contained in:
Brian C 2019-10-30 14:08:11 -05:00 committed by GitHub
parent 05b4c573d2
commit 08072a90b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 1 deletions

View File

@ -5,7 +5,7 @@ var Readable = require('stream').Readable
class PgQueryStream extends Readable {
constructor (text, values, options) {
super(Object.assign({ objectMode: true }, options))
this.cursor = new Cursor(text, values)
this.cursor = new Cursor(text, values, options)
this._reading = false
this._closed = false
this.batchSize = (options || {}).batchSize || 100

38
test/passing-options.js Normal file
View File

@ -0,0 +1,38 @@
var assert = require('assert')
var helper = require('./helper')
var QueryStream = require('../')
helper('passing options', function(client) {
it('passes row mode array', function(done) {
var stream = new QueryStream('SELECT * FROM generate_series(0, 10) num', [], { rowMode: 'array' })
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) => [i])
assert.deepEqual(result, expected)
done()
})
})
it('passes custom types', function(done) {
const types = {
getTypeParser: () => string => string,
}
var stream = new QueryStream('SELECT * FROM generate_series(0, 10) num', [], { types })
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)
done()
})
})
})