odbc_api_helper/executor/
query.rs

1use crate::extension::odbc::{OdbcColumn, OdbcColumnItem};
2use odbc_common::print_table::Print;
3use odbc_common::{StyledString, Table, TableTheme, TextStyle};
4
5#[derive(Debug, Default)]
6pub struct QueryResult {
7    // table columns header
8    pub columns: Vec<OdbcColumn>,
9    // table columns data
10    pub data: Vec<Vec<OdbcColumnItem>>,
11}
12
13impl Print for QueryResult {
14    fn convert_table(self) -> anyhow::Result<Table> {
15        let headers: Vec<StyledString> = self
16            .columns
17            .iter()
18            .map(|x| StyledString::new(x.name.to_string(), TextStyle::default_header()))
19            .collect();
20
21        let rows = self
22            .data
23            .iter()
24            .map(|x| {
25                x.iter()
26                    .map(|y| y.to_string())
27                    .map(|y| StyledString::new(y, TextStyle::basic_left()))
28                    .collect::<Vec<_>>()
29            })
30            .collect();
31        Ok(Table::new(headers, rows, TableTheme::rounded()))
32    }
33}