cat_gateway/db/event/common/
uuid_selector.rs

1//! `EqOrRangedUuid` query conditional stmt object.
2
3use crate::db::event::common::{ConditionalStmt, uuid_list::UuidList};
4
5/// Search either by a singe UUID, a range of UUIDs or a list of UUIDs.
6#[derive(Clone, Debug, PartialEq)]
7pub(crate) enum UuidSelector {
8    /// Search by the exact UUID
9    Eq(uuid::Uuid),
10    /// Search in this UUID's range
11    Range {
12        /// Minimum UUID to find (inclusive)
13        min: uuid::Uuid,
14        /// Maximum UUID to find (inclusive)
15        max: uuid::Uuid,
16    },
17    /// Search UUIDs in the given list.
18    In(UuidList),
19}
20
21impl ConditionalStmt for UuidSelector {
22    fn conditional_stmt(
23        &self,
24        f: &mut std::fmt::Formatter<'_>,
25        table_field: &str,
26    ) -> std::fmt::Result {
27        match self {
28            Self::Eq(id) => write!(f, "{table_field} = '{id}'"),
29            Self::Range { min, max } => {
30                write!(f, "{table_field} >= '{min}' AND {table_field} <= '{max}'")
31            },
32            Self::In(ids) => ids.conditional_stmt(f, table_field),
33        }
34    }
35}