surrealkv

Struct 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 insert_or_replace(&mut self, key: &[u8], value: &[u8]) -> Result<()>

Inserts if not present or replaces an existing key-value pair.

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<()>

Delete all the versions of a key. This is a hard delete. This will remove the key from the index and disk.

Source

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

Mark all versions of a key as deleted. This is a soft delete, and does not remove the key from the index, or disk, rather just marks it as deleted, and the key will remain hidden.

Source

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

Gets a value for a key if it exists.

Source

pub fn scan<'b, R>( &'b mut 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. These APIs do not take part in conflict detection.

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<Option<(Vec<u8>, 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.

Source

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

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

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.