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 | |
Arbitrary precision number | |
Timezone-aware point in time | |
Absolute time span | |
Date and time without timezone | |
Date type | |
Time type | |
Relative time span | |
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 {
property 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 {
property str_array -> array<str>;
property json_array -> array<json>;
# INVALID: arrays of object types not allowed
# property friends -> array<Person>
# INVALID: arrays cannot be nested
# property 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. Tuples elements can be any type, including primitives, objects, arrays, and other tuples.
type Person {
property unnamed_tuple -> tuple<str, bool, int64>;
property nested_tuple -> tuple<tuple<str, tuple<bool, int64>>>;
property 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 {
property 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.
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 {
property number -> ticket_number;
}
Reference the Sequence reference for details.