Python-powered chat apps with Twilio and SendGrid Transcripts
Chapter: Appendix: Using SQLAlchemy
Lecture: Concept: Database updates

Login or purchase this course to watch this video and the rest of the course contents.
0:00 In order to update existing data
0:02 we start like we always do, we get a session.
0:05 And then we retrieve one or more records form the database.
0:08 Here we're just getting one package.
0:10 When I get this package back, and if we make changes to it
0:13 so we set the author value to a new name
0:16 we set the author email to a new email
0:19 SQLAlchemy will track within the session that
0:22 that record is dirty and it needs to be updated
0:25 because we've changed some fields.
0:27 And then, when we're ready to actually save it
0:30 push all the changes back.
0:32 I could apply this to as many entities as we'd like
0:34 it doesn't have to just be one.
0:36 Then we're going to commit the unit of work
0:38 and it's going to look at the changes
0:40 do all the changes in a single transaction
0:42 back to the database.
0:44 We use the unit of work to do our updates
0:47 just like we do the inserts.