diff --git a/src/app.rs b/src/app.rs index db41011..184bb55 100644 --- a/src/app.rs +++ b/src/app.rs @@ -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?; diff --git a/src/components/properties.rs b/src/components/properties.rs index acd6ee4..ff92322 100644 --- a/src/components/properties.rs +++ b/src/components/properties.rs @@ -74,6 +74,7 @@ impl PropertiesComponent { .iter() .map(|c| c.columns()) .collect::>>(), + Some(columns.len()), columns.get(0).unwrap().fields(), database.clone(), table.clone(), @@ -87,6 +88,7 @@ impl PropertiesComponent { .iter() .map(|c| c.columns()) .collect::>>(), + Some(constraints.len()), constraints.get(0).unwrap().fields(), database.clone(), table.clone(), @@ -100,6 +102,7 @@ impl PropertiesComponent { .iter() .map(|c| c.columns()) .collect::>>(), + 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::>>(), + Some(indexes.len()), indexes.get(0).unwrap().fields(), database.clone(), table.clone(), diff --git a/src/components/record_table.rs b/src/components/record_table.rs index d4857aa..8eae65c 100644 --- a/src/components/record_table.rs +++ b/src/components/record_table.rs @@ -36,11 +36,13 @@ impl RecordTableComponent { pub fn update( &mut self, rows: Vec>, + total_rows: usize, headers: Vec, 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); } diff --git a/src/components/sql_editor.rs b/src/components/sql_editor.rs index 50e53cf..6a95b79 100644 --- a/src/components/sql_editor.rs +++ b/src/components/sql_editor.rs @@ -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; } diff --git a/src/components/table.rs b/src/components/table.rs index 0c5da62..6860261 100644 --- a/src/components/table.rs +++ b/src/components/table.rs @@ -20,6 +20,7 @@ use unicode_width::UnicodeWidthStr; pub struct TableComponent { pub headers: Vec, pub rows: Vec>, + pub total_rows: Option, 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>, + total_rows: Option, headers: Vec, 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 { diff --git a/src/components/table_status.rs b/src/components/table_status.rs index 1b49342..0f187cd 100644 --- a/src/components/table_status.rs +++ b/src/components/table_status.rs @@ -15,6 +15,7 @@ use tui::{ pub struct TableStatusComponent { column_count: Option, row_count: Option, + total_row_count: Option, table: Option, } @@ -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, + total_row_count: Option, column_count: Option, table: Option
, ) -> 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())