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

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

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

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

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

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

Loading…
Cancel
Save