1
use std::path;
2

            
3
use okaywal::file_manager;
4
use okaywal::file_manager::fs::StdFileManager;
5
use okaywal::file_manager::memory::MemoryFileManager;
6

            
7
use crate::{Database, Result};
8

            
9
4
#[derive(Clone)]
10
pub struct Config<FileManager> {
11
    pub wal: okaywal::Configuration<FileManager>,
12
}
13

            
14
impl Config<StdFileManager> {
15
333
    pub fn for_directory<Path>(directory: Path) -> Self
16
333
    where
17
333
        Path: AsRef<path::Path>,
18
333
    {
19
333
        Self {
20
333
            wal: okaywal::Configuration::default_for(directory),
21
333
        }
22
333
    }
23
}
24

            
25
impl Config<MemoryFileManager> {
26
1
    pub fn in_memory() -> Self {
27
1
        Self {
28
1
            wal: okaywal::Configuration::default_with_manager("/", MemoryFileManager::default()),
29
1
        }
30
1
    }
31
}
32
impl<FileManager> Config<FileManager>
33
where
34
    FileManager: file_manager::FileManager,
35
{
36
325
    pub fn configure_wal<
37
325
        Configuration: FnOnce(okaywal::Configuration<FileManager>) -> okaywal::Configuration<FileManager>,
38
325
    >(
39
325
        mut self,
40
325
        configurator: Configuration,
41
325
    ) -> Self {
42
325
        self.wal = configurator(self.wal);
43
325
        self
44
325
    }
45

            
46
336
    pub fn recover(self) -> Result<Database<FileManager>> {
47
336
        Database::recover_config(self)
48
336
    }
49
}
50

            
51
impl<FileManager> From<okaywal::Configuration<FileManager>> for Config<FileManager> {
52
    fn from(wal: okaywal::Configuration<FileManager>) -> Self {
53
        Self { wal }
54
    }
55
}