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