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.


1. type Movie {
2. property title -> str;  # optional by default
3. }

See Schema > Object types.

Optional and required properties


1. type Movie {
2. required property title -> str;       # required
3. property release_year -> int64;       # optional
4. }

See Schema > Properties.

Constraints


1. type Movie {
2. required property title -> str {
3. constraint unique;
4. constraint min_len_value(8);
5. constraint regexp(r'^[A-Za-z0-9 ]+$');
6. }
7. }

See Schema > Constraints.

Indexes


1. type Movie {
2. required property title -> str;
3. required property release_year -> int64;

5. index on (.title);                        # simple index
6. index on ((.title, .release_year));       # composite index
7. index on (str_trim(str_lower(.title)));   # computed index
8. }

The id property, all links, and all properties with exclusive constraints are automatically indexed.

See Schema > Indexes.

Computed properties


1. type Movie {
2. required property title -> str;
3. property uppercase_title := str_upper(.title);
4. }

See Schema > Computeds.


1. type Movie {
2. required property title -> str;
3. link director -> Person;
4. }

6. type Person {
7. required property name -> str;
8. }

Use the required and multi keywords to specify the cardinality of the relation.


1. type Movie {
2. required property title -> str;

4. link cinematographer -> Person;             # zero or one
5. required link director -> Person;           # exactly one
6. multi link writers -> Person;               # zero or more
7. required multi link actors -> Person;       # one or more
8. }

10. type Person {
11. required property name -> str;
12. }

To define a one-to-one relation, use an exclusive constraint.


1. type Movie {
2. required property title -> str;
3. required link stats -> MovieStats {
4. constraint exclusive;
5. };
6. }

8. type MovieStats {
9. required property budget -> int64;
10. required property box_office -> int64;
11. }

See Schema > Links.

Links can be computed. The example below defines a backlink.


1. type Movie {
2. required property title -> str;
3. multi link actors -> Person;
4. }

6. type Person {
7. required property name -> str;
8. link acted_in := .<actors[is Movie];
9. }

See Schema > Computeds > Backlinks.

Schema mixins


1. abstract type Content {
2. required property title -> str;
3. }

5. type Movie extending Content {
6. required property release_year -> int64;
7. }

9. type TVShow extending Content {
10. required property num_seasons -> int64;
11. }

See Schema > Object types > Inheritance.


1. abstract type Content {
2. required property title -> str;
3. }

5. type Movie extending Content {
6. required property release_year -> int64;
7. }

9. type TVShow extending Content {
10. required property num_seasons -> int64;
11. }

13. type Franchise {
14. required property name -> str;
15. multi link entries -> Content;
16. }

See Schema > Links > Polymorphism.