linear_motion/db/
mod.rs

1pub mod mapping;
2pub mod status;
3
4use crate::Result;
5use std::path::Path;
6
7pub struct SyncDatabase {
8    pub mappings: mapping::MappingStore,
9    pub status: status::StatusStore,
10}
11
12impl SyncDatabase {
13    pub async fn new<P: AsRef<Path>>(db_path: P) -> Result<Self> {
14        let db_path = db_path.as_ref();
15
16        // Create the database directory if it doesn't exist
17        if let Some(parent) = db_path.parent() {
18            std::fs::create_dir_all(parent)?;
19        }
20
21        let mappings = mapping::MappingStore::new(db_path).await?;
22        let status = status::StatusStore::new(db_path).await?;
23
24        Ok(Self { mappings, status })
25    }
26
27    pub async fn initialize_with_default_path() -> Result<Self> {
28        use crate::config::ConfigLoader;
29
30        ConfigLoader::ensure_data_dir()?;
31        let db_path = ConfigLoader::get_default_database_path()?;
32
33        Self::new(db_path).await
34    }
35
36    pub async fn flush(&self) -> Result<()> {
37        self.mappings.flush().await?;
38        self.status.flush().await?;
39        Ok(())
40    }
41}
42
43pub use mapping::{MappingStatus, TaskMapping};
44pub use status::{SyncSourceStatus, SyncStatus, SyncStatusEntry};