public
Last active

  • Download Gist
pouch.advanced.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
var db,
callback = function(err,database){
if(err){
console.error("Bad Stuff happend");
}else{
console.log("good news!")
db=database;
}
};
var makePouch = function(url,cb){
var rep;
if(url.slice(-1)==="/"){
url = url.slice(0,-1);
}
var dbName = url.split("/").pop();
Pouch(dbName, function(err1,db1){
if (err1) {
Pouch(url,function(err2,db2){
if (err2) {
cb(err2);
} else {
cb(null,db2)
}
});
} else {
rep = function(err3){
if (err3) {
console.error(err3);
}
};
Pouch.replicate(dbName, url, {continuous: true}, rep);
Pouch.replicate(url, dbName, {continuous: true}, rep);
cb(null, db1);
}
});
};
makePouch("http://url.to.couchdb/dbname",callback);

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.