(
&self,
operation: &str,
work: impl std::future::Future<Output = Result<T>>,
)
| 4 | |
| 5 | impl Database { |
| 6 | pub(super) async fn with_batch_transaction<T>( |
| 7 | &self, |
| 8 | operation: &str, |
| 9 | work: impl std::future::Future<Output = Result<T>>, |
| 10 | ) -> Result<T> { |
| 11 | self.conn() |
| 12 | .execute("BEGIN", ()) |
| 13 | .await |
| 14 | .map_err(|e| TraceDecayError::Database { |
| 15 | message: format!("failed to begin: {e}"), |
| 16 | operation: operation.to_string(), |
| 17 | })?; |
| 18 | |
| 19 | match work.await { |
| 20 | Ok(value) => { |
| 21 | if let Err(e) = self.conn().execute("COMMIT", ()).await { |
| 22 | let _ = self.conn().execute("ROLLBACK", ()).await; |
| 23 | return Err(TraceDecayError::Database { |
| 24 | message: format!("failed to commit: {e}"), |
| 25 | operation: operation.to_string(), |
| 26 | }); |
| 27 | } |
| 28 | Ok(value) |
| 29 | } |
| 30 | Err(e) => { |
| 31 | let _ = self.conn().execute("ROLLBACK", ()).await; |
| 32 | Err(e) |
| 33 | } |
| 34 | } |
| 35 | } |
| 36 | } |
no test coverage detected