--
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To post to this group, send email to sqlal...@googlegroups.com.
To unsubscribe from this group, send email to sqlalchemy+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Great, and to answer your TODO no, metadata.bind = engine is not necessary and I try to discourage people from using that activity by default (but the plethora of Turbogears and Pylons tutorials that keep using it makes this task more or less impossible). A discussion of that feature specifically is at http://www.sqlalchemy.org/docs/core/schema.html#binding-metadata-to-an-engine-or-connection .
On 08/17/2011 11:16 AM, Michael Bayer wrote:Great, and to answer your TODO no, metadata.bind = engine is not necessary and I try to discourage people from using that activity by default (but the plethora of Turbogears and Pylons tutorials that keep using it makes this task more or less impossible). A discussion of that feature specifically is at http://www.sqlalchemy.org/docs/core/schema.html#binding-metadata-to-an-engine-or-connection .I read that, and because the docs indicate removing metadata.bind = engine1 would make me lose "implicit" execution (unless it's provided by some other means in TurboGears' config), I worried that might break TurboGears' transaction management or query execution configuration somehow--is that possible? I only ask because TurboGears' creators may have some question like this in mind--maybe you can see better than I whether this indicates a way the docs can be improved. After reading more of the SQLAlchemy docs, it appears to me the answer to that question is "No," because "implicit" execution and transaction management are two very different and unrelated things in SQLAlchemy, and that whatever "implicit" execution TurboGears may need is probably provided by binding the engine to the session. And, so far, my code works without the metadata.bind = engine1 statement.
I'll mention one more thing where maybe the docs should be improved--when I created the lines below, I had to read through SQLAlchemy's code to try to figure out whether I could use both bind (singular) and binds (plural) simultaneously on the same object. Initially the docs made me feel uncomfortable using both bind and binds; it seemed like if bind stores one connectable in the session, binds might replace that one connectable with a list of connectables, so maybe I could only use one and not both (bind and binds). But, through trial and error (which docs need never attempt to completely replace), using both works!
DBSession.configure(bind=engine1)
- DBSession2.configure(bind=engine2)
+ DBSession.configure(binds={Ticket:engine2})
But here is how the docs could be made more clear - simply state 1. whether it is allowable to use bind and binds simultaneously on the same object, and (if 2. is the case) 2. that the engine specified in bind will be used for all classes, mappers, and tables except where another engine is specified by binds. For brevity's sake, I note that 1. is implicit in 2.
Tim
Tim