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
impl Database
Sourcepub fn open(path: impl AsRef<Path>) -> Result<Self, NookError>
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.
Sourcepub fn add_observer(&self, obs: Arc<dyn CommitObserver>) -> ObserverHandle
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).
Sourcepub fn read<F, R>(&self, f: F) -> Result<R, NookError>
pub fn read<F, R>(&self, f: F) -> 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.
Sourcepub fn write<F, R>(&self, f: F) -> Result<R, NookError>
pub fn write<F, R>(&self, f: F) -> 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.