Python-powered Chat Apps with Twilio and SendGrid Transcripts
Chapter: Course conclusion and review
Lecture: Review: SQLAlchemy model class

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Eventually we wanted to save the information that we got from twilio and all the computation that we did. Save that into a database.
0:09 We're going to use that for admin backend We're going to use that later for probably when a customer comes into the store and
0:14 we pull it up on our application and say, Oh yeah, here's the order and we're ready to hand your cake over and so on. So in order to do that,
0:22 we use SQLAlchemy. Instead of going straight to the database and defining the tables there, we said, Well,
0:27 let's define some classes, in this case, a user class that derives from SQLalchemy base
0:32 And we said it's going to correspond through the Dunder table name over to the
0:37 users table in the database, and we mapped out the columns as fields in the classes with SQLalchemy column types.
0:43 So, for example, the 'id' is a string and code, but in practice and SQLAlchemy Landed, it's a SQLAlchemy column, which is a SQLAlchemy string.
0:52 It's a primary key, and in this case it has a default id of some arbitrary uuid, we're generating we have created date.
0:59 It's datetime. It has the default of datetime. Now, now be really careful. You don't want now parentheses just now. The function with the name, phone,
1:09 email and so on. And we also have orders. And we created a relationship which was very useful in binding our orders and our users
1:18 together encode, for example, when we wanted to insert an order into the data base, we just found the users,
1:23 put it onto the order, object and SQLAlchemy to put that into the database.
1:28 That's it. When I create a couple classes and SQLAlchemy will actually create the tables for us. When it first sees those classes,
1:34 Just remember it won't propagate changes after it's already created the table.


Talk Python's Mastodon Michael Kennedy's Mastodon