Skip to content

Instantly share code, notes, and snippets.

@marten-de-vries
Created January 28, 2015 20:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marten-de-vries/d4d1f202d051aa31b87c to your computer and use it in GitHub Desktop.
Save marten-de-vries/d4d1f202d051aa31b87c to your computer and use it in GitHub Desktop.
Resurrecting the .destroy() function
//PouchDB.destroy() is (going to be) deprecated by PouchDB, but the
//semantics from db.destroy() differ when wrapped so re-add it.
if (!(PouchDB.destroy || {}).isResurrected) {
var orig = PouchDB.destroy;
PouchDB.destroy = function (name, options, callback) {
var args = parseBaseArgs(PouchDB, this, options, callback);
//3.2.2 deprecates .destroy() and introduces opts.internal for as
//long as PouchDB will still use the method internally (hopefully)
if (!(PouchDB.version >= '3.2.2') || args.options.internal) {
return orig.apply(this, arguments);
}
var db = new PouchDB(name, args.options);
var promise = db.destroy();
nodify(promise, args.callback);
return promise;
}
PouchDB.destroy.isResurrected = true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment