Re: [flask] Proper way to attach a SQLAlchemy session to an application
- From:
- Adam Patterson
- Date:
- 2011-05-18 @ 16:08
Is there a reason you aren't using
http://packages.python.org/Flask-SQLAlchemy/ ?
On Tue, May 17, 2011 at 6:25 AM, Franck <franck.perez@gmail.com> wrote:
> Hi all,
> I've been reading this page to understand how to configure a SQLAlchemy
> session per application in a proper way :
> http://flask.pocoo.org/snippets/22/
> These patterns actually seem to rely on shared global variables : wouldn't
> something like that work instead ?
> def init_orm(dsn):
>
> engine = create_engine(dsn)
> _sessionmaker = sessionmaker(bind = engine)
> return scoped_session(_sessionmaker)
> app.orm = init_orm(app.config['DSN'])
> I'm new to Flask, therefore I'm not sure if it's a good pattern to attach
> such objects to the application itself.
> Does it seem fine to you though ?
> Thanks !
> Franck
>
>