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
use crate::structs::shared::Tabular;
use postgres::Row;
use rust_decimal::prelude::Decimal;
use rust_decimal_macros::dec;

#[derive(Debug, Clone)]
pub struct Bloat {
    typefield: String,
    schemaname: String,
    object_name: String,
    bloat: Decimal,
    waste: String,
}

impl Tabular for Bloat {
    const FILE_NAME: &'static str = "bloat";

    fn new(row: &Row) -> Self {
        Self {
            typefield: row.get::<_, Option<String>>(0).unwrap_or_default(),
            schemaname: row.get::<_, Option<String>>(1).unwrap_or_default(),
            object_name: row.get::<_, Option<String>>(2).unwrap_or_default(),
            bloat: row.get::<_, Option<Decimal>>(3).unwrap_or(dec!(0)),
            waste: row.get::<_, Option<String>>(4).unwrap_or_default(),
        }
    }

    fn to_row(&self) -> prettytable::Row {
        row![
            self.typefield,
            self.schemaname,
            self.object_name,
            self.bloat,
            self.waste
        ]
    }

    fn headers() -> prettytable::Row {
        row!["type", "schemaname", "object_name", "bloat", "waste"]
    }
}