SQL-based searching

In any web application, it is important to be able to search the database for records based on some criteria. In this recipe, we will go through how to implement basic SQL-based searching in SQLAlchemy. The same principle can be used to search any other database system.

Getting ready

We have been implementing some level of search in our catalog application from the beginning. Whenever we show the product page, we search for a specific product using its ID. We will now take it to a more advanced level and search on the basis of name and category.

How to do it…

The following is a method that searches in our catalog application for name, price, company, and category. We can search for any one or multiple criterion (except for the ...

Get Flask Framework Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.