lazy database connections ?

37 views
Skip to first unread message

Jonathan Vanasco

unread,
Sep 24, 2012, 12:55:51 PM9/24/12
to pylons-...@googlegroups.com
in my apps, i attach a db connection object to the request.

It's basically just a wrapper that holds SqlAlchemy connections

my code tends to look like this:

    class AView():
        @viewconfig(...)
        def something(self):
             self._setupDb('reader')

the _setupDb function attaches an object that has a .reader and/or .writer attribute , and in keeping with some really old Pylons conventions --  issues an initial rollback and adds an 'add_finished_callback' to the request that will issue a close() on the SqlAlchemy ScopedSession(s).  [ i use separate reader and writer connections for both replication and a bit of security , one day i'll move to sharding - just not today ].

i have a few questions about this setup:

   1. i recall seeing an announcement a few weeks ago about the set_request_method adding some sort of lazy access by incorporating @reify .  has anyone used this for establishing dbConnections yet ?

   2. does anyone know if the initial rollback and cleanup of the ScopedSession are needed anymore ?
Reply all
Reply to author
Forward
0 new messages