use std::future::Future;

use crate::db::{DatabasePool, DatabaseResult};

/// Runs a function with a database pool.
///
/// The MVP keeps the helper pool-based so generated repositories can stay
/// independent from SQLx transaction lifetime details while still testing
/// commit/rollback behavior through explicit SQL.
pub async fn run_transaction<F, Fut, T>(pool: &DatabasePool, operation: F) -> DatabaseResult<T>
where
    F: FnOnce(DatabasePool) -> Fut,
    Fut: Future<Output = DatabaseResult<T>>,
{
    operation(pool.clone()).await
}
