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

Method put

nodedb/src/engine/sparse/btree.rs:109–135  ·  view source on GitHub ↗

Insert or update a document (tenant-scoped). Returns the prior bytes when this write replaced an existing document, or `None` when it was a fresh insert. Callers thread the prior value into Event Plane emission so the `WriteOp` tag (Insert vs Update) reflects the actual mutation — there is no separate probe.

(
        &self,
        tenant_id: u64,
        collection: &str,
        document_id: &str,
        value: &[u8],
    )

Source from the content-addressed store, hash-verified

107 /// into Event Plane emission so the `WriteOp` tag (Insert vs Update)
108 /// reflects the actual mutation — there is no separate probe.
109 pub fn put(
110 &self,
111 tenant_id: u64,
112 collection: &str,
113 document_id: &str,
114 value: &[u8],
115 ) -> crate::Result<Option<Vec<u8>>> {
116 with_tenant_key(tenant_id, collection, document_id, |key| {
117 let write_txn = self
118 .db
119 .begin_write()
120 .map_err(|e| redb_err("write txn", e))?;
121 let prior = {
122 let mut table = write_txn
123 .open_table(DOCUMENTS)
124 .map_err(|e| redb_err("open table", e))?;
125 table
126 .insert(key, value)
127 .map_err(|e| redb_err("insert", e))?
128 .map(|g| g.value().to_vec())
129 };
130 write_txn.commit().map_err(|e| redb_err("commit", e))?;
131
132 debug!(collection, document_id, len = value.len(), "document put");
133 Ok(prior)
134 })
135 }
136
137 /// Insert or update a document within an externally-owned write transaction.
138 /// Same prior-bytes semantics as [`SparseEngine::put`].

Calls 6

with_tenant_keyFunction · 0.85
begin_writeMethod · 0.80
redb_errFunction · 0.70
insertMethod · 0.45
to_vecMethod · 0.45
commitMethod · 0.45