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

Method document_get_impl

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

Source from the content-addressed store, hash-verified

15
16impl NodeDbRemote {
17 pub(super) async fn document_get_impl(
18 &self,
19 collection: &str,
20 id: &str,
21 ) -> NodeDbResult<Option<Document>> {
22 let collection = quote_identifier(collection);
23 let sql = format!("SELECT id, data FROM {collection} WHERE id = $1");
24 let (_, rows) = self.query_raw(&sql, &[&id]).await?;
25
26 if let Some(row) = rows.first() {
27 let doc_id = row
28 .first()
29 .and_then(|v| v.as_str())
30 .unwrap_or(id)
31 .to_string();
32
33 let mut doc = Document::new(doc_id);
34
35 // If the second column is JSON, parse it into fields.
36 if let Some(Value::Object(fields)) = row.get(1) {
37 for (k, v) in fields {
38 doc.set(k.clone(), v.clone());
39 }
40 } else if let Some(Value::String(json_str)) = row.get(1)
41 && let Ok(parsed) =
42 sonic_rs::from_str::<HashMap<String, serde_json::Value>>(json_str)
43 {
44 for (k, v) in &parsed {
45 doc.set(k.clone(), json_to_value(v));
46 }
47 }
48
49 Ok(Some(doc))
50 } else {
51 Ok(None)
52 }
53 }
54
55 pub(super) async fn document_put_impl(
56 &self,

Callers 1

document_getMethod · 0.45

Calls 9

quote_identifierFunction · 0.85
query_rawMethod · 0.80
firstMethod · 0.80
to_stringMethod · 0.80
json_to_valueFunction · 0.50
as_strMethod · 0.45
getMethod · 0.45
setMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected