any-db-pool
Advanced tools
Comparing version 0.0.6 to 0.1.0
14
index.js
@@ -17,10 +17,12 @@ var inherits = require('util').inherits | ||
var onConnect = options.onConnect; | ||
var poolOpts = { | ||
min: options.min, | ||
max: options.max, | ||
create: options.onConnect ? | ||
create: onConnect ? | ||
function (ready) { | ||
adapter.createConnection(connParams, function (err, conn) { | ||
if (err) ready(err); | ||
else options.onConnect(conn, ready) | ||
else onConnect(conn, ready) | ||
}) | ||
@@ -56,3 +58,9 @@ } | ||
var release = once(self.release.bind(self, conn)) | ||
query.once('end', release).once('error', release) | ||
query.once('end', release).once('error', function (err) { | ||
release() | ||
// If this was the only error listener, re-emit the error. | ||
if (!this.listeners('error').length) { | ||
this.emit('error', err) | ||
} | ||
}) | ||
}) | ||
@@ -59,0 +67,0 @@ |
@@ -1,12 +0,21 @@ | ||
module.exports = chain; | ||
module.exports = makeChain; | ||
function chain (steps) { | ||
return function (it, callback) { | ||
var i = 0; | ||
(function next (err) { | ||
function makeChain(steps) { | ||
return chain; | ||
function chain(it, callback) { | ||
var i = 0, currentStep; | ||
(function next(err) { | ||
if (err) return callback(err); | ||
var step = steps[i++]; | ||
return step ? step(it, next) : callback(null, it); | ||
if ((currentStep = steps[i++])) { | ||
try { | ||
currentStep(it, next); | ||
} catch (err) { | ||
callback(err); | ||
} | ||
} else { | ||
callback(null, it); | ||
} | ||
})(); | ||
}; | ||
} | ||
} | ||
@@ -17,3 +26,4 @@ | ||
var assert = require('assert'); | ||
chain([ | ||
console.log('1..4'); | ||
makeChain([ | ||
function (thing, next) { thing.prop = 1; next(); }, | ||
@@ -24,5 +34,6 @@ function (thing, next) { thing.prop2 = 2; next(); } | ||
assert.equal(thing.prop2, 2); | ||
console.log("ok - all steps called"); | ||
}); | ||
chain([ | ||
makeChain([ | ||
function (thing, next) { thing.prop = 1; next('error'); }, | ||
@@ -33,7 +44,16 @@ function (thing, next) { thing.prop2 = 2; next(); } | ||
assert(!thing); | ||
console.log("ok - errors cause short-circuit"); | ||
}); | ||
chain([])('passthru', function (err, thing) { | ||
makeChain([])('passthru', function (err, thing) { | ||
assert.equal(thing, 'passthru'); | ||
console.log("ok - empty chain is a pass-through"); | ||
}); | ||
makeChain([ | ||
function (thing, next) { throw "error"; } | ||
])('passthru', function (err, thing) { | ||
assert.equal(err, 'error'); | ||
console.log("ok - thrown errors get forwarded"); | ||
}); | ||
} |
{ | ||
"name": "any-db-pool", | ||
"version": "0.0.6", | ||
"description": "AnyDB connection pool", | ||
"version": "0.1.0", | ||
"description": "Any-DB connection pool", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": "", | ||
@@ -10,0 +7,0 @@ "author": "", |
@@ -67,3 +67,3 @@ # any-db-pool - database agnostic connection pool | ||
You can find the API documentation for this connection pool inclued in the rest of | ||
You can find the API documentation for this connection pool included in the rest of | ||
the any-db API docs | ||
@@ -70,0 +70,0 @@ [here](https://github.com/grncdr/node-any-db/blob/master/API.md#connectionpool). |
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
6534
129
2