feat: added total rows count logic

pull/170/head
Valentin271 1 year ago
parent 77a0a22ea0
commit 49b7b1a315
No known key found for this signature in database
GPG Key ID: 77B4667C08D99D91

@ -165,10 +165,9 @@ impl App {
async fn update_record_table(&mut self) -> anyhow::Result<()> {
if let Some((database, table)) = self.databases.tree().selected_table() {
let (headers, records) = self
.pool
.as_ref()
.unwrap()
let pool = self.pool.as_ref().unwrap();
let (headers, records) = pool
.get_records(
&database,
&table,
@ -180,8 +179,26 @@ impl App {
},
)
.await?;
self.record_table
.update(records, headers, database.clone(), table.clone());
let total_rows = pool
.get_total_records_count(
&database,
&table,
if self.record_table.filter.input_str().is_empty() {
None
} else {
Some(self.record_table.filter.input_str())
},
)
.await?;
self.record_table.update(
records,
total_rows,
headers,
database.clone(),
table.clone(),
);
}
Ok(())
}
@ -227,14 +244,23 @@ impl App {
if key == self.config.key_config.enter && self.databases.tree_focused() {
if let Some((database, table)) = self.databases.tree().selected_table() {
self.record_table.reset();
let (headers, records) = self
.pool
.as_ref()
.unwrap()
.get_records(&database, &table, 0, None)
let pool = self.pool.as_ref().unwrap();
let (headers, records) =
pool.get_records(&database, &table, 0, None).await?;
let total_rows = pool
.get_total_records_count(&database, &table, None)
.await?;
self.record_table
.update(records, headers, database.clone(), table.clone());
self.record_table.update(
records,
total_rows,
headers,
database.clone(),
table.clone(),
);
self.properties
.update(database.clone(), table.clone(), self.pool.as_ref().unwrap())
.await?;

@ -74,6 +74,7 @@ impl PropertiesComponent {
.iter()
.map(|c| c.columns())
.collect::<Vec<Vec<String>>>(),
Some(columns.len()),
columns.get(0).unwrap().fields(),
database.clone(),
table.clone(),
@ -87,6 +88,7 @@ impl PropertiesComponent {
.iter()
.map(|c| c.columns())
.collect::<Vec<Vec<String>>>(),
Some(constraints.len()),
constraints.get(0).unwrap().fields(),
database.clone(),
table.clone(),
@ -100,6 +102,7 @@ impl PropertiesComponent {
.iter()
.map(|c| c.columns())
.collect::<Vec<Vec<String>>>(),
Some(foreign_keys.len()),
foreign_keys.get(0).unwrap().fields(),
database.clone(),
table.clone(),
@ -113,6 +116,7 @@ impl PropertiesComponent {
.iter()
.map(|c| c.columns())
.collect::<Vec<Vec<String>>>(),
Some(indexes.len()),
indexes.get(0).unwrap().fields(),
database.clone(),
table.clone(),

@ -36,11 +36,13 @@ impl RecordTableComponent {
pub fn update(
&mut self,
rows: Vec<Vec<String>>,
total_rows: usize,
headers: Vec<String>,
database: Database,
table: DTable,
) {
self.table.update(rows, headers, database, table.clone());
self.table
.update(rows, Some(total_rows), headers, database, table.clone());
self.filter.table = Some(table);
}

@ -269,7 +269,8 @@ impl Component for SqlEditorComponent {
database,
table,
} => {
self.table.update(rows, headers, database, table);
// TODO
self.table.update(rows, None, headers, database, table);
self.focus = Focus::Table;
self.query_result = None;
}

@ -20,6 +20,7 @@ use unicode_width::UnicodeWidthStr;
pub struct TableComponent {
pub headers: Vec<String>,
pub rows: Vec<Vec<String>>,
pub total_rows: Option<usize>,
pub eod: bool,
pub selected_row: TableState,
table: Option<(Database, DTable)>,
@ -36,6 +37,7 @@ impl TableComponent {
selected_row: TableState::default(),
headers: vec![],
rows: vec![],
total_rows: None,
table: None,
selected_column: 0,
selection_area_corner: None,
@ -55,6 +57,7 @@ impl TableComponent {
pub fn update(
&mut self,
rows: Vec<Vec<String>>,
total_rows: Option<usize>,
headers: Vec<String>,
database: Database,
table: DTable,
@ -65,6 +68,7 @@ impl TableComponent {
}
self.headers = headers;
self.rows = rows;
self.total_rows = total_rows;
self.selected_column = 0;
self.selection_area_corner = None;
self.column_page_start = std::cell::Cell::new(0);
@ -503,6 +507,7 @@ impl StatefulDrawableComponent for TableComponent {
} else {
Some(self.rows.len())
},
self.total_rows,
if self.headers.is_empty() {
None
} else {

@ -15,6 +15,7 @@ use tui::{
pub struct TableStatusComponent {
column_count: Option<usize>,
row_count: Option<usize>,
total_row_count: Option<usize>,
table: Option<Table>,
}
@ -22,6 +23,7 @@ impl Default for TableStatusComponent {
fn default() -> Self {
Self {
row_count: None,
total_row_count: None,
column_count: None,
table: None,
}
@ -31,11 +33,13 @@ impl Default for TableStatusComponent {
impl TableStatusComponent {
pub fn new(
row_count: Option<usize>,
total_row_count: Option<usize>,
column_count: Option<usize>,
table: Option<Table>,
) -> Self {
Self {
row_count,
total_row_count,
column_count,
table,
}
@ -49,6 +53,11 @@ impl DrawableComponent for TableStatusComponent {
"rows: {}, ",
self.row_count.map_or("-".to_string(), |c| c.to_string())
)),
Span::from(format!(
"total rows : {}, ",
self.total_row_count
.map_or("-".to_string(), |c| c.to_string())
)),
Span::from(format!(
"columns: {}, ",
self.column_count.map_or("-".to_string(), |c| c.to_string())

Loading…
Cancel
Save