From 9741435026f29ac2f8138daa4b32aef1b978b269 Mon Sep 17 00:00:00 2001 From: Emily Toop Date: Thu, 5 Apr 2018 11:19:52 +0100 Subject: [PATCH] Add helper functions for FFI. Many of these will go away as we expose the entity builder --- src/conn.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/conn.rs b/src/conn.rs index 822c3e8c..d2439fea 100644 --- a/src/conn.rs +++ b/src/conn.rs @@ -81,6 +81,7 @@ use mentat_tolstoy::Syncer; use uuid::Uuid; use entity_builder::{ + BuildTerms, InProgressBuilder, }; @@ -586,6 +587,10 @@ impl Store { pub fn unregister_observer(&mut self, key: &String) { self.conn.unregister_observer(key); } + + pub fn add_value_for_attribute(&mut self, entid: T, attribute: NamespacedKeyword, value: TypedValue) -> Result<()> where T: Into { + self.conn.add_value_for_attribute(&mut self.sqlite, entid, attribute, value) + } } impl Queryable for Store { @@ -873,6 +878,18 @@ impl Conn { pub fn unregister_observer(&mut self, key: &String) { self.tx_observer_service.lock().unwrap().deregister(key); } + + // TODO: expose the entity builder over FFI and remove the need for this function entirely + // It's really only here in order to keep the FFI layer as thin as possible. + // Once the entity builder is exposed, we can perform all of these functions over FFI from the client. + pub fn add_value_for_attribute(&mut self, sqlite: &mut rusqlite::Connection, entid: T, attribute: NamespacedKeyword, value: TypedValue) -> Result<()> where T: Into { + let in_progress = self.begin_transaction(sqlite)?; + let mut builder = in_progress.builder().describe(entid.into()); + builder.add_kw(&attribute, value)?; + builder.commit() + .map_err(|e| e.into()) + .and(Ok(())) + } } #[cfg(test)]