The code and information about the library in this article may be out of date since this article is pretty old now and was written when the library was first released. Check the project page for a more updated description.
Recently I read a lot about CouchDB, couchapps and Backbone.js and I really liked the way you can create apps with these tools. To combine them I created a connector for Backbone that syncs your Backbone app to your CouchDB. The source is available on Github and an example couchapp is hosted at couchone.
Vote it up on Hackernews if you like it: vote.
This is the description that I also published on Github:
Why a new connector?
I developed this connector because I didn’t want to write a whole new server that persists the models that Backbone.js creates. Instead of writing a server I now only have to write a simple design document containing one simple view and I’m done with server-side code and can fully concentrate on my Backbone App.
Also I wanted to get real time updates when my models are changed on the server (e.g. by a second user). The CouchDB changes-feed seemed like a perfect match for this problem.
All Backbone apps should work normally without any changes. Simply include
backbone-couchdb.js with its dependencies into your project and configure the connector with your database infos.
As you can see you also need to create a new database in your CouchDB and a new design document that contains the following view:
If you set
Backbone.couchConnector.enableChanges to true, the connector will update your models with remote changes in near real time.
Give your couchapp some backbone
An easy way to host single-page apps is to enclose them in a couchapp. I included a sample couchapp project to show you how to create couchapps with backbone and this CouchDB connector. Also there is a step by step tutorial located in the readme of the couchapp.
To show how backbone-couchdb works under the hood I created an annotated source file located here.