Classes
The following classes are available globally.
-
A wrapper around Mentat’s
TypedValueRust object. This class wraps a raw pointer to a RustTypedValuestruct and provides accessors to the values according to expected result type.As the FFI functions for fetching values are consuming, this class keeps a copy of the result internally after fetching so that the value can be referenced several times.
Also, due to the consuming nature of the FFI layer, this class also manages it’s raw pointer, nilling it after calling the FFI conversion function so that the underlying base class can manage cleanup.
See moreDeclaration
Swift
open class TypedValue : OptionalRustObject
-
The primary class for accessing Mentat’s API. This class provides all of the basic API that can be found in Mentat’s Store struct. The raw pointer it holds is a pointer to a Store.
See moreDeclaration
Swift
open class Mentat : RustObject
-
This class allows you to construct a query, bind values to variables and run those queries against a mentat DB.
This class cannot be created directly, but must be created through
Mentat.query(String:).The types of values you can bind are
Int64EntidKeywordBoolDoubleDateStringUUID.
Each bound variable must have a corresponding value in the query string used to create this query.
let query = """ [:find ?name ?cat :in ?type :where [?c :community/name ?name] [?c :community/type ?type] [?c :community/category ?cat]] """ mentat.query(query: query) .bind(varName: "?type", toKeyword: ":community.type/website") .run { result in ... }Queries can be run and the results returned in a number of different formats. Individual result values are returned as
TypedValuesand the format differences relate to the number and structure of those values. The result format is related to the format provided in the query string.Rel- This is the defaultrunfunction and returns a list of rows of values. Queries that wish to haveRelresults should format their query strings:let query = """ [: find ?a ?b ?c : where ... ] """ mentat.query(query: query) .run { result in ... }Scalar- This returns a single value as a result. This can be optional, as the value may not be present. Queries that wish to haveScalarresults should format their query strings:let query = """ [: find ?a . : where ... ] """ mentat.query(query: query) .runScalar { result in ... }Coll- This returns a list of single values as a result. Queries that wish to haveCollresults should format their query strings:let query = """ [: find [?a ...] : where ... ] """ mentat.query(query: query) .runColl { result in ... }Tuple- This returns a single row of values. Queries that wish to haveTupleresults should format their query strings:let query = """ [: find [?a ?b ?c] : where ... ] """ mentat.query(query: query) .runTuple { result in ... }
Declaration
Swift
open class Query : OptionalRustObject
-
Wraps a
Relresult from a Mentat query. ARelresult is a list of rows ofTypedValues. Individual rows can be fetched or the set can be iterated.To fetch individual rows from a
RelResultuserow(Int32).query.run { rows in let row1 = rows.row(0) let row2 = rows.row(1) }To iterate over the result set use standard iteration flows.
query.run { rows in rows.forEach { row in ... } }Note that iteration is consuming and can only be done once.
See moreDeclaration
Swift
open class RelResult : OptionalRustObject -
Iterator for
RelResult.To iterate over the result set use standard iteration flows.
query.run { result in rows.forEach { row in ... } }Note that iteration is consuming and can only be done once.
See moreDeclaration
Swift
open class RelResultIterator : OptionalRustObject, IteratorProtocol
-
Wraps a
Tupleresult from a Mentat query. ATupleresult is a list ofTypedValues. Individual values can be fetched asTypedValuesor converted into a requested type.Values can be fetched as one of the following types:
TypedValueInt64EntidKeywordBoolDoubleDateStringUUID.
Declaration
Swift
open class TupleResult : OptionalRustObject -
Wraps a
Collresult from a Mentat query. ACollresult is a list of rows of single values of typeTypedValue. Values for individual rows can be fetched asTypedValueor converted into a requested type.Row values can be fetched as one of the following types:
TypedValueInt64EntidKeywordBoolDoubleDateStringUUID.
Declaration
Swift
open class ColResult : TupleResult -
Iterator for
ColResult.To iterate over the result set use standard iteration flows.
query.runColl { rows in rows.forEach { value in ... } }Note that iteration is consuming and can only be done once.
See moreDeclaration
Swift
open class ColResultIterator : OptionalRustObject, IteratorProtocol
-
Base class that wraps an optional
See moreOpaquePointerrepresenting a pointer to a Rust object. This class should be used to wrap Rust pointer that point to consuming structs, that is, calling a function for that Rust pointer, will cause Rust to destroy the pointer, leaving the Swift pointer dangling. These classes are responsible for ensuring that their rawOpaquePointerarenilled after calling a consuming FFI function. This class provides cleanup functions on deinit, ensuring that all classes that inherit from it will have theirOpaquePointerdestroyed when the Swift wrapper is destroyed. If a class does not overridecleanupthen afatalErroris thrown. The optional pointer is managed here such that is the pointer is nil, then the cleanup function is not called ensuring that we do not double free the pointer on exit.Declaration
Swift
open class OptionalRustObject : Destroyable
-
Base class that wraps an non-optional
See moreOpaquePointerrepresenting a pointer to a Rust object. This class provides cleanup functions on deinit, ensuring that all classes that inherit from it will have theirOpaquePointerdestroyed when the Swift wrapper is destroyed. If a class does not overridecleanupthen afatalErroris thrown.Declaration
Swift
open class RustObject : Destroyable
-
This class wraps a raw pointer that points to a Rust
EntityBuilder<InProgressBuilder>object.EntityBuilderprovides a programmatic interface to performing assertions on a specific entity. It provides functions for adding and retracting values for attributes for an entity within an in progress transaction.The
transactfunction will transact the assertions that have been added to theEntityBuilderand pass back theTxReportthat was generated by this transact and theInProgressthat was used to perform the transact. This enables you to perform further transacts on the sameInProgressbefore committing.let aEntid = txReport.entid(forTempId: "a") let bEntid = txReport.entid(forTempId: "b") do { let builder = try mentat.entityBuilder(forEntid: bEntid) try builder.add(keyword: ":foo/boolean", boolean: true) try builder.add(keyword: ":foo/instant", date: newDate) let (inProgress, report) = try builder.transact() try inProgress.transact(transaction: "[[:db/add \(aEntid) :foo/long 22]]") try inProgress.commit() } catch { ... }The
commitfunction will transact and commit the assertions that have been added to theEntityBuilder. It will consume theInProgressused to perform the transact. It returns theTxReportgenerated by the transact. After callingcommit, a new transaction must be started by callingMentat.beginTransaction()in order to perform further actions.
See morelet aEntid = txReport.entid(forTempId: "a") do { let builder = try mentat.entityBuilder(forEntid: aEntid) try builder.add(keyword: ":foo/boolean", boolean: true) try builder.add(keyword: ":foo/instant", date: newDate) let report = try builder.commit() ... } catch { ... }Declaration
Swift
open class EntityBuilder : OptionalRustObject
-
This class wraps a raw pointer that points to a Rust
InProgressobject.InProgressallows for multiple transacts to be performed in a single transaction. Each transact performed results in aTxReportthat can be used to gather information to be used in subsequent transacts.Committing an
InProgresscommits all the transacts that have been performed using thatInProgress.Rolling back and
InProgressrolls back all the transacts that have been performed using thatInProgress.do { let inProgress = try mentat.beginTransaction() let txReport = try inProgress.transact(transaction: "[[:db/add "a" :foo/long 22]]") let aEntid = txReport.entid(forTempId: "a") let report = try inProgress.transact(transaction: "[[:db/add "b" :foo/ref \(aEntid)] [:db/add "b" :foo/boolean true]]") try inProgress.commit() } catch { ... }InProgressalso provides a number of functions to generating an builder to assert datoms programatically. The two types of builder areInProgressBuilderandEntityBuilder.InProgressBuildertakes the currentInProgressand provides a programmatic interface to add and retract values from entities for which there exists anEntid. The providedInProgressis used to perform the transacts.let aEntid = txReport.entid(forTempId: "a") let bEntid = txReport.entid(forTempId: "b") do { let inProgress = try mentat.beginTransaction() let builder = try inProgress.builder() try builder.add(entid: bEntid, keyword: ":foo/boolean", boolean: true) try builder.add(entid: aEntid, keyword: ":foo/instant", date: newDate) let (inProgress, report) = try builder.transact() try inProgress.transact(transaction: "[[:db/add \(aEntid) :foo/long 22]]") try inProgress.commit() } catch { ... }EntityBuildertakes the currentInProgressand either anEntidor atempidto provide a programmatic interface to add and retract values from a specific entity. The providedInProgressis used to perform the transacts.
See moredo { let transaction = try mentat.beginTransaction() let builder = try transaction.builder(forTempId: "b") try builder.add(keyword: ":foo/boolean", boolean: true) try builder.add(keyword: ":foo/instant", date: newDate) let (inProgress, report) = try builder.transact() let bEntid = report.entid(forTempId: "b") try inProgress.transact(transaction: "[[:db/add \(bEntid) :foo/long 22]]") try inProgress.commit() } catch { ... }Declaration
Swift
open class InProgress : OptionalRustObject
-
This class wraps a raw pointer that points to a Rust
InProgressBuilderobject.InProgressBuilderprovides a programmatic interface to performing assertions for entities. It provides functions for adding and retracting values for attributes for an entity within an in progress transaction.The
transactfunction will transact the assertions that have been added to theInProgressBuilderand pass back theTxReportthat was generated by this transact and theInProgressthat was used to perform the transact. This enables you to perform further transacts on the sameInProgressbefore committing.let aEntid = txReport.entid(forTempId: "a") let bEntid = txReport.entid(forTempId: "b") do { let builder = try mentat.entityBuilder() try builder.add(entid: bEntid, keyword: ":foo/boolean", boolean: true) try builder.add(entid: aEntid, keyword: ":foo/instant", date: newDate) let (inProgress, report) = try builder.transact() try inProgress.transact(transaction: "[[:db/add \(aEntid) :foo/long 22]]") try inProgress.commit() ... } catch { ... }The
commitfunction will transact and commit the assertions that have been added to theEntityBuilder. It will consume theInProgressused to perform the transact. It returns theTxReportgenerated by the transact. After callingcommit, a new transaction must be started by callingMentat.beginTransaction()in order to perform further actions.
See morelet aEntid = txReport.entid(forTempId: "a") let bEntid = txReport.entid(forTempId: "b") do { let builder = try mentat.entityBuilder(forEntid: aEntid) try builder.add(entid: bEntid, keyword: ":foo/boolean", boolean: true) try builder.add(entid: aEntid, keyword: ":foo/instant", date: newDate) let report = try builder.commit() ... } catch { ... }Declaration
Swift
open class InProgressBuilder : OptionalRustObject
-
This class wraps a raw pointer that points to a Rust
TxReportobject.The
TxReportcontains information about a successful Mentat transaction.This information includes:
txId- the identifier for the transaction.txInstant- the time that the transaction occured.- a map of temporary identifiers provided in the transaction and the
Entids that they were mapped to,
Access an
Entidfor a temporary identifier that was provided in the transaction can be done throughentid(String:).
See morelet report = mentat.transact("[[:db/add "a" :foo/boolean true]]") let aEntid = report.entid(forTempId: "a")Declaration
Swift
open class TxReport : RustObject
Classes Reference