MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / project_doc

Function project_doc

nodedb/src/data/executor/handlers/spatial.rs:329–349  ·  view source on GitHub ↗

Apply projection to a document, returning `nodedb_types::Value`.

(doc: &Value, doc_id: &str, projection: &[String])

Source from the content-addressed store, hash-verified

327
328/// Apply projection to a document, returning `nodedb_types::Value`.
329fn project_doc(doc: &Value, doc_id: &str, projection: &[String]) -> Value {
330 if projection.is_empty() {
331 // Add id if not present.
332 if let Value::Object(mut map) = doc.clone() {
333 map.entry("id".to_string())
334 .or_insert(Value::String(doc_id.to_string()));
335 Value::Object(map)
336 } else {
337 doc.clone()
338 }
339 } else {
340 let mut map = std::collections::HashMap::new();
341 map.insert("id".to_string(), Value::String(doc_id.to_string()));
342 for col in projection {
343 if let Some(v) = doc.get(col) {
344 map.insert(col.clone(), v.clone());
345 }
346 }
347 Value::Object(map)
348 }
349}
350
351/// Expand a bounding box by a distance in meters.
352fn expand_bbox(bbox: &nodedb_types::BoundingBox, meters: f64) -> nodedb_types::BoundingBox {

Callers 2

execute_spatial_scanMethod · 0.85
spatial_full_scanMethod · 0.85

Calls 6

entryMethod · 0.80
to_stringMethod · 0.80
is_emptyMethod · 0.45
cloneMethod · 0.45
insertMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected