...

/

Using The Query Method: Filter

Using The Query Method: Filter

Learn how to use the filter in the query method.

To delete a record with a particular primary key, or all records meeting some condition, we first perform the query and then apply the delete method. This is described below in the context of queries.

Search a table based on conditions

To search a table, we create a query for that table and then apply filters. The result is not a list but iterable overall matches.

Press + to interact
print('Which books are available to be checked out?')
for book in session.query(Book).filter(Book.available == True):
print(book.title, book.author)

Different types of conditionals

In order to apply the filter, the filter method is used where conditions are specified using the class columns. Besides equality, other operators can be used when they make sense with the type, such as inequality operators for strings and numbers. Here are some ...

Access this course and 1400+ top-rated courses and projects.