views:

71

answers:

2

I'm writing an application in Python where I wish to use sqlite as the backing store for documents edited by the app, with documents generally living in memory, but being saved to disk-based databases when the application saves.

Ideally I'd like to use something like an ORM to make access to the data from my Python application code simple. Unfortunately it seems like the majority of Python ORMs, including SQLAlchemy, SQLObject, Django, and Storm, associate the database connection (or engine or whatever) with the classes representing table data, rather than instances of those classes. This restricts these ORMs to working with a single database connection across all instances. Since I'd like to support having multiple documents open simultaneously, this isn't going to work for me.

Are there any ORMs out there that support this usage model in Python? Bazaar seems to support this, but it's quite out of date, and at first glance appears to have some other shortcomings.

Thanks for any suggestions!

+1  A: 

The upcoming django 1.2 release supports this.

Here's a description of it: http://djangoadvent.com/1.2/multiple-database-support/

ablerman
That looks pretty good, thanks!
sdt
+2  A: 

SQLAlchemy does support multiple database connections per class, as in this example: http://svn.sqlalchemy.org/sqlalchemy/trunk/examples/sharding/attribute_shard.py

Daniel Dourvaris
Unfortunately, that alone doesn't seem to fit my needs. [ShardedSession](http://www.sqlalchemy.org/docs/reference/ext/horizontal_shard.html) accepts a parameter during construction that maps shard identifiers to engines. It does not appear to provide a way to add new engines later. Since I want to support opening and closing files dynamically, I need to be able to add new engines and remove existing ones during the application's lifetime.
sdt