Skip to main content

moltendb_core/engine/
config.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Serialize, Deserialize)]
4pub struct DbConfig {
5    /// Path to the database file (e.g., "my_database.log")
6    pub path: String,
7    /// Enable tiered storage (hot + cold log)
8    pub tiered_mode: bool,
9    /// Force synchronous writes (no data loss, lower performance)
10    pub sync_mode: bool,
11    /// Max documents to keep in RAM per collection
12    pub hot_threshold: usize,
13    /// Rate limiting: max requests per window (server-only, None = disabled/use default)
14    pub rate_limit_requests: Option<u32>,
15    /// Rate limiting: window size in seconds (server-only, None = disabled/use default)
16    pub rate_limit_window: Option<u64>,
17    /// Max request body size in bytes
18    pub max_body_size: usize,
19    /// Max keys allowed per request (default: 1000)
20    pub max_keys_per_request: usize,
21    /// Optional encryption key (32 bytes)
22    #[serde(skip)]
23    pub encryption_key: Option<[u8; 32]>,
24    /// Optional script to run after backups
25    pub post_backup_script: Option<String>,
26    /// Run entirely in RAM — no disk I/O, all data lost on exit
27    pub in_memory: bool,
28}
29
30impl Default for DbConfig {
31    fn default() -> Self {
32        Self {
33            path: "molten.db".to_string(),
34            tiered_mode: false,
35            sync_mode: false,
36            hot_threshold: 50000,
37            rate_limit_requests: Some(1000),
38            rate_limit_window: Some(60),
39            max_body_size: 10 * 1024 * 1024,
40            max_keys_per_request: 1000,
41            encryption_key: None,
42            post_backup_script: None,
43            in_memory: false,
44        }
45    }
46}