mirror of
https://github.com/brianc/node-postgres.git
synced 2025-12-08 20:16:25 +00:00
Add ability to configure highWaterMark and batchSize
This commit is contained in:
parent
278c5ceb87
commit
33be525dbb
9
index.js
9
index.js
@ -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
10
test/config.js
Normal 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
17
test/instant.js
Normal 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()
|
||||
Loading…
x
Reference in New Issue
Block a user