Flask-SQLAlchemy gives the option to filter a query. There are a wide number of ways you can filter a query - the examples the Flask-SQLAlchemy docs give:
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 one-to-many relationships:
User.query.filter(User.addresses.any(address=address)) # Returns all users who have a particular address listed as one of their addresses
Questions:
For a list of filters check SQLAlchemy documentation
what filter would I use to check if a user's email is contained within a particular set of email addresses?
Columns have a .in_()
method to use in query. So something like:
res = User.query.filter(User.email.in_(('[email protected]', '[email protected]')))
Here you can find the list of column method for expressions.
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