moltendb_core/handlers/
process_analytics.rs1#![allow(dead_code)]
2use serde_json::{Value, json};
3use crate::validation;
4use crate::{engine, analytics};
5
6pub fn process_analytics(db: &engine::Db, payload: &Value, max_body_size: usize) -> Value {
14 if let Err(e) = validation::validate_request(payload, max_body_size) {
16 return json!({ "error": e.to_string() });
17 }
18
19 let query: analytics::AnalyticsQuery = match serde_json::from_value(payload.clone()) {
21 Ok(q) => q,
22 Err(e) => return json!({ "error": format!("Invalid analytics query: {}", e) }),
23 };
24
25 let result = match analytics::execute_query(db, &query) {
27 Ok(res) => res,
28 Err(e) => return json!({ "error": format!("Analytics execution failed: {}", e) }),
29 };
30
31 json!({
33 "result": result.result,
34 "metadata": {
35 "execution_time_ms": result.metadata.execution_time_ms,
36 "rows_scanned": result.metadata.rows_scanned
37 }
38 })
39}