Sqlalchemy has a very useful query_property feature that can be used to avoid passing the session around all the time.
See the start of the models module (in init) for details on how it is set up.
models
init
rebased
I did not know about query_property until now. :thumbsup: for me.
query_property
Ahhh, this is great. I've seen this pattern in a lot of the Fedora infra apps and found it very odd. I'm happy with this as-is, but I do wonder if we want to use http://flask-sqlalchemy.pocoo.org/ at some point in the future.
I know some projects don't want to tie their database models to the web framework (although it looks like it's a very easy-to-untie coupling), but flask-sqlalchemy has a lot of the boilerplate I see in terms of pre/post-request hooks, session setup, etc. Also, I find how they set up a orm.Query subclass to be very nice and inline with the manager pattern I'm used to from Django.
Anyway, that's all exciting ramblings (I'm glad the patterns from Django I know and love are possible with SQLAlchemy and Flask) and like I said, I'm happy with this as-is. Merge away!
Pull-Request has been merged by abompard
Sqlalchemy has a very useful query_property feature that can be used to avoid passing the session around all the time.
See the start of the
modelsmodule (ininit) for details on how it is set up.