mithril_aggregator/database/record/
immutable_file_digest.rs1use sqlite::Row;
2
3use mithril_common::entities::{HexEncodedDigest, ImmutableFileName};
4use mithril_persistence::sqlite::{HydrationError, Projection, SourceAlias, SqLiteEntity};
5
6#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
8pub struct ImmutableFileDigestRecord {
9 pub immutable_file_name: ImmutableFileName,
11
12 pub digest: HexEncodedDigest,
14}
15
16impl ImmutableFileDigestRecord {
17 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}