View Source EdgeDB.NamedTuple (EdgeDB v0.4.0)

An immutable value representing an EdgeDB named tuple value.

EdgeDB.NamedTuple implements Access behavior to access fields by index or key and Enumerable protocol for iterating over tuple values.

iex(1)> {:ok, pid} = EdgeDB.start_link()
iex(2)> nt = EdgeDB.query_required_single!(pid, "select (a := 1, b := 'a', c := [3])")
#EdgeDB.NamedTuple<a: 1, b: "a", c: [3]>
iex(3)> nt[:b]
"a"
iex(4)> nt["c"]
[3]
iex(4)> nt[0]
1

Link to this section Summary

Types

t()

An immutable value representing an EdgeDB named tuple value.

Functions

Get named tuple keys.

Convert a named tuple into a regular map.

Convert a named tuple to a regular erlang tuple.

Link to this section Types

@opaque t()

An immutable value representing an EdgeDB named tuple value.

Link to this section Functions

@spec keys(t()) :: [String.t()]

Get named tuple keys.

iex(1)> {:ok, pid} = EdgeDB.start_link()
iex(2)> nt = EdgeDB.query_required_single!(pid, "select (a := 1, b := 'a', c := [3])")
iex(3)> EdgeDB.NamedTuple.keys(nt)
["a", "b", "c"]
Link to this function

to_map(named_tuple)

View Source (since 0.3.0)
@spec to_map(t()) :: %{required(String.t()) => term()}

Convert a named tuple into a regular map.

iex(1)> {:ok, pid} = EdgeDB.start_link()
iex(2)> nt = EdgeDB.query_required_single!(pid, "select (a := 1, b := 'a', c := [3])")
iex(3)> EdgeDB.NamedTuple.to_map(nt)
%{"a" => 1, "b" => "a", "c" => [3]}
@spec to_tuple(t()) :: tuple()

Convert a named tuple to a regular erlang tuple.

iex(1)> {:ok, pid} = EdgeDB.start_link()
iex(2)> nt = EdgeDB.query_required_single!(pid, "select (a := 1, b := 'a', c := [3])")
iex(3)> EdgeDB.NamedTuple.to_tuple(nt)
{1, "a", [3]}