Primer
This page is indended as a rapid-fire overview of SDL syntax so you can hit the ground running with EdgeDB. Refer to the linked pages for more in-depth documentation.
Object types
Object types contain properties and links to other object types. They are analogous to tables in SQL.
type Movie {
property title -> str; # optional by default
}
Optional and required properties
type Movie {
required property title -> str; # required
property release_year -> int64; # optional
}
See Schema > Properties.
Constraints
type Movie {
required property title -> str {
constraint unique;
constraint min_len_value(8);
constraint regexp(r'^[A-Za-z0-9 ]+$');
}
}
See Schema > Constraints.
Indexes
type Movie {
required property title -> str;
required property release_year -> int64;
index on (.title); # simple index
index on ((.title, .release_year)); # composite index
index on (str_trim(str_lower(.title))); # computed index
}
The id
property, all links, and all properties with exclusive
constraints are automatically indexed.
See Schema > Indexes.
Computed properties
type Movie {
required property title -> str;
property uppercase_title := str_upper(.title);
}
See Schema > Computeds.
Links
type Movie {
required property title -> str;
link director -> Person;
}
type Person {
required property name -> str;
}
Use the required
and multi
keywords to specify the cardinality of the relation.
type Movie {
required property title -> str;
link cinematographer -> Person; # zero or one
required link director -> Person; # exactly one
multi link writers -> Person; # zero or more
required multi link actors -> Person; # one or more
}
type Person {
required property name -> str;
}
To define a one-to-one relation, use an exclusive
constraint.
type Movie {
required property title -> str;
required link stats -> MovieStats {
constraint exclusive;
};
}
type MovieStats {
required property budget -> int64;
required property box_office -> int64;
}
See Schema > Links.
Computed links
Links can be computed. The example below defines a backlink.
type Movie {
required property title -> str;
multi link actors -> Person;
}
type Person {
required property name -> str;
link acted_in := .<actors[is Movie];
}
See Schema > Computeds > Backlinks.
Schema mixins
abstract type Content {
required property title -> str;
}
type Movie extending Content {
required property release_year -> int64;
}
type TVShow extending Content {
required property num_seasons -> int64;
}
See Schema > Object types > Inheritance.
Polymorphic links
abstract type Content {
required property title -> str;
}
type Movie extending Content {
required property release_year -> int64;
}
type TVShow extending Content {
required property num_seasons -> int64;
}
type Franchise {
required property name -> str;
multi link entries -> Content;
}