From 08072a90b8620d8dc70881e96afcb61f661e0735 Mon Sep 17 00:00:00 2001 From: Brian C Date: Wed, 30 Oct 2019 14:08:11 -0500 Subject: [PATCH] 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 --- index.js | 2 +- test/passing-options.js | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 test/passing-options.js diff --git a/index.js b/index.js index ddfc66f1..9c34207e 100644 --- a/index.js +++ b/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 diff --git a/test/passing-options.js b/test/passing-options.js new file mode 100644 index 00000000..e2ddd185 --- /dev/null +++ b/test/passing-options.js @@ -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() + }) + }) +})