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
use crate::structs::shared::{get_default_interval, Tabular};
use sqlx::postgres::{types::PgInterval, PgRow};
use sqlx::Row;

#[derive(Debug, Clone)]
pub struct LongRunningQueries {
    pid: i32,
    duration: PgInterval,
    query: String,
}

impl Tabular for LongRunningQueries {
    fn new(row: &PgRow) -> Self {
        Self {
            pid: row.try_get("pid").unwrap_or_default(),
            duration: row.try_get("duration").unwrap_or(get_default_interval()),
            query: row.try_get("query").unwrap_or_default(),
        }
    }

    fn to_row(&self) -> prettytable::Row {
        row![self.pid, format!("{:?}", self.duration), self.query]
    }

    fn headers() -> prettytable::Row {
        row!["pid", "duration", "query"]
    }
}