Skip to content

Commit

Permalink
feat: limit query
Browse files Browse the repository at this point in the history
  • Loading branch information
l1xnan committed Mar 17, 2024
1 parent 6d5a2cb commit 165c5a8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
11 changes: 11 additions & 0 deletions src-tauri/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ pub struct DialectPayload {
pub cwd: Option<String>,
}

#[allow(clippy::unused_async)]
pub fn get_ast_dialect(dialect: &str) -> Box<dyn sqlparser::dialect::Dialect> {
match dialect {
"folder" | "file" | "duckdb" => Box::new(sqlparser::dialect::DuckDbDialect {}),
"clickhouse" => Box::new(sqlparser::dialect::ClickHouseDialect {}),
"mysql" => Box::new(sqlparser::dialect::MySqlDialect {}),
"postgres" => Box::new(sqlparser::dialect::PostgreSqlDialect {}),
_ => Box::new(sqlparser::dialect::GenericDialect {}),
}
}

#[allow(clippy::unused_async)]
pub async fn get_dialect(
DialectPayload {
Expand Down
5 changes: 3 additions & 2 deletions src-tauri/src/dialect/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,13 @@ pub async fn _paging_query(
if let Some(ref _stmt) = stmt {
sql = ast::limit_stmt(dialect, _stmt, limit, offset).unwrap_or(sql);
}
let mut res = d.query_all(&sql).await?;
let mut res = d.query(&sql, 0, 0).await?;

// get total row count
if let Some(ref _stmt) = stmt {
if let Some(count_sql) = ast::count_stmt(dialect, _stmt) {
if let Ok(count) = d._sql_row_count(&count_sql).await {
log::info!("count_sql: {count_sql}");
if let Ok(count) = d.query_count(&count_sql).await {
res.total = count;
};
}
Expand Down
1 change: 0 additions & 1 deletion src-tauri/src/dialect/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::convert::From;
use std::sync::Arc;

use arrow::array::*;
use arrow::datatypes::*;
use arrow::datatypes::{DataType, Field, Schema};
use async_trait::async_trait;
use rusqlite::types::Value;
Expand Down

0 comments on commit 165c5a8

Please # to comment.