Most types are just referred to by their name, however, EdgeQL has a
special syntax for referring to array
,
tuple
, and enum
types. This syntax is used in
property, scalar, or function
declarations as well as in type expressions involving IS
or a cast
.
An array type can be explicitly defined in an expression or schema declaration using the following syntax:
array "<" element_type ">"
With the exception of other array types, any scalar or collection type can be used as an array element type.
Here’s an example of using this syntax in a schema definition:
type User {
required property name -> str;
property favorites -> array<str>;
}
Here’s a few examples of using array types in EdgeQL queries:
db>
SELECT <array<int64>>['1', '2', '3'];
{[1, 2, 3]}
db>
SELECT [1, 2, 3] IS (array<int64>);
{true}
db>
SELECT [(1, 'a')] IS (array<tuple<int64, str>>);
{true}
A tuple type can be explicitly declared in an expression or schema declaration using the following syntax:
tuple "<" element-type, [element-type, ...] ">"
A named tuple:
tuple "<" element-name : element-type [, ... ] ">"
Any type can be used as a tuple element type.
Here’s an example of using this syntax in a schema definition:
type GameElement {
required property name -> str;
required property position -> tuple<x: int64, y: int64>;
}
Here’s a few examples of using tuple types in EdgeQL queries:
db>
SELECT <tuple<int64, str>>('1', 3);
{(1, '3')}
db>
SELECT <tuple<x: int64, y: int64>>(1, 2);
{(x := 1, y := 2)}
db>
SELECT (1, '3') IS (tuple<int64, str>);
{true}
db>
SELECT ([1, 2], 'a') IS (tuple<array<int64>, str>);
{true}
An enumerated type can be declared in a schema declaration using the following syntax:
enum "<" enum-values ">"
Where enum-values is a comma-separated list of quoted string constants comprising the enum type. Currently, the only valid application of the enum declaration is to define an enumerated scalar type:
scalar type Color extending enum<Red, Green, Blue>;