use crate::error::Result;
use crate::txn::TxnManager;
use crate::types::{Key, TxnId, TxnMode, Value};
pub mod any;
#[cfg(feature = "tokio")]
pub mod async_adapter;
#[cfg(feature = "async")]
pub mod async_kv;
pub mod memory;
pub mod storage;
#[cfg(feature = "s3")]
pub mod s3;
pub use any::AnyKV;
#[cfg(feature = "tokio")]
pub use async_adapter::{AsyncKVStoreAdapter, AsyncKVTransactionAdapter};
#[cfg(feature = "async")]
pub use async_kv::{AsyncKVStore, AsyncKVTransaction};
#[cfg(feature = "s3")]
pub use s3::{S3Config, S3KV};
pub trait KVTransaction<'a> {
fn id(&self) -> TxnId;
fn mode(&self) -> TxnMode;
fn get(&mut self, key: &Key) -> Result<Option<Value>>;
fn put(&mut self, key: Key, value: Value) -> Result<()>;
fn delete(&mut self, key: Key) -> Result<()>;
fn scan_prefix(&mut self, prefix: &[u8])
-> Result<Box<dyn Iterator<Item = (Key, Value)> + '_>>;
fn scan_range(
&mut self,
start: &[u8],
end: &[u8],
) -> Result<Box<dyn Iterator<Item = (Key, Value)> + '_>>;
fn commit_self(self) -> Result<()>;
fn rollback_self(self) -> Result<()>;
}
pub trait KVStore: Send + Sync {
type Transaction<'a>: KVTransaction<'a>
where
Self: 'a;
type Manager<'a>: TxnManager<'a, Self::Transaction<'a>>
where
Self: 'a;
fn txn_manager(&self) -> Self::Manager<'_>;
fn begin(&self, mode: TxnMode) -> Result<Self::Transaction<'_>>;
}