mirror of
https://github.com/brianc/node-postgres.git
synced 2025-12-08 20:16:25 +00:00
clean ups
This commit is contained in:
parent
41b7d7d4de
commit
fec090972b
21
index.js
21
index.js
@ -1,8 +1,9 @@
|
||||
var util = require('util')
|
||||
var Cursor = require('pg-cursor')
|
||||
var Readable = require('stream').Readable
|
||||
var Readable = require('readable-stream').Readable
|
||||
|
||||
var QueryStream = module.exports = function(text, values, options) {
|
||||
var self = this;
|
||||
options = options || { }
|
||||
Cursor.call(this, text, values)
|
||||
Readable.call(this, {
|
||||
@ -10,22 +11,23 @@ var QueryStream = module.exports = function(text, values, options) {
|
||||
highWaterMark: options.highWaterMark || 1000
|
||||
})
|
||||
this.batchSize = options.batchSize || 100
|
||||
this._ready = false
|
||||
this.once('end', function() {
|
||||
setImmediate(function() { this.emit('close') }.bind(this));
|
||||
})
|
||||
//kick reader
|
||||
this.read()
|
||||
process.nextTick(function() {
|
||||
self.emit('close')
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
util.inherits(QueryStream, Readable)
|
||||
for(var key in Cursor.prototype) {
|
||||
if(key != 'read') {
|
||||
if(key == 'read') {
|
||||
QueryStream.prototype._fetch = Cursor.prototype.read
|
||||
} else {
|
||||
QueryStream.prototype[key] = Cursor.prototype[key]
|
||||
}
|
||||
}
|
||||
|
||||
QueryStream.prototype._fetch = Cursor.prototype.read
|
||||
|
||||
|
||||
QueryStream.prototype._read = function(n) {
|
||||
if(this._reading) return false;
|
||||
@ -36,9 +38,10 @@ QueryStream.prototype._read = function(n) {
|
||||
return self.emit('error', err)
|
||||
}
|
||||
if(!rows.length) {
|
||||
setImmediate(function() {
|
||||
process.nextTick(function() {
|
||||
self.push(null)
|
||||
})
|
||||
return;
|
||||
}
|
||||
self._reading = false
|
||||
for(var i = 0; i < rows.length; i++) {
|
||||
|
||||
@ -23,7 +23,6 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"pg.js": "~2.8.0",
|
||||
"lodash": "~2.2.1",
|
||||
"concat-stream": "~1.0.1",
|
||||
"through": "~2.3.4",
|
||||
"stream-tester": "0.0.5",
|
||||
@ -33,6 +32,7 @@
|
||||
"mocha": "~1.17.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"pg-cursor": "0.1.3"
|
||||
"pg-cursor": "0.1.3",
|
||||
"readable-stream": "^1.0.27-1"
|
||||
}
|
||||
}
|
||||
|
||||
@ -11,6 +11,8 @@ helper('error', function(client) {
|
||||
assert(err)
|
||||
assert.equal(err.code, '42P01')
|
||||
done()
|
||||
}).on('data', function () {
|
||||
//noop to kick of reading
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user