SQLAlchemy scoped_session: Best approach of getting it to views
I am creating a web application using WebApp2, SQLAlchemy, Apache,
PostgrSQL etc. I have a config file which stores the database credentials
and create the session object using scoped_session. Right now all my view
files import this config file and use the session object like this:
some_view.py
import config
def view():
query = config.session.query(bla bla)
This approach is not the final one and I want to use the best possible
method.
What I want to achieve here is some way of getting the session object
using a decorator or webapp2 related inbuilt method so that after the
execution of view function the session object is closed. I tried many ways
but not able to achieve it. A working snippet will be highly appreciated.
If anyone having a better approach please suggest.
Thanks
No comments:
Post a Comment