pub struct WriteTx<'tx> { /* private fields */ }Expand description
Handle exposed to write transaction callbacks. Serializable.
Implementations§
Source§impl<'tx> WriteTx<'tx>
impl<'tx> WriteTx<'tx>
Sourcepub fn take_touched(&mut self) -> Vec<DocChange>
pub fn take_touched(&mut self) -> Vec<DocChange>
Drains and returns every document change accumulated so far in this
transaction. A second call on the same transaction returns an empty
Vec. Intended to be called by Database::write immediately after
a successful commit to build a crate::notify::CommitEvent;
rollback simply drops WriteTx without calling this method.
Sourcepub fn put(
&mut self,
collection: &str,
key: &[u8],
value: &[u8],
) -> Result<(), NookError>
pub fn put( &mut self, collection: &str, key: &[u8], value: &[u8], ) -> Result<(), NookError>
Inserts or overwrites (collection, key) -> value.
§Errors
Returns NookError::InvalidArg if collection is empty or contains
a null byte. Returns NookError::Storage on underlying storage failure.
Sourcepub fn get(
&self,
collection: &str,
key: &[u8],
) -> Result<Option<Vec<u8>>, NookError>
pub fn get( &self, collection: &str, key: &[u8], ) -> Result<Option<Vec<u8>>, NookError>
Same semantics as ReadTx::get, but reads from the current
uncommitted state of this write transaction.
§Errors
Returns NookError::InvalidArg if collection is empty or contains
a null byte. Returns NookError::Storage or NookError::Corruption
on underlying storage failure.
Sourcepub fn delete(
&mut self,
collection: &str,
key: &[u8],
) -> Result<bool, NookError>
pub fn delete( &mut self, collection: &str, key: &[u8], ) -> Result<bool, NookError>
Removes (collection, key). Returns true if the key was
present, false otherwise.
§Errors
Returns NookError::InvalidArg if collection is empty or contains
a null byte. Returns NookError::Storage on underlying storage failure.
Sourcepub fn index_put(&mut self, k: &[u8], v: &[u8]) -> Result<(), NookError>
pub fn index_put(&mut self, k: &[u8], v: &[u8]) -> Result<(), NookError>
Inserts (or overwrites) a raw key -> value pair into the
secondary-index table within this write transaction. The
composite index key layout is owned by crate::index::engine;
this method is layout-agnostic.
§Errors
Returns NookError::Storage on underlying storage failure.
Sourcepub fn index_delete(&mut self, k: &[u8]) -> Result<(), NookError>
pub fn index_delete(&mut self, k: &[u8]) -> Result<(), NookError>
Removes a raw key from the secondary-index table within this write transaction. A missing key is not an error.
§Errors
Returns NookError::Storage on underlying storage failure.
Sourcepub fn index_range_values(
&self,
lo: &[u8],
hi: &[u8],
) -> Result<Vec<Vec<u8>>, NookError>
pub fn index_range_values( &self, lo: &[u8], hi: &[u8], ) -> Result<Vec<Vec<u8>>, NookError>
Same semantics as ReadTx::index_range_values, but reads from the
current uncommitted state of this write transaction. Lets the
index engine perform a unique-constraint pre-check that observes
the in-flight write (a separate read snapshot would miss prior
inserts made within the same transaction).
Returns an empty vector when no index maintenance has occurred in
this transaction (the index table is created lazily). The
composite index key layout is owned by crate::index::engine;
this method is layout-agnostic.
§Errors
Returns NookError::Storage or NookError::Corruption on
underlying storage failure.
Sourcepub fn has_any_entry(&self) -> Result<bool, NookError>
pub fn has_any_entry(&self) -> Result<bool, NookError>
Returns true iff the entries table has at least one row.
Used by backup restore to enforce the allow_overwrite gate.
§Errors
Returns NookError::Storage on underlying storage failure.
Sourcepub fn clear_entries(&mut self) -> Result<(), NookError>
pub fn clear_entries(&mut self) -> Result<(), NookError>
Removes every row from the entries table AND the index table.
Used by backup restore when allow_overwrite=true.
§Errors
Returns NookError::Storage on underlying storage failure.
Sourcepub fn put_raw(
&mut self,
composite_key: &[u8],
value: &[u8],
) -> Result<(), NookError>
pub fn put_raw( &mut self, composite_key: &[u8], value: &[u8], ) -> Result<(), NookError>
Inserts a raw (composite_key, value) pair into the entries table.
Used by backup restore to replay a .nbkp snapshot. Does NOT touch
the index table — backup restore replays composite keys from the same
source table, and the index table is empty (cleared by clear_entries)
so secondary indexes will be lost after restore until reindexed.
§Errors
Returns NookError::Storage on underlying storage failure.
Sourcepub fn list_collection(&self, collection: &str) -> Result<Vec<Entry>, NookError>
pub fn list_collection(&self, collection: &str) -> Result<Vec<Entry>, NookError>
Same semantics as ReadTx::list_collection, but reads from the
current uncommitted state of this write transaction.
§Errors
Returns NookError::InvalidArg if collection is empty or contains
a null byte. Returns NookError::Storage or NookError::Corruption
on underlying storage failure.