Open ldelossa opened 6 years ago
Hello @ldelossa , maybe so:
from api.app import db
db.connect()
db.session.begin()
db.session.add(user1)
db.session.commit()
db.close()
I'm new to SQLAlchemy & hug, but this answer doesn't seem to leverage the scoped session that is being created in the middleware. In fact there's a few things about the middleware that concern me:
sessionmaker
is being made once per object, whereas it's encouraged by the documentation to be made once at the module-level.scoped_session
returns a factory, not a concrete session as it's being used in the middlewareconnect
and close
, if I understand scoped sessions.scoped_session
relies on thread local storage - is that supported by Falcon, which uses green threads / asyncio?I think a session could be saved to the context once per request with a @context_factory
and used by name in endpoints via a custom @directive
. If I get it working I'll submit a PR
With this repository how can I access the session within a handler to make use of the .add() method ?