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"
Links and links properties
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
Options for EdgeDB.Object.fields/2
Options for EdgeDB.Object.properties/2
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
@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 istrue
.:links
- flag to include object links in returning list. The default istrue
.:link_properies
- flag to include object link properties in returning list. The default istrue
.:id
- flag to include implicit:id
in returning list. The default isfalse
.:implicit
- flag to include implicit fields (like:id
or:__tid__
) in returning list. The default isfalse
.
Options for EdgeDB.Object.properties/2
Supported options:
:id
- flag to include implicit:id
in returning list. The default isfalse
.:implicit
- flag to include implicit properties (like:id
or:__tid__
) in returning list. The default isfalse
.
@opaque t()
An immutable representation of an object instance returned from a query.
@type uuid() :: String.t()
UUID value.
Functions
@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.
Get an object ID if it was returned from the query.
Get object link propeties names as list.
Get object links names as list.
@spec properties(t(), [properties_option()]) :: [String.t()]
Get object properties names as list.
See EdgeDB.Object.properties_option/0
for supported options.
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"}]}