cat_gateway/db/event/signed_docs/
doc_ref.rs1use crate::db::event::common::{ConditionalStmt, uuid_selector::UuidSelector};
4
5#[derive(Clone, Debug)]
7pub(crate) struct DocumentRef {
8 pub(crate) id: Option<UuidSelector>,
10 pub(crate) ver: Option<UuidSelector>,
12}
13
14impl ConditionalStmt for DocumentRef {
15 fn conditional_stmt(
16 &self,
17 f: &mut std::fmt::Formatter<'_>,
18 table_field: &str,
19 ) -> std::fmt::Result {
20 write!(
21 f,
22 "EXISTS (SELECT 1 FROM JSONB_ARRAY_ELEMENTS({table_field}) AS doc_ref WHERE TRUE"
23 )?;
24
25 if let Some(id) = &self.id {
26 write!(f, " AND ")?;
27 id.conditional_stmt(f, "(doc_ref->>'id')::uuid")?;
28 }
29 if let Some(ver) = &self.ver {
30 write!(f, " AND ")?;
31 ver.conditional_stmt(f, "(doc_ref->>'ver')::uuid")?;
32 }
33
34 write!(f, ")")
35 }
36}