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