Struct surrealkv::Transaction

source ·
pub struct Transaction { /* private fields */ }
Expand description

Transaction is a struct representing a transaction in a database.

Implementations§

source§

impl Transaction

source

pub fn new(core: Arc<Core>, mode: Mode) -> Result<Self>

Prepare a new transaction in the given mode.

source

pub fn mode(&self) -> Mode

Returns the transaction mode.

source

pub fn set_durability(&mut self, durability: Durability)

Sets the durability level of the transaction.

source

pub fn set(&mut self, key: &[u8], value: &[u8]) -> Result<()>

Adds a key-value pair to the store.

source

pub fn set_at_ts(&mut self, key: &[u8], value: &[u8], ts: u64) -> Result<()>

Adds a key-value pair to the store with the given timestamp.

source

pub fn delete(&mut self, key: &[u8]) -> Result<()>

source

pub fn clear(&mut self, key: &[u8]) -> Result<()>

Clear the key but not delete it. This is a soft delete.

source

pub fn get(&self, key: &[u8]) -> Result<Option<Vec<u8>>>

Gets a value for a key if it exists.

source

pub fn scan<'b, R>( &'b self, range: R, limit: Option<usize>, ) -> Result<Vec<(Vec<u8>, Vec<u8>, u64, u64)>>
where R: RangeBounds<&'b [u8]>,

Scans a range of keys and returns a vector of tuples containing the value, version, and timestamp for each key.

source

pub async fn commit(&mut self) -> Result<()>

Commits the transaction, by writing all pending entries to the store.

source

pub fn rollback(&mut self)

Rolls back the transaction by removing all updated entries.

source

pub fn set_savepoint(&mut self) -> Result<()>

After calling this method the subsequent modifications within this transaction can be rolled back by calling rollback_to_savepoint.

This method is stackable and can be called multiple times with the corresponding calls to rollback_to_savepoint.

source

pub fn rollback_to_savepoint(&mut self) -> Result<()>

Rollback the state of the transaction to the latest savepoint set by calling set_savepoint.

source§

impl Transaction

Implement Versioned APIs for read-only transactions.

source

pub fn get_at_ts(&self, key: &[u8], ts: u64) -> Result<Option<Vec<u8>>>

Returns the value associated with the key at the given timestamp.

source

pub fn get_history(&self, key: &[u8]) -> Result<Vec<(Vec<u8>, u64)>>

Returns all the versioned values and timestamps associated with the key.

source

pub fn scan_at_ts<'b, R>( &'b self, range: R, ts: u64, limit: Option<usize>, ) -> Result<Vec<(Vec<u8>, Vec<u8>)>>
where R: RangeBounds<&'b [u8]>,

Returns key-value pairs within the specified range, at the given timestamp.

source

pub fn keys_at_ts<'b, R>(&'b self, range: R, ts: u64) -> Result<Vec<Vec<u8>>>
where R: RangeBounds<&'b [u8]>,

Returns keys within the specified range, at the given timestamp.

source

pub fn get_value_by_query( &self, key: &VariableSizeKey, query_type: QueryType, ) -> Result<(Bytes, u64, u64)>

Returns the value associated with the key at the given timestamp. The query type specifies the type of query to perform. The query type can be LatestByVersion, LatestByTs, LastLessThanTs, LastLessOrEqualTs, FirstGreaterOrEqualTs or FirstGreaterThanTs.

Trait Implementations§

source§

impl Drop for Transaction

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

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.