odbc_api_helper/executor/
table.rs

1use odbc_common::{Print, StyledString, Table, TableTheme, TextStyle};
2
3pub type TableDescResult = (Vec<String>, Vec<Vec<String>>);
4
5#[derive(Debug)]
6pub struct TableDescResultInner {
7    pub column_names: Vec<String>,
8    pub columns_desc: Vec<Vec<String>>,
9}
10
11impl From<TableDescResult> for TableDescResultInner {
12    fn from(t: TableDescResult) -> Self {
13        Self {
14            column_names: t.0,
15            columns_desc: t.1,
16        }
17    }
18}
19
20impl Print for TableDescResultInner {
21    fn convert_table(self) -> anyhow::Result<Table> {
22        let headers: Vec<StyledString> = self
23            .column_names
24            .iter()
25            .map(|x| StyledString::new(x.to_string(), TextStyle::default_header()))
26            .collect();
27
28        let rows = self
29            .columns_desc
30            .iter()
31            .map(|x| {
32                x.iter()
33                    .map(|y| y.to_string())
34                    .map(|y| StyledString::new(y, TextStyle::basic_left()))
35                    .collect::<Vec<_>>()
36            })
37            .collect();
38        Ok(Table::new(headers, rows, TableTheme::rounded()))
39    }
40}