Function transaction_with_pool

Source
pub fn transaction_with_pool<F, T>(operations: F) -> Result<T, Error>
where F: FnOnce(&mut Client) -> Result<T, Error>,
Expand description

Transaction functions for PostgreSQL using the connection pool

These functions provide a way to execute queries within a transaction using the connection pool. The transaction is automatically committed when the function returns successfully, or rolled back if an error occurs.

Example:

use sal_postgresclient::{transaction_with_pool, QueryParams};

let result = transaction_with_pool(|client| {
    // Execute queries within the transaction
    client.execute("INSERT INTO users (name) VALUES ($1)", &[&"John"])?;
    client.execute("UPDATE users SET active = true WHERE name = $1", &[&"John"])?;

    // Return a result from the transaction
    Ok(())
});