The intend of this project is to provide a plain, straight-forward abstraction of the CouchDB REST API. The resources exposed by the API are simply wrapped into classes.
<img src=“http://travis-ci.org/phifty/couchdb.png” />
server = CouchDB::Server.new"localhost", 5984database = CouchDB::Database.newserver, "test"database.delete_if_exists!database.create_if_missing!document_one = CouchDB::Document.newdatabase, "_id"=>"test_document_1", "category"=>"one"document_one.savedocument_two = CouchDB::Document.newdatabase, "_id"=>"test_document_2", "category"=>"two"document_two.savedesign = CouchDB::Design.newdatabase, "design_1"view = CouchDB::Design::View.newdesign, "view_1", "function(document) { emit([ document['category'], document['_id'] ]); }"design.savecollection = view.collection:startkey=> [ "one", nil ], :endkey=> [ "one", { } ] collection.total_count# => 2collection.size# => 1collection[0].id# => "test_document_1"collection[0].key# => [ "one", "test_document_1" ]collection[0].value# => nilcollection.documents.include?document_one# => truecollection.documents.include?document_two# => false
This example creates a database on the local CouchDB server (if it’s missing) and stores two documents in it. It also creates a design document with a view, that makes it possible to select the results by the document’s category.
The collection call on that view, returns a subset of the results, by defining a start- and an endkey. The collection object itself acts as a proxy to the results. This first request of it’s content will actually fetch the data from the server.
If the results are accessed by the documents proxy, the include_docs parameter will be passed to the server and the delivered document hashes will be returned as an array of document (CouchDB::Document) objects.
This project is still under development. Any bug report and contribution is welcome!
Apart from contribution, support via Flattr is welcome.