During OSCON this year I attended Jan Lehnardt’s talk on CouchDB. Somewhere in the middle of the talk I realized how much time I spend “dealing” with RDBMS and what a pain in the ass it is.
That weekend, in between OSCON and Mozilla Summit, I started playing with CouchDB and totally fell in love. Certainly my favorite part of CouchDB is that I no longer feel like I need huge abstractions between me and the datastore. The datastore is simple enough to get your head around and it comes with a beautiful web interface and it makes me feel like I don’t need a heavy duty ORM that handles everything for me, I can have a more intimate relationship with my datastore.
At some point I decided to seek out the Python library for interfacing with CouchDB, couchdb-python, and wasn’t too pleased. It’s a big library and a lot of great work was put in to it, but it just wasn’t what I wanted at all.
It feels like an ORM for RDBMS in that it does a lot of work to be a complete abstraction between you and CouchDB, which I just don’t want. The “schema” stuff, which is it’s mapper classes, feels a lot like RDBMS ORM. One of the great things about CouchDB is that there is no “schema” and that all your documents can fully mutate. This is how I want to define most of my “models”.
class User(Model): pass
So on the plane to Mozilla Summit I wrote a CouchDB library and spent free minutes here and there tweaking it. It’s incredibly small, about 243 lines with whitespace and comments, which is a testament to how much easier a REST API is to program for than SQL. You can create “Restrictions” which can do type checking and other validation before an attribute is set for a given property, and you can also use a Restriction to define custom marshalling before it hits the JSON parser. But all Models are fully mutatable and no validation is done at read time from the datastore, this way the ORM won’t ever get in your way as you change you data definitions over time in your application.
The whole thing is hosted on Google Code at http://code.google.com/p/pouch/ .
The docs right now are short and sweet http://code.google.com/p/pouch/wiki/Usage .
There are some features I’d like to add, it currently uses httplib and I’d like the option of using httplib2 so that you could do caching pretty seamlessly. Any other features or patches are welcome. I’ll be pushing it to the cheeseshop later today when I get a chance. Here’s a taste;
import pouch pouch.set_globals('http://127.0.0.1:5984', 'test') class TestModel(pouch.Model): pass class TestModelTwo(pouch.Model): unicode_test = pouch.Unicode() int_test = pouch.Int() float_test = pouch.Float() list_test = pouch.List() dict_test = pouch.Dict() bool_test = pouch.Bool() test = TestModel(anything="yes") test.another = "ok" test.save() test == TestModel.get(test.id) result = pouch.GLOBAL_DB.views.company.all() # Retrieves the response for view I have named company.









