diff options
| author | metamuffin <metamuffin@disroot.org> | 2025-12-18 18:45:53 +0100 |
|---|---|---|
| committer | metamuffin <metamuffin@disroot.org> | 2025-12-18 18:45:53 +0100 |
| commit | da985cc06e4caa7501222dbf54f212536fd42b0c (patch) | |
| tree | 106ebacb66abb8fd97a7be4e802ac45d8ce9852d /database/src/table.rs | |
| parent | fc7f3ae8e39a0398ceba7b9c44f58679c01a98da (diff) | |
| download | jellything-da985cc06e4caa7501222dbf54f212536fd42b0c.tar jellything-da985cc06e4caa7501222dbf54f212536fd42b0c.tar.bz2 jellything-da985cc06e4caa7501222dbf54f212536fd42b0c.tar.zst | |
transaction interface
Diffstat (limited to 'database/src/table.rs')
| -rw-r--r-- | database/src/table.rs | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/database/src/table.rs b/database/src/table.rs index 8c6b724..e2f6196 100644 --- a/database/src/table.rs +++ b/database/src/table.rs @@ -4,7 +4,10 @@ Copyright (C) 2025 metamuffin <metamuffin.org> */ -use crate::{backends::KV, indices::Index}; +use crate::{ + backends::{ReadTransaction, WriteTransaction}, + indices::Index, +}; use anyhow::Result; use serde::{Serialize, de::DeserializeOwned}; @@ -27,7 +30,7 @@ impl<T: Serialize + DeserializeOwned> Table<T> { key.extend(row.to_be_bytes()); key } - pub fn insert(&self, db: &dyn KV, entry: T) -> Result<RowNum> { + pub fn insert(&self, db: &mut dyn WriteTransaction, entry: T) -> Result<RowNum> { let mut id_counter = db .get(&self.id.to_be_bytes())? .map(|k| k.as_slice().try_into().map(RowNum::from_be_bytes).ok()) @@ -45,13 +48,13 @@ impl<T: Serialize + DeserializeOwned> Table<T> { Ok(id_counter) } - pub fn get(&self, db: &dyn KV, row: RowNum) -> Result<Option<T>> { + pub fn get(&self, db: &dyn ReadTransaction, row: RowNum) -> Result<Option<T>> { Ok(db .get(&self.key(row))? .map(|v| serde_json::from_slice(&v)) .transpose()?) } - pub fn remove(&self, db: &dyn KV, row: RowNum) -> Result<bool> { + pub fn remove(&self, db: &mut dyn WriteTransaction, row: RowNum) -> Result<bool> { let Some(entry) = self.get(db, row)? else { return Ok(false); }; |