Skip to main content

WriteTx

Struct WriteTx 

Source
pub struct WriteTx<'tx> { /* private fields */ }
Expand description

Handle exposed to write transaction callbacks. Serializable.

Implementations§

Source§

impl<'tx> WriteTx<'tx>

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Auto Trait Implementations§

§

impl<'tx> Freeze for WriteTx<'tx>

§

impl<'tx> !RefUnwindSafe for WriteTx<'tx>

§

impl<'tx> Send for WriteTx<'tx>

§

impl<'tx> Sync for WriteTx<'tx>

§

impl<'tx> Unpin for WriteTx<'tx>

§

impl<'tx> UnsafeUnpin for WriteTx<'tx>

§

impl<'tx> !UnwindSafe for WriteTx<'tx>

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> Same for T

Source§

type Output = T

Should always be Self
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.