mirror of
https://github.com/brianc/node-postgres.git
synced 2026-01-18 15:55:05 +00:00
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:
parent
05b4c573d2
commit
08072a90b8
2
index.js
2
index.js
@ -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
38
test/passing-options.js
Normal 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()
|
||||
})
|
||||
})
|
||||
})
|
||||
Loading…
x
Reference in New Issue
Block a user