pub struct MemoryDatabase { /* private fields */ }Expand description
SQLite-backed memory database.
All memory data lives in a single .db file with ACID guarantees.
Thread-safe via Mutex<Connection> (SQLite supports serialised access).
Implementations§
Source§impl MemoryDatabase
impl MemoryDatabase
Sourcepub fn open(
db_path: &Path,
embedding_dim: usize,
) -> Result<MemoryDatabase, Error>
pub fn open( db_path: &Path, embedding_dim: usize, ) -> Result<MemoryDatabase, Error>
Open (or create) the memory database at the given path.
Loads the sqlite-vec extension, sets WAL mode, and initialises the schema.
Sourcepub fn open_in_memory(embedding_dim: usize) -> Result<MemoryDatabase, Error>
pub fn open_in_memory(embedding_dim: usize) -> Result<MemoryDatabase, Error>
Open an in-memory database (for testing).
Sourcepub fn conn(&self) -> MutexGuard<'_, RawMutex, Connection>
pub fn conn(&self) -> MutexGuard<'_, RawMutex, Connection>
Get a locked connection reference.
Returns a MutexGuard<Connection> for executing queries.
parking_lot::Mutex is Send and safe to use in async contexts.
IMPORTANT: Always drop the guard before any .await point.
Sourcepub fn embedding_dim(&self) -> usize
pub fn embedding_dim(&self) -> usize
Returns the configured embedding dimension.
Sourcepub fn backup(&self, backup_path: &Path) -> Result<(), Error>
pub fn backup(&self, backup_path: &Path) -> Result<(), Error>
Backup the database by copying the file.
For best results, call after a checkpoint to ensure WAL is flushed.
Simply copies the .db file (does not use VACUUM INTO to avoid
compatibility issues with sqlite-vec virtual tables).
Sourcepub fn get_dream_state(&self, key: &str) -> Result<Option<String>, Error>
pub fn get_dream_state(&self, key: &str) -> Result<Option<String>, Error>
Get a dream state value.
Sourcepub fn set_dream_state(&self, key: &str, value: &str) -> Result<(), Error>
pub fn set_dream_state(&self, key: &str, value: &str) -> Result<(), Error>
Set a dream state value.
Sourcepub fn is_migration_complete(&self) -> bool
pub fn is_migration_complete(&self) -> bool
Check whether the JSON→SQLite migration has been completed.