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;
  4. index on (.title); # simple index
  5. index on ((.title, .release_year)); # composite index
  6. index on (str_trim(str_lower(.title))); # computed index
  7. }

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. }
  5. type Person {
  6. required property name -> str;
  7. }

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

  1. type Movie {
  2. required property title -> str;
  3. link cinematographer -> Person; # zero or one
  4. required link director -> Person; # exactly one
  5. multi link writers -> Person; # zero or more
  6. required multi link actors -> Person; # one or more
  7. }
  8. type Person {
  9. required property name -> str;
  10. }

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. }
  7. type MovieStats {
  8. required property budget -> int64;
  9. required property box_office -> int64;
  10. }

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

See Schema > Computeds > Backlinks.

Schema mixins

  1. abstract type Content {
  2. required property title -> str;
  3. }
  4. type Movie extending Content {
  5. required property release_year -> int64;
  6. }
  7. type TVShow extending Content {
  8. required property num_seasons -> int64;
  9. }

See Schema > Object types > Inheritance.

  1. abstract type Content {
  2. required property title -> str;
  3. }
  4. type Movie extending Content {
  5. required property release_year -> int64;
  6. }
  7. type TVShow extending Content {
  8. required property num_seasons -> int64;
  9. }
  10. type Franchise {
  11. required property name -> str;
  12. multi link entries -> Content;
  13. }

See Schema > Links > Polymorphism.