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

#[derive(Debug, Clone)]
pub struct Connections {
    username: String,
    pid: i32,
    client_addr: String,
}

impl Tabular for Connections {
    const FILE_NAME: &'static str = "connections";

    fn new(row: &Row) -> Self {
        Self {
            username: row.get::<_, Option<String>>(0).unwrap_or_default(),
            pid: row.get::<_, Option<i32>>(1).unwrap_or_default(),
            client_addr: row.get::<_, Option<String>>(2).unwrap_or_default(),
        }
    }

    fn to_row(&self) -> prettytable::Row {
        row![self.username, self.pid, self.client_addr]
    }

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