View Source EdgeDB.Object (EdgeDB v0.6.1)

An immutable representation of an object instance returned from a query.

EdgeDB.Object implements Access behavior to access properties by key.

iex(1)> {:ok, client} = EdgeDB.start_link()
iex(2)> %EdgeDB.Object{} = object =
iex(2)>  EdgeDB.query_required_single!(client, "
...(2)>   select schema::ObjectType{
...(2)>     name
...(2)>   }
...(2)>   filter .name = 'std::Object'
...(2)>   limit 1
...(2)>  ")
#EdgeDB.Object<name := "std::Object">
iex(3)> object[:name]
"std::Object"
iex(4)> object["name"]
"std::Object"

In EdgeDB, objects can have links to other objects or a set of objects. You can use the same syntax to access links values as for object properties. Links can also have their own properties (denoted as @<link_prop_name> in EdgeQL syntax). You can use the same property name as in the query to access them from the links.

iex(1)> {:ok, client} = EdgeDB.start_link()
iex(2)> %EdgeDB.Object{} = object =
iex(2)>  EdgeDB.query_required_single!(client, "
...(2)>   select schema::Property {
...(2)>       name,
...(2)>       annotations: {
...(2)>         name,
...(2)>         @value
...(2)>       }
...(2)>   }
...(2)>   filter .name = 'listen_port' and .source.name = 'cfg::Config'
...(2)>   limit 1
...(2)>  ")
#EdgeDB.Object<name := "listen_port", annotations := #EdgeDB.Set<{#EdgeDB.Object<name := "cfg::system", @value := "true">}>>
iex(3)> annotations = object[:annotations]
#EdgeDB.Set<{#EdgeDB.Object<name := "cfg::system", @value := "true">}>
iex(4)> link = Enum.at(annotations, 0)
#EdgeDB.Object<name := "cfg::system", @value := "true">
iex(5)> link["@value"]
"true"

Link to this section Summary

Types

An immutable representation of an object instance returned from a query.

t()

An immutable representation of an object instance returned from a query.

UUID value.

Functions

Get object fields names (properties, links and link propries) as list of strings.

Get object link propeties names as list.

Get object links names as list.

Get object properties names as list.

Convert an object into a regular map.

Link to this section Types

Link to this type

fields_option()

View Source (since 0.2.0)
@type fields_option() ::
  {:properties, boolean()}
  | {:links, boolean()}
  | {:link_properties, boolean()}
  | {:id, boolean()}
  | {:implicit, boolean()}

Options for EdgeDB.Object.fields/2

Supported options:

  • :properties - flag to include object properties in returning list. The default is true.
  • :links - flag to include object links in returning list. The default is true.
  • :link_properies - flag to include object link properties in returning list. The default is true.
  • :id - flag to include implicit :id in returning list. The default is false.
  • :implicit - flag to include implicit fields (like :id or :__tid__) in returning list. The default is false.
Link to this opaque

object()

View Source (opaque) (since 0.2.0)
@opaque object()

An immutable representation of an object instance returned from a query.

Link to this type

properties_option()

View Source (since 0.2.0)
@type properties_option() :: {:id, boolean()} | {:implicit, boolean()}

Options for EdgeDB.Object.properties/2

Supported options:

  • :id - flag to include implicit :id in returning list. The default is false.
  • :implicit - flag to include implicit properties (like :id or :__tid__) in returning list. The default is false.
@type t() :: %EdgeDB.Object{id: uuid() | nil}

An immutable representation of an object instance returned from a query.

Fields:

  • :id - a unique ID of the object instance in the database.
@type uuid() :: String.t()

UUID value.

Link to this section Functions

Link to this function

fields(object, opts \\ [])

View Source (since 0.2.0)
@spec fields(object(), [fields_option()]) :: [String.t()]

Get object fields names (properties, links and link propries) as list of strings.

See fields_option/0 for supported options.

Link to this function

links(object)

View Source (since 0.2.0)
@spec links(object()) :: [String.t()]

Get object links names as list.

Link to this function

properties(object, opts \\ [])

View Source (since 0.2.0)
@spec properties(object(), [properties_option()]) :: [String.t()]

Get object properties names as list.

See properties_option/0 for supported options.

Link to this function

to_map(object)

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

Convert an object into a regular map.

iex(1)> {:ok, client} = EdgeDB.start_link()
iex(2)> object =
iex(2)>  EdgeDB.query_required_single!(client, "
...(2)>   select schema::Property {
...(2)>       name,
...(2)>       annotations: {
...(2)>         name,
...(2)>         @value
...(2)>       }
...(2)>   }
...(2)>   filter .name = 'listen_port' and .source.name = 'cfg::Config'
...(2)>   limit 1
...(2)>  ")
iex(3)> EdgeDB.Object.to_map(object)
%{"name" => "listen_port", "annotations" => [%{"name" => "cfg::system", "@value" => "true"}]}