Building Data-Driven Web Apps with Pyramid and SQLAlchemy Transcripts
Chapter: Using SQLAchemy
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
0:03 like we always do, we get a session, and then we
0:05 retrieve one or more records from the database.
0:08 Here we're just getting one package.
0:10 We're going to get this package back, and if we make
0:12 changes to it, so we set the author value to a new name
0:16 and we set the author email to a new email
0:18 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
0:29 save it, 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, then we're going to
0:37 commit the unit to work, and it's going to look
0:39 at the changes, do all the changes in a single
0:42 transaction, back to the database.
0:44 We use the unit of work to do
0:46 our updates just like we do the inserts.