mithril_aggregator/database/query/immutable_file_digest/
get_immutable_file_digest.rs

1use sqlite::Value;
2
3use mithril_common::{entities::ImmutableFileName, StdResult};
4use mithril_persistence::sqlite::{Query, WhereCondition};
5
6use crate::database::record::ImmutableFileDigestRecord;
7
8/// Simple queries to retrieve [ImmutableFileDigestRecord] from the sqlite database.
9pub struct GetImmutableFileDigestQuery {
10    condition: WhereCondition,
11}
12
13impl GetImmutableFileDigestQuery {
14    pub fn by_immutable_file_name(immutable_file_name: &ImmutableFileName) -> StdResult<Self> {
15        let condition = WhereCondition::new(
16            "immutable_file_name = ?*",
17            vec![Value::String(immutable_file_name.to_string())],
18        );
19
20        Ok(Self { condition })
21    }
22
23    pub fn all() -> Self {
24        Self {
25            condition: WhereCondition::default(),
26        }
27    }
28}
29
30impl Query for GetImmutableFileDigestQuery {
31    type Entity = ImmutableFileDigestRecord;
32
33    fn filters(&self) -> WhereCondition {
34        self.condition.clone()
35    }
36
37    fn get_definition(&self, condition: &str) -> String {
38        let projection = Self::Entity::expand_projection("immutable_file_digest");
39
40        format!(
41            "select {projection} from immutable_file_digest where {condition} order by rowid desc"
42        )
43    }
44}