Created
October 12, 2018 03:31
-
-
Save Ma233/c54646755afcead0b409b6dcfe9472b3 to your computer and use it in GitHub Desktop.
sqlalchemy query
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sqlalchemy.orm import load_only | |
def model_query(M, *, select_=None, order_by_=None, conditions_=None, **kwargs): | |
q = M.query | |
if select_: | |
q = q.options(load_only(*select_)) | |
if conditions_: | |
q = q.filter(*conditions_) | |
if order_by_: | |
q = q.order_by(*order_by_) | |
if kwargs: | |
q = q.filter_by(**kwargs) | |
return q |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment