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

Method document_get_impl

nodedb-client/src/native/client/document.rs:15–50  ·  view source on GitHub ↗
(
        &self,
        collection: &str,
        id: &str,
    )

Source from the content-addressed store, hash-verified

13
14impl NativeClient {
15 pub(super) async fn document_get_impl(
16 &self,
17 collection: &str,
18 id: &str,
19 ) -> NodeDbResult<Option<Document>> {
20 let mut conn = self.pool.acquire().await?;
21 let resp = conn
22 .send(
23 OpCode::PointGet,
24 TextFields {
25 collection: Some(collection.to_string()),
26 document_id: Some(id.to_string()),
27 ..Default::default()
28 },
29 )
30 .await?;
31
32 let rows = resp.rows.unwrap_or_default();
33 if rows.is_empty() {
34 return Ok(None);
35 }
36
37 let json_text = rows[0].first().and_then(|v| v.as_str()).unwrap_or("{}");
38 let obj: HashMap<String, serde_json::Value> =
39 sonic_rs::from_str(json_text).map_err(|e| {
40 NodeDbError::serialization(
41 "json",
42 format!("document_get response for id '{id}': {e}"),
43 )
44 })?;
45 let mut doc = Document::new(id);
46 for (k, v) in obj {
47 doc.set(&k, json_to_value(v));
48 }
49 Ok(Some(doc))
50 }
51
52 pub(super) async fn document_put_impl(
53 &self,

Callers 1

document_getMethod · 0.45

Calls 9

serializationFunction · 0.85
to_stringMethod · 0.80
firstMethod · 0.80
json_to_valueFunction · 0.50
acquireMethod · 0.45
sendMethod · 0.45
is_emptyMethod · 0.45
as_strMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected