Comparing version 0.15.1 to 1.0.0
@@ -13,4 +13,2 @@ var crypto = require('crypto'); | ||
var deprecate = require('deprecate'); | ||
var Client = function(config) { | ||
@@ -218,9 +216,3 @@ EventEmitter.call(this); | ||
this.activeQuery = null; | ||
//TODO remove pauseDrain for v1.0 | ||
if(this._drainPaused > 0) { | ||
this._drainPaused++; | ||
} | ||
else { | ||
this.emit('drain'); | ||
} | ||
this.emit('drain'); | ||
} | ||
@@ -269,28 +261,2 @@ } | ||
//prevents client from otherwise emitting 'drain' event until 'resumeDrain' is | ||
//called | ||
Client.prototype.pauseDrain = function() { | ||
deprecate('Client.prototype.pauseDrain is deprecated and will be removed it v1.0.0 (very soon)', | ||
'please see the following for more details:', | ||
'https://github.com/brianc/node-postgres/wiki/pg', | ||
'https://github.com/brianc/node-postgres/issues/227', | ||
'https://github.com/brianc/node-postgres/pull/274', | ||
'feel free to get in touch via github if you have questions'); | ||
this._drainPaused = 1; | ||
}; | ||
//resume raising 'drain' event | ||
Client.prototype.resumeDrain = function() { | ||
deprecate('Client.prototype.resumeDrain is deprecated and will be removed it v1.0.0 (very soon)', | ||
'please see the following for more details:', | ||
'https://github.com/brianc/node-postgres/wiki/pg', | ||
'https://github.com/brianc/node-postgres/issues/227', | ||
'https://github.com/brianc/node-postgres/pull/274', | ||
'feel free to get in touch via github if you have questions'); | ||
if(this._drainPaused > 1) { | ||
this.emit('drain'); | ||
} | ||
this._drainPaused = 0; | ||
}; | ||
Client.prototype.end = function() { | ||
@@ -297,0 +263,0 @@ this.connection.end(); |
@@ -7,3 +7,3 @@ var net = require('net'); | ||
var utils = require(__dirname + '/utils'); | ||
var Writer = require(__dirname + '/writer'); | ||
var Writer = require('buffer-writer'); | ||
@@ -10,0 +10,0 @@ var Connection = function(config) { |
@@ -36,10 +36,1 @@ module.exports = { | ||
}; | ||
var deprecate = require('deprecate'); | ||
//getter/setter to disable deprecation warnings | ||
module.exports.__defineGetter__("hideDeprecationWarnings", function() { | ||
return deprecate.silent; | ||
}); | ||
module.exports.__defineSetter__("hideDeprecationWarnings", function(val) { | ||
deprecate.silence = val; | ||
}); |
@@ -6,4 +6,2 @@ var EventEmitter = require('events').EventEmitter; | ||
var deprecate = require('deprecate'); | ||
var pools = { | ||
@@ -58,4 +56,9 @@ //dictionary of all key:pool pairs | ||
if(err) return cb(err, null, function() {/*NOOP*/}); | ||
//support both 2 (old) and 3 arguments | ||
(cb.length > 2 ? newConnect : oldConnect)(pool, client, cb); | ||
cb(null, client, function(err) { | ||
if(err) { | ||
pool.destroy(client); | ||
} else { | ||
pool.release(client); | ||
} | ||
}); | ||
}); | ||
@@ -67,54 +70,2 @@ }; | ||
//the old connect method of the pool | ||
//would automatically subscribe to the 'drain' | ||
//event and automatically return the client to | ||
//the pool once 'drain' fired once. This caused | ||
//a bunch of problems, but for backwards compatibility | ||
//we're leaving it in | ||
var alarmDuration = 5000; | ||
var errorMessage = [ | ||
'A client has been checked out from the pool for longer than ' + alarmDuration + ' ms.', | ||
'You might have a leak!', | ||
'You should use the following new way to check out clients','pg.connect(function(err, client, done)) {', | ||
' //do something', | ||
' done(); //call done() to signal you are finished with the client', | ||
'}' | ||
].join(require('os').EOL); | ||
var oldConnect = function(pool, client, cb) { | ||
deprecate('pg.connect(function(err, client) { ...}) is deprecated and will be removed it v1.0.0 (very soon)', | ||
'instead, use pg.connect(function(err, client, done) { ... })', | ||
'automatic releasing of clients back to the pool was a mistake and will be removed', | ||
'please see the following for more details:', | ||
'https://github.com/brianc/node-postgres/wiki/pg', | ||
'https://github.com/brianc/node-postgres/issues/227', | ||
'https://github.com/brianc/node-postgres/pull/274', | ||
'feel free to get in touch via github if you have questions'); | ||
var tid = setTimeout(function() { | ||
console.error(errorMessage); | ||
}, alarmDuration); | ||
var onError = function() { | ||
clearTimeout(tid); | ||
client.removeListener('drain', release); | ||
}; | ||
var release = function() { | ||
clearTimeout(tid); | ||
pool.release(client); | ||
client.removeListener('error', onError); | ||
}; | ||
client.once('drain', release); | ||
client.once('error', onError); | ||
cb(null, client); | ||
}; | ||
var newConnect = function(pool, client, cb) { | ||
cb(null, client, function(err) { | ||
if(err) { | ||
pool.destroy(client); | ||
} else { | ||
pool.release(client); | ||
} | ||
}); | ||
}; | ||
module.exports = pools; |
@@ -1,3 +0,1 @@ | ||
var deprecate = require('deprecate'); | ||
var parseBits = function(data, bits, offset, invert, callback) { | ||
@@ -50,8 +48,2 @@ offset = offset || 0; | ||
var parseFloatFromBits = function(data, precisionBits, exponentBits) { | ||
deprecate('parsing and returning floats from PostgreSQL server is deprecated', | ||
'JavaScript has a hard time with floats and there is precision loss which can cause', | ||
'unexpected, hard to trace, potentially bad bugs in your program', | ||
'for more information see the following:', | ||
'https://github.com/brianc/node-postgres/pull/271', | ||
'in node-postgres v1.0.0 all floats & decimals will be returned as strings'); | ||
var bias = Math.pow(2, exponentBits - 1) - 1; | ||
@@ -58,0 +50,0 @@ var sign = parseBits(data, 1); |
@@ -1,3 +0,1 @@ | ||
var deprecate = require('deprecate'); | ||
var arrayParser = require(__dirname + "/arrayParser.js"); | ||
@@ -81,14 +79,4 @@ | ||
var parseFloatArray = function(val) { | ||
deprecate('parsing and returning floats from PostgreSQL server is deprecated', | ||
'JavaScript has a hard time with floats and there is precision loss which can cause', | ||
'unexpected, hard to trace, potentially bad bugs in your program', | ||
'for more information see the following:', | ||
'https://github.com/brianc/node-postgres/pull/271', | ||
'in node-postgres v1.0.0 all floats & decimals will be returned as strings', | ||
'feel free to get in touch via a github issue if you have any questions'); | ||
if(!val) { return null; } | ||
var p = arrayParser.create(val, function(entry){ | ||
if(entry !== null) { | ||
entry = parseFloat(entry, 10); | ||
} | ||
var p = arrayParser.create(val, function(entry) { | ||
return entry; | ||
@@ -175,12 +163,2 @@ }); | ||
var parseFloatAndWarn = function(val) { | ||
deprecate('parsing and returning floats from PostgreSQL server is deprecated', | ||
'JavaScript has a hard time with floats and there is precision loss which can cause', | ||
'unexpected, hard to trace, potentially bad bugs in your program', | ||
'for more information see the following:', | ||
'https://github.com/brianc/node-postgres/pull/271', | ||
'in node-postgres v1.0.0 all floats & decimals will be returned as strings'); | ||
return parseFloat(val); | ||
}; | ||
var init = function(register) { | ||
@@ -191,8 +169,2 @@ register(20, parseInteger); | ||
register(26, parseInteger); | ||
//TODO remove for v1.0 | ||
register(1700, parseFloatAndWarn); | ||
//TODO remove for v1.0 | ||
register(700, parseFloatAndWarn); | ||
//TODO remove for v1.0 | ||
register(701, parseFloatAndWarn); | ||
register(16, parseBool); | ||
@@ -199,0 +171,0 @@ register(1082, parseDate); // date |
@@ -7,3 +7,3 @@ All major and minor releases are briefly explained below. | ||
### v1.0 - not released yet | ||
### v1.0 | ||
@@ -10,0 +10,0 @@ - remove deprecated functionality |
{ | ||
"name": "pg", | ||
"version": "0.15.1", | ||
"version": "1.0.0", | ||
"description": "PostgreSQL client - pure javascript & libpq with the same API", | ||
@@ -21,4 +21,4 @@ "keywords": [ | ||
"dependencies": { | ||
"generic-pool": "~2.0.2", | ||
"deprecate": "~0.1.0" | ||
"generic-pool": "2.0.2", | ||
"buffer-writer": "1.0.0" | ||
}, | ||
@@ -25,0 +25,0 @@ "devDependencies": { |
@@ -6,3 +6,3 @@ var helper = require(__dirname + '/../test/test-helper'); | ||
var pg = require(__dirname + '/../lib'); | ||
pg.connect(helper.config, function(err, client) { | ||
pg.connect(helper.config, function(err, client, done) { | ||
if(err !== null) { | ||
@@ -22,4 +22,5 @@ console.error("Recieved connection error when attempting to contact PostgreSQL:"); | ||
} | ||
done(); | ||
pg.end(); | ||
}) | ||
}) |
var helper = require(__dirname + '/../test-helper'); | ||
var pg = require(__dirname + '/../../../lib'); | ||
var pg = helper.pg; | ||
if(helper.args.native) { | ||
pg = require(__dirname + '/../../../lib').native; | ||
} | ||
var log = function() { | ||
@@ -23,4 +19,5 @@ //console.log.apply(console, arguments); | ||
arguments[1].emit('drain'); | ||
arguments[2](); | ||
}); | ||
pg.connect(helper.config, assert.calls(function(err, client) { | ||
pg.connect(helper.config, assert.calls(function(err, client, done) { | ||
assert.equal(err, null, "Failed to connect: " + helper.sys.inspect(err)); | ||
@@ -60,5 +57,5 @@ | ||
sink.add(); | ||
done(); | ||
})) | ||
})) | ||
})) | ||
@@ -68,3 +65,3 @@ }) | ||
test('executing nested queries', function() { | ||
pg.connect(helper.config, assert.calls(function(err, client) { | ||
pg.connect(helper.config, assert.calls(function(err, client, done) { | ||
assert.isNull(err); | ||
@@ -79,2 +76,3 @@ log("connected for nested queriese") | ||
sink.add(); | ||
done(); | ||
})) | ||
@@ -89,6 +87,7 @@ })) | ||
log("trying to connect to invalid place for error") | ||
pg.connect(connectionString, assert.calls(function(err, client) { | ||
pg.connect(connectionString, assert.calls(function(err, client, done) { | ||
assert.ok(err, 'should have raised an error') | ||
log("invalid connection supplied error to callback") | ||
sink.add(); | ||
done(); | ||
})) | ||
@@ -98,3 +97,3 @@ }) | ||
test("query errors are handled and do not bubble if callback is provded", function() { | ||
pg.connect(helper.config, assert.calls(function(err, client) { | ||
pg.connect(helper.config, assert.calls(function(err, client, done) { | ||
assert.isNull(err) | ||
@@ -106,2 +105,3 @@ log("checking for query error") | ||
sink.add(); | ||
done(); | ||
})) | ||
@@ -112,3 +112,3 @@ })) | ||
test('callback is fired once and only once', function() { | ||
pg.connect(helper.config, assert.calls(function(err, client) { | ||
pg.connect(helper.config, assert.calls(function(err, client, done) { | ||
assert.isNull(err); | ||
@@ -124,2 +124,3 @@ client.query("CREATE TEMP TABLE boom(name varchar(10))"); | ||
sink.add(); | ||
done(); | ||
}) | ||
@@ -130,3 +131,3 @@ })) | ||
test('can provide callback and config object', function() { | ||
pg.connect(helper.config, assert.calls(function(err, client) { | ||
pg.connect(helper.config, assert.calls(function(err, client, done) { | ||
assert.isNull(err); | ||
@@ -139,2 +140,3 @@ client.query({ | ||
assert.equal(result.rows[0].now.getYear(), new Date().getYear()) | ||
done(); | ||
})) | ||
@@ -145,3 +147,3 @@ })) | ||
test('can provide callback and config and parameters', function() { | ||
pg.connect(helper.config, assert.calls(function(err, client) { | ||
pg.connect(helper.config, assert.calls(function(err, client, done) { | ||
assert.isNull(err); | ||
@@ -155,2 +157,3 @@ var config = { | ||
assert.equal(result.rows[0].val, 'hi'); | ||
done(); | ||
})) | ||
@@ -161,3 +164,3 @@ })) | ||
test('null and undefined are both inserted as NULL', function() { | ||
pg.connect(helper.config, assert.calls(function(err, client) { | ||
pg.connect(helper.config, assert.calls(function(err, client, done) { | ||
assert.isNull(err); | ||
@@ -175,4 +178,5 @@ client.query("CREATE TEMP TABLE my_nulls(a varchar(1), b varchar(1), c integer, d integer, e date, f date)"); | ||
assert.isNull(result.rows[0].f); | ||
done(); | ||
})) | ||
})) | ||
}) |
@@ -5,3 +5,3 @@ var helper = require(__dirname + "/test-helper"); | ||
test('parsing array results', function() { | ||
pg.connect(helper.config, assert.calls(function(err, client) { | ||
pg.connect(helper.config, assert.calls(function(err, client, done) { | ||
assert.isNull(err); | ||
@@ -27,3 +27,2 @@ client.query("CREATE TEMP TABLE why(names text[], numbors integer[])"); | ||
assert.equal(names[2], "a b c"); | ||
pg.end(); | ||
})) | ||
@@ -36,3 +35,2 @@ }) | ||
assert.lengthIs(names, 0); | ||
pg.end(); | ||
})) | ||
@@ -47,3 +45,2 @@ }) | ||
assert.equal(names[1], 'jim'); | ||
pg.end(); | ||
})) | ||
@@ -58,3 +55,2 @@ }) | ||
assert.equal(names[1], '}'); | ||
pg.end(); | ||
})) | ||
@@ -71,3 +67,2 @@ }) | ||
assert.equal(names[3], 'NULL'); | ||
pg.end(); | ||
})) | ||
@@ -83,3 +78,2 @@ }) | ||
assert.equal(names[2], 'bob"'); | ||
pg.end(); | ||
})) | ||
@@ -101,3 +95,2 @@ }) | ||
pg.end(); | ||
})) | ||
@@ -113,3 +106,2 @@ }) | ||
assert.equal(names[2], 3); | ||
pg.end(); | ||
})) | ||
@@ -130,3 +122,2 @@ }) | ||
assert.equal(names[2][1], 100); | ||
pg.end(); | ||
})) | ||
@@ -147,2 +138,3 @@ }) | ||
assert.equal(names[2][1], 100); | ||
done(); | ||
pg.end(); | ||
@@ -149,0 +141,0 @@ })) |
@@ -17,3 +17,3 @@ var helper = require(__dirname + '/../test-helper'); | ||
test('COPY FROM', function () { | ||
pg.connect(helper.config, function (error, client) { | ||
pg.connect(helper.config, function (error, client, done) { | ||
assert.equal(error, null, "Failed to connect: " + helper.sys.inspect(error)); | ||
@@ -34,3 +34,3 @@ prepareTable(client, function () { | ||
assert.equal(result.rows[0].count, ROWS_TO_INSERT); | ||
pg.end(helper.config); | ||
done(); | ||
}); | ||
@@ -43,3 +43,3 @@ }, "COPY FROM stream should emit close after query end"); | ||
test('COPY TO', function () { | ||
pg.connect(helper.config, function (error, client) { | ||
pg.connect(helper.config, function (error, client, done) { | ||
assert.equal(error, null, "Failed to connect: " + helper.sys.inspect(error)); | ||
@@ -59,3 +59,3 @@ prepareTable(client, function () { | ||
assert.equal(lines[0].split(',').length, 3, "each line should consists of 3 fields"); | ||
pg.end(helper.config); | ||
done(); | ||
}, "COPY IN stream should emit end event after all rows"); | ||
@@ -68,3 +68,3 @@ }); | ||
if(helper.config.native) return false; | ||
pg.connect(helper.config, assert.calls(function (error, client) { | ||
pg.connect(helper.config, assert.calls(function (error, client, done) { | ||
assert.equal(error, null, "Failed to connect: " + helper.sys.inspect(error)); | ||
@@ -100,3 +100,3 @@ prepareTable(client, function () { | ||
assert.equal(lines[0].split(',').length, 3, "each line should consists of 3 fields"); | ||
pg.end(helper.config); | ||
done(); | ||
}, "COPY IN stream should emit end event after all rows"); | ||
@@ -114,3 +114,3 @@ }); | ||
//so we need to test both situations | ||
pg.connect(helper.config, assert.calls(function (error, client) { | ||
pg.connect(helper.config, assert.calls(function (error, client, done) { | ||
assert.equal(error, null, "Failed to connect: " + helper.sys.inspect(error)); | ||
@@ -126,3 +126,3 @@ //intentionally incorrect usage of copy. | ||
assert.ok(result, "incorrect copy usage should not break connection"); | ||
pg.end(helper.config); | ||
done(); | ||
})); | ||
@@ -136,3 +136,3 @@ }) | ||
if(helper.config.native) return false; | ||
pg.connect(helper.config, assert.calls(function (error, client) { | ||
pg.connect(helper.config, assert.calls(function (error, client, done) { | ||
assert.equal(error, null, "Failed to connect: " + helper.sys.inspect(error)); | ||
@@ -148,3 +148,3 @@ //intentionally incorrect usage of copy. | ||
assert.ok(result, "incorrect copy usage should not break connection"); | ||
pg.end(helper.config); | ||
done(); | ||
})); | ||
@@ -157,3 +157,3 @@ }) | ||
test("COPY FROM incorrect usage", function () { | ||
pg.connect(helper.config, function (error, client) { | ||
pg.connect(helper.config, function (error, client, done) { | ||
assert.equal(error, null, "Failed to connect: " + helper.sys.inspect(error)); | ||
@@ -170,2 +170,3 @@ prepareTable(client, function () { | ||
assert.ok(result, "incorrect copy usage should not break connection"); | ||
done(); | ||
pg.end(helper.config); | ||
@@ -172,0 +173,0 @@ })); |
var helper = require(__dirname + '/test-helper'); | ||
helper.pg.connect(helper.config, assert.success(function(client) { | ||
helper.pg.connect(helper.config, assert.success(function(client, done) { | ||
var types = require(__dirname + '/../../../lib/types'); | ||
@@ -18,2 +18,3 @@ //1231 = numericOID | ||
helper.pg.end(); | ||
done(); | ||
})) | ||
@@ -20,0 +21,0 @@ })); |
@@ -11,3 +11,2 @@ var helper = require(__dirname + '/test-helper'); | ||
client.end(); | ||
assert.emits(client, 'end'); | ||
})); | ||
@@ -14,0 +13,0 @@ var client2 = new Client(helper.args); |
@@ -5,3 +5,3 @@ var helper = require(__dirname + "/test-helper"); | ||
test('should return insert metadata', function() { | ||
pg.connect(helper.config, assert.calls(function(err, client) { | ||
pg.connect(helper.config, assert.calls(function(err, client, done) { | ||
assert.isNull(err); | ||
@@ -29,2 +29,3 @@ | ||
assert.equal(result.rowCount, 1); | ||
done(); | ||
}); | ||
@@ -31,0 +32,0 @@ |
@@ -8,4 +8,3 @@ var helper = require(__dirname + '/test-helper'); | ||
test('a single connection transaction', function() { | ||
helper.pg.connect(helper.config, assert.calls(function(err, client) { | ||
assert.isNull(err); | ||
helper.pg.connect(helper.config, assert.success(function(client, done) { | ||
@@ -43,2 +42,3 @@ client.query('begin'); | ||
assert.empty(result.rows); | ||
done(); | ||
sink.add(); | ||
@@ -51,4 +51,3 @@ })) | ||
test('gh#36', function() { | ||
helper.pg.connect(helper.config, function(err, client) { | ||
if(err) throw err; | ||
helper.pg.connect(helper.config, assert.success(function(client, done) { | ||
client.query("BEGIN"); | ||
@@ -73,4 +72,5 @@ client.query({ | ||
sink.add(); | ||
done(); | ||
}) | ||
}) | ||
})); | ||
}) |
@@ -5,3 +5,3 @@ var helper = require(__dirname + '/test-helper'); | ||
var testForTypeCoercion = function(type){ | ||
helper.pg.connect(helper.config, function(err, client) { | ||
helper.pg.connect(helper.config, function(err, client, done) { | ||
assert.isNull(err); | ||
@@ -35,2 +35,3 @@ client.query("create temp table test_type(col " + type.name + ")", assert.calls(function(err, result) { | ||
sink.add(); | ||
done(); | ||
}); | ||
@@ -61,11 +62,10 @@ }) | ||
},{ | ||
//TODO get some actual huge numbers here | ||
name: 'numeric', | ||
values: [-12.34, 0, 12.34, null] | ||
values: ['-12.34', '0', '12.34', null] | ||
},{ | ||
name: 'real', | ||
values: [101.1, 0, -101.3, null] | ||
values: ['101.1', '0', '-101.3', null] | ||
},{ | ||
name: 'double precision', | ||
values: [-1.2, 0, 1.2, null] | ||
values: ['-1.2', '0', '1.2', null] | ||
},{ | ||
@@ -88,3 +88,3 @@ name: 'timestamptz', | ||
types = types.filter(function(type) { | ||
return !(type.name in {'real':1, 'timetz':1, 'time':1}); | ||
return !(type.name in {'real':1, 'timetz':1, 'time':1, 'numeric': 1, 'double precision': 1}); | ||
}); | ||
@@ -140,3 +140,3 @@ } | ||
helper.pg.connect(helper.config, assert.calls(function(err, client) { | ||
helper.pg.connect(helper.config, assert.calls(function(err, client, done) { | ||
assert.isNull(err); | ||
@@ -151,2 +151,3 @@ client.query('select null as res;', assert.calls(function(err, res) { | ||
sink.add(); | ||
done(); | ||
}) | ||
@@ -153,0 +154,0 @@ })) |
@@ -11,3 +11,3 @@ var helper = require(__dirname + '/test-helper') | ||
[helper.config, helper.config, helper.config, helper.config].forEach(function(config) { | ||
helper.pg.connect(config, function(err, client) { | ||
helper.pg.connect(config, function(err, client, done) { | ||
assert.isNull(err); | ||
@@ -18,2 +18,3 @@ client.query("SELECT * FROM NOW()", function(err, result) { | ||
sink.add(); | ||
done(); | ||
}) | ||
@@ -20,0 +21,0 @@ }) |
var helper = require(__dirname + "/../test-helper"); | ||
var pg = require(__dirname + "/../../../lib"); | ||
helper.pg = pg; | ||
pg = pg; | ||
//first make pool hold 2 clients | ||
helper.pg.defaults.poolSize = 2; | ||
pg.defaults.poolSize = 2; | ||
@@ -11,12 +11,12 @@ var killIdleQuery = 'SELECT procpid, (SELECT pg_terminate_backend(procpid)) AS killed FROM pg_stat_activity WHERE current_query LIKE \'<IDLE>\''; | ||
//get first client | ||
helper.pg.connect(helper.config, assert.success(function(client) { | ||
pg.connect(helper.config, assert.success(function(client, done) { | ||
client.id = 1; | ||
helper.pg.connect(helper.config, assert.success(function(client2) { | ||
pg.connect(helper.config, assert.success(function(client2, done2) { | ||
client2.id = 2; | ||
done2(); | ||
//subscribe to the pg error event | ||
assert.emits(helper.pg, 'error', function(error, brokenClient) { | ||
assert.emits(pg, 'error', function(error, brokenClient) { | ||
assert.ok(error); | ||
assert.ok(brokenClient); | ||
assert.equal(client.id, brokenClient.id); | ||
helper.pg.end(); | ||
}); | ||
@@ -27,4 +27,5 @@ //kill the connection from client | ||
assert.lengthIs(res.rows, 1); | ||
pg.end(); | ||
})); | ||
})); | ||
})); |
@@ -6,3 +6,3 @@ var helper = require(__dirname + '/test-helper'); | ||
test('idle timeout', function() { | ||
helper.pg.connect(helper.config, assert.calls(function(err, client) { | ||
helper.pg.connect(helper.config, assert.calls(function(err, client, done) { | ||
assert.isNull(err); | ||
@@ -12,3 +12,4 @@ client.query('SELECT NOW()'); | ||
//test will hang if pool doesn't timeout | ||
done(); | ||
})); | ||
}); |
@@ -11,3 +11,3 @@ var helper = require(__dirname + '/test-helper'); | ||
helper.pg.connect(assert.calls(function(err, client) { | ||
helper.pg.connect(assert.calls(function(err, client, done) { | ||
assert.isNull(err); | ||
@@ -18,2 +18,3 @@ client.query('SELECT NOW()'); | ||
helper.pg.end(); | ||
done(); | ||
@@ -20,0 +21,0 @@ }, 10); |
@@ -10,4 +10,2 @@ //make assert a global... | ||
require(__dirname + '/../lib').defaults.hideDeprecationWarnings = true; | ||
Client = require(__dirname + '/../lib').Client; | ||
@@ -102,9 +100,21 @@ | ||
assert.success = function(callback) { | ||
return assert.calls(function(err, arg) { | ||
if(err) { | ||
console.log(err); | ||
} | ||
assert.isNull(err); | ||
callback(arg); | ||
}) | ||
if(callback.length === 1 || callback.length === 0) { | ||
return assert.calls(function(err, arg) { | ||
if(err) { | ||
console.log(err); | ||
} | ||
assert.isNull(err); | ||
callback(arg); | ||
}); | ||
} else if (callback.length === 2) { | ||
return assert.calls(function(err, arg1, arg2) { | ||
if(err) { | ||
console.log(err); | ||
} | ||
assert.isNull(err); | ||
callback(arg1, arg2); | ||
}); | ||
} else { | ||
throw new Error('need to preserve arrity of wrapped function'); | ||
} | ||
} | ||
@@ -132,9 +142,22 @@ | ||
return function(err, queryResult) { | ||
clearTimeout(id); | ||
if (err) { | ||
assert.ok(err instanceof Error, "Expected errors to be instances of Error: " + sys.inspect(err)); | ||
if(callback.length < 3) { | ||
return function(err, queryResult) { | ||
clearTimeout(id); | ||
if (err) { | ||
assert.ok(err instanceof Error, "Expected errors to be instances of Error: " + sys.inspect(err)); | ||
} | ||
callback.apply(this, arguments) | ||
} | ||
callback.apply(this, arguments) | ||
} else if(callback.length == 3) { | ||
return function(err, arg1, arg2) { | ||
clearTimeout(id); | ||
if (err) { | ||
assert.ok(err instanceof Error, "Expected errors to be instances of Error: " + sys.inspect(err)); | ||
} | ||
callback.apply(this, arguments) | ||
} | ||
} else { | ||
throw new Error("Unsupported arrity " + callback.length); | ||
} | ||
} | ||
@@ -141,0 +164,0 @@ assert.calls = expect; |
@@ -53,61 +53,1 @@ var helper = require(__dirname + '/test-helper'); | ||
}); | ||
test('with drain paused', function() { | ||
//mock out a fake connection | ||
var con = new Connection({stream: "NO"}); | ||
con.connect = function() { | ||
con.emit('connect'); | ||
}; | ||
con.query = function() { | ||
}; | ||
var client = new Client({connection:con}); | ||
client.connect(); | ||
var drainCount = 0; | ||
client.on('drain', function() { | ||
drainCount++; | ||
}); | ||
test('normally unpaused', function() { | ||
con.emit('readyForQuery'); | ||
client.query('boom'); | ||
assert.emits(client, 'drain', function() { | ||
assert.equal(drainCount, 1); | ||
}); | ||
con.emit('readyForQuery'); | ||
}); | ||
test('pausing', function() { | ||
test('unpaused with no queries in between', function() { | ||
client.pauseDrain(); | ||
client.resumeDrain(); | ||
assert.equal(drainCount, 1); | ||
}); | ||
test('paused', function() { | ||
test('resumeDrain after empty', function() { | ||
client.pauseDrain(); | ||
client.query('asdf'); | ||
con.emit('readyForQuery'); | ||
assert.equal(drainCount, 1); | ||
client.resumeDrain(); | ||
assert.equal(drainCount, 2); | ||
}); | ||
test('resumDrain while still pending', function() { | ||
client.pauseDrain(); | ||
client.query('asdf'); | ||
client.query('asdf1'); | ||
con.emit('readyForQuery'); | ||
client.resumeDrain(); | ||
assert.equal(drainCount, 2); | ||
con.emit('readyForQuery'); | ||
assert.equal(drainCount, 3); | ||
}); | ||
}); | ||
}); | ||
}); |
@@ -46,3 +46,3 @@ var helper = require(__dirname + '/test-helper'); | ||
actual: '12.34', | ||
expected: 12.34 | ||
expected: '12.34' | ||
},{ | ||
@@ -53,3 +53,3 @@ name: 'real/float4', | ||
actual: '123.456', | ||
expected: 123.456 | ||
expected: '123.456' | ||
},{ | ||
@@ -60,3 +60,3 @@ name: 'double precision / float8', | ||
actual: '1.2', | ||
expected: 1.2 | ||
expected: '1.2' | ||
},{ | ||
@@ -63,0 +63,0 @@ name: 'boolean true', |
@@ -71,15 +71,2 @@ var util = require('util'); | ||
test('pool#connect with 2 parameters (legacy, for backwards compat)', function() { | ||
var p = pools.getOrCreate(poolId++); | ||
p.connect(assert.success(function(client) { | ||
assert.ok(client); | ||
assert.equal(p.availableObjectsCount(), 0); | ||
assert.equal(p.getPoolSize(), 1); | ||
client.emit('drain'); | ||
assert.equal(p.availableObjectsCount(), 1); | ||
assert.equal(p.getPoolSize(), 1); | ||
p.destroyAllNow(); | ||
})); | ||
}); | ||
test('pool#connect with 3 parameters', function() { | ||
@@ -92,3 +79,3 @@ var p = pools.getOrCreate(poolId++); | ||
clearTimeout(tid); | ||
assert.equal(err, null); | ||
assert.ifError(err, null); | ||
assert.ok(client); | ||
@@ -109,5 +96,5 @@ assert.equal(p.availableObjectsCount(), 0); | ||
var p = pools.getOrCreate(poolId++); | ||
p.connect(assert.success(function(client) { | ||
p.connect(assert.success(function(client, done) { | ||
assert.ok(client); | ||
client.emit('drain'); | ||
done(); | ||
assert.equal(p.availableObjectsCount(), 1); | ||
@@ -114,0 +101,0 @@ assert.equal(p.getPoolSize(), 1); |
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
0
193
256930
103
6795
+ Addedbuffer-writer@1.0.0
+ Addedbuffer-writer@1.0.0(transitive)
+ Addedgeneric-pool@2.0.2(transitive)
- Removeddeprecate@~0.1.0
- Removeddeprecate@0.1.0(transitive)
- Removedgeneric-pool@2.0.4(transitive)
Updatedgeneric-pool@2.0.2