pub struct Memory { /* private fields */ }Expand description
Memory connection. open(path) is persistent (auto-flushes every
apply via atomic write); new() is in-RAM only.
Implementations§
Source§impl Memory
impl Memory
Sourcepub fn open(path: impl AsRef<Path>) -> Result<Self>
pub fn open(path: impl AsRef<Path>) -> Result<Self>
Open (or create) a memory db at path. Reads the file if it
exists; otherwise the db starts empty and the file is created on
the first write.
Sourcepub fn apply(&mut self, op: Op) -> Result<()>
pub fn apply(&mut self, op: Op) -> Result<()>
Apply a write op and persist. RAM is mutated before flush, so a
flush failure leaves RAM ahead of disk until the next successful
op (or the next open, which re-reads the file). WAL will close
this window in v2.
pub fn get(&self, name: &str) -> Option<&Entry>
pub fn list(&self) -> impl Iterator<Item = &Entry>
pub fn search(&self, query: &str, limit: usize) -> Vec<SearchHit>
Sourcepub fn search_kind(
&self,
query: &str,
limit: usize,
kind: EntryKind,
) -> Vec<SearchHit>
pub fn search_kind( &self, query: &str, limit: usize, kind: EntryKind, ) -> Vec<SearchHit>
BM25 search restricted to a single EntryKind. The inner search
runs unbounded so the kind filter can’t truncate matches mid-list;
we clone only the survivors that fit inside limit.
Sourcepub fn checkpoint(&self) -> Result<()>
pub fn checkpoint(&self) -> Result<()>
Force a write of the current state to disk, whether or not any mutation has happened. Useful for one-shot migration paths that need the db file to exist even when every incoming op failed. A no-op when the memory is in-RAM only (no path).