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
32
use std::fmt::{Display, Formatter};

#[derive(PartialEq, Debug, Clone)]
pub enum BatchType {
    Logged,
    Counter,
    Unlogged,
}

/// defines the `BEGIN BATCH` data
#[derive(PartialEq, Debug, Clone)]
pub struct BeginBatch {
    pub ty: BatchType,
    /// the optional timestamp for the `BEGIN BATCH` command
    pub timestamp: Option<u64>,
}

impl Display for BeginBatch {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        let modifiers = match self.ty {
            BatchType::Logged => "",
            BatchType::Counter => "COUNTER ",
            BatchType::Unlogged => "UNLOGGED ",
        };

        if let Some(timestamp) = self.timestamp {
            write!(f, "BEGIN {}BATCH USING TIMESTAMP {} ", modifiers, timestamp)
        } else {
            write!(f, "BEGIN {}BATCH ", modifiers)
        }
    }
}