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

Method put_in_txn

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

Insert or update a document within an externally-owned write transaction. Same prior-bytes semantics as [`SparseEngine::put`].

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

Source from the content-addressed store, hash-verified

137 /// Insert or update a document within an externally-owned write transaction.
138 /// Same prior-bytes semantics as [`SparseEngine::put`].
139 pub fn put_in_txn(
140 &self,
141 txn: &WriteTransaction,
142 tenant_id: u64,
143 collection: &str,
144 document_id: &str,
145 value: &[u8],
146 ) -> crate::Result<Option<Vec<u8>>> {
147 with_tenant_key(tenant_id, collection, document_id, |key| {
148 let mut table = txn
149 .open_table(DOCUMENTS)
150 .map_err(|e| redb_err("open table", e))?;
151 let prior = table
152 .insert(key, value)
153 .map_err(|e| redb_err("insert", e))?
154 .map(|g| g.value().to_vec());
155 Ok(prior)
156 })
157 }
158
159 /// Check whether a document exists within an externally-owned write
160 /// transaction — the probe used by INSERT-with-unique-PK semantics.

Callers 1

apply_point_putMethod · 0.80

Calls 4

with_tenant_keyFunction · 0.85
redb_errFunction · 0.70
insertMethod · 0.45
to_vecMethod · 0.45

Tested by

no test coverage detected