View Source EdgeDB.NamedTuple (EdgeDB v0.7.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, client} = EdgeDB.start_link()
iex(2)> nt = EdgeDB.query_required_single!(client, "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

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.

Types

@opaque t()

An immutable value representing an EdgeDB named tuple value.

Functions

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

Get named tuple keys.

iex(1)> {:ok, client} = EdgeDB.start_link()
iex(2)> nt = EdgeDB.query_required_single!(client, "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, client} = EdgeDB.start_link()
iex(2)> nt = EdgeDB.query_required_single!(client, "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, client} = EdgeDB.start_link()
iex(2)> nt = EdgeDB.query_required_single!(client, "select (a := 1, b := 'a', c := [3])")
iex(3)> EdgeDB.NamedTuple.to_tuple(nt)
{1, "a", [3]}