Skip to main content

khive_db/backend/
policy_open.rs

1use super::*;
2
3impl StorageBackend {
4    /// File-backed SQLite database whose volume advisory lock files live in
5    /// `volume_lock_dir`. Every cooperating process must choose the same directory.
6    pub fn sqlite_with_volume_lock_dir(
7        path: impl AsRef<Path>,
8        volume_lock_dir: std::path::PathBuf,
9    ) -> Result<Self, SqliteError> {
10        Self::sqlite_with_pool_config(
11            path,
12            PoolConfig {
13                volume_lock_dir: Some(volume_lock_dir),
14                ..PoolConfig::default()
15            },
16            None,
17        )
18    }
19
20    /// The host supplies the same captured policies used for daemon identity.
21    pub fn sqlite_with_max_readers_and_policies(
22        path: impl AsRef<Path>,
23        max_readers: Option<usize>,
24        wal_ceiling: WalCeilingPolicy,
25        disk_guard_config: crate::EffectiveDiskGuardConfig,
26        volume_lock_dir: std::path::PathBuf,
27    ) -> Result<Self, SqliteError> {
28        Self::sqlite_with_pool_config(
29            path,
30            PoolConfig {
31                wal_ceiling,
32                disk_guard_config: Some(disk_guard_config),
33                volume_lock_dir: Some(volume_lock_dir),
34                ..PoolConfig::default()
35            },
36            max_readers,
37        )
38    }
39
40    #[cfg(any(test, feature = "test-support"))]
41    pub fn sqlite_for_test_with_policies(
42        path: impl AsRef<Path>,
43        wal_ceiling: WalCeilingPolicy,
44        disk_guard_config: crate::EffectiveDiskGuardConfig,
45    ) -> Result<Self, SqliteError> {
46        Self::sqlite_with_pool_config(
47            path,
48            PoolConfig {
49                wal_ceiling,
50                disk_guard_config: Some(disk_guard_config),
51                ..PoolConfig::for_test()
52            },
53            Some(2),
54        )
55    }
56}