Skip to main content

azoth_core/config/
projection.rs

1use serde::{Deserialize, Serialize};
2use std::path::PathBuf;
3
4/// Configuration for projection store
5#[derive(Debug, Clone, Serialize, Deserialize)]
6pub struct ProjectionConfig {
7    /// Path to the SQLite database file
8    pub path: PathBuf,
9
10    /// Enable WAL mode
11    /// Default: true
12    #[serde(default = "default_wal_mode")]
13    pub wal_mode: bool,
14
15    /// SQLite synchronous mode
16    #[serde(default)]
17    pub synchronous: SynchronousMode,
18
19    /// Target schema version for migrations
20    /// Default: 1
21    #[serde(default = "default_schema_version")]
22    pub schema_version: u32,
23
24    /// SQLite cache size (in pages, negative = KB)
25    /// Default: -64000 (64MB)
26    #[serde(default = "default_cache_size")]
27    pub cache_size: i32,
28}
29
30#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Default)]
31pub enum SynchronousMode {
32    /// Full fsync (safest, slowest)
33    Full,
34    /// fsync at critical moments (good balance)
35    #[default]
36    Normal,
37    /// No fsync (fastest, least safe)
38    Off,
39}
40
41fn default_wal_mode() -> bool {
42    true
43}
44
45fn default_schema_version() -> u32 {
46    1
47}
48
49fn default_cache_size() -> i32 {
50    -64000 // 64MB
51}
52
53impl ProjectionConfig {
54    pub fn new(path: PathBuf) -> Self {
55        Self {
56            path,
57            wal_mode: default_wal_mode(),
58            synchronous: SynchronousMode::default(),
59            schema_version: default_schema_version(),
60            cache_size: default_cache_size(),
61        }
62    }
63
64    pub fn with_synchronous(mut self, synchronous: SynchronousMode) -> Self {
65        self.synchronous = synchronous;
66        self
67    }
68
69    pub fn with_wal_mode(mut self, wal_mode: bool) -> Self {
70        self.wal_mode = wal_mode;
71        self
72    }
73}