#100DaysOfWeb in Python Transcripts
Chapter: Days 33-36: Database access with SQLAlchemy
Lecture: Setting up our app

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Here we are in our GitHub repository for this chapter.
0:03 Let's get our app set up.
0:04 We're going to start from just a little bit of code
0:06 so we stay focused on the database sides of things
0:08 instead of all the user interaction stuff
0:10 that I'm going to write.
0:11 Let's go over here to the starter.
0:13 It's empty right now.
0:14 I'm going to set up a little bit of this for you
0:17 and then make a snapshot so if you want to pick up from there
0:19 and keep going, that'd be great.
0:21 So we're going to go over to that folder
0:23 and as always create a virtual environment
0:26 for installing third-party packages
0:28 let's stay focused on just the ones we need.
0:35 Should be good.
0:37 Now we're going to need a couple of utility libraries
0:39 to get started, so I'm just going to put those in here.
0:42 So over here we have this switch statement thing
0:44 that I'm going to use and this thing for parsing
0:46 numbers a little more nicely and the ability
0:50 to locate our database folder, we're going to use
0:52 SQLite which means we're just going to have a
0:54 file living here, we're not using what you might call
0:57 a proper database server.
0:59 What we're doing here will exactly work on things
1:02 like Postgres and MySQL and so on.
1:05 It just so happens it's easier for you
1:07 to pick up this project and use SQLite 'cause
1:09 I don't have to give you lots of instructions
1:11 on how to set up the database
1:13 how to set it up so it's at the right location
1:15 so it has the right permissions.
1:17 You can just run it.
1:18 So we're going to use SQLite 'cause it's simple
1:20 but what you learn here will apply to all the databases.
1:23 And finally, because we're using SQLite
1:25 we added that as a requirement, so let's go ahead
1:27 and install that.
1:33 Okay, looks like it's all good for the foundations
1:36 and then the last thing I want to do is add
1:37 the actual program that we're going to write
1:39 and I'll call it program just so it's clear
1:41 what we're going to run and go ahead and run it
1:43 to create a run configuration up here.
1:46 Obviously it does nothing.
1:48 But, I do want to get the structure in place.
1:50 Let's talk about that really quick.
1:52 So, over here, we're going to have a main method
1:55 it's going to set up the database
1:57 and then it's going to go through this loop
1:59 over and over asking for a command
2:01 and then using my little switch statement
2:03 that I created.
2:04 Get this in GitHub if you care.
2:06 Or you obviously have it here as well.
2:08 It'll say if they typed in r, run the method.
2:11 Rent a scooter.
2:12 If they typed in a, run the method.
2:14 Find available scooters.
2:15 If they hit x or nothing, exit the app, things like that.
2:20 And it's just going to go along and run
2:22 these various methods, none of which have
2:24 any implementation other than just a little bit
2:26 of printout and even
2:28 a cool little misspelling there.
2:30 So, we're going to run this.
2:32 And I'll just show you the interaction.
2:33 There's zero database stuff going on right?
2:36 This is just a little user interaction here
2:38 so we could say I'd like to locate my scooters.
2:40 It says, here's your scooters.
2:42 I'd like to see my personal history.
2:43 It says here's your rental history.
2:45 I could say boo it says I don't know what to do with Boo
2:47 I could hit X and we're done.
2:49 So this is where we're starting from.
2:51 We have this structure of the sort of interactive
2:55 command line interface.
2:57 And then we have these methods that are going to
2:58 do the database thing.
3:00 Now, one thing you might notice is
3:01 this is not a web app.
3:03 We're talking about databases because databases are
3:06 the foundation of web applications.
3:09 However, I wanted to start
3:11 just from the pure data access side of things.
3:14 So we're going to do it in a command line interface
3:16 that has nothing to do with HTML and CSS and views
3:19 and forms and all of that.
3:21 We're just going to do the simple
3:22 command line interface here
3:24 and then part of your project may be to
3:26 adapt it to the web, but once you learn
3:29 how to use SQLAlchemy, it doesn't matter
3:30 if it's a web app or not.
3:32 Right, now you just write the same code.
3:35 So this lets us focus on just the
3:36 data access side of things.