rs-zero 0.2.7

Rust-first microservice framework inspired by go-zero engineering practices
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
}