towards storage API
parent
4e8cfbaed2
commit
1743922dfd
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2022, The Cozo Project Authors. Licensed under MPL-2.0.
|
||||
*/
|
||||
|
||||
use miette::Result;
|
||||
|
||||
pub(crate) mod rocks;
|
||||
pub(crate) mod sled;
|
||||
pub(crate) mod tikv;
|
||||
|
||||
pub(crate) trait Storage {
|
||||
type Tx: StoreTx;
|
||||
|
||||
fn tx(&self) -> Result<Self::Tx>;
|
||||
fn del_range(&self, lower: &[u8], upper: &[u8]) -> Result<()>;
|
||||
}
|
||||
|
||||
pub(crate) trait StoreTx {
|
||||
type ReadSlice: AsRef<[u8]>;
|
||||
type IterSlice: AsRef<[u8]>;
|
||||
|
||||
type KeyIter: Iterator<Item = Result<Self::IterSlice>>;
|
||||
type KeyValueIter: Iterator<Item = Result<(Self::IterSlice, Self::IterSlice)>>;
|
||||
|
||||
fn get(&self, key: &[u8], for_update: bool) -> Result<Option<Self::ReadSlice>>;
|
||||
fn put(&mut self, key: &[u8], val: &[u8]) -> Result<()>;
|
||||
fn del(&mut self, key: &[u8]) -> Result<()>;
|
||||
fn exists(&self, key: &[u8], for_update: bool) -> Result<bool>;
|
||||
fn commit(&mut self) -> Result<()>;
|
||||
fn range_scan(&self, lower: &[u8], upper: &[u8]) -> Self::KeyValueIter;
|
||||
fn range_key_scan(&self, lower: &[u8], upper: &[u8]) -> Self::KeyIter;
|
||||
}
|
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright 2022, The Cozo Project Authors. Licensed under MPL-2.0.
|
||||
*/
|
||||
|
||||
use miette::Result;
|
||||
|
||||
use crate::storage::{Storage, StoreTx};
|
||||
|
||||
struct RocksDbStorage;
|
||||
|
||||
impl Storage for RocksDbStorage {
|
||||
type Tx = RocksDbTx;
|
||||
|
||||
fn tx(&self) -> miette::Result<Self::Tx> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn del_range(&self, lower: &[u8], upper: &[u8]) -> miette::Result<()> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
struct RocksDbTx;
|
||||
|
||||
impl StoreTx for RocksDbTx {
|
||||
type ReadSlice = Vec<u8>;
|
||||
type IterSlice = Vec<u8>;
|
||||
type KeyIter = RocksDbKeyIter;
|
||||
type KeyValueIter = RocksDbIter;
|
||||
|
||||
fn get(&self, key: &[u8], for_update: bool) -> miette::Result<Option<Self::ReadSlice>> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn put(&mut self, key: &[u8], val: &[u8]) -> miette::Result<()> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn del(&mut self, key: &[u8]) -> miette::Result<()> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn exists(&self, key: &[u8], for_update: bool) -> miette::Result<bool> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn commit(&mut self) -> miette::Result<()> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn range_scan(&self, lower: &[u8], upper: &[u8]) -> Self::KeyValueIter {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn range_key_scan(&self, lower: &[u8], upper: &[u8]) -> Self::KeyIter {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
struct RocksDbKeyIter;
|
||||
|
||||
impl Iterator for RocksDbKeyIter {
|
||||
type Item = Result<Vec<u8>>;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
struct RocksDbIter;
|
||||
|
||||
impl Iterator for RocksDbIter {
|
||||
type Item = Result<(Vec<u8>, Vec<u8>)>;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
todo!()
|
||||
}
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
/*
|
||||
* Copyright 2022, The Cozo Project Authors. Licensed under MPL-2.0.
|
||||
*/
|
||||
|
@ -0,0 +1,4 @@
|
||||
/*
|
||||
* Copyright 2022, The Cozo Project Authors. Licensed under MPL-2.0.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue