Object Types

Object types are the primary components of EdgeDB schema. They are analogous to SQL tables or ORM models, and consist of properties and links.

Properties are used to attach primitive data to an object type. They are declared with the property keyword. For the full documentation on properties, see Properties.

  1. type Person {
  2. property email -> str;
  3. }

Links are used to define relationships between object types. They are declared with the link keyword. For the full documentation on links, see Links.

  1. type Person {
  2. link best_friend -> Person;
  3. }

IDs

There’s no need to manually declare a primary key on your object types. All object types automatically contain a property id of type UUID that’s required, globally unique, and readonly. This id is assigned upon creation and never changes.

Abstract types

Object types can either be abstract or non-abstract. By default all object types are non-abstract. You can’t create or store instances of abstract types, but they’re a useful way to share functionality and structure across among other object types.

  1. abstract type HasName {
  2. property first_name -> str;
  3. property last_name -> str;
  4. }

Abstract types are commonly used in tandem with inheritance.

Inheritance

Object types can extend other object types. The extending type (AKA the subtype) inherits all links, properties, indexes, constraints, etc. from its supertypes.

  1. abstract type Animal {
  2. property species -> str;
  3. }
  4. type Dog extending Animal {
  5. property breed -> str;
  6. }

Multiple Inheritance

Object types can extend more than one type — that’s called multiple inheritance. This mechanism allows building complex object types out of combinations of more basic types.

  1. abstract type HasName {
  2. property first_name -> str;
  3. property last_name -> str;
  4. }
  5. abstract type HasEmail {
  6. property email -> str;
  7. }
  8. type Person extending HasName, HasEmail {
  9. property profession -> str;
  10. }

If multiple supertypes share links or properties, those properties must be of the same type and cardinality.

Refer to the dedicated pages on Indexes, Constraints, Object-Level Security, and Annotations for documentation on these concepts.

See also

SDL > Object types

DDL > Object types

Introspection > Object types

Cheatsheets > Object types