Full Web Apps with FastAPI 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 we start like we always do, we get a session. And then we retrieve one or more records form the database.
0:09 Here we're just getting one package. When I get this package back, and if we make changes to it so we set the author value to a new name
0:17 we set the author email to a new email SQLAlchemy will track within the session that that record is dirty and it needs to be updated
0:26 because we've changed some fields. And then, when we're ready to actually save it push all the changes back.
0:33 I could apply this to as many entities as we'd like it doesn't have to just be one. Then we're going to commit the unit of work
0:39 and it's going to look at the changes do all the changes in a single transaction back to the database. We use the unit of work to do our updates
0:48 just like we do the inserts.


Talk Python's Mastodon Michael Kennedy's Mastodon