Full Web Apps with FastAPI Transcripts
Chapter: Storing data with SQLAlchemy
Lecture: Package details queries

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Well we've got this page working really well out of the database. Let's click on this. Oh, well, maybe that one is not working yet.
0:06 The project details. So what we've got to do is, we've got to go and actually get this thing to work.
0:11 So let's just jump in here real quick and see what the problem is. It said, oh, you passed a bunch of arguments, that doesn't really work for
0:17 SQLAlchemy anymore. So we could really quickly fix this by saying some of these values, just, if you specify the key names we'd be good to go.
0:26 This is gonna be description, this'll be home_page url, we've got the license, and this'll be the author_name. All right, so that should make it run.
0:36 I guess the same problem is true for releases, created_date, OK. Oh, yeah. We've also got to pull out the version here,
0:43 so let's just do a little f-string. Really, I just don't want to write that same thing a lot. So let's just say
0:52 f"{r.major_version}.{r.minor_version}.{r.build_version}", All right, so that's the same thing we're trying to get out there.
0:59 Okay, so we've got it working, sort of, didn't we? This is live, this is live. All this stuff is fake. All of those things are fake.
1:06 So actually, this may also be fake, right here. I'm not entirely sure, but definitely everything else is fake here.
1:10 So what we need to do is write the queries to make this page go, don't we? So let's just go through like we did before.
1:17 Go through the view model and say were we're getting the stuff. So the package name is being passed over, that's great. And it's get_package_by_id
1:22 Yeah, this is the one we "fixed". We made it run, but this is certainly not what we're wanting to do.
1:29 Let me just grab this real quick here because it's gonna give us a lot of what we need to work with. We're gonna go over here and do a query
1:37 against a Package. I don't know why I grabbed the most complicated one. We'll do a query against the package, and what we've got to say is filter
1:53 and, what do we want? the id is the package_name so we'll say Package.id == package_name, then first(). Just the one, we'll return package.
2:07 Perfect, let's see what's gonna happen here. It's gonna work? Oh, yes. So let's just see. this is working.
2:14 Check this out. So we've got this whole thing coming back and working. You ca see this is the latest version. The release was that, I guess,
2:21 is probably when we inserted it. Let's go back over here, click on gevent, perfect. Got our gevent, all the details, were not actually converting
2:30 the, cause that's Markdown, that's restructured text, were not rendering the restructured text as HTML, kind of a pain. If we did,
2:37 then you know, would come out great, but see the license is MIT. If we click in the Homepage,
2:42 it really takes us over to gevent, where they probably need an SSL certificate. But nonetheless, this thing is working great,
2:48 right? So we've got our home page, and now we've got our details page working as well.


Talk Python's Mastodon Michael Kennedy's Mastodon