sqlitegraph/config/
sqlite.rs

1//! SQLite backend configuration.
2
3use std::collections::HashMap;
4
5/// Configuration for SQLite backend operations.
6#[derive(Clone, Debug, Default)]
7pub struct SqliteConfig {
8    /// Skip schema initialization during opening
9    pub without_migrations: bool,
10    /// Optional cache size for prepared statements
11    pub cache_size: Option<usize>,
12    /// Additional SQLite PRAGMA settings
13    pub pragma_settings: HashMap<String, String>,
14}
15
16impl SqliteConfig {
17    /// Create a new SQLite config with default settings
18    pub fn new() -> Self {
19        Self::default()
20    }
21
22    /// Set whether to skip schema initialization (builder pattern)
23    pub fn with_migrations_disabled(mut self, without_migrations: bool) -> Self {
24        self.without_migrations = without_migrations;
25        self
26    }
27
28    /// Set the prepared statement cache size (builder pattern)
29    pub fn with_cache_size(mut self, cache_size: usize) -> Self {
30        self.cache_size = Some(cache_size);
31        self
32    }
33
34    /// Add a PRAGMA setting (builder pattern)
35    pub fn with_pragma(mut self, key: &str, value: &str) -> Self {
36        self.pragma_settings
37            .insert(key.to_string(), value.to_string());
38        self
39    }
40
41    /// Configure for WAL mode (builder pattern convenience method)
42    pub fn with_wal_mode(mut self) -> Self {
43        self.pragma_settings
44            .insert("journal_mode".to_string(), "WAL".to_string());
45        self
46    }
47
48    /// Configure for better performance with some safety trade-offs
49    pub fn with_performance_mode(mut self) -> Self {
50        self.pragma_settings
51            .insert("journal_mode".to_string(), "WAL".to_string());
52        self.pragma_settings
53            .insert("synchronous".to_string(), "NORMAL".to_string());
54        self
55    }
56}