Skip to main content

turtle_build/infrastructure/
database.rs

1mod error;
2#[cfg(test)]
3mod fake;
4mod fjall;
5mod log;
6mod redb;
7
8#[cfg(test)]
9pub use self::fake::FakeDatabase;
10pub use self::{error::DatabaseError, fjall::FjallDatabase, log::LogDatabase, redb::RedbDatabase};
11use crate::{build_hash::BuildHash, ir::BuildId};
12use alloc::sync::Arc;
13use async_trait::async_trait;
14
15/// A database.
16#[async_trait]
17pub trait Database {
18    /// Gets a hash of a build.
19    async fn get_hash(&self, id: BuildId) -> Result<Option<BuildHash>, DatabaseError>;
20    /// Sets a hash of a build.
21    async fn set_hash(&self, id: BuildId, hash: BuildHash) -> Result<(), DatabaseError>;
22
23    /// Gets header inputs of a build.
24    async fn get_header_inputs(&self, id: BuildId) -> Result<Vec<Arc<str>>, DatabaseError>;
25    /// Sets header inputs of a build.
26    async fn set_header_inputs(
27        &self,
28        id: BuildId,
29        inputs: &[Arc<str>],
30    ) -> Result<(), DatabaseError>;
31
32    /// Gets all outputs.
33    async fn get_outputs(&self) -> Result<Vec<String>, DatabaseError>;
34    /// Sets an output and its source in a source map.
35    async fn set_output(&self, path: &str, source: Option<&str>) -> Result<(), DatabaseError>;
36    /// Gets a source of an output in a source map.
37    async fn get_source(&self, output: &str) -> Result<Option<String>, DatabaseError>;
38}