Simple sequence based document versioning for CouchDB
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore
README.md
index.js
package.json

README.md

node-couch-sequence

Simple sequence based document versioning for CouchDB. Requires a Cradle connection to CouchDB for the Changes API. It can be used to publish version based datasets to clients, without having to resend the entire dataset each time an update is requested.

Usage

The module will subscribe to a changes feed via the CouchDB Changes API and monitor all the documents within the 'watchList' array.

npm install node-couch-sequence

var opts = { 
	db: [CRADLE_CONNECTION], 
	versioningDoc: 'NAME_OF_DOC_TO_STORE_VERSIONS', 
	watchList: ['products', 'categories']
};

var SequenceHandler = require('node-couch-sequence')(opts);

You can then query the sequence handler as much as you like:

var latest = SequenceHandler.getLatestSequenceIndex();
SequenceHandler.getChangesSince([SEQUENCE NUMBER], function(err, changes) {
	console.log(changes);
});

Example response from getChangesSince()

"1": {
   "products": [
       {
           "action": "UPDATE",
           "key": "FirstProduct",
           "data": "New product name"
       }
   ]
},
"2": {
   "products": [
       {
           "action": "INSERT",
           "key": "AnotherProduct",
           "data": null
       },
       {
           "action": "DELETE",
           "key": "FirstProduct"
       }
   ]
}

As in,

"SEQUENCE_NUMBER": {
	"DOCUMENT_NAME": [
		// ARRAY_OF_CHANGES
		{
			"action": "INSERT/UPDATE/DELETE",
			"key": "KEY THAT HAS BEEN MODIFIED",
			"data": "THE NEW DATA"
		},
		///
	]
}