...and that's sometimes a good thing. We use SA here with two databases (MSSQL + Sqlite) using exactly the type of single session + multiple-bound-metadata scheme that Mike describes above. Works fine (just don't try to join across databases...)
On 1/28/07, Michael Bayer <[EMAIL PROTECTED]> wrote: > > > > On Jan 23, 10:36 am, "Max Ischenko" <[EMAIL PROTECTED]> wrote: > > As far as I understand, I need a session per database. In Pylons, I get > > it "for free" via session_context binding. In other words, I have setup > > a session_context object for each of the database I need to work with. > > youd need a separate engine for each database. since different > connection strings and all that. A single Session can in fact talk to > multiple databases at once, so im not sure if multiple sessions/ > sessioncontexts are really required (however, i can see how it may be > the most intuitive approach to just use separate sessions). > > > > > Do I need to use separate DynamicMetaData() for each db conn? Do I need > > to connect single metadata to the correct session? SA docs shows how to > > connect metadata to a engine but all I have is a session. > > > > OK i think talking to multiple DB's is a little involved and there is > currently no official "pattern" to this. it also depends on how your > multiple DB's relate to your classes. for example, if you have > certain classes that are stored in certain DB's, you can map quite > easily using just regular BoundMetaData instances: > > metadata1 = BoundMetaData('foo://database1') > metadata2 = BoundMetaData('foo://database2') > > table1 = Table('table1', metadata1, autoload=True) > table2 = Table('table2', metadata2, autoload=True) > > mapper(ClassA, table1) > mapper(ClassB, table2) > > ...and youre done. You can use just one Session that has ClassA and > ClassB in it at the same time. So, we have a lot of possibilities > here, but app configs and database configs can vary greatly so it may > be a little bit overwhelmingly open ended. > > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---