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
41
42
43
44
45
46
47
48
49
50
use crate::structs::shared::{get_default_interval, Tabular};
use pg_interval::Interval;
use postgres::Row;

#[derive(Debug, Clone)]
pub struct Calls {
    qry: String,
    exec_time: Interval,
    prop_exec_time: String,
    ncalls: String,
    sync_io_time: Interval,
}

impl Tabular for Calls {
    const FILE_NAME: &'static str = "calls";

    fn new(row: &Row) -> Self {
        Self {
            qry: row.get::<_, Option<String>>(0).unwrap_or_default(),
            exec_time: row
                .get::<_, Option<Interval>>(1)
                .unwrap_or(get_default_interval()),
            prop_exec_time: row.get::<_, Option<String>>(2).unwrap_or_default(),
            ncalls: row.get::<_, Option<String>>(3).unwrap_or_default(),
            sync_io_time: row
                .get::<_, Option<Interval>>(4)
                .unwrap_or(get_default_interval()),
        }
    }

    fn to_row(&self) -> prettytable::Row {
        row![
            self.qry,
            self.exec_time.to_iso_8601(),
            self.prop_exec_time,
            self.ncalls,
            self.sync_io_time.to_iso_8601()
        ]
    }

    fn headers() -> prettytable::Row {
        row![
            "qry",
            "exec_time",
            "prop_exec_time",
            "ncalls",
            "sync_io_time"
        ]
    }
}