node-couch-sequence

0.0.1 • Public • Published

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"
		},
		///
	]
}

Readme

Keywords

none

Package Sidebar

Install

npm i node-couch-sequence

Weekly Downloads

2

Version

0.0.1

License

none

Last publish

Collaborators

  • benbarnett