#100DaysOfWeb in Python Transcripts
Chapter: Days 33-36: Database access with SQLAlchemy
Lecture: The database is created
0:00 Lets look at our main now. So heres our main method in our program and this stuff UI loop if you can call it that. It goes around and around
0:08 and asks the user what they want but first thing we have to do is setup the DB. Now I've thrown in a few little to-dos
0:14 to remind me what this means in the right order. So what we are going to do is we're actually going to have to
0:19 initialize the connection by calling global_init. Make sure the table schema is there call it a second time SQLAlchemy will just verify
0:27 that things are set up okay. And then we actually want to import some data eventually and set what's called the default user.
0:35 That will basically be whoever is logged in. So lets go over here and say, session_factory and import that at the top and say global_init
0:44 and what do we call it hover_share.sqlite called DB SQLite name doesn't actually matter. This line should actually
0:54 have the database created right here. You'll see it appear and that's a folder but it will have no schema. It'll have, just be an empty database okay?
1:02 The next thing we need to do is go to session_factory and say create_tables. Then I'm going to leave these other two things here
1:09 because we are not ready for those yet. Let's run this and see what happens. Well this is already a good sign
1:16 the fact that it did that without crashing that's like hurray. Now if we look over here we now have this thing popping up
1:24 and it has a little database icon see that blue icon? That didn't come from the file extension that came from PyCharm looking at
1:31 and going Ah-ha I understand what's in that file it is a database a SQLite database, Professional Community Edition this doesn't work for
1:40 so professional we go over here to the database we can drop this here and we can open it up and look at it. Now notice it didn't really work
1:48 hmm why didn't it work? Lets hit this. It says the driver is SQLite except for there are no drivers for it so you got to download them
1:56 wait a moment. Now we can click test success. Go okay hit the little refresh now we have a schema. We open up our schema
2:07 we have a main and look at that locations, rentals, scooters what's in here? Open it up, oh it has an id which you can see there's a primary key
2:15 these yellow vertical things mean those have indexes all sorts of good stuff. And this is an integer and this is a varchar
2:22 and things like that. This is the datetime so it looks like SQLAlchemy has properly created our database schema based on our classes.
2:31 Yay! Put that away so that part is pretty much up and running.