First page Back Continue Last page Overview Graphics


Notes:

The only way to use transactions with Sequel is through the database object's transaction method.

It takes a block and ensures that all database interaction inside the block uses the same database connection inside a database transaction.

This is necessary if you are making changes to the database and want to ensure that either all changes are made or no changes are made.

In the example on the screen, we want to add an accounting entry to the database, and update the account balance at the same time.

Since we shouldn't be inserting an entry unless the account balance is updated, we use a database transaction to ensure that either both statements are successful, or neither are.