mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 20:29:23 +00:00
Bind RocksDB into serai-db
This commit is contained in:
34
common/db/src/rocks.rs
Normal file
34
common/db/src/rocks.rs
Normal file
@@ -0,0 +1,34 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use rocksdb::{ThreadMode, Transaction, TransactionDB};
|
||||
|
||||
use crate::*;
|
||||
|
||||
impl<T: ThreadMode> Get for Transaction<'_, TransactionDB<T>> {
|
||||
fn get(&self, key: impl AsRef<[u8]>) -> Option<Vec<u8>> {
|
||||
self.get(key).expect("couldn't read from RocksDB via transaction")
|
||||
}
|
||||
}
|
||||
impl<T: ThreadMode> DbTxn for Transaction<'_, TransactionDB<T>> {
|
||||
fn put(&mut self, key: impl AsRef<[u8]>, value: impl AsRef<[u8]>) {
|
||||
Transaction::put(self, key, value).expect("couldn't write to RocksDB via transaction")
|
||||
}
|
||||
fn del(&mut self, key: impl AsRef<[u8]>) {
|
||||
self.delete(key).expect("couldn't delete from RocksDB via transaction")
|
||||
}
|
||||
fn commit(self) {
|
||||
Transaction::commit(self).expect("couldn't commit to RocksDB via transaction")
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: ThreadMode> Get for Arc<TransactionDB<T>> {
|
||||
fn get(&self, key: impl AsRef<[u8]>) -> Option<Vec<u8>> {
|
||||
TransactionDB::get(self, key).expect("couldn't read from RocksDB")
|
||||
}
|
||||
}
|
||||
impl<T: ThreadMode + 'static> Db for Arc<TransactionDB<T>> {
|
||||
type Transaction<'a> = Transaction<'a, TransactionDB<T>>;
|
||||
fn txn(&mut self) -> Self::Transaction<'_> {
|
||||
self.transaction()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user