Primitives
EdgeDB has a robust type system consisting of primitive and object types. Below is a review of EdgeDB’s primitive types; later, these will be used to declare properties on object types.
Scalar types
A variable-length string | |
Logical boolean (true/false) | |
16-bit integer | |
32-bit integer | |
64-bit integer | |
32-bit floating point number | |
64-bit floating point number | |
Arbitrary precision integer | |
Arbitrary precision number | |
Arbitrary JSON data | |
UUID type | |
Raw binary data | |
Timezone-aware point in time | |
Absolute time span | |
Date and time without timezone | |
Date type | |
Time type | |
Relative time span (in months, days, and seconds) | |
Relative time span (in months and days only) | |
Auto-incrementing sequence of |
Custom scalar types can also be declared. For full documentation, see SDL > Scalar types.
Enums
To represent an enum, declare a custom scalar that extends the abstract enum type.
scalar type Color extending enum<Red, Green, Blue>;
type Shirt {
color: Color;
}
To reference enum values inside EdgeQL queries, use dot notation, e.g.
Color.Green
.
For a full reference on enum types, see the Enum docs.
Arrays
Arrays store zero or more primitive values of the same type in an ordered list. Arrays cannot contain object types or other arrays.
type Person {
str_array: array<str>;
json_array: array<json>;
# INVALID: arrays of object types not allowed
# friends: array<Person>
# INVALID: arrays cannot be nested
# nested_array: array<array<str>>
}
For a full reference on array types, see the Array docs.
Tuples
Like arrays, tuples are ordered sequences of primitive data. Unlike arrays, each element of a tuple can have a distinct type. Tuple elements can be any type, including primitives, objects, arrays, and other tuples.
type Person {
unnamed_tuple: tuple<str, bool, int64>;
nested_tuple: tuple<tuple<str, tuple<bool, int64>>>;
tuple_of_arrays: tuple<array<str>, array<int64>>;
}
Optionally, you can assign a key to each element of the tuple. Tuples containing explicit keys are known as named tuples. You must assign keys to all elements (or none of them).
type BlogPost {
metadata: tuple<title: str, published: bool, upvotes: int64>;
}
Named and unnamed tuples are the same data structure under the hood. You can add, remove, and change keys in a tuple type after it’s been declared. For details, see EdgeQL > Literals > Tuples.
When you query an unnamed tuple using one of EdgeQL’s client libraries, its value is converted to a list/array. When you fetch a named tuple, it is converted into an object/dictionary/hashmap depending on the language.
Ranges
Ranges represent some interval of values. The intervals can be bound or unbound on either end. They can also be empty, containing no values. Only some scalar types have corresponding range types:
-
range<int32>
-
range<int64>
-
range<float32>
-
range<float64>
-
range<decimal>
-
range<datetime>
-
range<cal::local_datetime>
-
range<cal::local_date>
type DieRoll {
values: range<int64>;
}
For a full reference on ranges, functions and operators see the Range docs.
Sequences
To represent an auto-incrementing integer property, declare a custom scalar
that extends the abstract sequence
type. Creating a sequence type
initializes a global int64
counter that auto-increments whenever a new
object is created. All properties that point to the same sequence type will
share the counter.
scalar type ticket_number extending sequence;
type Ticket {
number: ticket_number;
}
For a full reference on sequences, see the Sequence docs.