Full Web Apps with FastAPI Transcripts
Chapter: Storing data with SQLAlchemy
Lecture: Latest release for a package

Login or purchase this course to watch this video and the rest of the course contents.
0:00 I almost overlooked something, really quickly before we move on from the Package
0:03 Details Page. Notice we were just sending this fake release back.
0:07 Let's actually rewrite this to return the real package release.
0:11 Let's go down here, we'll say, create a session and we want to get the latest release,
0:16 right? And I guess there's a couple ways we could do it,
0:18 we could get the package and then we could get the releases.
0:21 Or we could just do a query where the package name is something and order by
0:26 release date, let's go with that one.
0:27 So we'll go to the release and we'll say filter
0:29 where Release.package_id
0:33 is package_name. That should still be set as that foreign key that we're working with.
0:38 And then we have the first,
0:39 that's fine, but we're also going to have, come over here,
0:43 and we want to say order_by(Release.created_date.desc()).
0:49 So we want all the releases for this package order by, going the newest ones first
0:54 and then just give us that. And that is going to be "release".
0:58 It could be, there's a release or there might not be a release,
1:01 it might be None, hence the Optional return value
1:03 here. Let's try this one more time,
1:05 make sure we're really using all the live data over there. If we go to
1:08 botocore, oh yeah,
1:09 look at that. It's got old snapshot data,
1:12 but there it is, botocore updates all the time
1:13 so it's a little out of date,
1:15 but check that out. We've got the latest release.
1:17 We come back to awscli,
1:20 05-31. Ah let's good, to kombu,
1:24 05-30 and so on.
1:28 Pretty cool. Now we've got that last query written and working beautifully.