1use std::collections::HashMap;
7use std::path::PathBuf;
8
9use serde::{Deserialize, Serialize};
10
11#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
13#[serde(rename_all = "lowercase")]
14pub enum DatabaseMode {
15 Lpg,
17 Rdf,
19}
20
21impl std::fmt::Display for DatabaseMode {
22 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
23 match self {
24 DatabaseMode::Lpg => write!(f, "lpg"),
25 DatabaseMode::Rdf => write!(f, "rdf"),
26 }
27 }
28}
29
30#[derive(Debug, Clone, Serialize, Deserialize)]
32pub struct DatabaseInfo {
33 pub mode: DatabaseMode,
35 pub node_count: usize,
37 pub edge_count: usize,
39 pub is_persistent: bool,
41 pub path: Option<PathBuf>,
43 pub wal_enabled: bool,
45 pub version: String,
47}
48
49#[derive(Debug, Clone, Serialize, Deserialize)]
51pub struct DatabaseStats {
52 pub node_count: usize,
54 pub edge_count: usize,
56 pub label_count: usize,
58 pub edge_type_count: usize,
60 pub property_key_count: usize,
62 pub index_count: usize,
64 pub memory_bytes: usize,
66 pub disk_bytes: Option<usize>,
68}
69
70#[derive(Debug, Clone, Serialize, Deserialize)]
72pub struct LpgSchemaInfo {
73 pub labels: Vec<LabelInfo>,
75 pub edge_types: Vec<EdgeTypeInfo>,
77 pub property_keys: Vec<String>,
79}
80
81#[derive(Debug, Clone, Serialize, Deserialize)]
83pub struct LabelInfo {
84 pub name: String,
86 pub count: usize,
88}
89
90#[derive(Debug, Clone, Serialize, Deserialize)]
92pub struct EdgeTypeInfo {
93 pub name: String,
95 pub count: usize,
97}
98
99#[derive(Debug, Clone, Serialize, Deserialize)]
101pub struct RdfSchemaInfo {
102 pub predicates: Vec<PredicateInfo>,
104 pub named_graphs: Vec<String>,
106 pub subject_count: usize,
108 pub object_count: usize,
110}
111
112#[derive(Debug, Clone, Serialize, Deserialize)]
114pub struct PredicateInfo {
115 pub iri: String,
117 pub count: usize,
119}
120
121#[derive(Debug, Clone, Serialize, Deserialize)]
123#[serde(tag = "mode")]
124pub enum SchemaInfo {
125 #[serde(rename = "lpg")]
127 Lpg(LpgSchemaInfo),
128 #[serde(rename = "rdf")]
130 Rdf(RdfSchemaInfo),
131}
132
133#[derive(Debug, Clone, Serialize, Deserialize)]
135pub struct IndexInfo {
136 pub name: String,
138 pub index_type: String,
140 pub target: String,
142 pub unique: bool,
144 pub cardinality: Option<usize>,
146 pub size_bytes: Option<usize>,
148}
149
150#[derive(Debug, Clone, Serialize, Deserialize)]
152pub struct WalStatus {
153 pub enabled: bool,
155 pub path: Option<PathBuf>,
157 pub size_bytes: usize,
159 pub record_count: usize,
161 pub last_checkpoint: Option<u64>,
163 pub current_epoch: u64,
165}
166
167#[derive(Debug, Clone, Default, Serialize, Deserialize)]
169pub struct ValidationResult {
170 pub errors: Vec<ValidationError>,
172 pub warnings: Vec<ValidationWarning>,
174}
175
176impl ValidationResult {
177 #[must_use]
179 pub fn is_valid(&self) -> bool {
180 self.errors.is_empty()
181 }
182}
183
184#[derive(Debug, Clone, Serialize, Deserialize)]
186pub struct ValidationError {
187 pub code: String,
189 pub message: String,
191 pub context: Option<String>,
193}
194
195#[derive(Debug, Clone, Serialize, Deserialize)]
197pub struct ValidationWarning {
198 pub code: String,
200 pub message: String,
202 pub context: Option<String>,
204}
205
206#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
208#[serde(rename_all = "lowercase")]
209pub enum DumpFormat {
210 Parquet,
212 Turtle,
214 Json,
216}
217
218impl Default for DumpFormat {
219 fn default() -> Self {
220 DumpFormat::Parquet
221 }
222}
223
224impl std::fmt::Display for DumpFormat {
225 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
226 match self {
227 DumpFormat::Parquet => write!(f, "parquet"),
228 DumpFormat::Turtle => write!(f, "turtle"),
229 DumpFormat::Json => write!(f, "json"),
230 }
231 }
232}
233
234impl std::str::FromStr for DumpFormat {
235 type Err = String;
236
237 fn from_str(s: &str) -> Result<Self, Self::Err> {
238 match s.to_lowercase().as_str() {
239 "parquet" => Ok(DumpFormat::Parquet),
240 "turtle" | "ttl" => Ok(DumpFormat::Turtle),
241 "json" | "jsonl" => Ok(DumpFormat::Json),
242 _ => Err(format!("Unknown dump format: {}", s)),
243 }
244 }
245}
246
247#[derive(Debug, Clone, Serialize, Deserialize)]
249pub struct CompactionStats {
250 pub bytes_reclaimed: usize,
252 pub nodes_compacted: usize,
254 pub edges_compacted: usize,
256 pub duration_ms: u64,
258}
259
260#[derive(Debug, Clone, Serialize, Deserialize)]
262pub struct DumpMetadata {
263 pub version: String,
265 pub mode: DatabaseMode,
267 pub format: DumpFormat,
269 pub node_count: usize,
271 pub edge_count: usize,
273 pub created_at: String,
275 #[serde(default)]
277 pub extra: HashMap<String, String>,
278}