Classes

The following classes are available globally.

  • A wrapper around Mentat’s TypedValue Rust object. This class wraps a raw pointer to a Rust TypedValue 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 more

    Declaration

    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 more

    Declaration

    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 default run function and returns a list of rows of values. Queries that wish to have Rel 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 have Scalar 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 have Coll 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 have Tuple results should format their query strings: let query = """ [: find [?a ?b ?c] : where ... ] """ mentat.query(query: query) .runTuple { result in ... }
    See more

    Declaration

    Swift

    open class Query : OptionalRustObject
  • Wraps a Rel result from a Mentat query. A Rel result is a list of rows of TypedValues. Individual rows can be fetched or the set can be iterated.

    To fetch individual rows from a RelResult use row(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 more

    Declaration

    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 more

    Declaration

    Swift

    open class RelResultIterator : OptionalRustObject, IteratorProtocol
  • Wraps a Tuple result from a Mentat query. A Tuple result is a list of TypedValues. Individual values can be fetched as TypedValues or converted into a requested type.

    Values can be fetched as one of the following types:

    See more

    Declaration

    Swift

    open class TupleResult : OptionalRustObject
  • Wraps a Coll result from a Mentat query. A Coll result is a list of rows of single values of type TypedValue. Values for individual rows can be fetched as TypedValue or converted into a requested type.

    Row values can be fetched as one of the following types:

    See more

    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 more

    Declaration

    Swift

    open class ColResultIterator : OptionalRustObject, IteratorProtocol
  • Base class that wraps an optional OpaquePointer 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 raw OpaquePointer are nilled after calling a consuming FFI function. This class provides cleanup functions on deinit, ensuring that all classes that inherit from it will have their OpaquePointer destroyed when the Swift wrapper is destroyed. If a class does not override cleanup then a fatalError 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.

    See more

    Declaration

    Swift

    open class OptionalRustObject : Destroyable
  • Base class that wraps an non-optional OpaquePointer representing a pointer to a Rust object. This class provides cleanup functions on deinit, ensuring that all classes that inherit from it will have their OpaquePointer destroyed when the Swift wrapper is destroyed. If a class does not override cleanup then a fatalError is thrown.

    See more

    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 the EntityBuilder and pass back the TxReport that was generated by this transact and the InProgress that was used to perform the transact. This enables you to perform further transacts on the same InProgress 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 the EntityBuilder. It will consume the InProgress used to perform the transact. It returns the TxReport generated by the transact. After calling commit, a new transaction must be started by calling Mentat.beginTransaction() in order to perform further actions.

    let 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 {
       ...
    }
    
    See more

    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 a TxReport 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 that InProgress.

    Rolling back and InProgress rolls back all the transacts that have been performed using that InProgress.

     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 are InProgressBuilder and EntityBuilder.

    InProgressBuilder takes the current InProgress and provides a programmatic interface to add and retract values from entities for which there exists an Entid. The provided InProgress 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 current InProgress and either an Entid or a tempid to provide a programmatic interface to add and retract values from a specific entity. The provided InProgress is used to perform the transacts.

     do {
         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 {
        ...
     }
    
    See more

    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 the InProgressBuilder and pass back the TxReport that was generated by this transact and the InProgress that was used to perform the transact. This enables you to perform further transacts on the same InProgress 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 the EntityBuilder. It will consume the InProgress used to perform the transact. It returns the TxReport generated by the transact. After calling commit, a new transaction must be started by calling Mentat.beginTransaction() in order to perform further actions.

    let 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 {
       ...
    }
    
    See more

    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 Entids that they were mapped to,

    Access an Entid for a temporary identifier that was provided in the transaction can be done through entid(String:).

    let report = mentat.transact("[[:db/add "a" :foo/boolean true]]")
    let aEntid = report.entid(forTempId: "a")
    
    See more

    Declaration

    Swift

    open class TxReport : RustObject