feat(mongo): improve completion and add distinct support

This commit is contained in:
Võ Văn Thành (Jay) authored and GitHub committed 2026-07-16 18:21:10 +08:00
1 parent 5bcad3adc6
commit 640e82cdc6
19 files changed
+1865 -275

No files matched your search

+40
View File
@@ -98,6 +98,16 @@ struct MongoAggregateDocumentsRequest {
max_rows: Option<usize>,
}
#[derive(Deserialize)]
struct MongoDistinctRequest {
connection_name: String,
connection_id: Option<String>,
database: Option<String>,
collection: String,
field: String,
filter: Option<String>,
}
#[derive(Deserialize)]
struct MongoCreateIndexRequest {
connection_name: String,
@@ -234,6 +244,8 @@ pub fn start(app_handle: AppHandle, state: Arc<AppState>, data_dir: PathBuf) {
handle_mongo_collection_stats_data(&st, body, &mut stream).await;
} else if first_line.starts_with("POST /data/mongo/aggregate-documents") {
handle_mongo_aggregate_documents_data(&st, body, &mut stream).await;
} else if first_line.starts_with("POST /data/mongo/distinct") {
handle_mongo_distinct_data(&st, body, &mut stream).await;
} else if first_line.starts_with("POST /data/mongo/create-index") {
handle_mongo_create_index_data(&st, body, &mut stream).await;
} else if first_line.starts_with("POST /data/mongo/drop-indexes") {
@@ -660,6 +672,34 @@ async fn handle_mongo_aggregate_documents_data(state: &Arc<AppState>, body: &str
}
}
async fn handle_mongo_distinct_data(state: &Arc<AppState>, body: &str, stream: &mut tokio::net::TcpStream) {
let req: MongoDistinctRequest = match serde_json::from_str(body) {
Ok(r) => r,
Err(_) => {
respond_error(stream, "400 Bad Request", "Invalid JSON").await;
return;
}
};
let Some((connection_id, database)) =
resolve_mongo_target(state, req.connection_id.as_deref(), &req.connection_name, req.database, stream).await
else {
return;
};
match dbx_core::mongo_ops::mongo_distinct_core(
state,
&connection_id,
&database,
&req.collection,
&req.field,
req.filter.as_deref(),
)
.await
{
Ok(result) => respond_json(stream, &result).await,
Err(e) => respond_error(stream, "500 Internal Server Error", &e).await,
}
}
async fn handle_mongo_create_index_data(state: &Arc<AppState>, body: &str, stream: &mut tokio::net::TcpStream) {
let req: MongoCreateIndexRequest = match serde_json::from_str(body) {
Ok(r) => r,
+26
View File
@@ -221,6 +221,32 @@ pub async fn mongo_aggregate_documents(
.await
}
#[tauri::command]
pub async fn mongo_distinct(
state: State<'_, Arc<AppState>>,
connection_id: String,
database: String,
collection: String,
field: String,
filter: Option<String>,
execution_id: Option<String>,
) -> Result<MongoDocumentResult, String> {
let app = state.inner().clone();
run_cancellable(
&app,
execution_id,
dbx_core::mongo_ops::mongo_distinct_core(
&app,
&connection_id,
&database,
&collection,
&field,
filter.as_deref(),
),
)
.await
}
#[tauri::command]
pub async fn mongo_create_index(
state: State<'_, Arc<AppState>>,