Python Database Projects Arise!
I just saw a post on bringing SQLAlchemy and Zope Transaction Manager together, now that’s good stuff.
I’m looking forward to having time to look into both of these projects soon. It seems like projects at work and TurboGears in general could certainly benefit from the combination of a good general purpose Transaction Manager, and a good ORM based on the Data Mapper pattern.
All this got me thinking about Python’s Database connectivity story. Yes, SQLObject and the Active Record pattern is easier to use than SQLAlchemy and the Data Mapper pattern. But, it is also true that Active Record is just a subset of Data Mapper where there is a 1 to 1 mapping between objects and table rows. So it should be fairly easy to implement an active record type interface on top of a good Data Mapper.
Then you get all the ease of use of Active Record, and only a small step up in complexity gives you all the power of Data Mapper. You can use both patterns in the same application, and choose the level of abstraction you need.
There are two projects working on this, Active Mapper, and Pocoo’s DatabaseApi. This is one place where Python is on the edge of greatness. SQLAlchemy is way easier to use and than Hibernate, and is already almost as powerful. Moreover, I don’t know of anything like it in Perl, Ruby, or even Smalltalk.
Stay tuned. The revolution will be televised.
This is basically the design of Dejavu: a Data Mapper that defaults to a “1 to 1 mapping between objects and table rows”. Dejavu out of the box looks very much like the ActiveMapper example you linked to. The big difference is that if you need to override the table/column names, you do so in the storage layer, not the model layer (so a single object model can be mapped to multiple concrete database schemas).