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

Method document_put_impl

nodedb-client/src/remote/client/document.rs:55–75  ·  view source on GitHub ↗
(
        &self,
        collection: &str,
        doc: Document,
    )

Source from the content-addressed store, hash-verified

53 }
54
55 pub(super) async fn document_put_impl(
56 &self,
57 collection: &str,
58 doc: Document,
59 ) -> NodeDbResult<()> {
60 let collection = quote_identifier(collection);
61 let data_json = sonic_rs::to_string(&doc.fields)
62 .map_err(|e| NodeDbError::storage(format!("document serialization: {e}")))?;
63 // NodeDB's SQL planner accepts JSON text values directly into
64 // the document `data` column — no `::jsonb` cast on the
65 // expression side, which the planner currently rejects as an
66 // "unsupported value expression". The server interprets the
67 // string literal as document JSON when the target column is the
68 // doc-engine `data` column.
69 let sql = format!(
70 "INSERT INTO {collection} (id, data) VALUES ($1, $2) \
71 ON CONFLICT (id) DO UPDATE SET data = $2"
72 );
73 self.execute_raw(&sql, &[&doc.id, &data_json]).await?;
74 Ok(())
75 }
76
77 pub(super) async fn document_delete_impl(
78 &self,

Callers 1

document_putMethod · 0.45

Calls 2

quote_identifierFunction · 0.85
execute_rawMethod · 0.80

Tested by

no test coverage detected