Delete a document (tenant-scoped). Returns the prior bytes when a row was actually removed, or `None` when nothing matched. The Event Plane needs the prior bytes as the `old_value` for CDC/trigger delete events; returning them here avoids a second read pass in the handler.
(
&self,
tenant_id: u64,
collection: &str,
document_id: &str,
)
| 282 | /// `old_value` for CDC/trigger delete events; returning them here |
| 283 | /// avoids a second read pass in the handler. |
| 284 | pub fn delete( |
| 285 | &self, |
| 286 | tenant_id: u64, |
| 287 | collection: &str, |
| 288 | document_id: &str, |
| 289 | ) -> crate::Result<Option<Vec<u8>>> { |
| 290 | with_tenant_key(tenant_id, collection, document_id, |key| { |
| 291 | let write_txn = self |
| 292 | .db |
| 293 | .begin_write() |
| 294 | .map_err(|e| redb_err("write txn", e))?; |
| 295 | let prior = { |
| 296 | let mut table = write_txn |
| 297 | .open_table(DOCUMENTS) |
| 298 | .map_err(|e| redb_err("open table", e))?; |
| 299 | table |
| 300 | .remove(key) |
| 301 | .map_err(|e| redb_err("remove", e))? |
| 302 | .map(|g| g.value().to_vec()) |
| 303 | }; |
| 304 | write_txn.commit().map_err(|e| redb_err("commit", e))?; |
| 305 | |
| 306 | debug!( |
| 307 | collection, |
| 308 | document_id, |
| 309 | removed = prior.is_some(), |
| 310 | "document delete" |
| 311 | ); |
| 312 | Ok(prior) |
| 313 | }) |
| 314 | } |
| 315 | |
| 316 | /// Begin a write transaction on the underlying database. |
| 317 | pub fn begin_write(&self) -> crate::Result<WriteTransaction> { |