feat: Allow users to retrieve the raw field value of a document

This commit is contained in:
Clément Renault 2019-02-22 15:30:20 +01:00
parent 8701cb3a8f
commit 24823da6f7
No known key found for this signature in database
GPG Key ID: 0151CDAB43460DAE

View File

@ -89,8 +89,21 @@ where D: Deref<Target=DB>
QueryBuilder::new(self)
}
pub fn raw_field_by_document_id(
&self,
name: &str,
id: DocumentId
) -> Result<Option<Vec<u8>>, Box<Error>>
{
let attr = self.schema.attribute(name).ok_or("field not found")?;
let key = DocumentKeyAttr::new(id, attr);
let vector = self.snapshot.get(key.as_ref())?;
Ok(vector.map(|v| v.to_vec()))
}
pub fn document_by_id<T>(&self, id: DocumentId) -> Result<T, Box<Error>>
where T: DeserializeOwned
where T: DeserializeOwned,
{
let mut deserializer = Deserializer::new(&self.snapshot, &self.schema, id);
Ok(T::deserialize(&mut deserializer)?)