On Mon, Mar 3, 2014 at 7:55 AM, Chris Withers <[email protected]> wrote: > Hi Simon, > > > On 26/02/2014 13:18, Simon King wrote: >> >> I don't know exactly what your needs are, but here's the example from the >> docs: >> >> engine1 = create_engine('postgresql://db1') >> engine2 = create_engine('postgresql://db2') >> >> Session = sessionmaker(twophase=True) >> >> # bind User operations to engine 1, Account operations to engine 2 >> Session.configure(binds={User:engine1, Account:engine2}) > > > Interesting, didn't know you could do that. However, how does that scale to > lots of mapped classes? I guess User and Account would need to have > different declarative bases? Is there a way to say all classes for a > particular base go to a particular engine? >
Skimming the source, I can't see anything that would do that directly. However, there is a method (Session.bind_mapper) for binding a mapper to a specific engine: http://docs.sqlalchemy.org/en/rel_0_9/orm/session.html#sqlalchemy.orm.session.Session.bind_mapper So you could easily write a loop over the subclasses of your declarative base calling Session.bind_mapper for each. > >> # commit. session will issue a flush to all DBs, and a prepare >> step to all DBs, >> # before committing both transactions >> session.commit() > > > ...and I guess, if configured, this would wire in two phase commits > correctly? I would assume so, but I've never used two-phase commit so can't say for sure. > > Partially innocent question: If one of the flushes you describe above fails > (say with an integrity error), then the transactions would be left in need > of a rollback on all engines and definitely no data would be committed? > Again, I would assume so. Hope that helps, Simon -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/groups/opt_out.
