Flask-SQLAlchemy Filters and Statements

Flask-SQLAlchemy allows you to filter a query. There are many ways to filter a query โ€” examples that provide Flask-SQLAlchemy documents:

User.query.filter_by(username='peter') # Returns all users named 'peter'
User.query.filter(User.email.endswith('@example.com')) # Returns all users with emails ending in '@example.com'

I also found this for a one-to-many relationship:

User.query.filter(User.addresses.any(address=address)) # Returns all users who have a particular address listed as one of their addresses

Questions:

  • Does anyone know which filters are really available for use? I can not find the list of filters in the documentation, which makes it difficult to query the databases.
  • In particular, which filter would I use to check if a user's email is contained in a specific set of email addresses?
+4
source share

Source: https://habr.com/ru/post/1526136/


All Articles