Python-powered chat apps with Twilio and SendGrid Transcripts
Chapter: Appendix: Using SQLAlchemy
Lecture: Connecting to the database (again)
Login or purchase this course to watch this video and the rest of the course contents.
0:00 Now what we're going to need to do is work with our SQLAlchemy engine and the factory and the connections and all that.
0:07 And remember in order for that to work we have to go to our db_session. We have to initialize it. So let me just copy over a function here.
0:14 This was just like the one we worked with before. So we're going to import os. import pypi.org and we can say that's spelled correctly.
0:25 And we also want our db_session like so. And now it has this global_init. So, we just have to call this somewhere.
0:36 Before we try to do anything, and just to remind you over here this sets up the connection string initializes the engine, and most importantly
0:45 initializes this factory right here. So, what we're going to do is we're going to have a def main. Here this is going to be like our main startup.
0:52 And in here we'll call global_init for the database. And we'll use our main convention at the bottom and just run the main function. Here we go.
1:03 I guess we can go ahead and test it and see that it runs. Oh, it didn't like that. Let's just use this in here we'll just go up one.
1:15 That should do. Okay, great. So here we're connecting to final, dah dah dah. It might even be worthwhile to say os.path.abspath. Here we go.
1:33 Now we have the absolute path, in looks right to me.