aboutsummaryrefslogtreecommitdiff
path: root/src/storage/in_memory.rs
diff options
context:
space:
mode:
authorQuentin Dufour <quentin@deuxfleurs.fr>2023-12-18 17:09:44 +0100
committerQuentin Dufour <quentin@deuxfleurs.fr>2023-12-18 17:09:44 +0100
commit3d41f40dc8cd6bdfa7a9279ab1959564d06eefaf (patch)
treefff5d16e266788b28e812c24669f50118831512b /src/storage/in_memory.rs
parent684f4de225c44464abcb6a9cb2ef6dcae90537a8 (diff)
downloadaerogramme-3d41f40dc8cd6bdfa7a9279ab1959564d06eefaf.tar.gz
aerogramme-3d41f40dc8cd6bdfa7a9279ab1959564d06eefaf.zip
Storage trait new implementation
Diffstat (limited to 'src/storage/in_memory.rs')
-rw-r--r--src/storage/in_memory.rs35
1 files changed, 28 insertions, 7 deletions
diff --git a/src/storage/in_memory.rs b/src/storage/in_memory.rs
index 09c6763..6d0460f 100644
--- a/src/storage/in_memory.rs
+++ b/src/storage/in_memory.rs
@@ -14,18 +14,36 @@ pub type ArcBlob = Arc<RwLock<HashMap<String, Vec<u8>>>>;
#[derive(Clone, Debug)]
pub struct MemBuilder {
user: String,
- url: String,
+ unicity: Vec<u8>,
row: ArcRow,
blob: ArcBlob,
}
+impl MemBuilder {
+ pub fn new(user: &str) -> Arc<Self> {
+ let mut unicity: Vec<u8> = vec![];
+ unicity.extend_from_slice(file!().as_bytes());
+ unicity.extend_from_slice(user.as_bytes());
+ Arc::new(Self {
+ user: user.to_string(),
+ unicity,
+ row: Arc::new(RwLock::new(HashMap::new())),
+ blob: Arc::new(RwLock::new(HashMap::new())),
+ })
+ }
+}
+
impl IBuilder for MemBuilder {
- fn build(&self) -> Box<dyn IStore> {
- Box::new(MemStore {
+ fn build(&self) -> Result<Store, StorageError> {
+ Ok(Box::new(MemStore {
row: self.row.clone(),
blob: self.blob.clone(),
- })
+ }))
}
+
+ fn unique(&self) -> UnicityBuffer {
+ UnicityBuffer(self.unicity.clone())
+ }
}
pub struct MemStore {
@@ -56,7 +74,7 @@ impl IStore for MemStore {
.or(Err(StorageError::Internal))?
.get(*shard)
.ok_or(StorageError::NotFound)?
- .range((Included(sort_begin.to_string()), Included(sort_end.to_string())))
+ .range((Included(sort_begin.to_string()), Excluded(sort_end.to_string())))
.map(|(k, v)| RowVal {
row_ref: RowRef { uid: RowUid { shard: shard.to_string(), sort: k.to_string() }, causality: Some("c".to_string()) },
value: vec![Alternative::Value(v.clone())],
@@ -100,7 +118,7 @@ impl IStore for MemStore {
},
Selector::Single(row_ref) => {
let bytes = self.inner_fetch(row_ref)?;
- Ok(vec![RowVal{ row_ref: row_ref.clone(), value: vec![Alternative::Value(bytes)]}])
+ Ok(vec![RowVal{ row_ref: (*row_ref).clone(), value: vec![Alternative::Value(bytes)]}])
}
}
}
@@ -113,7 +131,7 @@ impl IStore for MemStore {
unimplemented!();
}
- async fn row_poll(&self, value: RowRef) -> Result<RowVal, StorageError> {
+ async fn row_poll(&self, value: &RowRef) -> Result<RowVal, StorageError> {
unimplemented!();
}
@@ -121,6 +139,9 @@ impl IStore for MemStore {
unimplemented!();
}
+ async fn blob_insert(&self, blob_val: &BlobVal) -> Result<BlobVal, StorageError> {
+ unimplemented!();
+ }
async fn blob_copy(&self, src: &BlobRef, dst: &BlobRef) -> Result<BlobVal, StorageError> {
unimplemented!();