View Source EdgeDB.Object (EdgeDB v0.8.0)

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)> object =
...(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"

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)> object =
...(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"

Summary

Types

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 an object ID if it was returned from the query.

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.

Types

fields_option()

(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.

properties_option()

(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.

t()

(since 0.7.0)
@opaque t()

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

uuid()

@type uuid() :: String.t()

UUID value.

Functions

fields(object, opts \\ [])

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

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

See EdgeDB.Object.fields_option/0 for supported options.

id(object)

(since 0.7.0)
@spec id(t()) :: uuid() | nil

Get an object ID if it was returned from the query.

links(object)

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

Get object links names as list.

properties(object, opts \\ [])

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

Get object properties names as list.

See EdgeDB.Object.properties_option/0 for supported options.

to_map(object)

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

Convert an object into a regular map.

iex(1)> {:ok, client} = EdgeDB.start_link()
iex(2)> object =
...(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"}]}