rs_zero/db/transaction.rs
1use std::future::Future;
2
3use crate::db::{DatabasePool, DatabaseResult};
4
5/// Runs a function with a database pool.
6///
7/// The MVP keeps the helper pool-based so generated repositories can stay
8/// independent from SQLx transaction lifetime details while still testing
9/// commit/rollback behavior through explicit SQL.
10pub async fn run_transaction<F, Fut, T>(pool: &DatabasePool, operation: F) -> DatabaseResult<T>
11where
12 F: FnOnce(DatabasePool) -> Fut,
13 Fut: Future<Output = DatabaseResult<T>>,
14{
15 operation(pool.clone()).await
16}