use super::{notify, Connection, Result, TransactionConfig};
impl Connection {
pub async fn begin(&mut self) -> Result<()> {
self.begin_with(TransactionConfig::new()).await
}
pub async fn begin_with(&mut self, config: TransactionConfig) -> Result<()> {
self.simple_query(&config.begin_sql()).await?;
Ok(())
}
pub async fn commit(&mut self) -> Result<()> {
self.simple_query("COMMIT").await?;
Ok(())
}
pub async fn rollback(&mut self) -> Result<()> {
self.simple_query("ROLLBACK").await?;
Ok(())
}
pub async fn savepoint(&mut self, name: &str) -> Result<()> {
self.simple_query(&format!("SAVEPOINT {}", notify::quote_identifier(name)))
.await?;
Ok(())
}
pub async fn rollback_to(&mut self, name: &str) -> Result<()> {
self.simple_query(&format!(
"ROLLBACK TO SAVEPOINT {}",
notify::quote_identifier(name)
))
.await?;
Ok(())
}
}