I've gone completely away from scoped sessions. In the main function I
create two engines for two databases as registry attributes
('request.registry.sa_engine_main'). My request subclass has two
reified properties ('request.registry.sa_session_main') that
initialize a session and hook it into Pyramid's transaction manager
('pyramid_tm'). Views use this session. Business-logic functions take
a session or connection as an argument, so they work the same when
called from views, console scripts, and unit tests. I put those in
separate modules, although in the past I've put them in the model
modules or as model class methods. For console scripts I have a
function 'get_sqlalchemy_session(settings, "main")' that creates an
engine from the app settings, binds it to a session, and returns the
session'. The caller is responsible for committing/rolling back (or
letting it implicitly roll back if the script aborts).

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/pylons-discuss/CAH9f%3Dup9eoebtjXjPQwshNX221B%2BscVAuQd9iBwRW8AtELGyyw%40mail.gmail.com.

Reply via email to