Store the schema in the main index
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<Option<Schema>>
+ {
+ 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,
