use crate::connection::ConnectionRef;
use crate::{Error, IsolationLevel, Transaction};
pub struct TransactionBuilder<'a> {
connection: ConnectionRef<'a>,
builder: tokio_postgres::TransactionBuilder<'a>,
}
impl<'a> TransactionBuilder<'a> {
pub(crate) fn new(
connection: ConnectionRef<'a>,
builder: tokio_postgres::TransactionBuilder<'a>,
) -> TransactionBuilder<'a> {
TransactionBuilder {
connection,
builder,
}
}
pub fn isolation_level(mut self, isolation_level: IsolationLevel) -> Self {
self.builder = self.builder.isolation_level(isolation_level);
self
}
pub fn read_only(mut self, read_only: bool) -> Self {
self.builder = self.builder.read_only(read_only);
self
}
pub fn deferrable(mut self, deferrable: bool) -> Self {
self.builder = self.builder.deferrable(deferrable);
self
}
pub fn start(mut self) -> Result<Transaction<'a>, Error> {
let transaction = self.connection.block_on(self.builder.start())?;
Ok(Transaction::new(self.connection, transaction))
}
}