mirror of
https://github.com/t8y2/dbx.git
synced 2026-10-29 00:09:52 +00:00
feat(query): add paged result fetching
This commit is contained in:
@@ -16,13 +16,25 @@ pub async fn execute_query(
|
||||
sql: String,
|
||||
schema: Option<String>,
|
||||
execution_id: Option<String>,
|
||||
max_rows: Option<usize>,
|
||||
fetch_size: Option<usize>,
|
||||
page_size: Option<usize>,
|
||||
result_session_id: Option<String>,
|
||||
) -> Result<db::QueryResult, String> {
|
||||
let registered_query =
|
||||
execution_id.as_ref().filter(|id| !id.trim().is_empty()).map(|id| state.running_queries.register(id.clone()));
|
||||
let cancel_token = registered_query.as_ref().map(|query| query.token());
|
||||
|
||||
dbx_core::query::execute_sql_statement(&state, &connection_id, &database, &sql, schema.as_deref(), cancel_token)
|
||||
.await
|
||||
dbx_core::query::execute_sql_statement_with_options(
|
||||
&state,
|
||||
&connection_id,
|
||||
&database,
|
||||
&sql,
|
||||
schema.as_deref(),
|
||||
cancel_token,
|
||||
dbx_core::query::QueryExecutionOptions { max_rows, fetch_size, page_size, result_session_id },
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
@@ -33,6 +45,10 @@ pub async fn execute_multi(
|
||||
sql: String,
|
||||
schema: Option<String>,
|
||||
execution_id: Option<String>,
|
||||
max_rows: Option<usize>,
|
||||
fetch_size: Option<usize>,
|
||||
page_size: Option<usize>,
|
||||
result_session_id: Option<String>,
|
||||
) -> Result<Vec<db::QueryResult>, String> {
|
||||
let registered_query =
|
||||
execution_id.as_ref().filter(|id| !id.trim().is_empty()).map(|id| state.running_queries.register(id.clone()));
|
||||
@@ -47,9 +63,16 @@ pub async fn execute_multi(
|
||||
sql
|
||||
);
|
||||
|
||||
let result =
|
||||
dbx_core::query::execute_multi_core(&state, &connection_id, &database, &sql, schema.as_deref(), cancel_token)
|
||||
.await;
|
||||
let result = dbx_core::query::execute_multi_core_with_options(
|
||||
&state,
|
||||
&connection_id,
|
||||
&database,
|
||||
&sql,
|
||||
schema.as_deref(),
|
||||
cancel_token,
|
||||
dbx_core::query::QueryExecutionOptions { max_rows, fetch_size, page_size, result_session_id },
|
||||
)
|
||||
.await;
|
||||
match &result {
|
||||
Ok(results) => log::info!(
|
||||
"[query][execute_multi:done] trace_id={} result_count={} row_counts={:?}",
|
||||
@@ -67,6 +90,16 @@ pub async fn cancel_query(state: State<'_, Arc<AppState>>, execution_id: String)
|
||||
Ok(state.running_queries.cancel(&execution_id))
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn close_query_session(
|
||||
state: State<'_, Arc<AppState>>,
|
||||
connection_id: String,
|
||||
database: String,
|
||||
session_id: String,
|
||||
) -> Result<bool, String> {
|
||||
dbx_core::query::close_query_session(&state, &connection_id, &database, &session_id).await
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn execute_batch(
|
||||
state: State<'_, Arc<AppState>>,
|
||||
|
||||
@@ -123,6 +123,7 @@ pub fn run() {
|
||||
commands::query::execute_query,
|
||||
commands::query::execute_multi,
|
||||
commands::query::cancel_query,
|
||||
commands::query::close_query_session,
|
||||
commands::query::execute_batch,
|
||||
commands::query::execute_script,
|
||||
commands::query::execute_in_transaction,
|
||||
|
||||
Reference in New Issue
Block a user