Classes
The following classes are available globally.
-
A wrapper around Mentat’s
TypedValue
Rust object. This class wraps a raw pointer to a RustTypedValue
struct 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
Int64
Entid
Keyword
Bool
Double
Date
String
UUID
.
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
TypedValues
and 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 defaultrun
function and returns a list of rows of values. Queries that wish to haveRel
results 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 haveScalar
results 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 haveColl
results 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 haveTuple
results 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
Rel
result from a Mentat query. ARel
result is a list of rows ofTypedValues
. Individual rows can be fetched or the set can be iterated.To fetch individual rows from a
RelResult
userow(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
Tuple
result from a Mentat query. ATuple
result is a list ofTypedValues
. Individual values can be fetched asTypedValues
or converted into a requested type.Values can be fetched as one of the following types:
TypedValue
Int64
Entid
Keyword
Bool
Double
Date
String
UUID
.
Declaration
Swift
open class TupleResult : OptionalRustObject
-
Wraps a
Coll
result from a Mentat query. AColl
result is a list of rows of single values of typeTypedValue
. Values for individual rows can be fetched asTypedValue
or converted into a requested type.Row values can be fetched as one of the following types:
TypedValue
Int64
Entid
Keyword
Bool
Double
Date
String
UUID
.
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 moreOpaquePointer
representing 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 rawOpaquePointer
arenil
led after calling a consuming FFI function. This class provides cleanup functions on deinit, ensuring that all classes that inherit from it will have theirOpaquePointer
destroyed when the Swift wrapper is destroyed. If a class does not overridecleanup
then afatalError
is 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 moreOpaquePointer
representing a pointer to a Rust object. This class provides cleanup functions on deinit, ensuring that all classes that inherit from it will have theirOpaquePointer
destroyed when the Swift wrapper is destroyed. If a class does not overridecleanup
then afatalError
is thrown.Declaration
Swift
open class RustObject : Destroyable
-
This class wraps a raw pointer that points to a Rust
EntityBuilder<InProgressBuilder>
object.EntityBuilder
provides 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
transact
function will transact the assertions that have been added to theEntityBuilder
and pass back theTxReport
that was generated by this transact and theInProgress
that was used to perform the transact. This enables you to perform further transacts on the sameInProgress
before 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
commit
function will transact and commit the assertions that have been added to theEntityBuilder
. It will consume theInProgress
used to perform the transact. It returns theTxReport
generated 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
InProgress
object.InProgress
allows for multiple transacts to be performed in a single transaction. Each transact performed results in aTxReport
that can be used to gather information to be used in subsequent transacts.Committing an
InProgress
commits all the transacts that have been performed using thatInProgress
.Rolling back and
InProgress
rolls 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 { ... }
InProgress
also provides a number of functions to generating an builder to assert datoms programatically. The two types of builder areInProgressBuilder
andEntityBuilder
.InProgressBuilder
takes the currentInProgress
and provides a programmatic interface to add and retract values from entities for which there exists anEntid
. The providedInProgress
is 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 { ... }
EntityBuilder
takes the currentInProgress
and either anEntid
or atempid
to provide a programmatic interface to add and retract values from a specific entity. The providedInProgress
is 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
InProgressBuilder
object.InProgressBuilder
provides 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
transact
function will transact the assertions that have been added to theInProgressBuilder
and pass back theTxReport
that was generated by this transact and theInProgress
that was used to perform the transact. This enables you to perform further transacts on the sameInProgress
before 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
commit
function will transact and commit the assertions that have been added to theEntityBuilder
. It will consume theInProgress
used to perform the transact. It returns theTxReport
generated 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
TxReport
object.The
TxReport
contains 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
Entid
s that they were mapped to,
Access an
Entid
for 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