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 no InProgress 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 an InProgressBuilder for that transaction.

    Throws

    ResultError.error if the creation of the transaction fails.

    Throws

    ResultError.empty if no InProgressBuilder is created.

    Declaration

    Swift

    open func entityBuilder() throws -> InProgressBuilder

    Return Value

    an InProgressBuilder for this InProgress

  • Creates a new transaction (InProgress) and returns an EntityBuilder for the entity with entid for that transaction.

    Throws

    ResultError.error if the creation of the transaction fails.

    Throws

    ResultError.empty if no EntityBuilder is created.

    Declaration

    Swift

    open func entityBuilder(forEntid entid: Entid) throws -> EntityBuilder

    Parameters

    entid

    The Entid for this entity.

    Return Value

    an EntityBuilder for this InProgress

  • Creates a new transaction (InProgress) and returns an EntityBuilder for a new entity with tempId for that transaction.

    Throws

    ResultError.error if the creation of the transaction fails.

    Throws

    ResultError.empty if no EntityBuilder 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 this InProgress

  • Get the the Entid of the attribute.

    Declaration

    Swift

    open func entidForAttribute(attribute: String) -> Entid

    Parameters

    attribute

    The string represeting the attribute whose Entid we are after. The string is represented as :namespace/name.

    Return Value

    The Entid associated with the attribute.

  • Start a query.

    Declaration

    Swift

    open func query(query: String) -> Query

    Parameters

    query

    The string represeting the the query to be executed.

    Return Value

    The Query representing the query that can be executed.

  • 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. The transactionDidOccur(String: [TxChange]:) function is called when a transaction occurs in the Store that this Mentat is connected to that affects the attributes that an Observing has registered for.

    Declaration

    Swift

    open func register(key: String, observer: Observing, attributes: [String])

    Parameters

    key

    String representing an identifier for the Observing.

    observer

    The Observing to be notified when a transaction occurs.

    attributes

    An Array of Strings representing the attributes that the Observing wishes to be notified about if they are referenced in a transaction.

  • 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 that Observing 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 the Observing.