Implement transact
This commit is contained in:
parent
666580301f
commit
6adb97c587
6 changed files with 57 additions and 10 deletions
|
@ -22,6 +22,8 @@
|
||||||
7BDB96C02077CD7A009D0651 /* libmentat.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 7BDB96BF2077CD7A009D0651 /* libmentat.a */; };
|
7BDB96C02077CD7A009D0651 /* libmentat.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 7BDB96BF2077CD7A009D0651 /* libmentat.a */; };
|
||||||
7BDB96C22077CD98009D0651 /* libresolv.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 7BDB96C12077CD98009D0651 /* libresolv.tbd */; };
|
7BDB96C22077CD98009D0651 /* libresolv.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 7BDB96C12077CD98009D0651 /* libresolv.tbd */; };
|
||||||
7BDB96C62077D347009D0651 /* Date+Int64.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BDB96C52077D346009D0651 /* Date+Int64.swift */; };
|
7BDB96C62077D347009D0651 /* Date+Int64.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BDB96C52077D346009D0651 /* Date+Int64.swift */; };
|
||||||
|
7BDB96C9207B735A009D0651 /* fixtures in Resources */ = {isa = PBXBuildFile; fileRef = 7BDB96C8207B735A009D0651 /* fixtures */; };
|
||||||
|
7BDB96CC207B7684009D0651 /* Errors.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BDB96CB207B7684009D0651 /* Errors.swift */; };
|
||||||
/* End PBXBuildFile section */
|
/* End PBXBuildFile section */
|
||||||
|
|
||||||
/* Begin PBXContainerItemProxy section */
|
/* Begin PBXContainerItemProxy section */
|
||||||
|
@ -54,6 +56,8 @@
|
||||||
7BDB96C12077CD98009D0651 /* libresolv.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libresolv.tbd; path = usr/lib/libresolv.tbd; sourceTree = SDKROOT; };
|
7BDB96C12077CD98009D0651 /* libresolv.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libresolv.tbd; path = usr/lib/libresolv.tbd; sourceTree = SDKROOT; };
|
||||||
7BDB96C32077D090009D0651 /* module.map */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.module-map"; path = module.map; sourceTree = "<group>"; };
|
7BDB96C32077D090009D0651 /* module.map */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.module-map"; path = module.map; sourceTree = "<group>"; };
|
||||||
7BDB96C52077D346009D0651 /* Date+Int64.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Date+Int64.swift"; sourceTree = "<group>"; };
|
7BDB96C52077D346009D0651 /* Date+Int64.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Date+Int64.swift"; sourceTree = "<group>"; };
|
||||||
|
7BDB96C8207B735A009D0651 /* fixtures */ = {isa = PBXFileReference; lastKnownFileType = folder; name = fixtures; path = ../../../../fixtures; sourceTree = "<group>"; };
|
||||||
|
7BDB96CB207B7684009D0651 /* Errors.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Errors.swift; sourceTree = "<group>"; };
|
||||||
/* End PBXFileReference section */
|
/* End PBXFileReference section */
|
||||||
|
|
||||||
/* Begin PBXFrameworksBuildPhase section */
|
/* Begin PBXFrameworksBuildPhase section */
|
||||||
|
@ -99,6 +103,7 @@
|
||||||
7BDB968C2077C299009D0651 /* Mentat */ = {
|
7BDB968C2077C299009D0651 /* Mentat */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
|
7BDB96CA207B7672009D0651 /* Errors */,
|
||||||
7BDB96C42077D346009D0651 /* Extensions */,
|
7BDB96C42077D346009D0651 /* Extensions */,
|
||||||
7BDB96BA2077C42B009D0651 /* Core */,
|
7BDB96BA2077C42B009D0651 /* Core */,
|
||||||
7BDB96B92077C403009D0651 /* Rust */,
|
7BDB96B92077C403009D0651 /* Rust */,
|
||||||
|
@ -116,6 +121,7 @@
|
||||||
7BDB96972077C299009D0651 /* MentatTests */ = {
|
7BDB96972077C299009D0651 /* MentatTests */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
|
7BDB96C8207B735A009D0651 /* fixtures */,
|
||||||
7BDB96982077C299009D0651 /* MentatTests.swift */,
|
7BDB96982077C299009D0651 /* MentatTests.swift */,
|
||||||
7BDB969A2077C299009D0651 /* Info.plist */,
|
7BDB969A2077C299009D0651 /* Info.plist */,
|
||||||
);
|
);
|
||||||
|
@ -174,6 +180,14 @@
|
||||||
path = Extensions;
|
path = Extensions;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
};
|
};
|
||||||
|
7BDB96CA207B7672009D0651 /* Errors */ = {
|
||||||
|
isa = PBXGroup;
|
||||||
|
children = (
|
||||||
|
7BDB96CB207B7684009D0651 /* Errors.swift */,
|
||||||
|
);
|
||||||
|
path = Errors;
|
||||||
|
sourceTree = "<group>";
|
||||||
|
};
|
||||||
/* End PBXGroup section */
|
/* End PBXGroup section */
|
||||||
|
|
||||||
/* Begin PBXHeadersBuildPhase section */
|
/* Begin PBXHeadersBuildPhase section */
|
||||||
|
@ -274,6 +288,7 @@
|
||||||
isa = PBXResourcesBuildPhase;
|
isa = PBXResourcesBuildPhase;
|
||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
|
7BDB96C9207B735A009D0651 /* fixtures in Resources */,
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
};
|
};
|
||||||
|
@ -290,6 +305,7 @@
|
||||||
7BDB96B42077C38E009D0651 /* OptionalRustObject.swift in Sources */,
|
7BDB96B42077C38E009D0651 /* OptionalRustObject.swift in Sources */,
|
||||||
7BDB96B22077C38E009D0651 /* RelResult.swift in Sources */,
|
7BDB96B22077C38E009D0651 /* RelResult.swift in Sources */,
|
||||||
7BDB96AF2077C38E009D0651 /* Query.swift in Sources */,
|
7BDB96AF2077C38E009D0651 /* Query.swift in Sources */,
|
||||||
|
7BDB96CC207B7684009D0651 /* Errors.swift in Sources */,
|
||||||
7BDB96B02077C38E009D0651 /* Mentat.swift in Sources */,
|
7BDB96B02077C38E009D0651 /* Mentat.swift in Sources */,
|
||||||
7BDB96B72077C38E009D0651 /* TypedValue.swift in Sources */,
|
7BDB96B72077C38E009D0651 /* TypedValue.swift in Sources */,
|
||||||
7BDB96B52077C38E009D0651 /* TupleResult.swift in Sources */,
|
7BDB96B52077C38E009D0651 /* TupleResult.swift in Sources */,
|
||||||
|
|
|
@ -27,6 +27,17 @@ class Mentat: RustObject {
|
||||||
self.init(raw: store_open(storeURI))
|
self.init(raw: store_open(storeURI))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func transact(transaction: String) throws -> Bool {
|
||||||
|
let result = store_transact(self.raw, transaction).pointee
|
||||||
|
guard let _ = result.ok else {
|
||||||
|
if let error = result.err {
|
||||||
|
throw MentatError(message: String(cString: error))
|
||||||
|
}
|
||||||
|
throw MentatError(message: "Unspecified Error")
|
||||||
|
}
|
||||||
|
print("Successfull")
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
func entidForAttribute(attribute: String) -> Int64 {
|
func entidForAttribute(attribute: String) -> Int64 {
|
||||||
return Int64(store_entid_for_attribute(self.raw, attribute))
|
return Int64(store_entid_for_attribute(self.raw, attribute))
|
||||||
|
|
|
@ -5,12 +5,6 @@
|
||||||
import Foundation
|
import Foundation
|
||||||
import Mentatlib
|
import Mentatlib
|
||||||
|
|
||||||
enum QueryError: Error {
|
|
||||||
case builderConsumed
|
|
||||||
case invalidKeyword(message: String)
|
|
||||||
case executionFailed(message: String)
|
|
||||||
}
|
|
||||||
|
|
||||||
enum QueryResult<T> {
|
enum QueryResult<T> {
|
||||||
case error(Error)
|
case error(Error)
|
||||||
case success(T)
|
case success(T)
|
||||||
|
|
|
@ -5,10 +5,6 @@
|
||||||
import Foundation
|
import Foundation
|
||||||
import Mentatlib
|
import Mentatlib
|
||||||
|
|
||||||
enum QueryResultError: Error {
|
|
||||||
case resultsConsumed
|
|
||||||
}
|
|
||||||
|
|
||||||
class RelResult: OptionalRustObject {
|
class RelResult: OptionalRustObject {
|
||||||
private func getRaw() throws -> OpaquePointer {
|
private func getRaw() throws -> OpaquePointer {
|
||||||
guard let r = self.raw else {
|
guard let r = self.raw else {
|
||||||
|
|
|
@ -50,6 +50,9 @@ void typed_value_list_iter_destroy(struct QueryRowIterator* _Nullable obj);
|
||||||
void typed_value_result_set_destroy(struct QueryResultRows* _Nullable obj);
|
void typed_value_result_set_destroy(struct QueryResultRows* _Nullable obj);
|
||||||
void typed_value_result_set_iter_destroy(struct QueryRowsIterator* _Nullable obj);
|
void typed_value_result_set_iter_destroy(struct QueryRowsIterator* _Nullable obj);
|
||||||
|
|
||||||
|
// transact
|
||||||
|
struct Result*_Nonnull store_transact(struct Store*_Nonnull store, const char* _Nonnull transaction);
|
||||||
|
|
||||||
// Sync
|
// Sync
|
||||||
struct Result*_Nonnull store_sync(struct Store*_Nonnull store, const char* _Nonnull user_uuid, const char* _Nonnull server_uri);
|
struct Result*_Nonnull store_sync(struct Store*_Nonnull store, const char* _Nonnull user_uuid, const char* _Nonnull server_uri);
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,8 @@ import XCTest
|
||||||
|
|
||||||
class MentatTests: XCTestCase {
|
class MentatTests: XCTestCase {
|
||||||
|
|
||||||
|
var schema: String?
|
||||||
|
|
||||||
override func setUp() {
|
override func setUp() {
|
||||||
super.setUp()
|
super.setUp()
|
||||||
// Put setup code here. This method is called before the invocation of each test method in the class.
|
// Put setup code here. This method is called before the invocation of each test method in the class.
|
||||||
|
@ -29,4 +31,29 @@ class MentatTests: XCTestCase {
|
||||||
let storeURI = documentsURL.appendingPathComponent("test.db", isDirectory: false).absoluteString
|
let storeURI = documentsURL.appendingPathComponent("test.db", isDirectory: false).absoluteString
|
||||||
XCTAssertNotNil(Mentat(storeURI: storeURI).intoRaw())
|
XCTAssertNotNil(Mentat(storeURI: storeURI).intoRaw())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func readSchema() throws -> String {
|
||||||
|
guard let schema = self.schema else {
|
||||||
|
let bundle = Bundle(for: type(of: self))
|
||||||
|
guard let schemaPath = bundle.path(forResource: "cities", ofType: "schema") else { return "" }
|
||||||
|
let schema = try String(contentsOf: URL(fileURLWithPath: schemaPath))
|
||||||
|
self.schema = schema
|
||||||
|
return schema
|
||||||
|
}
|
||||||
|
|
||||||
|
return schema
|
||||||
|
}
|
||||||
|
|
||||||
|
func testTransactVocabulary() {
|
||||||
|
do {
|
||||||
|
let vocab = try readSchema()
|
||||||
|
let mentat = Mentat()
|
||||||
|
let success = try mentat.transact(transaction: vocab)
|
||||||
|
assert( success )
|
||||||
|
} catch {
|
||||||
|
assertionFailure(error.localizedDescription)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Add more tests once we are able to add vocabulary and transact entities
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue