cat_gateway/db/event/signed_docs/
doc_ref.rs

1//! Document Reference filtering object.
2
3use crate::db::event::common::eq_or_ranged_uuid::EqOrRangedUuid;
4
5/// Document Reference filtering struct.
6#[derive(Clone, Debug)]
7pub(crate) struct DocumentRef {
8    /// Document id filtering
9    pub(crate) id: Option<EqOrRangedUuid>,
10    /// Document ver filtering
11    pub(crate) ver: Option<EqOrRangedUuid>,
12}
13
14impl DocumentRef {
15    /// Return a sql conditional statement by the provided `table_field`
16    pub(crate) fn conditional_stmt(&self, table_field: &str) -> String {
17        let mut stmt = "TRUE".to_string();
18        if let Some(id) = &self.id {
19            stmt.push_str(&format!(
20                " AND {}",
21                id.conditional_stmt(&format!("({table_field}->>'id')::uuid"))
22            ));
23        }
24        if let Some(ver) = &self.ver {
25            stmt.push_str(&format!(
26                " AND {}",
27                ver.conditional_stmt(&format!("({table_field}->>'ver')::uuid"))
28            ));
29        }
30        stmt
31    }
32}