Comparing version 1.0.0 to 1.0.1
33
index.js
@@ -22,2 +22,3 @@ var Libpq = require('libpq'); | ||
var self = this; | ||
this.on('newListener', function(event) { | ||
@@ -158,8 +159,16 @@ if(event != 'notification') return; | ||
//wait for the writable socket to drain | ||
var waitForDrain = function(pq, cb) { | ||
Client.prototype.waitForDrain = function(pq, cb) { | ||
var res = pq.flush(); | ||
if(res === 0) return cb(); | ||
if(res === -1) return cb(pq.errorMessage()); | ||
if(res === 0) return setImmediate(cb); | ||
if(res === -1) return setImmediate(function() { | ||
cb(pq.errorMessage()); | ||
}) | ||
var self = this | ||
//you cannot read & write on a socket at the same time | ||
self._stopReading(); | ||
return pq.writable(function() { | ||
waitForDrain(pq, cb); | ||
self.waitForDrain(pq, function() { | ||
self._startReading(); | ||
cb(); | ||
}); | ||
}); | ||
@@ -170,3 +179,3 @@ }; | ||
//finish writing query text to the socket | ||
var dispatchQuery = function(pq, fn, cb) { | ||
Client.prototype.dispatchQuery = function(pq, fn, cb) { | ||
var success = pq.setNonBlocking(true); | ||
@@ -176,3 +185,3 @@ if(!success) return cb(new Error('Unable to set non-blocking to true')); | ||
if(!sent) return cb(new Error(pq.errorMessage() || 'Something went wrong dispatching the query')); | ||
return waitForDrain(pq, cb); | ||
this.waitForDrain(pq, cb); | ||
}; | ||
@@ -192,7 +201,7 @@ | ||
var self = this | ||
dispatchQuery(pq, queryFn, function(err) { | ||
self._awaitResult(function(err) { | ||
return cb(err, err ? null : mapResults(pq, types)); | ||
}); | ||
self.dispatchQuery(pq, queryFn, function(err) { | ||
if(err) return cb(err); | ||
self._awaitResult(function(err) { | ||
return cb(err, err ? null : mapResults(pq, types)); | ||
}); | ||
}); | ||
@@ -207,3 +216,3 @@ }; | ||
} | ||
dispatchQuery(pq, fn, function(err) { | ||
self.dispatchQuery(pq, fn, function(err) { | ||
if(err) return cb(err); | ||
@@ -219,3 +228,3 @@ self._awaitResult(cb); | ||
var fn = pq.sendQueryPrepared.bind(pq, statementName, parameters); | ||
dispatchQuery(pq, fn, function(err, rows) { | ||
self.dispatchQuery(pq, fn, function(err, rows) { | ||
if(err) return cb(err); | ||
@@ -222,0 +231,0 @@ self._awaitResult(function(err) { |
{ | ||
"name": "pg-native", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "A slightly nicer interface to Postgres over node-libpq", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -119,3 +119,3 @@ #node-pg-native | ||
var client2 = new Client() | ||
client2.connect('postgresql://user:password@host:5432/database?param=value`, function(err) { | ||
client2.connect('postgresql://user:password@host:5432/database?param=value', function(err) { | ||
if(err) throw err | ||
@@ -122,0 +122,0 @@ |
@@ -51,2 +51,5 @@ var Client = require('../'); | ||
var output = self.client.getCopyStream(); | ||
//pump the stream | ||
output.read(); | ||
output.pipe(concat(function(err, res) { | ||
@@ -53,0 +56,0 @@ done(); |
@@ -23,2 +23,4 @@ var assert = require('assert'); | ||
var stream = self.client.getCopyStream(); | ||
//pump the stream for node v0.11.x | ||
stream.read(); | ||
stream.pipe(concat(function(buff) { | ||
@@ -25,0 +27,0 @@ var res = buff.toString('utf8') |
@@ -7,12 +7,11 @@ var Client = require('../'); | ||
var client = new Client(); | ||
client.connect(ok(done, function() { | ||
var query = function(n, cb) { | ||
client.query('SELECT $1::int as num', [n], function() { | ||
cb() | ||
}); | ||
}; | ||
async.timesSeries(50, query, ok(done, function() { | ||
client.end(); | ||
done() | ||
})); | ||
client.connectSync() | ||
var query = function(n, cb) { | ||
client.query('SELECT $1::int as num', [n], function(err) { | ||
cb(err) | ||
}); | ||
}; | ||
return async.timesSeries(5, query, ok(done, function() { | ||
client.end(); | ||
done() | ||
})); | ||
@@ -25,7 +24,5 @@ } | ||
it.only('multiple client and many queries', function(done) { | ||
this.timeout(5000); | ||
//this segfaults or throws 'Abort trap: 6' | ||
async.times(10, execute, done); | ||
it('multiple client and many queries', function(done) { | ||
async.times(20, execute, done); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
36815
908