pub struct Txn<'s> { /* private fields */ }Expand description
A transaction on the Store: a consistent snapshot of the records, and for a
write transaction, the changes to commit. Dropping it without committing discards
the changes.
Implementations§
Source§impl Txn<'_>
impl Txn<'_>
Sourcepub fn get<R: Record>(&self, key: &R::Key) -> Result<Option<R>, StoreError>
pub fn get<R: Record>(&self, key: &R::Key) -> Result<Option<R>, StoreError>
The record of type R at key, if there is one.
§Errors
StoreError::Database when the read fails, and StoreError::Decode when
the stored record cannot be decoded.
Sourcepub fn put<R: Record>(
&mut self,
key: &R::Key,
record: &R,
) -> Result<(), StoreError>
pub fn put<R: Record>( &mut self, key: &R::Key, record: &R, ) -> Result<(), StoreError>
Writes record at key, replacing any record there, when the transaction
commits.
§Errors
StoreError::Encode when the record cannot be encoded, and
StoreError::Database when the transaction is read-only.
Sourcepub fn delete<R: Record>(&mut self, key: &R::Key) -> Result<(), StoreError>
pub fn delete<R: Record>(&mut self, key: &R::Key) -> Result<(), StoreError>
Deletes the record of type R at key, if there is one, when the transaction
commits.
§Errors
StoreError::Database when the transaction is read-only.
Sourcepub fn scan<R: Record>(
&self,
prefix: &[u8],
) -> Result<Vec<(R::Key, R)>, StoreError>
pub fn scan<R: Record>( &self, prefix: &[u8], ) -> Result<Vec<(R::Key, R)>, StoreError>
Every record of type R whose key, after the family prefix, starts with
prefix, in key order. An empty prefix selects the whole family.
§Errors
StoreError::Database when the scan fails, StoreError::MalformedKey and
StoreError::Decode when a stored key or record cannot be decoded.
Sourcepub fn commit(self) -> Result<(), StoreError>
pub fn commit(self) -> Result<(), StoreError>
Commits every change of the transaction, or none of them.
§Errors
StoreError::Conflict when a concurrent transaction committed a change to a
record this one wrote, and StoreError::Database when the commit fails; in
both cases nothing was written.