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"
links-and-links-properties
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)> %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
Options for EdgeDB.Object.fields/2
An immutable representation of an object instance returned from a query.
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 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
@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
.
@opaque object()
An immutable representation of an object instance returned from a query.
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
.
@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
@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.
Get object link propeties names as list.
Get object links names as list.
@spec properties(object(), [properties_option()]) :: [String.t()]
Get object properties names as list.
See properties_option/0
for supported options.
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"}]}