mongopatch
Advanced tools
Comparing version 0.8.0 to 0.8.1
{ | ||
"name": "mongopatch", | ||
"version": "0.8.0", | ||
"version": "0.8.1", | ||
"repository": "git://github.com/e-conomic/mongopatch.git", | ||
@@ -5,0 +5,0 @@ "description": "MongoDB patching tool", |
@@ -168,2 +168,6 @@ mongopatch [![Build Status](https://travis-ci.org/e-conomic/mongopatch.png?branch=master)](https://travis-ci.org/e-conomic/mongopatch) | ||
#### Version 0.8.1 | ||
- Make it possible to pass a `mongojs` database instance to `mongopatch` when used programmatically (the database is not closed). | ||
#### Version 0.8.0 | ||
@@ -170,0 +174,0 @@ |
@@ -15,2 +15,17 @@ var util = require('util'); | ||
var getDatabase = function(db) { | ||
return (typeof db === 'string') ? mongojs(db) : db; | ||
}; | ||
var closeDatabase = function(db, original) { | ||
var close = function(callback) { | ||
db.close(callback); | ||
}; | ||
var noop = function(callback) { | ||
callback(); | ||
}; | ||
return (typeof original === 'string') && db ? close : noop; | ||
}; | ||
var propagateError = function(src, dest) { | ||
@@ -27,5 +42,8 @@ src.on('error', function(err) { | ||
var create = function(patch, options) { | ||
var applicationDb = mongojs(options.db); | ||
var logDb = options.logDb && mongojs(options.logDb); | ||
var applicationDb = getDatabase(options.db); | ||
var logDb = options.logDb && getDatabase(options.logDb); | ||
var closeApplicationDb = closeDatabase(applicationDb, options.db); | ||
var closeLogDb = closeDatabase(logDb, options.logDb); | ||
var progress = { | ||
@@ -180,12 +198,4 @@ total: 0, | ||
async.parallel([ | ||
function(next) { | ||
applicationDb.close(next); | ||
}, | ||
function(next) { | ||
if(!logDb) { | ||
return next(); | ||
} | ||
logDb.close(next); | ||
} | ||
closeApplicationDb, | ||
closeLogDb | ||
], callback); | ||
@@ -192,0 +202,0 @@ }); |
39317
977
199