Transaction

Struct Transaction 

Source
pub struct Transaction<'a, K, V>{ /* private fields */ }

Implementations§

Source§

impl<'a, K, V> Transaction<'a, K, V>

Source

pub fn commit(self) -> IsamResult<()>

Flush store and index to disk (fsync) and release the database lock.

After commit returns the changes are durable and the lock is released, allowing other threads to begin their own transactions.

§Example
let mut txn = db.begin_transaction().unwrap();
db.insert(&mut txn, 1u32, &"hello".to_string()).unwrap();
txn.commit().unwrap();

// Data is now durable — visible after reopen.
let db2: Isam<u32, String> = Isam::open(&path).unwrap();
let mut txn2 = db2.begin_transaction().unwrap();
assert_eq!(db2.get(&mut txn2, &1u32).unwrap(), Some("hello".to_string()));
txn2.commit().unwrap();
Source

pub fn rollback(self) -> IsamResult<()>

Roll back all changes made in this transaction and release the lock.

The undo log is applied in reverse order, restoring the index to the state it had before the transaction began. Dropping a Transaction without calling commit has the same effect automatically.

§Example
let mut txn = db.begin_transaction().unwrap();
db.insert(&mut txn, 1u32, &"oops".to_string()).unwrap();
txn.rollback().unwrap();

// Insert was rolled back — key is absent.
let mut txn2 = db.begin_transaction().unwrap();
assert_eq!(db.get(&mut txn2, &1u32).unwrap(), None);
txn2.commit().unwrap();

Trait Implementations§

Source§

impl<'a, K, V> Drop for Transaction<'a, K, V>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'a, K, V> Freeze for Transaction<'a, K, V>

§

impl<'a, K, V> RefUnwindSafe for Transaction<'a, K, V>

§

impl<'a, K, V> !Send for Transaction<'a, K, V>

§

impl<'a, K, V> !Sync for Transaction<'a, K, V>

§

impl<'a, K, V> Unpin for Transaction<'a, K, V>
where K: Unpin, V: Unpin,

§

impl<'a, K, V> UnwindSafe for Transaction<'a, K, V>
where K: UnwindSafe, V: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.