From 24823da6f798fdc23bfb79cafb8cf20a3bfdf3f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Fri, 22 Feb 2019 15:30:20 +0100 Subject: [PATCH] feat: Allow users to retrieve the raw field value of a document --- src/database/view.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/database/view.rs b/src/database/view.rs index 81d14c3d5..5988f6ba4 100644 --- a/src/database/view.rs +++ b/src/database/view.rs @@ -89,8 +89,21 @@ where D: Deref QueryBuilder::new(self) } + pub fn raw_field_by_document_id( + &self, + name: &str, + id: DocumentId + ) -> Result>, Box> + { + 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(&self, id: DocumentId) -> Result> - where T: DeserializeOwned + where T: DeserializeOwned, { let mut deserializer = Deserializer::new(&self.snapshot, &self.schema, id); Ok(T::deserialize(&mut deserializer)?)