diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index db24c4e..0e413b0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -61,7 +61,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, macos-latest] + os: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.os }} needs: check steps: diff --git a/sample.toml b/sample.toml index 2b82b0f..28c5487 100644 --- a/sample.toml +++ b/sample.toml @@ -9,3 +9,9 @@ user = "root" host = "localhost" port = 3306 database = "world" + +[[conn]] +user = "root" +host = "localhost" +port = 3306 +database = "employees" diff --git a/src/components/table.rs b/src/components/table.rs index 872c502..4d03b38 100644 --- a/src/components/table.rs +++ b/src/components/table.rs @@ -11,6 +11,9 @@ use tui::{ widgets::{Block, Borders, Cell, Row, Table, TableState}, Frame, }; +use unicode_width::UnicodeWidthStr; + +pub const RECORDS_LIMIT_PER_PAGE: u8 = 200; pub struct TableComponent { pub state: TableState, @@ -158,16 +161,7 @@ impl TableComponent { .iter() .map(|row| row[self.column_page..].to_vec()) .collect::>>(); - let mut new_rows = match self.state.selected() { - Some(index) => { - if index + 100 <= self.rows.len() { - rows[..index + 100].to_vec() - } else { - rows - } - } - None => rows, - }; + let mut new_rows = rows; for (index, row) in new_rows.iter_mut().enumerate() { row.insert(0, (index + 1).to_string()) } diff --git a/src/handlers/database_list.rs b/src/handlers/database_list.rs index 88ca64c..b88130d 100644 --- a/src/handlers/database_list.rs +++ b/src/handlers/database_list.rs @@ -1,4 +1,5 @@ use crate::app::{App, FocusBlock}; +use crate::components::table::RECORDS_LIMIT_PER_PAGE; use crate::components::Component as _; use crate::event::Key; use crate::utils::{get_columns, get_records}; @@ -19,6 +20,8 @@ pub async fn handler(key: Key, app: &mut App) -> anyhow::Result<()> { tables: vec![], }, &table, + 0, + RECORDS_LIMIT_PER_PAGE, app.pool.as_ref().unwrap(), ) .await?; diff --git a/src/handlers/record_table.rs b/src/handlers/record_table.rs index ab8e9cd..7f710f3 100644 --- a/src/handlers/record_table.rs +++ b/src/handlers/record_table.rs @@ -1,6 +1,9 @@ use crate::app::{App, FocusBlock}; +use crate::components::table::RECORDS_LIMIT_PER_PAGE; use crate::components::Component as _; use crate::event::Key; +use crate::utils::get_records; +use database_tree::Database; pub async fn handler(key: Key, app: &mut App) -> anyhow::Result<()> { match key { @@ -11,7 +14,29 @@ pub async fn handler(key: Key, app: &mut App) -> anyhow::Result<()> { app.clipboard.store(text) } } - key => app.record_table.event(key)?, + key => { + app.record_table.event(key)?; + if let Some(index) = app.record_table.state.selected() { + if index == app.record_table.rows.len().saturating_sub(1) { + if let Some((table, database)) = app.databases.tree().selected_table() { + let (_, records) = get_records( + &Database { + name: database.clone(), + tables: vec![], + }, + &table, + index as u16, + RECORDS_LIMIT_PER_PAGE, + app.pool.as_ref().unwrap(), + ) + .await?; + if !records.is_empty() { + app.record_table.rows.extend(records); + } + } + } + } + } } Ok(()) } diff --git a/src/utils.rs b/src/utils.rs index a75d311..d53adca 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -32,9 +32,17 @@ pub async fn get_tables(database: String, pool: &MySqlPool) -> anyhow::Result anyhow::Result<(Vec, Vec>)> { - let query = format!("SELECT * FROM `{}`.`{}`", database.name, table.name); + let query = format!( + "SELECT * FROM `{}`.`{}` limit {page}, {limit}", + database.name, + table.name, + page = page, + limit = limit + ); let mut rows = sqlx::query(query.as_str()).fetch(pool); let headers = sqlx::query(format!("SHOW COLUMNS FROM `{}`.`{}`", database.name, table.name).as_str())