Transactions and low-level SQL
ORM methods that are called from a client run in a transaction. Transactions ensure correctness in the case of concurrent writes or failures. During a transaction, the data records used are locked, protecting them from other concurrent transactions and ensuring that they are not unexpectedly changed. In case of failure, all the transaction changes are rolled back, returning to the initial state.
Transaction support is provided by the PostgreSQL database. When an ORM method is called from a client, a new transaction is initiated. If an error occurs during the method execution, any changes that have been made are reverted. If the method execution completes with no errors, then the changes made are committed, making them effective and visible to all other transactions.
This is automatically handled for us, and we usually don't need to worry about it. However, in some advanced use cases, it might be useful to have control over the current transaction...