TypeDB.Concept (TypeDB v0.2.0)

Copy Markdown View Source

The concepts TypeDB returns inside conceptRows answers.

Every entry in a row is one of:

StructTypeQLNotes
TypeDB.Concept.Entityan entity instanceiid, optional type
TypeDB.Concept.Relationa relation instanceiid, optional type
TypeDB.Concept.Attributean attribute instanceiid, value, value_type, optional type
TypeDB.Concept.Valuea computed valuevalue, value_type
TypeDB.Concept.EntityTypeentity typelabel
TypeDB.Concept.RelationTyperelation typelabel
TypeDB.Concept.AttributeTypeattribute typelabel, optional value_type
TypeDB.Concept.RoleTypea relation rolelabel
nilan unbound optional variable
a lista list-valued variableelements are concepts

type is nil when the query ran with include_instance_types: false.

Values

value holds the value exactly as it came over the wire, which is what the HTTP API defines: JSON primitives for boolean, integer, double and string, and strings for decimal, date, datetime, datetime-tz and duration.

Use typed_value/1 to convert to native Elixir terms:

iex> attr = %TypeDB.Concept.Attribute{iid: "0x1", value: "2024-03-01", value_type: "date"}
iex> TypeDB.Concept.typed_value(attr)
~D[2024-03-01]

Conversion never loses information: datetime-tz and duration become TypeDB.DateTimeTZ and TypeDB.Duration structs, which keep the original wire form alongside the parsed fields.

Summary

Types

A row entry: a concept, an unbound variable, or a list of concepts.

t()

Functions

Casts a wire value given its TypeDB value type name.

Decodes one wire-format row entry into concept structs.

Returns the iid of an instance, or nil for types and values.

Returns the label of a type, or of the type of an instance when it was included.

Returns the value converted to a native Elixir term.

Returns the wire-format value of an attribute or value concept, nil otherwise.

Types

entry()

@type entry() :: t() | nil | [t()]

A row entry: a concept, an unbound variable, or a list of concepts.

instance()

t()

@type t() :: instance() | type() | TypeDB.Concept.Value.t()

type()

Functions

cast(value, arg2)

@spec cast(term(), String.t()) :: term()

Casts a wire value given its TypeDB value type name.

decode(entries)

@spec decode(term()) :: entry()

Decodes one wire-format row entry into concept structs.

Raises TypeDB.Error with kind: :decode when the payload does not look like anything the HTTP API can produce.

iid(arg1)

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

Returns the iid of an instance, or nil for types and values.

label(arg1)

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

Returns the label of a type, or of the type of an instance when it was included.

typed_value(arg1)

@spec typed_value(t()) :: term()

Returns the value converted to a native Elixir term.

  • booleanboolean
  • integerinteger
  • doublefloat
  • stringString.t()
  • decimalDecimal.t() when the optional Decimal library is loaded, otherwise a string. TypeDB renders decimals with TypeQL's literal suffix ("12.345dec"), which is stripped either way — the value differs in type when Decimal is absent, not in content. The suffix survives in TypeDB.Concept.value/1, which is the raw wire value
  • dateDate.t()
  • datetimeNaiveDateTime.t()
  • datetime-tzTypeDB.DateTimeTZ.t()
  • durationTypeDB.Duration.t()

Values that cannot be parsed are returned unchanged rather than raising, so a future TypeDB value type never breaks a running application.

value(arg1)

@spec value(t()) :: term()

Returns the wire-format value of an attribute or value concept, nil otherwise.