codeprism_storage/
config.rs1use serde::{Deserialize, Serialize};
4use std::path::PathBuf;
5use std::time::Duration;
6
7use crate::StorageBackend;
8
9#[derive(Debug, Clone, Serialize, Deserialize)]
11pub struct StorageConfig {
12 pub backend: StorageBackend,
14 pub data_path: PathBuf,
16 pub cache_size_mb: usize,
18 pub persistence_interval: Duration,
20 pub compression_enabled: bool,
22 pub retention_period: Duration,
24 pub connection_string: Option<String>,
26}
27
28impl Default for StorageConfig {
29 fn default() -> Self {
30 Self {
31 backend: StorageBackend::InMemory,
32 data_path: PathBuf::from("./codeprism_data"),
33 cache_size_mb: 256,
34 persistence_interval: Duration::from_secs(300), compression_enabled: true,
36 retention_period: Duration::from_secs(86400 * 7), connection_string: None,
38 }
39 }
40}
41
42impl StorageConfig {
43 pub fn new(backend: StorageBackend, data_path: PathBuf) -> Self {
45 Self {
46 backend,
47 data_path,
48 ..Default::default()
49 }
50 }
51
52 pub fn in_memory() -> Self {
54 Self {
55 backend: StorageBackend::InMemory,
56 ..Default::default()
57 }
58 }
59
60 pub fn file_based(data_path: PathBuf) -> Self {
62 Self {
63 backend: StorageBackend::File,
64 data_path,
65 ..Default::default()
66 }
67 }
68
69 pub fn sqlite(data_path: PathBuf) -> Self {
71 Self {
72 backend: StorageBackend::Sqlite,
73 data_path,
74 ..Default::default()
75 }
76 }
77
78 pub fn with_cache_size(mut self, size_mb: usize) -> Self {
80 self.cache_size_mb = size_mb;
81 self
82 }
83
84 pub fn with_persistence_interval(mut self, interval: Duration) -> Self {
86 self.persistence_interval = interval;
87 self
88 }
89
90 pub fn with_compression(mut self, enabled: bool) -> Self {
92 self.compression_enabled = enabled;
93 self
94 }
95
96 pub fn with_retention_period(mut self, period: Duration) -> Self {
98 self.retention_period = period;
99 self
100 }
101
102 #[cfg(test)]
103 pub fn default_for_testing(data_path: &std::path::Path) -> Self {
104 Self {
105 backend: StorageBackend::InMemory,
106 data_path: data_path.to_path_buf(),
107 cache_size_mb: 64,
108 persistence_interval: Duration::from_secs(60),
109 compression_enabled: false,
110 retention_period: Duration::from_secs(86400),
111 connection_string: None,
112 }
113 }
114}