Skip to main content

kanban_persistence_sqlite/
backend_factory.rs

1use crate::SqliteBackend;
2use kanban_backend::{KanbanBackend, KanbanBackendFactory};
3use kanban_core::AppConfig;
4use kanban_domain::KanbanResult;
5use std::sync::Arc;
6
7pub struct SqliteBackendFactory;
8
9#[async_trait::async_trait]
10impl KanbanBackendFactory for SqliteBackendFactory {
11    fn name(&self) -> &str {
12        "sqlite"
13    }
14
15    fn matches_locator(&self, locator: &str, header: &[u8]) -> bool {
16        header.starts_with(b"SQLite format 3\0")
17            || (header.is_empty()
18                && (locator.ends_with(".sqlite")
19                    || locator.ends_with(".sqlite3")
20                    || locator.ends_with(".db")))
21    }
22
23    async fn create(
24        &self,
25        locator: &str,
26        _config: &AppConfig,
27    ) -> KanbanResult<Arc<dyn KanbanBackend>> {
28        Ok(Arc::new(SqliteBackend::open(locator).await?))
29    }
30}