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 ?