mithril_aggregator/database/record/
immutable_file_digest.rs

1use sqlite::Row;
2
3use mithril_common::entities::{HexEncodedDigest, ImmutableFileName};
4use mithril_persistence::sqlite::{HydrationError, Projection, SourceAlias, SqLiteEntity};
5
6/// ImmutableFileDigestRecord is the record that stores the digest of an immutable file.
7#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
8pub struct ImmutableFileDigestRecord {
9    /// Immutable file name
10    pub immutable_file_name: ImmutableFileName,
11
12    /// Digest of an immutable file
13    pub digest: HexEncodedDigest,
14}
15
16impl ImmutableFileDigestRecord {
17    /// Construct a [Projection] that will allow to hydrate this `ImmutableFileDigestRecord` and expend table alias.
18    pub fn expand_projection(table: &str) -> String {
19        let aliases = SourceAlias::new(&[("{:immutable_file_digest:}", table)]);
20        Self::get_projection().expand(aliases)
21    }
22}
23
24impl SqLiteEntity for ImmutableFileDigestRecord {
25    fn hydrate(row: Row) -> Result<Self, HydrationError>
26    where
27        Self: Sized,
28    {
29        let immutable_file_name = row.read::<&str, _>(0).to_string();
30        let digest = row.read::<&str, _>(1).to_string();
31
32        Ok(Self {
33            immutable_file_name,
34            digest,
35        })
36    }
37
38    fn get_projection() -> Projection {
39        Projection::from(&[
40            (
41                "immutable_file_name",
42                "{:immutable_file_digest:}.immutable_file_name",
43                "text",
44            ),
45            ("digest", "{:immutable_file_digest:}.digest", "text"),
46        ])
47    }
48}