From 1f4d501ecb14de81dd7bf4da13b264f47ced9ed4 Mon Sep 17 00:00:00 2001 From: Alexander Sandor Date: Thu, 12 Dec 2024 15:29:55 +0100 Subject: [PATCH] fix: improve transaction description correctness. --- docs/06-concepts/06-database/08-transactions.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/06-concepts/06-database/08-transactions.md b/docs/06-concepts/06-database/08-transactions.md index 3b9b08ec..0aa3b9a7 100644 --- a/docs/06-concepts/06-database/08-transactions.md +++ b/docs/06-concepts/06-database/08-transactions.md @@ -2,7 +2,9 @@ The essential point of a database transaction is that it bundles multiple steps into a single, all-or-nothing operation. The intermediate states between the steps are not visible to other concurrent transactions, and if some failure occurs that prevents the transaction from completing, then none of the steps affect the database at all. -Serverpod handles database transactions through the `session.db.transaction` method. The transaction takes a method that performs any database queries or other operations and optionally returns a value. +Serverpod handles database transactions through the `session.db.transaction` method. The method takes a callback function that receives a transaction object. The transaction object is then passed to any database operation to be included in the same transaction. + +The transaction is committed when the callback function returns, and rolled back if an exception is thrown. Any return value of the callback function is returned by the `transaction` method. Simply pass the transaction object to each database operation method to include them in the same atomic operation: