Skip to main content

Database

Struct Database 

Source
pub struct Database { /* private fields */ }
Expand description

Owning handle to a Nook database file.

Holds the OS-level file lock for the duration of its lifetime. Drop releases the lock. There is no explicit close() method on this type; the NAPI binding implements its own closure semantics on top.

Implementations§

Source§

impl Database

Source

pub fn open(path: impl AsRef<Path>) -> Result<Self, NookError>

Opens the database at path, creating it (and any missing parent directories) if necessary.

§Errors

Returns NookError::Storage if the file or parent directories cannot be created, or if the database file cannot be opened or is locked by another process.

Source

pub fn add_observer(&self, obs: Arc<dyn CommitObserver>) -> ObserverHandle

Registers a commit observer (stable extension seam, M3). The returned handle unregisters on drop (RAII).

Source

pub fn read<F, R>(&self, f: F) -> Result<R, NookError>
where F: FnOnce(&ReadTx) -> Result<R, NookError>,

Runs f inside a read transaction (MVCC snapshot). Read transactions never block writers and may run in parallel with each other.

§Errors

Returns NookError::Transaction if the read transaction cannot be started, or propagates any error returned by f.

Source

pub fn write<F, R>(&self, f: F) -> Result<R, NookError>
where F: for<'tx> FnOnce(&mut WriteTx<'tx>) -> Result<R, NookError>,

Runs f inside a write transaction. The transaction commits on Ok and rolls back on Err or panic.

Write transactions are serializable: only one runs at a time.

§Errors

Returns NookError::Transaction if the write transaction cannot be started or committed, or propagates any error returned by f. Returns NookError::Storage or NookError::Corruption on underlying storage failure.

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> 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.