| 483 | /// If the function returns an error, the transaction will be rolled back. If it does not return an error, the transaction will be committed. |
| 484 | #[instrument(level = "trace", skip(_callback))] |
| 485 | async fn transaction<F, T, E>(&self, _callback: F) -> Result<T, TransactionError<E>> |
| 486 | where |
| 487 | F: for<'c> FnOnce( |
| 488 | &'c DatabaseTransaction, |
| 489 | ) -> Pin<Box<dyn Future<Output = Result<T, E>> + Send + 'c>> |
| 490 | + Send, |
| 491 | T: Send, |
| 492 | E: std::fmt::Display + std::fmt::Debug + Send, |
| 493 | { |
| 494 | let transaction = self.begin().await.map_err(TransactionError::Connection)?; |
| 495 | transaction.run(_callback).await |
| 496 | } |
| 497 | |
| 498 | /// Execute the function inside a transaction with isolation level and/or access mode. |
| 499 | /// If the function returns an error, the transaction will be rolled back. If it does not return an error, the transaction will be committed. |