mithril_aggregator/database/query/signer_registration/
delete_signer_registration.rs1use sqlite::Value;
2
3use mithril_common::entities::Epoch;
4use mithril_persistence::sqlite::{Query, SourceAlias, SqLiteEntity, WhereCondition};
5
6use crate::database::record::SignerRegistrationRecord;
7
8pub struct DeleteSignerRegistrationRecordQuery {
10 condition: WhereCondition,
11}
12
13impl Query for DeleteSignerRegistrationRecordQuery {
14 type Entity = SignerRegistrationRecord;
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 "{:signer_registration:}",
25 "signer_registration",
26 )]));
27
28 format!("delete from signer_registration where {condition} returning {projection}")
29 }
30}
31
32impl DeleteSignerRegistrationRecordQuery {
33 pub fn below_epoch_threshold(epoch_threshold: Epoch) -> Self {
35 let epoch_threshold = Value::Integer(epoch_threshold.try_into().unwrap());
36
37 Self {
38 condition: WhereCondition::new("epoch_setting_id < ?*", vec![epoch_threshold]),
39 }
40 }
41}