Retrieval
In this lesson, we will discover how to retrieve objects from the database using the "query" object of the model class.
In the previous lesson, we inserted elements in the database by creating objects of the models. In this lesson, we will retrieve these objects from the database using the SQLAlchemy
ORM.
Common methods of retrieval in the query
object #
The query
object is a member variable of the Model
class. This object provides us with a method to execute the SELECT
statement of SQL
. We can find details on all the methods that can be used on this object in the SQLAlchemy docs.
query.all()
#
This method will retrieve all entries of the Model class on which it is called. A demonstration is given below.
Get hands-on with 1400+ tech skills courses.