mithril_aggregator/database/record/
immutable_file_digest.rsuse sqlite::Row;
use mithril_common::entities::{HexEncodedDigest, ImmutableFileName};
use mithril_persistence::sqlite::{HydrationError, Projection, SourceAlias, SqLiteEntity};
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct ImmutableFileDigestRecord {
pub immutable_file_name: ImmutableFileName,
pub digest: HexEncodedDigest,
}
impl ImmutableFileDigestRecord {
pub fn expand_projection(table: &str) -> String {
let aliases = SourceAlias::new(&[("{:immutable_file_digest:}", table)]);
Self::get_projection().expand(aliases)
}
#[cfg(test)]
pub fn dummy() -> Self {
Self {
immutable_file_name: "123.chunk".to_string(),
digest: "dummy_digest".to_string(),
}
}
}
impl SqLiteEntity for ImmutableFileDigestRecord {
fn hydrate(row: Row) -> Result<Self, HydrationError>
where
Self: Sized,
{
let immutable_file_name = row.read::<&str, _>(0).to_string();
let digest = row.read::<&str, _>(1).to_string();
Ok(Self {
immutable_file_name,
digest,
})
}
fn get_projection() -> Projection {
Projection::from(&[
(
"immutable_file_name",
"{:immutable_file_digest:}.immutable_file_name",
"text",
),
("digest", "{:immutable_file_digest:}.digest", "text"),
])
}
}