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::Tabular;
use sqlx::postgres::PgRow;
use sqlx::Row;

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

impl Tabular for Connections {
    fn new(row: &PgRow) -> Self {
        Self {
            username: row.try_get("username").unwrap_or_default(),
            pid: row.try_get("pid").unwrap_or_default(),
            client_addr: row.try_get("client_addr").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"]
    }
}