Add transact FFI function
This commit is contained in:
parent
e83c4ef1ba
commit
666580301f
3 changed files with 34 additions and 7 deletions
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "mentat_ffi"
|
name = "mentat_ffi"
|
||||||
version = "0.1.0"
|
version = "0.0.1"
|
||||||
authors = ["Emily Toop <etoop@mozilla.com>"]
|
authors = ["Emily Toop <etoop@mozilla.com>"]
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
|
|
|
@ -137,6 +137,19 @@ pub extern "C" fn store_open(uri: *const c_char) -> *mut Store {
|
||||||
|
|
||||||
// TODO: begin_transaction
|
// 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: cache
|
||||||
|
|
||||||
// TODO: q_once
|
// TODO: q_once
|
||||||
|
@ -469,12 +482,6 @@ pub unsafe extern "C" fn value_at_index_as_uuid(values: *mut Vec<TypedValue>, in
|
||||||
string_to_c_char(value.clone().into_uuid_string().expect("Typed value cannot be coerced into a Uuid"))
|
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]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn store_value_for_attribute(store: *mut Store, entid: i64, attribute: *const c_char) -> *mut ExternResult {
|
pub unsafe extern "C" fn store_value_for_attribute(store: *mut Store, entid: i64, attribute: *const c_char) -> *mut ExternResult {
|
||||||
let store = &*store;
|
let store = &*store;
|
||||||
|
|
20
sdks/swift/Mentat/Mentat/Errors/Errors.swift
Normal file
20
sdks/swift/Mentat/Mentat/Errors/Errors.swift
Normal file
|
@ -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
|
||||||
|
}
|
Loading…
Reference in a new issue