aboutsummaryrefslogtreecommitdiff
path: root/database/src/backends/rocksdb.rs
diff options
context:
space:
mode:
Diffstat (limited to 'database/src/backends/rocksdb.rs')
-rw-r--r--database/src/backends/rocksdb.rs35
1 files changed, 35 insertions, 0 deletions
diff --git a/database/src/backends/rocksdb.rs b/database/src/backends/rocksdb.rs
new file mode 100644
index 0000000..7c6f5f3
--- /dev/null
+++ b/database/src/backends/rocksdb.rs
@@ -0,0 +1,35 @@
+/*
+ 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) 2025 metamuffin <metamuffin.org>
+*/
+
+use crate::backends::DatabaseStorage;
+use anyhow::Result;
+use rocksdb::DB;
+
+pub struct Rocksdb {
+ db: DB,
+}
+
+impl DatabaseStorage for Rocksdb {
+ fn set(&self, key: &[u8], value: &[u8]) -> Result<()> {
+ self.db.put(key, value)?;
+ Ok(())
+ }
+ fn get<'a>(&'a self, key: &[u8]) -> Result<Option<Vec<u8>>> {
+ Ok(self.db.get(key)?)
+ }
+ fn next(&self, key: &[u8]) -> Result<Option<Vec<u8>>> {
+ let mut it = self.db.raw_iterator();
+ it.seek_for_prev(key);
+ it.next();
+ Ok(it.key().map(Vec::from))
+ }
+ fn prev(&self, key: &[u8]) -> Result<Option<Vec<u8>>> {
+ let mut it = self.db.raw_iterator();
+ it.seek(key);
+ it.prev();
+ Ok(it.key().map(Vec::from))
+ }
+}