User login

Fork backbone-couch.js: support for custom views and lists

Two issues are addressed here:

<h3>backbone-couch.js is not transparent</h3>

backbone-couch.js as it is enforces to use its own database model ('byCollection'). A universal JS Couchdb plugin should not do things like that. It must be transparent to the user-defined models, which should be reflected in the DB as they are without additional 3rd party stuff.

<h3>Couchdb lucking support for views/lists in the _changes API</h3>

Couchdb instead of views and lists provided by the "plain read" (GET) access) returns only plain documents in its _changes API. There were some efforts from Couchdb to adopt the view/list conccept to the _changes API:

https://issues.apache.org/jira/browse/COUCHDB-979

but unfortunately there is no sign of progress in that direction for more than a year.

On the other hand, proper usage of MVC implies that one gets the same objects, structured in the same way both on the initial read and on all subsequent reads or change notifications. If not provided on the server side (couchdb), this however is readily achievable on the client side by applying the view and list functions to the changes reported by the server. Here it is done in the backbone-couch plugin for Backbone JavaScript MVC.

Not all kind of lists are supported, but only ones returning JSON structured as a view.

In addition, it is added support for accessing multiple databases. A new parameter "db_name" in the plugin configuration, as follows:


Backbone.Collection.extend({
db: {
db_name: 'somedb',
ddoc: 'somedocument',
view: 'someview',
list: 'somelist',
changes : true,
filter: ''
},

if provided is overriding the global Backbone.couch_connector.config.ddoc_name.

 

Source code is here:

https://github.com/allexpert/backbone-couchdb