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
33
34
35
36
37
38
39
40
use tokio::time::Instant;

/// Show affected Info
pub struct Show {
    is_show_affected: bool,
    is_repl: bool,

    start: Instant,
}

impl Show {
    pub fn new(is_show_affected: bool, is_repl: bool) -> Self {
        let start = Instant::now();

        Self::new_with_start(is_show_affected, is_repl, start)
    }

    pub fn new_with_start(is_show_affected: bool, is_repl: bool, start: Instant) -> Self {
        Show {
            is_show_affected,
            is_repl,
            start,
        }
    }

    pub fn output(&self, affected: i64) {
        if self.is_show_affected && self.is_repl {
            if affected > 0 {
                eprintln!(
                    "{} rows affected in ({:.3} sec)",
                    affected,
                    self.start.elapsed().as_secs_f64()
                );
            } else {
                eprintln!("processed in ({:.3} sec)", self.start.elapsed().as_secs_f64());
            }
            eprintln!();
        }
    }
}