Full Web Apps with FastAPI Transcripts
Chapter: Appendix: Using SQLAlchemy
Lecture: Concept: Ordering data

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Databases are really good at filtering and ordering. Here is a function, find_all_packages and the idea is I would like, ideally
0:08 a list of all the packages in the database showing the newest ones first and the oldest ones last. So we're going to do a query on package
0:16 and we don't do any filtering because like we said the in name, we want them all. But we are going do an order_by so we say, query of package.order_by
0:25 and then we always express these operations in terms of the type, so package.created If we just said package.created
0:31 it would order ascending by the created_date but we want descending, so we go into that descriptor created and we say .desc we call the function
0:40 to reverse the sort, and then we just say give us all the packages, here they come.


Talk Python's Mastodon Michael Kennedy's Mastodon