pub async fn begin(client: &mut Client) -> Result<Transaction<'_>, Error>
Expand description
§begin
Starts a new database transaction from a pool client.
§Parameters
client
: Pool client to start the transaction from
§Return Value
Result<Transaction<'_>, Error>
: On success, returns the new transaction
§Example Usage
use tokio_postgres::{NoTls, Error};
use deadpool_postgres::{Config, Runtime};
use parsql::deadpool_postgres::transactional::begin;
#[tokio::main]
async fn main() -> Result<(), Error> {
let mut cfg = Config::new();
cfg.host = Some("localhost".to_string());
cfg.dbname = Some("test".to_string());
let pool = cfg.create_pool(Some(Runtime::Tokio1), NoTls)?;
let mut client = pool.get().await?;
let tx = begin(&mut client).await?;
// Now you can use the transaction
// Commit the transaction
tx.commit().await?;
Ok(())
}