#100DaysOfCode in Python Transcripts
Chapter: Days 91-93: Database access with SQLAlchemy
Lecture: Demo: The app skeleton
Login or
purchase this course
to watch this video and the rest of the course contents.
0:00
So, you saw the game being played. Let's look at the code that we're going to work with. We're going to come here to our main method and programs.
0:08
This is where it all gets started. So, we'll print out the header, we'll print the high scores. Right now there are no high scores 'cause
0:14
we have no memory of stuff. So there's not going to be a whole lot happenin' there. We're going to build up the roles and now,
0:20
this is worth checking out. Over here, in this battle CSV, we actually have the sort of win-lose table for rocks, guns, lightening and
0:29
if it, you know, the lightening attacks the devil then apparently the devil beats, the devil beats lightening. Alright, something to this effect.
0:37
We're going to use that, we're going to build up these roles and sort of indicate which thing can be which.
0:42
We're going to create a couple players and then, we're going to go to this game loop thing and say, "Run."
0:47
So we have three parts of the game happening over there. Notice here we're just pulling in this CSV file and we're
0:53
allocating a row object, which we'll talk about in a second. And here we're just putting in some more details to
0:59
figure out what opponents this thing loses or wins to. Here's a little header. And here's the high scores.
1:06
So, let's go ahead and start by looking at this game service. This is where much of the database access is going to happen.
1:11
So you can see all those little parts here basically become database queries or inserts or updates.
1:16
So, here we're going to go do a query and find all the roles. Here we're going to find one for, a particular name. So, Devil, for example.
1:26
Here we're going to record a move given by a particular player, a particular role, that was their move, the game id,
1:34
whether that won the game, if it was the final game play. what stage in... you know, what step in that particular game. Was it 1, 2, 3, 4 or 5?
1:43
As we saw, the 5 that we played with. So, we're going to go. Basically our job during this section is to use SQLAlchemy to fill out this section here.
1:50
And, over in the models we have things like a role, which has almost nothing on it right now. This is like Devil or so on. We have some moves.
1:58
And this is more interesting. This is like a history. So this is like, what role did they play by id,
2:04
what game is this associated with, uhm, what position. Right, this is what we're just looking at there.
2:09
So, we're going to convert these standard classes into classes that map to our database using SQLAlchemy. So, I think that's a good place to start.
2:17
And, we'll do that next.