diff --git a/meilidb-core/src/store/main.rs b/meilidb-core/src/store/main.rs index 8011e0e7d..62c059bd9 100644 --- a/meilidb-core/src/store/main.rs +++ b/meilidb-core/src/store/main.rs @@ -1,6 +1,7 @@ use std::sync::Arc; use std::convert::TryInto; +use meilidb_schema::Schema; use rkv::Value; use crate::{RankedMap, MResult}; @@ -43,6 +44,33 @@ impl Main { } } + pub fn put_schema( + &self, + writer: &mut rkv::Writer, + schema: &Schema, + ) -> MResult<()> + { + let bytes = bincode::serialize(schema)?; + let blob = Value::Blob(&bytes[..]); + self.main.put(writer, SCHEMA_KEY, &blob)?; + Ok(()) + } + + pub fn schema( + &self, + reader: &impl rkv::Readable, + ) -> MResult> + { + match self.main.get(reader, SCHEMA_KEY)? { + Some(Value::Blob(bytes)) => { + let schema = bincode::deserialize_from(bytes.as_ref())?; + Ok(Some(schema)) + }, + Some(value) => panic!("invalid type {:?}", value), + None => Ok(None), + } + } + pub fn put_ranked_map( &self, writer: &mut rkv::Writer,