Building data-driven web apps with Pyramid and SQLAlchemy Transcripts
Chapter: Using SQLAchemy
Lecture: Concept: Ordering data
0:00 Databases are really good at filtering and ordering.
0:03 Here's a function, find_all_packages
0:05 and the idea is I would like really
0:07 a list of all the packages in the database
0:10 showing the newest ones first
0:11 and the oldest ones last.
0:13 So we're going to do a query on package
0:15 and we don't do any filtering 'cause
0:16 you know, we said in the name, we want them all
0:19 but we are going to do an order by.
0:21 So we say query a package.orderby
0:24 and then we always express these operations
0:26 in terms of the type, so package.created.
0:29 And if we just said package, dot, created
0:30 it would order ascending by the created date
0:33 but we want descending, so we go to that descriptor created
0:37 and we say, .desc, we call the function
0:39 to reverse the sort and then we just say
0:42 give us all the packages, here they come.