Skip to main content

sqlitegraph_cli/
client.rs

1//! Minimal BackendClient wrapper for v0.2.5 compatibility
2//!
3//! This provides a simplified BackendClient that wraps existing v0.2.5 backends
4//! without the missing pipeline/subgraph/safety modules.
5
6use sqlitegraph::{GraphBackend, NativeGraphBackend, SqliteGraph, SqliteGraphBackend};
7
8/// Minimal client wrapper for v0.2.5
9pub enum BackendClient {
10    Sqlite(SqliteGraphBackend),
11    Native(NativeGraphBackend),
12    /// Dynamic backend for factory-created backends (e.g., from open_graph())
13    Dynamic(Box<dyn GraphBackend>),
14}
15
16impl BackendClient {
17    pub fn new(backend: SqliteGraphBackend) -> Self {
18        Self::Sqlite(backend)
19    }
20
21    pub fn new_native(backend: NativeGraphBackend) -> Self {
22        Self::Native(backend)
23    }
24
25    /// Create from a boxed trait object (e.g., from open_graph factory)
26    pub fn from_dynamic(backend: Box<dyn GraphBackend>) -> Self {
27        Self::Dynamic(backend)
28    }
29
30    /// Get the GraphBackend trait object
31    pub fn backend(&self) -> &dyn GraphBackend {
32        match self {
33            BackendClient::Sqlite(b) => b,
34            BackendClient::Native(b) => b,
35            BackendClient::Dynamic(b) => b.as_ref(),
36        }
37    }
38
39    /// Get the underlying SqliteGraph if this is a SQLite backend
40    pub fn graph(&self) -> Option<&SqliteGraph> {
41        match self {
42            BackendClient::Sqlite(b) => Some(b.graph()),
43            BackendClient::Native(_) => None,
44            BackendClient::Dynamic(_) => None,
45        }
46    }
47
48    /// Get all entity IDs if this is a SQLite backend
49    pub fn entity_ids(&self) -> Result<Option<Vec<i64>>, sqlitegraph::SqliteGraphError> {
50        match self {
51            BackendClient::Sqlite(b) => Ok(Some(b.entity_ids()?)),
52            BackendClient::Native(_) => Ok(None),
53            BackendClient::Dynamic(_) => Ok(None),
54        }
55    }
56
57    /// Get backend type name for debugging
58    pub fn backend_type(&self) -> &str {
59        match self {
60            BackendClient::Sqlite(_) => "sqlite",
61            BackendClient::Native(_) => "native",
62            BackendClient::Dynamic(_) => "dynamic",
63        }
64    }
65
66    /// Get WAL metrics (only available for Native backend with native-v2 feature)
67    #[cfg(feature = "native-v2")]
68    pub fn get_wal_metrics(
69        &self,
70    ) -> Option<sqlitegraph::backend::native::v2::wal::WALManagerMetrics> {
71        match self {
72            BackendClient::Native(b) => b.get_wal_metrics(),
73            BackendClient::Dynamic(_) => None, // Dynamic backends don't expose WAL-specific methods
74            BackendClient::Sqlite(_) => None,
75        }
76    }
77
78    /// Get active transaction count (only available for Native backend with native-v2 feature)
79    #[cfg(feature = "native-v2")]
80    pub fn get_active_transaction_count(&self) -> Option<usize> {
81        match self {
82            BackendClient::Native(b) => b.get_active_transaction_count(),
83            BackendClient::Dynamic(_) => None,
84            BackendClient::Sqlite(_) => None,
85        }
86    }
87}