Skip to main content

khive_db/backend/core_stores/
sql.rs

1use super::super::StorageBackend;
2use crate::sql_bridge::SqlBridge;
3use async_trait::async_trait;
4use khive_storage::{AtomicUnitOp, SqlAccess, SqlReader, SqlWriter, StorageResult};
5use std::any::Any;
6use std::sync::Arc;
7
8#[async_trait]
9impl SqlAccess for StorageBackend {
10    fn database_path(&self) -> Option<std::path::PathBuf> {
11        self.sql().database_path()
12    }
13
14    async fn reader(&self) -> StorageResult<Box<dyn SqlReader>> {
15        self.sql().reader().await
16    }
17
18    async fn writer(&self) -> StorageResult<Box<dyn SqlWriter>> {
19        self.sql().writer().await
20    }
21
22    async fn atomic_unit(&self, op: AtomicUnitOp) -> StorageResult<Box<dyn Any + Send>> {
23        self.sql().atomic_unit(op).await
24    }
25}
26
27impl StorageBackend {
28    /// Get the SQL access capability.
29    ///
30    /// Returns an `Arc<dyn SqlAccess>` suitable for passing to services.
31    pub fn sql(&self) -> Arc<dyn khive_storage::SqlAccess> {
32        Arc::new(SqlBridge::new(Arc::clone(&self.pool), self.is_file_backed))
33    }
34}