PouchDB Undo Plugin
Adds undo functionality to all operations (put, post, remove and bulkDocs) on a database. It allows the reversal of creations, changes and deletions.
Each operation will return a undoId
within the response. Use the undoId to revert the operation.
Undo creating a document:
pouch;
Undo changing a document:
pouch;
Undo deleting a document:
pouch;
Usage
To use this plugin, include it after pouchdb.js
in your HTML page:
Or to use it in Node.js, just npm install it:
npm install pouchdb-undo
Attach it to the PouchDB
object and enable it per database:
var PouchDB = ;PouchDB; var animals = 'animals';animals;
API
put
, post
and remove
Undo For put, post and remove, an undoId
is returned within the result, which must be provided to the undo
method:
pouch;
bulkDocs
Undo For bulkDocs, the undoId
is returned within the each row of the result (and they will have identical undoId
s):
pouch;
Advanced usage
Undo history is stored in _local documents (so they will not show up in allDocs, and they are not synced). By default, up to 100 undo's are stored, which can be changed by providing options to enableUndo:
pouch;
You can clear the entire undo history manually:
pouch;
Known issues
- At the moment only the latest operation on a document can be reverted.
- Race condition: making multiple changes at once to a database will lead to only one being kept in the undo history.
- Undo will not work well if there are multiple leaves (unresolved conflicts) - it will try to apply the undo to the first leaf found.
Building
npm installnpm run build
Testing
This will run the tests in Node using LevelDB:
npm test