towards storage API

main
Ziyang Hu 2 years ago
parent 4e8cfbaed2
commit 1743922dfd

@ -1,6 +1,6 @@
[package]
name = "cozo"
version = "0.1.6"
version = "0.1.7"
edition = "2021"
description = "A general-purpose, transactional, relational database that uses Datalog and focuses on graph data and algorithms"
authors = ["Ziyang Hu"]

@ -26,3 +26,4 @@ pub(crate) mod parse;
pub(crate) mod query;
pub(crate) mod runtime;
pub(crate) mod utils;
pub(crate) mod storage;

@ -280,9 +280,6 @@ impl RelationIterator {
None => None,
Some((k_slice, v_slice)) => {
if self.upper_bound.as_slice() <= k_slice {
//
// }
// if compare_tuple_keys(&self.upper_bound, k_slice) != Greater {
None
} else {
let mut tup = Tuple::decode_from_key(k_slice);
@ -290,12 +287,6 @@ impl RelationIterator {
let vals: Vec<DataValue> = rmp_serde::from_slice(&v_slice[ENCODED_KEY_MIN_LEN..]).unwrap();
tup.0.extend(vals);
}
// if !v_slice.is_empty() {
// let v_tup = EncodedTuple(v_slice);
// if v_tup.arity() > 0 {
// tup.0.extend(v_tup.decode().0);
// }
// }
Some(tup)
}
}

@ -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…
Cancel
Save