Datatypes
edgedb-python automatically converts EdgeDB types to the corresponding Python types and vice versa.
The table below shows the correspondence between EdgeDB and Python types.
EdgeDB Type |
Python Type |
---|---|
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
offset-naive |
|
offset-naive |
| |
| |
|
offset-aware |
| |
| |
| |
| |
| |
|
Inexact single-precision float
values may have a different
representation when decoded into a Python float. This is inherent
to the implementation of limited-precision floating point types.
If you need the decimal representation to match, cast the expression
to float64
or decimal
in your query.
Sets
This is list
since version 1.0.
Objects
An immutable representation of an object instance returned from a query.
edgedb.Object
instances are dataclass-compatible since version 1.0,
for example, dataclasses.is_dataclass()
will return True
, and
dataclasses.asdict()
will work on edgedb.Object
instances.
edgedb.Object.__hash__
is just object.__hash__
in version 1.0.
Similarly, ==
is equivalent to the is
operator comparing
edgedb.Object
instances, and <
, <=
, >
, >=
are not
allowed on edgedb.Object
instances.
The value of an object property or a link can be accessed through a corresponding attribute:
>>>
import edgedb
>>>
client = edgedb.create_client()
>>> ... ... ...
r = client.query_single('''
SELECT schema::ObjectType {name}
FILTER .name = 'std::Object'
LIMIT 1''')
>>>
r
Object{name := 'std::Object'}
>>>
r.name
'std::Object'
Return a edgedb.Link
or a edgedb.LinkSet
instance
representing the instance(s) of link linkname associated with
obj.
Example:
>>>
import edgedb
>>>
client = edgedb.create_client()
>>> ... ... ... ...
r = client.query_single('''
SELECT schema::Property {name, annotations: {name, @value}}
FILTER .name = 'listen_port'
AND .source.name = 'cfg::Config'
LIMIT 1''')
>>>
r
Object { name: 'listen_port', annotations: { Object { name: 'cfg::system', @value: 'true' } } }
>>>
r['annotations']
LinkSet(name='annotations')
>>>
l = list(r['annotations])[0]
>>>
l.value
'true'
Links
An immutable representation of an object link.
Links are created when edgedb.Object
is accessed via
a []
operator. Using Link objects explicitly is useful for
accessing link properties.
An immutable representation of a set of Links.
LinkSets are created when a multi link on edgedb.Object
is accessed via a []
operator.
Tuples
This is tuple
since version 1.0.
Named Tuples
An immutable value representing an EdgeDB named tuple value.
edgedb.NamedTuple
is a subclass of tuple
and is duck-type compatible with collections.namedtuple
since
version 1.0.
Instances of edgedb.NamedTuple
generally behave similarly to
namedtuple
:
>>>
import edgedb
>>>
client = edgedb.create_client()
>>>
r = client.query_single('''SELECT (a := 1, b := 'a', c := [3])''')
>>>
r
(a := 1, b := 'a', c := [3])
>>>
r.b
'a'
>>>
r[0]
1
>>>
r == (1, 'a', [3])
True
>>>
r._fields
('a', 'b', 'c')
Arrays
This is list
since version 1.0.
RelativeDuration
An immutable value representing an EdgeDB cal::relative_duration
value.
>>>
import edgedb
>>>
client = edgedb.create_client()
>>>
r = client.query_single('''SELECT <cal::relative_duration>"1 year 2 days 3 seconds"''')
>>>
r
<edgedb.RelativeDuration "P1Y2DT3S">
>>>
r.months
12
>>>
r.days
2
>>>
r.microseconds
3000000
DateDuration
EnumValue
An immutable value representing an EdgeDB enum value.
Since version 1.0, edgedb.EnumValue
is a subclass of
enum.Enum
. Actual enum values are
instances of ad-hoc enum classes created by the codecs to represent
the actual members defined in your EdgeDB schema.
>>>
import edgedb
>>>
client = edgedb.create_client()
>>>
r = client.query_single("""SELECT <Color>'red'""")
>>>
r
<edgedb.EnumValue 'red'>
>>>
str(r)
'red'
>>>
r.value # added in 1.0
'red'
>>>
r.name # added in 1.0, simply str.upper() of r.value
'RED'