Add ability to configure highWaterMark and batchSize

This commit is contained in:
Brian M. Carlson 2013-10-23 17:11:43 -05:00
parent 278c5ceb87
commit 33be525dbb
3 changed files with 30 additions and 6 deletions

View File

@ -17,20 +17,17 @@ var Result = require(path.join(pgdir, 'result'))
var utils = require(path.join(pgdir, 'utils'))
var QueryStream = module.exports = function(text, values, options) {
options = options || {
highWaterMark: 100,
batchSize: 100
}
options = options || { }
Readable.call(this, {
objectMode: true,
highWaterMark: 100
highWaterMark: options.highWaterMark || 1000
})
this.text = text
assert(this.text, 'text cannot be falsy')
this.values = (values || []).map(utils.prepareValue)
this.name = ''
this._result = new Result()
this.batchSize = 100
this.batchSize = options.batchSize || 100
this._idle = true
}

10
test/config.js Normal file
View File

@ -0,0 +1,10 @@
var assert = require('assert')
var QueryStream = require('../')
var stream = new QueryStream('SELECT NOW()', [], {
highWaterMark: 999,
batchSize: 88
})
assert.equal(stream._readableState.highWaterMark, 999)
assert.equal(stream.batchSize, 88)

17
test/instant.js Normal file
View File

@ -0,0 +1,17 @@
var pg = require('pg')
var assert = require('assert')
var gonna = require('gonna')
var concat = require('concat-stream')
var QueryStream = require('../')
var client = new pg.Client()
var query = new QueryStream('SELECT pg_sleep(1)', [])
var stream = client.query(query)
var done = gonna('read results', 5000)
stream.pipe(concat(function(res) {
assert.equal(res.length, 1)
done()
client.end()
}))
client.connect()