Add helper functions for FFI. Many of these will go away as we expose the entity builder

This commit is contained in:
Emily Toop 2018-04-05 11:19:52 +01:00
parent 7382e3297d
commit 9741435026

View file

@ -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<T>(&mut self, entid: T, attribute: NamespacedKeyword, value: TypedValue) -> Result<()> where T: Into<KnownEntid> {
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<T>(&mut self, sqlite: &mut rusqlite::Connection, entid: T, attribute: NamespacedKeyword, value: TypedValue) -> Result<()> where T: Into<KnownEntid> {
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)]