Skip to main content

arrow_graph_git/
object_store.rs

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