mithril_aggregator/database/query/pending_certificate/
delete_pending_certificate.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use mithril_persistence::sqlite::{Query, WhereCondition};

use crate::database::record::CertificatePendingRecord;

/// Query to delete old [CertificatePendingRecord] from the sqlite database
pub struct DeletePendingCertificateRecordQuery {
    condition: WhereCondition,
}

impl DeletePendingCertificateRecordQuery {
    pub fn get() -> Self {
        Self {
            condition: WhereCondition::default(),
        }
    }
}

impl Query for DeletePendingCertificateRecordQuery {
    type Entity = CertificatePendingRecord;

    fn filters(&self) -> WhereCondition {
        self.condition.clone()
    }

    fn get_definition(&self, condition: &str) -> String {
        // it is important to alias the fields with the same name as the table
        // since the table cannot be aliased in a RETURNING statement in SQLite.
        let projection = Self::Entity::expand_projection("pending_certificate");
        format!("delete from pending_certificate where {condition} returning {projection}")
    }
}