mithril_signer/database/query/protocol_initializer/
delete_protocol_initializer.rs1use sqlite::Value;
2
3use mithril_common::entities::Epoch;
4use mithril_persistence::sqlite::{Query, SourceAlias, SqLiteEntity, WhereCondition};
5
6use crate::database::record::ProtocolInitializerRecord;
7
8pub struct DeleteProtocolInitializerQuery {
10 condition: WhereCondition,
11}
12
13impl Query for DeleteProtocolInitializerQuery {
14 type Entity = ProtocolInitializerRecord;
15
16 fn filters(&self) -> WhereCondition {
17 self.condition.clone()
18 }
19
20 fn get_definition(&self, condition: &str) -> String {
21 let projection = Self::Entity::get_projection().expand(SourceAlias::new(&[(
24 "{:protocol_initializer:}",
25 "protocol_initializer",
26 )]));
27
28 format!("delete from protocol_initializer where {condition} returning {projection}")
29 }
30}
31
32impl DeleteProtocolInitializerQuery {
33 pub fn below_epoch_threshold(epoch_threshold: Epoch) -> Self {
35 let condition = WhereCondition::new(
36 "epoch < ?*",
37 vec![Value::Integer(epoch_threshold.try_into().unwrap())],
38 );
39
40 Self { condition }
41 }
42}