fix(mongodb): support shell projection and db.version
This commit is contained in:
1 parent
44011cb9a4
commit
7a5984a1fd
24 files changed
+390
-38
No files matched your search
@@ -51,9 +51,16 @@ struct MongoFindDocumentsRequest {
|
||||
skip: Option<u64>,
|
||||
limit: Option<i64>,
|
||||
filter: Option<String>,
|
||||
projection: Option<String>,
|
||||
sort: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct MongoServerVersionRequest {
|
||||
connection_name: String,
|
||||
database: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct MongoAggregateDocumentsRequest {
|
||||
connection_name: String,
|
||||
@@ -157,6 +164,8 @@ pub fn start(app_handle: AppHandle, state: Arc<AppState>) {
|
||||
handle_mongo_list_collections_data(&st, body, &mut stream).await;
|
||||
} else if first_line.starts_with("POST /data/mongo/find-documents") {
|
||||
handle_mongo_find_documents_data(&st, body, &mut stream).await;
|
||||
} else if first_line.starts_with("POST /data/mongo/server-version") {
|
||||
handle_mongo_server_version_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/insert-documents") {
|
||||
@@ -410,6 +419,7 @@ async fn handle_mongo_find_documents_data(state: &Arc<AppState>, body: &str, str
|
||||
req.skip.unwrap_or(0),
|
||||
req.limit.unwrap_or(100),
|
||||
req.filter.as_deref(),
|
||||
req.projection.as_deref(),
|
||||
req.sort.as_deref(),
|
||||
)
|
||||
.await
|
||||
@@ -419,6 +429,25 @@ async fn handle_mongo_find_documents_data(state: &Arc<AppState>, body: &str, str
|
||||
}
|
||||
}
|
||||
|
||||
async fn handle_mongo_server_version_data(state: &Arc<AppState>, body: &str, stream: &mut tokio::net::TcpStream) {
|
||||
let req: MongoServerVersionRequest = match serde_json::from_str(body) {
|
||||
Ok(r) => r,
|
||||
Err(_) => {
|
||||
respond_error(stream, "400 Bad Request", "Invalid JSON").await;
|
||||
return;
|
||||
}
|
||||
};
|
||||
let Some((pool_key, database, _connection_id)) =
|
||||
resolve_mongo_pool_key(state, &req.connection_name, req.database, stream).await
|
||||
else {
|
||||
return;
|
||||
};
|
||||
match dbx_core::mongo_ops::mongo_server_version_core(state, &pool_key, &database).await {
|
||||
Ok(version) => respond_json(stream, &version).await,
|
||||
Err(e) => respond_error(stream, "500 Internal Server Error", &e).await,
|
||||
}
|
||||
}
|
||||
|
||||
async fn handle_mongo_aggregate_documents_data(state: &Arc<AppState>, body: &str, stream: &mut tokio::net::TcpStream) {
|
||||
let req: MongoAggregateDocumentsRequest = match serde_json::from_str(body) {
|
||||
Ok(r) => r,
|
||||
|
||||
@@ -81,6 +81,7 @@ pub async fn mongo_find_documents(
|
||||
skip: u64,
|
||||
limit: i64,
|
||||
filter: Option<String>,
|
||||
projection: Option<String>,
|
||||
sort: Option<String>,
|
||||
execution_id: Option<String>,
|
||||
) -> Result<MongoDocumentResult, String> {
|
||||
@@ -96,6 +97,7 @@ pub async fn mongo_find_documents(
|
||||
skip,
|
||||
limit,
|
||||
filter.as_deref(),
|
||||
projection.as_deref(),
|
||||
sort.as_deref(),
|
||||
),
|
||||
)
|
||||
@@ -112,6 +114,7 @@ pub async fn document_find_documents(
|
||||
skip: u64,
|
||||
limit: i64,
|
||||
filter: Option<String>,
|
||||
projection: Option<String>,
|
||||
sort: Option<String>,
|
||||
execution_id: Option<String>,
|
||||
) -> Result<MongoDocumentResult, String> {
|
||||
@@ -127,12 +130,25 @@ pub async fn document_find_documents(
|
||||
skip,
|
||||
limit,
|
||||
filter.as_deref(),
|
||||
projection.as_deref(),
|
||||
sort.as_deref(),
|
||||
),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn mongo_server_version(
|
||||
state: State<'_, Arc<AppState>>,
|
||||
connection_id: String,
|
||||
database: String,
|
||||
execution_id: Option<String>,
|
||||
) -> Result<String, String> {
|
||||
let app = state.inner().clone();
|
||||
run_cancellable(&app, execution_id, dbx_core::mongo_ops::mongo_server_version_core(&app, &connection_id, &database))
|
||||
.await
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn mongo_aggregate_documents(
|
||||
state: State<'_, Arc<AppState>>,
|
||||
|
||||
Reference in new issue
Block a user