Expand description
Request-scoped PostgreSQL transactions for axum.
This crate provides a Tower Layer and Service
that automatically manage request-scoped PostgreSQL transactions using
either bb8-postgres or deadpool-postgres. Handlers can extract a
Tx to access the transaction; it is committed automatically
when the response is sent.
§Examples
use axum::extract::State;
use axum_postgres_tx::Tx;
async fn handler(State(pool): State<axum_postgres_tx::pool::Pool>, Tx(tx): Tx) -> String {
let row = tx.query_one("SELECT 1", &[]).await.unwrap();
format!("{}", row.get::<_, i32>(0))
}Modules§
- layer
- Tower
LayerandServicefor managing request-scoped PostgreSQL transactions. - pool
- Re-exported pool types for use in application state. Pool type re-exports.
- tx
- The
Txextractor for accessing the current transaction.
Enums§
- Error
- Errors that can occur when using this crate.