Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pg-query-stream

Package Overview
Dependencies
Maintainers
1
Versions
60
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pg-query-stream - npm Package Compare versions

Comparing version 0.6.0 to 0.7.0

.travis.yml

28

index.js

@@ -6,3 +6,5 @@ var util = require('util')

var QueryStream = module.exports = function(text, values, options) {
var self = this;
var self = this
this._reading = false
this._closing = false
options = options || { }

@@ -17,8 +19,11 @@ Cursor.call(this, text, values)

process.nextTick(function() {
self.emit('close')
});
})
self.emit('close')
})
})
}
util.inherits(QueryStream, Readable)
//copy cursor prototype to QueryStream
//so we can handle all the events emitted by the connection
for(var key in Cursor.prototype) {

@@ -32,6 +37,15 @@ if(key == 'read') {

QueryStream.prototype.close = function() {
this._closing = true
var self = this
Cursor.prototype.close.call(this, function(err) {
if(err) return self.emit('error', err)
process.nextTick(function() {
self.push(null)
})
})
}
QueryStream.prototype._read = function(n) {
if(this._reading) return false;
if(this._reading || this._closing) return false
this._reading = true

@@ -47,3 +61,3 @@ var self = this

})
return;
return
}

@@ -50,0 +64,0 @@ self._reading = false

{
"name": "pg-query-stream",
"version": "0.6.0",
"version": "0.7.0",
"description": "Postgres query result returned as readable stream",

@@ -34,5 +34,5 @@ "main": "index.js",

"dependencies": {
"pg-cursor": "0.2.0",
"pg-cursor": "1.0.0",
"readable-stream": "^1.0.27-1"
}
}

@@ -7,4 +7,5 @@ var assert = require('assert')

var QueryStream = require('../')
var helper = require('./helper')
require('./helper')('close', function(client) {
helper('close', function(client) {
it('emits close', function(done) {

@@ -17,1 +18,20 @@ var stream = new QueryStream('SELECT * FROM generate_series(0, $1) num', [3], {batchSize: 2, highWaterMark: 2})

})
helper('early close', function(client) {
it('can be closed early', function(done) {
var stream = new QueryStream('SELECT * FROM generate_series(0, $1) num', [20000], {batchSize: 2, highWaterMark: 2})
var query = client.query(stream)
var readCount = 0
query.on('readable', function() {
readCount++
query.read()
})
query.once('readable', function() {
query.close()
})
query.on('close', function() {
assert(readCount < 10, 'should not have read more than 10 rows')
done()
})
})
})
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc