Building Data-Driven Web Apps with Pyramid and SQLAlchemy Transcripts
Chapter: Using SQLAchemy
Lecture: Concept: Database updates
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 from the database.
0:09 Here we're just getting one package. We're going to get this package back, and if we make changes to it, so we set the author value to a new name
0:17 and 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 to work, and it's going to look
0:40 at the changes, do all the changes in a single transaction, back to the database. We use the unit of work to do
0:47 our updates just like we do the inserts.