Hi,

I use a global session instance to work with my DB, so all module
import it and use it. But at some point I sometimes need to
reconfigure the engine to use another DB. I want to reconfigure the
existing instance so other modules can still use the same session
object to work with the DB.

can I safely change the bind attribute of an existing scoped session
or is there any things to be taken care of before I do it ? (like
closing active connections in the pool maybe ?)

I've tried to use "configure" to reset the engine, but it doesn't work
(the bind attribute remain unchanged) :

>>> from sqlalchemy.orm import scoped_session, sessionmaker
>>> from sqlalchemy import create_engine
>>> Session = scoped_session(sessionmaker())
>>> Session.configure(bind=create_engine('sqlite:///tmp/db1'))
>>> Session.bind
Engine(sqlite:///tmp/db1)
>>> Session.configure(bind=create_engine('sqlite:///tmp/db2'))
>>> Session.bind
Engine(sqlite:///tmp/db1)  <--- same !

So, it this safe :

>>> from sqlalchemy.orm import scoped_session, sessionmaker
>>> from sqlalchemy import create_engine
>>> Session = scoped_session(sessionmaker())
>>> Session.configure(bind=create_engine('sqlite:///tmp/db1'))
>>> Session.bind
Engine(sqlite:///tmp/db1)
>>> Session.bind = create_engine('sqlite:///tmp/db2')
>>> Session.bind
Engine(sqlite:///tmp/db2)

Thanks
Tarek
-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.


Reply via email to