On Fri, Nov 13, 2009 at 2:28 AM, Warren Smith <[email protected]> wrote: > On Wed, Nov 11, 2009 at 5:08 PM, Russell Keith-Magee > <[email protected]> wrote: >> Multi-db allows you to set up multiple database credentials; the usual >> reason for this is to split DB load across multiple database servers, >> but I don't see any reason you couldn't also use it to provide >> multiple connections to a single server, each with different >> credentials. So - you should be able to use the using() query operator >> to force a particular query to use a particular set of credentials >> (and thus a particular database connection). > > So, if understand you correctly, with multi-db I could do the > following for each request: > > 1. Retrieve the credentials from the session. > 2. Create a new, or update an existing, entry for those credentials in > the database configuration. > 3. Somehow ensure that the using() operator is used on all ORM operations. > > Would this work?
This sounds a little more dynamic that I was anticipating. Multi-DB changes the way you define your database - instead of DATABASE_HOST, DATABASE_NAME etc, you have a single DATABASES dictionary, with each key-value pair representing a full database configuration, including signin credentials. The process of actually opening a connection is handled by a ConnectionHandler class in django.db.utils. Although we haven't provided any way to override this, I suppose it could be replaced by an alternate implementation that creates connections based on credentials obtained from a session or something similar. I haven't given this much thought though. > If so, I think it could be implemented as middleware. > > My only concern is #3. Could the ORM be made to check some > request-specific place for a default using() argument if one is not > passed explicitly? The details aren't quite sorted out yet, but I expect the answer will be yes. We will need a similiar sort of approach will be needed to handle master/slave replication (i.e., write to database X if it's a write, or a read of something recently written). Yours, Russ Magee %-) -- You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/django-developers?hl=.
