Add helper functions for FFI. Many of these will go away as we expose the entity builder
This commit is contained in:
parent
23e7ff0585
commit
ca412b3a8b
1 changed files with 17 additions and 0 deletions
17
src/conn.rs
17
src/conn.rs
|
@ -81,6 +81,7 @@ use mentat_tolstoy::Syncer;
|
|||
use uuid::Uuid;
|
||||
|
||||
use entity_builder::{
|
||||
BuildTerms,
|
||||
InProgressBuilder,
|
||||
};
|
||||
|
||||
|
@ -578,6 +579,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 {
|
||||
|
@ -865,6 +870,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)]
|
||||
|
|
Loading…
Reference in a new issue