Skip to content

Instantly share code, notes, and snippets.

@calvinmetcalf
Created January 3, 2013 15:30
Show Gist options
  • Select an option

  • Save calvinmetcalf/4444296 to your computer and use it in GitHub Desktop.

Select an option

Save calvinmetcalf/4444296 to your computer and use it in GitHub Desktop.
connect to a CouchDB that syncs locally to indexDB if available, if not tries webSQL, finally just follow the CouchDB directly.
function pouchSync(dbURL,cb){
var dbName = dbURL.split("/").pop();
Pouch(dbName,function(err1,db1){
Pouch(dbUrl,function(err2,db2){
if (db1 && db2){
db1.replicate.from(db2,{continuous:true});
db1.replicate.to(db2,{continuous:true});
cb(null, db1);
}else if (db2){
cb(null, db2);
}else{
cb(true);
}
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment