Asynchronous and synchronous Postgres protocol transaction retries.
Providing a mechanism for serialized transaction retries for PostgresSQL compatible databases in Rust.
The closure over the transaction must return an error that implements
Into<postgres_tx_retry::Error<E>>
and for serialization failure determination,
your error type should implement (depending on enabled features):
From<deadpool::managed::PoolError<tokio_postgres::Error>>
From<tokio_postgres::Error>
From<r2d2::Error>
A basic error type might be:
```rust
pub enum MyError {
Pool(deadpool::managed::PoolError
impl Into
impl
```rust let values = Arc::new("London"); let population = tx(&pool, COCKROACH_SAVEPOINT, |tx| { let values = values.clone();
Box::pin(async move {
let name = values.as_ref();
let row = tx
.query_one(
"SELECT population FROM city WHERE name = $1",
&[&name],
)
.await?;
Ok(row.get(0))
})
}) .await?; ```
```rust let name = "London"; let population = txsync(&db, COCKROACHSAVEPOINT, |tx| { let row = tx.query_one( "SELECT population FROM city WHERE name = $1", &[&name], )?;
Ok(row.get(0))
})?; ```