pg_extras/queries/
vacuum_stats.rs

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
58
59
use crate::{queries::shared::Query, PgStatsVersion};
use sqlx::{postgres::PgRow, Row};

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

impl Query for VacuumStats {
    fn new(row: &PgRow) -> Self {
        Self {
            schema: row.try_get("schema").unwrap_or_default(),
            table: row.try_get("table").unwrap_or_default(),
            last_vacuum: row.try_get("last_vacuum").unwrap_or_default(),
            last_autovacuum: row.try_get("last_autovacuum").unwrap_or_default(),
            rowcount: row.try_get("rowcount").unwrap_or_default(),
            dead_rowcount: row.try_get("dead_rowcount").unwrap_or_default(),
            autovacuum_threshold: row.try_get("autovacuum_threshold").unwrap_or_default(),
            expect_autovacuum: row.try_get("expect_autovacuum").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"
        ]
    }

    fn read_file(_pg_statement_version: Option<PgStatsVersion>) -> String {
        include_str!("../sql/vacuum_stats.sql").to_string()
    }
}