aboutsummaryrefslogtreecommitdiff
path: root/kv/src/lib.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2026-01-24 04:31:48 +0100
committermetamuffin <metamuffin@disroot.org>2026-01-24 04:31:48 +0100
commitb2e88a8beabf04adc28947cf82996e8692a68b71 (patch)
tree23d66c8672b69cce7835ffabae4092669062ada8 /kv/src/lib.rs
parent774f64c0789529884dd7a5232f190e347ad29532 (diff)
downloadjellything-b2e88a8beabf04adc28947cf82996e8692a68b71.tar
jellything-b2e88a8beabf04adc28947cf82996e8692a68b71.tar.bz2
jellything-b2e88a8beabf04adc28947cf82996e8692a68b71.tar.zst
move things around; kv crate
Diffstat (limited to 'kv/src/lib.rs')
-rw-r--r--kv/src/lib.rs44
1 files changed, 44 insertions, 0 deletions
diff --git a/kv/src/lib.rs b/kv/src/lib.rs
new file mode 100644
index 0000000..0e9b78e
--- /dev/null
+++ b/kv/src/lib.rs
@@ -0,0 +1,44 @@
+/*
+ This file is part of jellything (https://codeberg.org/metamuffin/jellything)
+ which is licensed under the GNU Affero General Public License (version 3); see /COPYING.
+ Copyright (C) 2026 metamuffin <metamuffin.org>
+*/
+
+pub mod dummy;
+pub mod filesystem;
+pub mod memory;
+pub mod redb;
+pub mod rocksdb;
+
+pub use anyhow;
+
+use anyhow::Result;
+
+pub type WriteTxnFunction = dyn FnMut(&mut dyn WriteTransaction) -> Result<()>;
+pub type ReadTxnFunction = dyn FnMut(&dyn ReadTransaction) -> Result<()>;
+
+pub trait Database: Send + Sync + 'static {
+ fn write_transaction(
+ &self,
+ f: &mut dyn FnMut(&mut dyn WriteTransaction) -> Result<()>,
+ ) -> Result<()>;
+ fn read_transaction(&self, f: &mut dyn FnMut(&dyn ReadTransaction) -> Result<()>)
+ -> Result<()>;
+}
+pub trait WriteTransaction: ReadTransaction {
+ fn set(&mut self, key: &[u8], value: &[u8]) -> Result<()>;
+ fn del(&mut self, key: &[u8]) -> Result<()>;
+}
+pub trait ReadTransaction {
+ fn get(&self, key: &[u8]) -> Result<Option<Vec<u8>>>;
+ fn iter<'a>(
+ &'a self,
+ key: &[u8],
+ reverse: bool,
+ ) -> Result<Box<dyn Iterator<Item = Result<Vec<u8>>> + 'a>>;
+}
+
+pub trait BlobStorage: Send + Sync + 'static {
+ fn store(&self, key: &str, value: &[u8]) -> Result<()>;
+ fn read(&self, key: &str) -> Result<Option<Vec<u8>>>;
+}