From 666580301fdaabdaf60e85f66db57fc8c2ac66e0 Mon Sep 17 00:00:00 2001 From: Emily Toop Date: Mon, 9 Apr 2018 16:14:30 +0100 Subject: [PATCH] Add transact FFI function --- ffi/Cargo.toml | 2 +- ffi/src/lib.rs | 19 +++++++++++++------ sdks/swift/Mentat/Mentat/Errors/Errors.swift | 20 ++++++++++++++++++++ 3 files changed, 34 insertions(+), 7 deletions(-) create mode 100644 sdks/swift/Mentat/Mentat/Errors/Errors.swift diff --git a/ffi/Cargo.toml b/ffi/Cargo.toml index d7b5451f..5aaa23a5 100644 --- a/ffi/Cargo.toml +++ b/ffi/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mentat_ffi" -version = "0.1.0" +version = "0.0.1" authors = ["Emily Toop "] [lib] diff --git a/ffi/src/lib.rs b/ffi/src/lib.rs index ff52d649..b692f90e 100644 --- a/ffi/src/lib.rs +++ b/ffi/src/lib.rs @@ -137,6 +137,19 @@ pub extern "C" fn store_open(uri: *const c_char) -> *mut Store { // TODO: begin_transaction +#[no_mangle] +pub unsafe extern "C" fn store_transact(store: *mut Store, transaction: *const c_char) -> *mut ExternResult { + let store = &mut*store; + let transaction = c_char_to_string(transaction); + let result = store.begin_transaction().map(|mut in_progress| { + in_progress.transact(&transaction).map(|tx_report| { + in_progress.commit() + .map(|_| tx_report) + }) + }); + Box::into_raw(Box::new(result.into())) +} + // TODO: cache // TODO: q_once @@ -469,12 +482,6 @@ pub unsafe extern "C" fn value_at_index_as_uuid(values: *mut Vec, in string_to_c_char(value.clone().into_uuid_string().expect("Typed value cannot be coerced into a Uuid")) } -// TODO: q_prepare - -// TODO: q_explain - -// TODO: lookup_values_for_attribute - #[no_mangle] pub unsafe extern "C" fn store_value_for_attribute(store: *mut Store, entid: i64, attribute: *const c_char) -> *mut ExternResult { let store = &*store; diff --git a/sdks/swift/Mentat/Mentat/Errors/Errors.swift b/sdks/swift/Mentat/Mentat/Errors/Errors.swift new file mode 100644 index 00000000..2b9b6313 --- /dev/null +++ b/sdks/swift/Mentat/Mentat/Errors/Errors.swift @@ -0,0 +1,20 @@ +// +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +import Foundation + +public enum QueryError: Error { + case builderConsumed + case invalidKeyword(message: String) + case executionFailed(message: String) +} + +public enum QueryResultError: Error { + case resultsConsumed +} + +public struct MentatError: Error { + let message: String +}