Skip to main content

nusy_arrow_git/
object_store.rs

1//! Object Store — the live in-memory Arrow tables from `nusy-arrow-core`.
2//!
3//! The Object Store IS the ArrowGraphStore. This module provides the
4//! git-aware wrapper that connects the live store to commit/checkout/save.
5
6use nusy_arrow_core::ArrowGraphStore;
7use std::path::PathBuf;
8
9/// Configuration for the git-aware object store.
10#[derive(Debug, Clone)]
11pub struct GitConfig {
12    /// Directory where Parquet snapshots are stored.
13    pub snapshot_dir: PathBuf,
14}
15
16impl GitConfig {
17    pub fn new(snapshot_dir: impl Into<PathBuf>) -> Self {
18        GitConfig {
19            snapshot_dir: snapshot_dir.into(),
20        }
21    }
22}
23
24impl Default for GitConfig {
25    fn default() -> Self {
26        GitConfig {
27            snapshot_dir: PathBuf::from(".nusy-arrow/snapshots"),
28        }
29    }
30}
31
32/// The git-aware graph store. Wraps ArrowGraphStore with versioning capabilities.
33pub struct GitObjectStore {
34    /// The live in-memory graph.
35    pub store: ArrowGraphStore,
36    /// Configuration.
37    pub config: GitConfig,
38}
39
40impl GitObjectStore {
41    /// Create a new git-aware store with default config.
42    pub fn new() -> Self {
43        GitObjectStore {
44            store: ArrowGraphStore::new(),
45            config: GitConfig::default(),
46        }
47    }
48
49    /// Create with a specific snapshot directory.
50    pub fn with_snapshot_dir(dir: impl Into<PathBuf>) -> Self {
51        GitObjectStore {
52            store: ArrowGraphStore::new(),
53            config: GitConfig::new(dir),
54        }
55    }
56
57    /// Path for a commit's snapshot directory.
58    pub fn commit_snapshot_dir(&self, commit_id: &str) -> PathBuf {
59        self.config.snapshot_dir.join(commit_id)
60    }
61
62    /// Path for a namespace's Parquet file within a commit snapshot.
63    pub fn namespace_parquet_path(&self, commit_id: &str, namespace: &str) -> PathBuf {
64        self.commit_snapshot_dir(commit_id)
65            .join(format!("{namespace}.parquet"))
66    }
67}
68
69impl Default for GitObjectStore {
70    fn default() -> Self {
71        Self::new()
72    }
73}