Using BrowserCouch
Suppose we want to add offline support for a blog. To get a database called blog-posts in BrowserCouch, you can use the following function:
It's clear that the first parameter is the name of the database we want; the second parameter is the callback that will be passed the database once it's fetched. The third parameter is optional, and specifies the engine that will be used to persistently store our database. In this case we're using a storage backend called FakeStorage, which just stores everything non-persistently in memory, because this is just a tutorial. We could just as easily leave out the third parameter to have BrowserCouch figure out the best storage backend based on our browser's capabilities.
If the database doesn't already exist, an empty one will be created for us. Putting blog posts into the database can be done via an onRetrieveDb() function like this:
Every item we put into our database needs to have an id attribute, but aside from that, the item can contain any JSON-encodable data.
Now it's possible to make a view that organizes all the posts by author:
The output placed in the author-keyed-view element is: