API/EdgeDB types
EdgeDB.Object
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)> ...(2)> ...(2)> ...(2)> ...(2)> ...(2)> ...(2)> ...(2)>
object =
EdgeDB.query_required_single!(client, """
select schema::ObjectType{
name
}
filter .name = 'std::Object'
limit 1
""")
#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)> ...(2)> ...(2)> ...(2)> ...(2)> ...(2)> ...(2)> ...(2)> ...(2)> ...(2)> ...(2)> ...(2)>
object =
EdgeDB.query_required_single!(client, """
select schema::Property {
name,
annotations: {
name,
@value
}
}
filter .name = 'listen_port' and .source.name = 'cfg::Config'
limit 1
""")
#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"
Types
type
EdgeDB.Object.fields_option/0
@type EdgeDB.Object.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
.
type
EdgeDB.Object.properties_option/0
@type EdgeDB.Object.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 isfalse
. -
:implicit
- flag to include implicit properties (like:id
or:__tid__
) in returning list. The default isfalse
.
type
EdgeDB.Object.t/0
@opaque EdgeDB.Object.t()
An immutable representation of an object instance returned from a query.
Functions
function
EdgeDB.Object.fields(object, opts \\ [])
@spec EdgeDB.Object.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.
function
EdgeDB.Object.id(object)
@spec EdgeDB.Object.id(t()) :: uuid() | nil
Get an object ID if it was returned from the query.
function
EdgeDB.Object.link_properties(object)
@spec EdgeDB.Object.link_properties(t()) :: [String.t()]
Get object link propeties names as list.
function
EdgeDB.Object.links(object)
@spec EdgeDB.Object.links(t()) :: [String.t()]
Get object links names as list.
function
EdgeDB.Object.properties(object, opts \\ [])
@spec EdgeDB.Object.properties(t(), [properties_option()]) :: [String.t()]
Get object properties names as list.
See EdgeDB.Object.properties_option/0
for supported options.
function
EdgeDB.Object.to_map(object)
@spec EdgeDB.Object.to_map(t()) :: %{required(String.t()) => term()}
Convert an object into a regular map.
iex(1)>
{:ok, client} = EdgeDB.start_link()
iex(2)> ...(2)> ...(2)> ...(2)> ...(2)> ...(2)> ...(2)> ...(2)> ...(2)> ...(2)> ...(2)> ...(2)>
object =
EdgeDB.query_required_single!(client, """
select schema::Property {
name,
annotations: {
name,
@value
}
}
filter .name = 'listen_port' and .source.name = 'cfg::Config'
limit 1
""")
iex(3)>
EdgeDB.Object.to_map(object)
%{"name" => "listen_port", "annotations" => [%{"name" => "cfg::system", "@value" => "true"}]}
EdgeDB.Set
A representation of an immutable set of values returned by a query. Nested sets in the result are also returned as EdgeDB.Set
objects.
EdgeDB.Set
implements Enumerable
protocol for iterating over set values.
iex(1)>
{:ok, client} = EdgeDB.start_link()
iex(2)> ...(2)> ...(2)> ...(2)> ...(2)> ...(2)> ...(2)> ...(2)>
set =
EdgeDB.query!(client, """
select schema::ObjectType{
name
}
filter .name IN {'std::BaseObject', 'std::Object', 'std::FreeObject'}
order by .name
""")
iex(3)>
set
#EdgeDB.Set<{#EdgeDB.Object<name := "std::BaseObject">, #EdgeDB.Object<name := "std::FreeObject">, #EdgeDB.Object<name := "std::Object">}>
Types
EdgeDB.NamedTuple
An immutable value representing an EdgeDB named tuple value.
EdgeDB.NamedTuple
implements Access
behavior to access fields by index or key and Enumerable
protocol for iterating over tuple
values.
iex(1)>
{:ok, client} = EdgeDB.start_link()
iex(2)>
nt = EdgeDB.query_required_single!(client, "select (a := 1, b := 'a', c := [3])")
#EdgeDB.NamedTuple<a: 1, b: "a", c: [3]>
iex(3)>
nt[:b]
"a"
iex(4)>
nt["c"]
[3]
iex(4)>
nt[0]
1
Types
Functions
function
EdgeDB.NamedTuple.keys(named_tuple)
@spec EdgeDB.NamedTuple.keys(t()) :: [String.t()]
Get named tuple keys.
iex(1)>
{:ok, client} = EdgeDB.start_link()
iex(2)>
nt = EdgeDB.query_required_single!(client, "select (a := 1, b := 'a', c := [3])")
iex(3)>
EdgeDB.NamedTuple.keys(nt)
["a", "b", "c"]
function
EdgeDB.NamedTuple.to_map(named_tuple)
@spec EdgeDB.NamedTuple.to_map(t()) :: %{required(String.t()) => term()}
Convert a named tuple into a regular map.
iex(1)>
{:ok, client} = EdgeDB.start_link()
iex(2)>
nt = EdgeDB.query_required_single!(client, "select (a := 1, b := 'a', c := [3])")
iex(3)>
EdgeDB.NamedTuple.to_map(nt)
%{"a" => 1, "b" => "a", "c" => [3]}
function
EdgeDB.NamedTuple.to_tuple(nt)
@spec EdgeDB.NamedTuple.to_tuple(t()) :: tuple()
Convert a named tuple to a regular erlang tuple.
iex(1)>
{:ok, client} = EdgeDB.start_link()
iex(2)>
nt = EdgeDB.query_required_single!(client, "select (a := 1, b := 'a', c := [3])")
iex(3)>
EdgeDB.NamedTuple.to_tuple(nt)
{1, "a", [3]}
EdgeDB.RelativeDuration
An immutable value represeting an EdgeDB cal::relative_duration
value.
iex(1)>
{:ok, client} = EdgeDB.start_link()
iex(2)>
EdgeDB.query_required_single!(client, "select <cal::relative_duration>'45.6 seconds'")
#EdgeDB.RelativeDuration<"PT45.6S">
Types
type
EdgeDB.RelativeDuration.t/0
@type EdgeDB.RelativeDuration.t() :: %EdgeDB.RelativeDuration{
days: pos_integer(),
microseconds: pos_integer(),
months: pos_integer()
}
An immutable value represeting an EdgeDB cal::relative_duration
value.
Fields:
-
:months
- number of months. -
:days
- number of days. -
:microseconds
- number of microseconds.
EdgeDB.DateDuration
An immutable value represeting an EdgeDB cal::date_duration
value.
iex(1)>
{:ok, client} = EdgeDB.start_link()
iex(2)>
EdgeDB.query_required_single!(client, "select <cal::date_duration>'1 year 2 days'")
#EdgeDB.DateDuration<"P1Y2D">
EdgeDB.ConfigMemory
An immutable value represeting an EdgeDB cfg::memory
value as a quantity of memory storage.
iex(1)>
{:ok, client} = EdgeDB.start_link()
iex(2)>
mem = EdgeDB.query_required_single!(client, "select <cfg::memory>'5KiB'")
#EdgeDB.ConfigMemory<"5KiB">
iex(3)>
EdgeDB.ConfigMemory.bytes(mem)
5120
Types
EdgeDB.Range
A value representing some interval of values.
iex(1)>
{:ok, client} = EdgeDB.start_link()
iex(2)>
EdgeDB.query_required_single!(client, "select range(1, 10)")
#EdgeDB.Range<[1, 10)>
Types
type
EdgeDB.Range.creation_option/0
@type EdgeDB.Range.creation_option() :: {:inc_lower, boolean()} | {:inc_upper, boolean()} | {:empty, boolean()}
Options for EdgeDB.Range.new/3
function.
Supported options:
-
:inc_lower
- flag whether the created range should strictly include the lower boundary. -
:inc_upper
- flag whether the created range should strictly include the upper boundary. -
:empty
- flag to create an empty range.
type
EdgeDB.Range.t/0
@type EdgeDB.Range.t() :: t(value())
A value of EdgeDB.Range.value/0
type representing some interval of values.
type
EdgeDB.Range.t/1
@type EdgeDB.Range.t(value) :: %EdgeDB.Range{
inc_lower: boolean(),
inc_upper: boolean(),
is_empty: boolean(),
lower: value | nil,
upper: value | nil
}
A value of EdgeDB.Range.value/0
type representing some interval of values.
Fields:
-
:lower
- data for the lower range boundary. -
:upper
- data for the upper range boundary. -
:inc_lower
- flag whether the range should strictly include the lower boundary. -
:inc_upper
- flag whether the range should strictly include the upper boundary. -
:is_empty
- flag for an empty range.
Functions
function
EdgeDB.Range.empty()
@spec EdgeDB.Range.empty() :: t()
Create an empty range.
iex(1)>
EdgeDB.Range.empty()
#EdgeDB.Range<empty>
EdgeDB.MultiRange
A value representing a collection of ranges.
EdgeDB.MultiRange
implements Enumerable
protocol for iterating over the collection. Each range in the collection is an instance of the
EdgeDB.Range.t/0
struct.
iex(1)>
{:ok, client} = EdgeDB.start_link()
iex(2)>
EdgeDB.query_required_single!(client, "select multirange([range(1, 10)])")
#EdgeDB.MultiRange<[#EdgeDB.Range<[1, 10)>]>
Types
type
EdgeDB.MultiRange.t/0
@type EdgeDB.MultiRange.t() :: t(value())
A value of EdgeDB.MultiRange.value/0
type representing a collection of intervals of values.
type
EdgeDB.MultiRange.t/1
@opaque EdgeDB.MultiRange.t(value)
A value of EdgeDB.MultiRange.value/0
type representing a collection of intervals of values.