Skip to main content

graphos_adapters/storage/
memory.rs

1//! Pure in-memory storage backend.
2
3use graphos_core::graph::lpg::LpgStore;
4use std::sync::Arc;
5
6/// In-memory storage backend.
7///
8/// This is the default storage backend that keeps all data in memory.
9/// Data is lost when the process exits unless WAL is enabled.
10pub struct MemoryBackend {
11    /// The underlying LPG store.
12    store: Arc<LpgStore>,
13}
14
15impl MemoryBackend {
16    /// Creates a new in-memory backend.
17    #[must_use]
18    pub fn new() -> Self {
19        Self {
20            store: Arc::new(LpgStore::new()),
21        }
22    }
23
24    /// Returns a reference to the underlying store.
25    #[must_use]
26    pub fn store(&self) -> &Arc<LpgStore> {
27        &self.store
28    }
29}
30
31impl Default for MemoryBackend {
32    fn default() -> Self {
33        Self::new()
34    }
35}
36
37#[cfg(test)]
38mod tests {
39    use super::*;
40
41    #[test]
42    fn test_memory_backend() {
43        let backend = MemoryBackend::new();
44        let store = backend.store();
45
46        let id = store.create_node(&["Test"]);
47        assert!(id.is_valid());
48    }
49}