November 2023
Beginner to intermediate
80 pages
2h 1m
English
If you are experienced with SQL-based databases, you may be wondering where database transactions fit in. If you aren’t, a database transaction is a useful tool related to idempotence. A database transaction allows you to make many changes to a database and then apply them all at once. If anything should go wrong attempting to apply the changes, none of the changes are made. It’s extremely handy, though it can’t help as often as you might like and can have unintended performance consequences if you aren’t careful.
As an example of how it works, suppose we want to reduce the hypothetical quantity_remaining of the product being ordered. You might do this by writing this code:
| | product.update! ... |
Read now
Unlock full access