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
0:04 that we did. Save that into a database.
0:08 We're going to use that for admin backend
0:10 We're going to use that later for probably when a customer comes into the store and
0:13 we pull it up on our application and say,
0:15 Oh yeah, here's the order and we're ready to hand your cake over and so
0:19 on. So in order to do that,
0:21 we use SQLAlchemy. Instead of going straight to the database and defining the tables
0:26 there, we said, Well, let's define some classes, in this case, a user class that derives from SQLalchemy base
0:31 And we said it's going to correspond through the Dunder table name over to the
0:36 users table in the database, and we mapped out the columns as fields in the
0:40 classes with SQLalchemy column types.
0:42 So, for example, the 'id' is a string and code,
0:46 but in practice and SQLAlchemy Landed,
0:48 it's a SQLAlchemy column, which is a SQLAlchemy string.
0:51 It's a primary key, and in this case it has a default id of some
0:55 arbitrary uuid, we're generating we have created date.
0:58 It's datetime. It has the default of datetime.
1:01 Now, now be really careful.
1:03 You don't want now parentheses just now.
1:06 The function with the name, phone,
1:08 email and so on. And we also have orders.
1:11 And we created a relationship which was very useful in binding our orders and our users
1:17 together encode, for example, when we wanted to insert an order into the data
1:20 base, we just found the users,
1:22 put it onto the order, object and SQLAlchemy
1:24 to put that into the database.
1:27 That's it. When I create a couple classes and SQLAlchemy will actually create the
1:30 tables for us. When it first sees those classes,
1:33 Just remember it won't propagate changes after it's already created the table.