Query
open class Query : OptionalRustObject
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
Int64EntidKeywordBoolDoubleDateStringUUID.
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 defaultrunfunction and returns a list of rows of values. Queries that wish to haveRelresults 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 haveScalarresults 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 haveCollresults 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 haveTupleresults should format their query strings:let query = """ [: find [?a ?b ?c] : where ... ] """ mentat.query(query: query) .runTuple { result in ... }
-
Binds a
Int64value to the provided variable name.Throws
PointerError.pointerConsumedif the underlying raw pointer has already consumed, which will occur if the query has already been executed.Declaration
Swift
open func bind(varName: String, toLong value: Int64) throws -> QueryParameters
varNameThe name of the variable in the format
?name.valueThe value to be bound
Return Value
This
Querysuch that further function can be called. -
Binds a
Entidvalue to the provided variable name.Throws
PointerError.pointerConsumedif the underlying raw pointer has already consumed, which will occur if the query has already been executed.Declaration
Swift
open func bind(varName: String, toReference value: Entid) throws -> QueryParameters
varNameThe name of the variable in the format
?name.valueThe value to be bound
Return Value
This
Querysuch that further function can be called. -
Binds a
Stringvalue representing a keyword for an attribute to the provided variable name. Keywords take the format:namespace/name.Throws
PointerError.pointerConsumedif the underlying raw pointer has already consumed, which will occur if the query has already been executed.Declaration
Swift
open func bind(varName: String, toReference value: String) throws -> QueryParameters
varNameThe name of the variable in the format
?name.valueThe value to be bound
Return Value
This
Querysuch that further function can be called. -
Binds a keyword
Stringvalue to the provided variable name. Keywords take the format:namespace/name.Throws
PointerError.pointerConsumedif the underlying raw pointer has already consumed, which will occur if the query has already been executed.Declaration
Swift
open func bind(varName: String, toKeyword value: String) throws -> QueryParameters
varNameThe name of the variable in the format
?name.valueThe value to be bound
Return Value
This
Querysuch that further function can be called. -
Binds a
Boolvalue to the provided variable name.Throws
PointerError.pointerConsumedif the underlying raw pointer has already consumed, which will occur if the query has already been executed.Declaration
Swift
open func bind(varName: String, toBoolean value: Bool) throws -> QueryParameters
varNameThe name of the variable in the format
?name.valueThe value to be bound
Return Value
This
Querysuch that further function can be called. -
Binds a
Doublevalue to the provided variable name.Throws
PointerError.pointerConsumedif the underlying raw pointer has already consumed, which will occur if the query has already been executed.Declaration
Swift
open func bind(varName: String, toDouble value: Double) throws -> QueryParameters
varNameThe name of the variable in the format
?name.valueThe value to be bound
Return Value
This
Querysuch that further function can be called. -
Binds a
Datevalue to the provided variable name.Throws
PointerError.pointerConsumedif the underlying raw pointer has already consumed, which will occur if the query has already been executed.Declaration
Swift
open func bind(varName: String, toDate value: Date) throws -> QueryParameters
varNameThe name of the variable in the format
?name.valueThe value to be bound
Return Value
This
Querysuch that further function can be called. -
Binds a
Stringvalue to the provided variable name.Throws
PointerError.pointerConsumedif the underlying raw pointer has already consumed, which will occur if the query has already been executed.Declaration
Swift
open func bind(varName: String, toString value: String) throws -> QueryParameters
varNameThe name of the variable in the format
?name.valueThe value to be bound
Return Value
This
Querysuch that further function can be called. -
Binds a
UUIDvalue to the provided variable name.Throws
PointerError.pointerConsumedif the underlying raw pointer has already consumed, which will occur if the query has already been executed.Declaration
Swift
open func bind(varName: String, toUuid value: UUID) throws -> QueryParameters
varNameThe name of the variable in the format
?name.valueThe value to be bound
Return Value
This
Querysuch that further function can be called. -
Execute the query with the values bound associated with this
Queryand call the provided callback function with the results as a list of rows ofTypedValues.Throws
QueryError.executionFailedif the query fails to execute. This could be because the provided query did not parse, or that variable we incorrectly bound, or that the query provided was notRel.Throws
PointerError.pointerConsumedif the underlying raw pointer has already consumed, which will occur if the query has previously been executed.Declaration
Swift
open func run(callback: @escaping (RelResult?) -> Void) throwsParameters
callbackthe function to call with the results of this query
-
Execute the query with the values bound associated with this
Queryand call the provided callback function with the result as a singleTypedValue.Throws
QueryError.executionFailedif the query fails to execute. This could be because the provided query did not parse, that variable we incorrectly bound, or that the query provided was notScalar.Throws
PointerError.pointerConsumedif the underlying raw pointer has already consumed, which will occur if the query has previously been executed.Declaration
Swift
open func runScalar(callback: @escaping (TypedValue?) -> Void) throwsParameters
callbackthe function to call with the results of this query
-
Execute the query with the values bound associated with this
Queryand call the provided callback function with the result as a list of singleTypedValues.Throws
QueryError.executionFailedif the query fails to execute. This could be because the provided query did not parse, that variable we incorrectly bound, or that the query provided was notColl.Throws
PointerError.pointerConsumedif the underlying raw pointer has already consumed, which will occur if the query has previously been executed.Declaration
Swift
open func runColl(callback: @escaping (ColResult?) -> Void) throwsParameters
callbackthe function to call with the results of this query
-
Execute the query with the values bound associated with this
Queryand call the provided callback function with the result as a list of singleTypedValues.Throws
QueryError.executionFailedif the query fails to execute. This could be because the provided query did not parse, that variable we incorrectly bound, or that the query provided was notTuple.Throws
PointerError.pointerConsumedif the underlying raw pointer has already consumed, which will occur if the query has previously been executed.Declaration
Swift
open func runTuple(callback: @escaping (TupleResult?) -> Void) throwsParameters
callbackthe function to call with the results of this query
-
Undocumented
Declaration
Swift
override open func cleanup(pointer: OpaquePointer)
Query Class Reference