One of the stores built on JsonRestStore and included in Dojo 1.2 is the new CouchDBRestStore. CouchDB server is a JSON-based schema-free database with clustering and fault-tolerance. This new module utilizes the JsonRestStore RESTful capabilities to interact with a CouchDB server. CouchDB has a standards-based REST interface that integrates well with JsonRestStore via a few adaptions from the CouchDBRestStore modules.
CouchDBRestStore is a subclass of JsonRestStore and therefore supports the same API. Instantiating a CouchDBRestStore to interact with a CouchDB table is very simple, just construct it with the URL of the table:
myStore = new dojox.data.CouchDBRestStore({target:"/MyTable"});
You can now interact with the store using the standard read, write, notification, and identity Dojo Data APIs. Data retrievals trigger queries to the CouchDB server and data modifications are persisted to CouchDB using the standard REST API.
The CouchDBRestStore also provides a method to automatically create a store instance for each table in the CouchDB database. You can get a map of the stores by calling getStores:
var allMyStores = dojox.data.CouchDBRestStore.getStores();
The returned object is a set of properties where the property name is the table name and the property value is the store:
for(var tableName in allMyStores){
console.log("Table name: ", tableName, "Store:", allMyStores[tableName]);
}
myFavoriteStore = allMyStores.Favorite;
We can now fetch data from a CouchDB table:
myFavoriteStore.fetch({
query:"_all_docs?startkey=doc2&count=2&descending=true",
onComplete:function(results){
// handle the results
}
});
Or we can do a query using CouchDB’s views:
myFavoriteStore.fetch({
query:"_view/favorites/veryFavorite",
onComplete:function(results){
// handle the results
}
});
CouchDB sports a schema-free database designed to flexibly persist JSON data and can handle much of the data that can be generated through the Dojo Data API implemented by the store. With JsonRestStore’s full REST capabilities, as well as other features like referencing and direct property access, the CouchDBRestStore is a powerful tool for rapidly prototyping and developing CRUD applications.

i’d like to see this working somewhere, with a real couchdb hooked up to it.. any examples in the wild/
The current version is broken against the 0.9 CouchDB release (limit not count). That was easily fixed. But I don’t get how to use this to, say, hook up a FilteringSelect to it. It would be awesome if you could do a simple example of that, say for a view that restricts it output to rows like
{key:”somekey”,value:”the value to display”}
trying to use the api for couchdb. Is there any example anywhere for reference?
Seems this version has not been updated for a long time. It doesn’t work with CouchDB v0.11. As James said above, a working example will benefit the community more.
this works perfectly for me with 1.5 from the google CDN.
I agree with Marshal. Working examples are worth their weight in gold. I would love to run persevere instead of couchdb as I feel it would be a better fit for me but I can’t get it installed on my local machine, let alone the server! The documentation on that is piss-poor. Couchdb was 1 command and humming beautifully and the documentation is great! I’m hoping to be able to use Dojo still and maybe convert to Persevere one day.
@anomynous: What error did you get starting Persevere? Did you follow the directions from http://www.persvr.org/Page/Installation?
OK, allow me to walk you through my experience as I really would like to give this project another shot. I define the scope of my app, decide on Persevere with Dojo, search for “dojo persevere example” and click on the first result, which takes me here:
http://www.sitepen.com/blog/2008/07/23/getting-started-with-persevere-using-dojo/
I follow the instructions for “Starting Persevere”; I download, create a directory in my home folder, cd into it, and run java -jar start.jar. Well, I have Java 1.6.0_22 installed and according to java -version and the article says that Persevere should start as long as its installed. So it’s back to searching.
The download site’s wiki page points me to http://docs.persvr.org/. The Live Site Demo leads to a blank page, click on documentation. OK cool, there’s installation. So, I’ve confirmed Java’s running and it’s a recent version. The program’s extracted into .persevere in my home directory. The documentation says “All you need is java installed” so I should be good right? Well, I create my symbolic link and enter persvr -v and get:
/home/bryan/.persevere/bin/start: line 5: cd: -v: invalid option
cd: usage: cd [-L|-P] [dir]
/home/bryan/.persevere/bin/start: line 10: jackup: command not found
If I try running as a super-user it gives the same error as above but with ERROR:
narwhal is not in your PATH nor in /home/bryan/bin.
The page you linked to is currently just serving up blank alternating with “The Connection Was Reset” errors, Kris. This is what I meant when I said the documentation is piss-poor. There are (at least) 3 versions of the installation instructions available, each different, each claiming no dependencies, and none working! Compare that to apt-get install couchdb. Here’s the documentation I’ve been using for Couchdb, it’s complete and simple, but Persevere is still the best fit for the project:
http://guide.couchdb.org/editions/1/en/index.html
Examples that run are priceless in learning anything. I would really appreciate any help in how to get Persevere up and running.
@bryan: Thank you for pointing out these old docs. I have put notes on them indicating that they are out of date. The current documentation at http://www.persvr.org/Page/Documentation and installation instructions at http://www.persvr.org/Page/Installation should be back up now.
Thanks, I’ve almost there but I’ve reached another error.
I’ve installed Node successfully but you may want to let people know that even if you have openssl installed you need libssl-dev in order to get Node to compile and to get past the warnings saying that you don’t have openssl.
In the documentation it says to run:
bin/node-persvr
What app are they referring to? Is it the example wiki? When I run node-persvr to a directory, be it the example wiki, the Node directory, or the Persevere directory I just keep getting:
/bin/node-persvr: line 9: /bin/node: No such file or directory
Thanks again for your help.
Hi is there a way i can use dojo.io.script.get to retreive the data. Or some other method of cross-domain scripting, or a way to avoid cros-domain scripting.
A simple test of loading the library, requiring dojox.data.CouchDBRestStore, and running var allMyStores = dojox.data.CouchDBRestStore.getStores(); produces an error “URI denied”. With all the requests already, why don’t you just provide a simple WORKING sample???