Fork me on GitHub

Wednesday, December 30, 2009

EventMachine Client for CouchDB (em-couchdb)

I have been crazy about NoSql databases for sometime. CouchDB is one of my favorite apart from redis :). I was looking for clients for CouchDB in Ruby and found most to be using Net/Http and blocking in nature. So I began my quest of writing an asynchronous non blocking awesome EventMachine based CouchDB client inspired by EventMachine::Redis client.

Here is a sample code to enjoy... It creates a database, saves a document inside it, reads the doc, deletes it and then deletes the database.



The current version supports database manipulation like creation and deletion and document manipulation.

Looks cool for the code I wrote in a day but still there are things to improve (a lot). One thing is the CPS style. Because the code is asynchronous and the EventMachine reactor loop will take control once the code starts to run we need to explicitly pass callbacks to actions. This can be fixed as it was done in EM::Redis using callcc to make the passing implicit.

Please feel free to fork and contribute and happy hacking :).

The code is available at http://github.com/saivenkat/em-couchdb

No comments: