From 8380a32846eca5227ce092ba0cad41c12c53ebfc Mon Sep 17 00:00:00 2001 From: Kareem Ebrahim Date: Tue, 17 Sep 2024 00:28:05 +0300 Subject: [PATCH] =?UTF-8?q?fix:=20div=20ceil=20to=20get=20page=20count=20?= =?UTF-8?q?=F0=9F=90=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/core/src-tauri/src/commands/row.rs | 2 +- crates/handlers/src/handler.rs | 8 +++++--- crates/lib/src/types.rs | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/apps/core/src-tauri/src/commands/row.rs b/apps/core/src-tauri/src/commands/row.rs index 64a0ae00..29baa065 100644 --- a/apps/core/src-tauri/src/commands/row.rs +++ b/apps/core/src-tauri/src/commands/row.rs @@ -16,7 +16,7 @@ pub async fn get_paginated_rows( state: State<'_, Mutex>, table_name: String, page_index: u16, - page_size: i32, + page_size: u32, ) -> Result { let state = state.lock().await; let pool = &state.pool; diff --git a/crates/handlers/src/handler.rs b/crates/handlers/src/handler.rs index a08dce2f..1c849ded 100644 --- a/crates/handlers/src/handler.rs +++ b/crates/handlers/src/handler.rs @@ -37,18 +37,19 @@ pub trait TableHandler { #[async_trait] /// The logic for this trait is almost identical between all drivers, so default implementation is created. pub trait RowHandler { + #[allow(clippy::incompatible_msrv)] async fn get_paginated_rows( &self, pool: &AnyPool, table_name: String, page_index: u16, - page_size: i32, + page_size: u32, ) -> Result { let query_str = format!( "SELECT * FROM {} limit {} offset {};", table_name, page_size, - page_index as i32 * page_size + page_index as u32 * page_size ); let rows = sqlx::query(&query_str).fetch_all(pool).await?; @@ -56,7 +57,8 @@ pub trait RowHandler { let query_str = format!("SELECT COUNT(*) from {}", table_name); let page_count_result = sqlx::query(&query_str).fetch_one(pool).await?; - let page_count = page_count_result.try_get::(0).unwrap() as i32 / page_size; + let page_count = + (page_count_result.try_get::(0).unwrap() as u32).div_ceil(page_size); let paginated_rows = PaginatedRows::new(decode::decode_raw_rows(rows)?, page_count); diff --git a/crates/lib/src/types.rs b/crates/lib/src/types.rs index cb56e680..33532ed4 100644 --- a/crates/lib/src/types.rs +++ b/crates/lib/src/types.rs @@ -36,11 +36,11 @@ pub type ConnectionsFileSchema = HashMap; #[serde(rename_all = "camelCase")] pub struct PaginatedRows { data: Vec>, - page_count: i32, + page_count: u32, } impl PaginatedRows { - pub fn new(data: Vec>, page_count: i32) -> Self { + pub fn new(data: Vec>, page_count: u32) -> Self { PaginatedRows { data, page_count } } }