1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
//! This module holds the definition of transactions
use crate::{internal, Error};
/**
Transactions can be used to provide a safe way to execute multiple SQL operations
after another with a way to go back to the start without something changed in the
database.
Can be obtained using [crate::Database::start_transaction].
*/
pub struct Transaction<'db> {
pub(crate) tx: internal::transaction::Impl<'db>,
}
impl<'db> Transaction<'db> {
/// This function commits the transaction.
pub async fn commit(self) -> Result<(), Error> {
internal::transaction::commit(self).await
}
/// Use this function to abort the transaction.
pub async fn rollback(self) -> Result<(), Error> {
internal::transaction::rollback(self).await
}
}