View Source EdgeDB.Object (EdgeDB v0.7.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

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 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.
@opaque t()

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

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

UUID value.

Functions

Link to this function

fields(object, opts \\ [])

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

Link to this function

id(object)

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

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

Link to this function

links(object)

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

Get object links names as list.

Link to this function

properties(object, opts \\ [])

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

Link to this function

to_map(object)

View Source (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"}]}