use std::error::Error; use std::ops::Deref; use ::rocksdb::rocksdb::{DB, Snapshot, DBVector}; use crate::index::schema::{Schema, SchemaAttr}; use crate::blob::PositiveBlob; use crate::DocumentId; pub struct DocDatabase<'a, R: ?Sized> { retrieve: &'a R, schema: Schema, } impl<'a, R> DocDatabase<'a, R> { pub fn get_document(&self, id: DocumentId) -> Result, Box> { // if ids.is_empty() { return Ok(Vec::new()) } unimplemented!() } pub fn get_document_attribute(&self, id: DocumentId, attr: SchemaAttr) -> Result> { unimplemented!() } } pub trait Retrieve { fn schema(&self) -> Result, Box>; fn data_index(&self) -> Result>; fn doc_database(&self) -> Result, Box>; } impl Retrieve for Snapshot where T: Deref, { fn schema(&self) -> Result, Box> { match self.deref().get(b"data-schema")? { Some(value) => Ok(Some(Schema::read_from(&*value)?)), None => Ok(None), } } fn data_index(&self) -> Result> { match self.deref().get(b"data-index")? { Some(value) => Ok(bincode::deserialize(&value)?), None => Ok(PositiveBlob::default()), } } fn doc_database(&self) -> Result, Box> { let schema = match self.schema()? { Some(schema) => schema, None => return Err(String::from("BUG: could not find schema").into()), }; Ok(DocDatabase { retrieve: self, schema: schema, }) } }