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
impl Transaction
sourcepub fn new(core: Arc<Core>, mode: Mode) -> Result<Self>
pub fn new(core: Arc<Core>, mode: Mode) -> Result<Self>
Prepare a new transaction in the given mode.
sourcepub fn set_durability(&mut self, durability: Durability)
pub fn set_durability(&mut self, durability: Durability)
Sets the durability level of the transaction.
sourcepub fn set(&mut self, key: &[u8], value: &[u8]) -> Result<()>
pub fn set(&mut self, key: &[u8], value: &[u8]) -> Result<()>
Adds a key-value pair to the store.
sourcepub fn set_at_ts(&mut self, key: &[u8], value: &[u8], ts: u64) -> Result<()>
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.
pub fn delete(&mut self, key: &[u8]) -> Result<()>
sourcepub fn clear(&mut self, key: &[u8]) -> Result<()>
pub fn clear(&mut self, key: &[u8]) -> Result<()>
Clear the key but not delete it. This is a soft delete.
sourcepub fn scan<'b, R>(
&'b self,
range: R,
limit: Option<usize>,
) -> Result<Vec<(Vec<u8>, Vec<u8>, u64, u64)>>where
R: RangeBounds<&'b [u8]>,
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.
sourcepub async fn commit(&mut self) -> Result<()>
pub async fn commit(&mut self) -> Result<()>
Commits the transaction, by writing all pending entries to the store.
sourcepub fn set_savepoint(&mut self) -> Result<()>
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
.
sourcepub fn rollback_to_savepoint(&mut self) -> Result<()>
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
impl Transaction
Implement Versioned APIs for read-only transactions.
sourcepub fn get_at_ts(&self, key: &[u8], ts: u64) -> Result<Option<Vec<u8>>>
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.
sourcepub fn get_history(&self, key: &[u8]) -> Result<Vec<(Vec<u8>, u64)>>
pub fn get_history(&self, key: &[u8]) -> Result<Vec<(Vec<u8>, u64)>>
Returns all the versioned values and timestamps associated with the key.
sourcepub 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]>,
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.
sourcepub fn keys_at_ts<'b, R>(&'b self, range: R, ts: u64) -> Result<Vec<Vec<u8>>>where
R: RangeBounds<&'b [u8]>,
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.
sourcepub fn get_value_by_query(
&self,
key: &VariableSizeKey,
query_type: QueryType,
) -> Result<(Bytes, u64, u64)>
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
.