TypeDB.Answer (TypeDB v0.2.2)

Copy Markdown View Source

The result of a TypeQL query.

TypeDB answers come in three shapes, and the driver gives each its own struct so you can pattern match on the one you expect:

Every answer carries query_type (:read, :write or :schema), which is what TypeDB determined the query to be — not what you asked for.

query = "match $p isa person; select $p;"

case TypeDB.query!(conn, "social", query, transaction_type: :read) do
  %TypeDB.Answer.ConceptRows{rows: rows} -> length(rows)
  %TypeDB.Answer.Ok{} -> 0
end

ConceptRows and ConceptDocuments are Enumerable, so they can be piped straight into Enum and Stream. Select an attribute if you want values — typed_value/2 on an entity answers nil, because an entity is a thing with an identity rather than a value:

conn
|> TypeDB.query!("social", "match $p isa person, has name $name; select $name;",
     transaction_type: :read)
|> Enum.map(&TypeDB.ConceptRow.typed_value(&1, "name"))
#=> ["Alice", "Bob"]

Summary

Types

What TypeDB classified the query as.

t()

Functions

Returns the documents of a ConceptDocuments answer, or [] for any other.

Returns the query type TypeDB classified this query as.

Returns the rows of a ConceptRows answer, or [] for any other answer.

Returns the server-side warning attached to an answer, if any.

Types

query_type()

@type query_type() :: :read | :write | :schema

What TypeDB classified the query as.

t()

Functions

documents(arg1)

@spec documents(t()) :: [term()]

Returns the documents of a ConceptDocuments answer, or [] for any other.

query_type(arg1)

@spec query_type(t()) :: query_type()

Returns the query type TypeDB classified this query as.

rows(arg1)

@spec rows(t()) :: [TypeDB.ConceptRow.t()]

Returns the rows of a ConceptRows answer, or [] for any other answer.

warning(arg1)

@spec warning(t()) :: String.t() | nil

Returns the server-side warning attached to an answer, if any.

TypeDB uses warnings for things like an answer set truncated by answer_count_limit.