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
51
52
53
54
55
56
57
use crate::structs::shared::Tabular;
use postgres::Row;

#[derive(Debug, Clone)]
pub struct VacuumStats {
    schema: String,
    table: String,
    last_vacuum: String,
    last_autovacuum: String,
    rowcount: String,
    dead_rowcount: String,
    autovacuum_threshold: String,
    expect_autovacuum: String,
}

impl Tabular for VacuumStats {
    const FILE_NAME: &'static str = "vacuum_stats";

    fn new(row: &Row) -> Self {
        Self {
            schema: row.get::<_, Option<String>>(0).unwrap_or_default(),
            table: row.get::<_, Option<String>>(1).unwrap_or_default(),
            last_vacuum: row.get::<_, Option<String>>(2).unwrap_or_default(),
            last_autovacuum: row.get::<_, Option<String>>(3).unwrap_or_default(),
            rowcount: row.get::<_, Option<String>>(4).unwrap_or_default(),
            dead_rowcount: row.get::<_, Option<String>>(4).unwrap_or_default(),
            autovacuum_threshold: row.get::<_, Option<String>>(4).unwrap_or_default(),
            expect_autovacuum: row.get::<_, Option<String>>(7).unwrap_or_default(),
        }
    }

    fn to_row(&self) -> prettytable::Row {
        row![
            self.schema,
            self.table,
            self.last_vacuum,
            self.last_autovacuum,
            self.rowcount,
            self.dead_rowcount,
            self.autovacuum_threshold,
            self.expect_autovacuum
        ]
    }

    fn headers() -> prettytable::Row {
        row![
            "schema",
            "table",
            "last_vacuum",
            "last_autovacuum",
            "rowcount",
            "dead_rowcount",
            "autovacuum_threshold",
            "expect_autovacuum"
        ]
    }
}