I've seen a few variations of running a query with SQLAlchemy. For example, here is one version:
posts = db.query(models.Post).filter(models.Post.owner_id==user.id).all()
What would be the difference between using the above or using .where? Why are there two variations here?
According to the documentation, there is no difference.
method
sqlalchemy.orm.Query.where(*criterion)A synonym for
Query.filter().
It was added in version 1.4 by this commit. According to the commit message the reason to add it was to Convert remaining ORM APIs to support 2.0 style.
You can read more about "2.0 style" here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With