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
rawA 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
storeURIThe 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.errorif an error occured while trying to cache the attribute.Declaration
Swift
open func cache(attribute: String, direction: CacheDirection) throwsParameters
attributeThe attribute to cache
directionThe direction the attribute should be keyed.
forwardcaches 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)reversecaches entities for an attribute keyed by value. (i.e. find entities that have a particular value for an attribute).bothadds an attribute such that it is cached in both directions. -
Simple transact of an EDN string.
Throws
ResultError.errorif the an error occured during the transaction, or the TxReport is nil.Declaration
Swift
open func transact(transaction: String) throws -> TxReportParameters
transactionThe string, as EDN, to be transacted
Return Value
The
TxReportof the completed transaction -
Start a new transaction.
Throws
ResultError.errorif the creation of the transaction fails.Throws
ResultError.emptyif noInProgressis created.Declaration
Swift
open func beginTransaction() throws -> InProgressReturn Value
The
InProgressused to manage the transaction -
Creates a new transaction (
InProgress) and returns anInProgressBuilderfor that transaction.Throws
ResultError.errorif the creation of the transaction fails.Throws
ResultError.emptyif noInProgressBuilderis created.Declaration
Swift
open func entityBuilder() throws -> InProgressBuilderReturn Value
an
InProgressBuilderfor thisInProgress -
Creates a new transaction (
InProgress) and returns anEntityBuilderfor the entity withentidfor that transaction.Throws
ResultError.errorif the creation of the transaction fails.Throws
ResultError.emptyif noEntityBuilderis created.Declaration
Swift
open func entityBuilder(forEntid entid: Entid) throws -> EntityBuilderParameters
entidThe
Entidfor this entity.Return Value
an
EntityBuilderfor thisInProgress -
Creates a new transaction (
InProgress) and returns anEntityBuilderfor a new entity withtempIdfor that transaction.Throws
ResultError.errorif the creation of the transaction fails.Throws
ResultError.emptyif noEntityBuilderis created.Declaration
Swift
open func entityBuilder(forTempId tempId: String) throws -> EntityBuilderParameters
tempIdThe temporary identifier for this entity.
Return Value
an
EntityBuilderfor 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
attributeThe string the attribute whose value is to be returned. The string is represented as
:namespace/name.entidThe
Entidof the entity we want the value from.Return Value
The
TypedValuecontaining the value of the attribute for the entity. -
Undocumented
Declaration
Swift
override open func cleanup(pointer: OpaquePointer)
-
Register an
Observingand a set of attributes to observer for transaction observation. ThetransactionDidOccur(String: [TxChange]:)function is called when a transaction occurs in theStorethat thisMentatis connected to that affects the attributes that anObservinghas registered for.Declaration
Swift
open func register(key: String, observer: Observing, attributes: [String]) -
Unregister the
Observingthat was registered with the provided key such that it will no longer be called if a transaction occurs that affects the attributes thatObservingwas registered to observe.The
Observingwill need to re-register if it wants to start observing again.Declaration
Swift
open func unregister(key: String)Parameters
keyStringrepresenting an identifier for theObserving.
Mentat Class Reference