Mentat
open class Mentat : RustObject
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.
-
Create a new Mentat with the provided pointer to a Mentat Store
Declaration
Swift
public required override init(raw: OpaquePointer)
Parameters
raw
A pointer to a Mentat Store.
-
Open a connection to a Store in a given location. If the store does not already exist, one will be created.
Declaration
Swift
public convenience init(storeURI: String = "")
Parameters
storeURI
The URI as a String of the store to open. If no store URI is provided, an in-memory store will be opened.
-
Add an attribute to the cache. The {@link CacheDirection} determines how that attribute can be looked up.
Throws
ResultError.error
if an error occured while trying to cache the attribute.Declaration
Swift
open func cache(attribute: String, direction: CacheDirection) throws
Parameters
attribute
The attribute to cache
direction
The direction the attribute should be keyed.
forward
caches values for an attribute keyed by entity (i.e. find values and entities that have this attribute, or find values of attribute for an entity)reverse
caches entities for an attribute keyed by value. (i.e. find entities that have a particular value for an attribute).both
adds an attribute such that it is cached in both directions. -
Simple transact of an EDN string.
Throws
ResultError.error
if the an error occured during the transaction, or the TxReport is nil.Declaration
Swift
open func transact(transaction: String) throws -> TxReport
Parameters
transaction
The string, as EDN, to be transacted
Return Value
The
TxReport
of the completed transaction -
Start a new transaction.
Throws
ResultError.error
if the creation of the transaction fails.Throws
ResultError.empty
if noInProgress
is created.Declaration
Swift
open func beginTransaction() throws -> InProgress
Return Value
The
InProgress
used to manage the transaction -
Creates a new transaction (
InProgress
) and returns anInProgressBuilder
for that transaction.Throws
ResultError.error
if the creation of the transaction fails.Throws
ResultError.empty
if noInProgressBuilder
is created.Declaration
Swift
open func entityBuilder() throws -> InProgressBuilder
Return Value
an
InProgressBuilder
for thisInProgress
-
Creates a new transaction (
InProgress
) and returns anEntityBuilder
for the entity withentid
for that transaction.Throws
ResultError.error
if the creation of the transaction fails.Throws
ResultError.empty
if noEntityBuilder
is created.Declaration
Swift
open func entityBuilder(forEntid entid: Entid) throws -> EntityBuilder
Parameters
entid
The
Entid
for this entity.Return Value
an
EntityBuilder
for thisInProgress
-
Creates a new transaction (
InProgress
) and returns anEntityBuilder
for a new entity withtempId
for that transaction.Throws
ResultError.error
if the creation of the transaction fails.Throws
ResultError.empty
if noEntityBuilder
is created.Declaration
Swift
open func entityBuilder(forTempId tempId: String) throws -> EntityBuilder
Parameters
tempId
The temporary identifier for this entity.
Return Value
an
EntityBuilder
for thisInProgress
-
Retrieve a single value of an attribute for an Entity
Declaration
Swift
open func value(forAttribute attribute: String, ofEntity entid: Entid) throws -> TypedValue?
Parameters
attribute
The string the attribute whose value is to be returned. The string is represented as
:namespace/name
.entid
The
Entid
of the entity we want the value from.Return Value
The
TypedValue
containing the value of the attribute for the entity. -
Undocumented
Declaration
Swift
override open func cleanup(pointer: OpaquePointer)
-
Register an
Observing
and a set of attributes to observer for transaction observation. ThetransactionDidOccur(String: [TxChange]:)
function is called when a transaction occurs in theStore
that thisMentat
is connected to that affects the attributes that anObserving
has registered for.Declaration
Swift
open func register(key: String, observer: Observing, attributes: [String])
-
Unregister the
Observing
that was registered with the provided key such that it will no longer be called if a transaction occurs that affects the attributes thatObserving
was registered to observe.The
Observing
will need to re-register if it wants to start observing again.Declaration
Swift
open func unregister(key: String)
Parameters
key
String
representing an identifier for theObserving
.