Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds a total row count in the footer #170

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,8 @@ which = "4.1"

[dev-dependencies]
pretty_assertions = "1.0.0"

[profile.release]
strip = true
lto = true
opt-level = 3
9 changes: 5 additions & 4 deletions database-tree/src/databasetree.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::{collections::BTreeSet, usize};

use crate::{
databasetreeitems::DatabaseTreeItems, error::Result, item::DatabaseTreeItemKind,
tree_iter::TreeIterator,
tree_iter::TreeIterator, Database, Table,
};
use crate::{Database, Table};
use std::{collections::BTreeSet, usize};

///
#[derive(Copy, Clone, Debug)]
Expand Down Expand Up @@ -366,9 +366,10 @@ impl DatabaseTree {

#[cfg(test)]
mod test {
use crate::{Database, DatabaseTree, MoveSelection, Schema, Table};
use std::collections::BTreeSet;

use crate::{Database, DatabaseTree, MoveSelection, Schema, Table};

impl Table {
fn new(name: String) -> Self {
Table {
Expand Down
8 changes: 5 additions & 3 deletions database-tree/src/databasetreeitems.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use crate::{error::Result, treeitems_iter::TreeItemsIterator};
use crate::{item::DatabaseTreeItemKind, DatabaseTreeItem};
use crate::{Child, Database};
use std::{
collections::{BTreeSet, HashMap},
usize,
};

use crate::{
error::Result, item::DatabaseTreeItemKind, treeitems_iter::TreeItemsIterator, Child, Database,
DatabaseTreeItem,
};

#[derive(Default)]
pub struct DatabaseTreeItems {
pub tree_items: Vec<DatabaseTreeItem>,
Expand Down
1 change: 1 addition & 0 deletions database-tree/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::num::TryFromIntError;

use thiserror::Error;

#[derive(Error, Debug)]
Expand Down
3 changes: 1 addition & 2 deletions database-tree/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ mod tree_iter;
mod treeitems_iter;

pub use crate::{
databasetree::DatabaseTree,
databasetree::MoveSelection,
databasetree::{DatabaseTree, MoveSelection},
item::{DatabaseTreeItem, TreeItemInfo},
};

Expand Down
76 changes: 50 additions & 26 deletions src/app.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
use crate::clipboard::copy_to_clipboard;
use crate::components::{
CommandInfo, Component as _, DrawableComponent as _, EventState, StatefulDrawableComponent,
use tui::{
backend::Backend,
layout::{Constraint, Direction, Layout, Rect},
Frame,
};
use crate::database::{MySqlPool, Pool, PostgresPool, SqlitePool, RECORDS_LIMIT_PER_PAGE};
use crate::event::Key;

use crate::{
components::tab::Tab,
clipboard::copy_to_clipboard,
components::{
command, ConnectionsComponent, DatabasesComponent, ErrorComponent, HelpComponent,
PropertiesComponent, RecordTableComponent, SqlEditorComponent, TabComponent,
command, tab::Tab, CommandInfo, Component as _, ConnectionsComponent, DatabasesComponent,
DrawableComponent as _, ErrorComponent, EventState, HelpComponent, PropertiesComponent,
RecordTableComponent, SqlEditorComponent, StatefulDrawableComponent, TabComponent,
},
config::Config,
};
use tui::{
backend::Backend,
layout::{Constraint, Direction, Layout, Rect},
Frame,
database::{MySqlPool, Pool, PostgresPool, SqlitePool, RECORDS_LIMIT_PER_PAGE},
event::Key,
};

pub enum Focus {
Expand Down Expand Up @@ -165,10 +163,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,
Expand All @@ -180,8 +177,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(())
}
Expand Down Expand Up @@ -227,14 +242,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?;
Expand Down
3 changes: 2 additions & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::config::CliConfig;
use structopt::StructOpt;

use crate::config::CliConfig;

/// A cross-platform TUI database management tool written in Rust
#[derive(StructOpt, Debug)]
#[structopt(name = "gobang")]
Expand Down
10 changes: 7 additions & 3 deletions src/clipboard.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
use anyhow::{anyhow, Result};
#[cfg(all(target_family = "unix", not(target_os = "macos")))]
use std::ffi::OsStr;
use std::io::Write;
use std::process::{Command, Stdio};
use std::{
io::Write,
process::{Command, Stdio},
};

use anyhow::{anyhow, Result};

fn execute_copy_command(command: Command, text: &str) -> Result<()> {
let mut command = command;
Expand Down Expand Up @@ -42,6 +45,7 @@ fn gen_command(path: impl AsRef<OsStr>, xclip_syntax: bool) -> Command {
#[cfg(all(target_family = "unix", not(target_os = "macos")))]
pub fn copy_to_clipboard(string: &str) -> Result<()> {
use std::path::PathBuf;

use which::which;
let (path, xclip_syntax) = which("xclip").ok().map_or_else(
|| {
Expand Down
7 changes: 3 additions & 4 deletions src/components/completion.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
use super::{Component, EventState, MovableComponent};
use crate::components::command::CommandInfo;
use crate::config::KeyConfig;
use crate::event::Key;
use anyhow::Result;
use tui::{
backend::Backend,
Expand All @@ -11,6 +7,9 @@ use tui::{
Frame,
};

use super::{Component, EventState, MovableComponent};
use crate::{components::command::CommandInfo, config::KeyConfig, event::Key};

const RESERVED_WORDS_IN_WHERE_CLAUSE: &[&str] = &["IN", "AND", "OR", "NOT", "NULL", "IS"];
const ALL_RESERVED_WORDS: &[&str] = &[
"IN", "AND", "OR", "NOT", "NULL", "IS", "SELECT", "UPDATE", "DELETE", "FROM", "LIMIT", "WHERE",
Expand Down
11 changes: 7 additions & 4 deletions src/components/connections.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
use super::{Component, EventState, StatefulDrawableComponent};
use crate::components::command::CommandInfo;
use crate::config::{Connection, KeyConfig};
use crate::event::Key;
use anyhow::Result;
use tui::{
backend::Backend,
Expand All @@ -12,6 +8,13 @@ use tui::{
Frame,
};

use super::{Component, EventState, StatefulDrawableComponent};
use crate::{
components::command::CommandInfo,
config::{Connection, KeyConfig},
event::Key,
};

pub struct ConnectionsComponent {
connections: Vec<Connection>,
state: ListState,
Expand Down
6 changes: 3 additions & 3 deletions src/components/database_filter.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
use super::{compute_character_width, Component, DrawableComponent, EventState};
use crate::components::command::CommandInfo;
use crate::event::Key;
use anyhow::Result;
use database_tree::Table;
use tui::{
Expand All @@ -13,6 +10,9 @@ use tui::{
};
use unicode_width::UnicodeWidthStr;

use super::{compute_character_width, Component, DrawableComponent, EventState};
use crate::{components::command::CommandInfo, event::Key};

pub struct DatabaseFilterComponent {
pub table: Option<Table>,
input: Vec<char>,
Expand Down
29 changes: 16 additions & 13 deletions src/components/databases.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
use super::{
utils::scroll_vertical::VerticalScroll, Component, DatabaseFilterComponent, DrawableComponent,
EventState,
};
use crate::components::command::{self, CommandInfo};
use crate::config::{Connection, KeyConfig};
use crate::database::Pool;
use crate::event::Key;
use crate::ui::common_nav;
use crate::ui::scrolllist::draw_list_block;
use std::{collections::BTreeSet, convert::From};

use anyhow::Result;
use database_tree::{Database, DatabaseTree, DatabaseTreeItem};
use std::collections::BTreeSet;
use std::convert::From;
use tui::{
backend::Backend,
layout::{Constraint, Direction, Layout, Rect},
Expand All @@ -21,6 +11,18 @@ use tui::{
Frame,
};

use super::{
utils::scroll_vertical::VerticalScroll, Component, DatabaseFilterComponent, DrawableComponent,
EventState,
};
use crate::{
components::command::{self, CommandInfo},
config::{Connection, KeyConfig},
database::Pool,
event::Key,
ui::{common_nav, scrolllist::draw_list_block},
};

// ▸
const FOLDER_ICON_COLLAPSED: &str = "\u{25b8}";
// ▾
Expand Down Expand Up @@ -274,9 +276,10 @@ fn tree_nav(tree: &mut DatabaseTree, key: Key, key_config: &KeyConfig) -> bool {

#[cfg(test)]
mod test {
use super::{Color, Database, DatabaseTreeItem, DatabasesComponent, Span, Spans, Style};
use database_tree::Table;

use super::{Color, Database, DatabaseTreeItem, DatabasesComponent, Span, Spans, Style};

#[test]
fn test_tree_database_tree_item_to_span() {
const WIDTH: u16 = 10;
Expand Down
7 changes: 3 additions & 4 deletions src/components/debug.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
use super::{Component, DrawableComponent, EventState};
use crate::components::command::CommandInfo;
use crate::config::KeyConfig;
use crate::event::Key;
use anyhow::Result;
use tui::{
backend::Backend,
Expand All @@ -10,6 +6,9 @@ use tui::{
Frame,
};

use super::{Component, DrawableComponent, EventState};
use crate::{components::command::CommandInfo, config::KeyConfig, event::Key};

pub struct DebugComponent {
msg: String,
visible: bool,
Expand Down
7 changes: 3 additions & 4 deletions src/components/error.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
use super::{Component, DrawableComponent, EventState};
use crate::components::command::CommandInfo;
use crate::config::KeyConfig;
use crate::event::Key;
use anyhow::Result;
use tui::{
backend::Backend,
Expand All @@ -11,6 +7,9 @@ use tui::{
Frame,
};

use super::{Component, DrawableComponent, EventState};
use crate::{components::command::CommandInfo, config::KeyConfig, event::Key};

pub struct ErrorComponent {
pub error: String,
visible: bool,
Expand Down
11 changes: 5 additions & 6 deletions src/components/help.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
use super::{Component, DrawableComponent, EventState};
use crate::components::command::CommandInfo;
use crate::config::KeyConfig;
use crate::event::Key;
use crate::version::Version;
use std::convert::From;

use anyhow::Result;
use itertools::Itertools;
use std::convert::From;
use tui::{
backend::Backend,
layout::{Alignment, Constraint, Direction, Layout, Rect},
Expand All @@ -15,6 +11,9 @@ use tui::{
Frame,
};

use super::{Component, DrawableComponent, EventState};
use crate::{components::command::CommandInfo, config::KeyConfig, event::Key, version::Version};

pub struct HelpComponent {
cmds: Vec<CommandInfo>,
visible: bool,
Expand Down
Loading