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
use crate::structs::shared::Tabular;
use sqlx::postgres::PgRow;
use sqlx::types::BigDecimal;
use sqlx::Row;

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

impl Tabular for Bloat {
    fn new(row: &PgRow) -> Self {
        Self {
            typefield: row.try_get("type").unwrap_or_default(),
            schemaname: row.try_get("schemaname").unwrap_or_default(),
            object_name: row.try_get("object_name").unwrap_or_default(),
            bloat: row.try_get("bloat").unwrap_or_default(),
            waste: row.try_get("waste").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"]
    }
}