This section describes the SDL declarations pertaining to object types.

Consider a User type with a few properties:

Copy
type User {
    # define some properties and a link
    required property name -> str;
    property address -> str;

    multi link friends -> User;

    # define an index for User based on name
    index on (__subject__.name);
}

An alternative way to define the same User type could be by using abstract types. These abstract types can then be re-used in other type definitions as well:

Copy
abstract type Named {
    required property name -> str;
}

abstract type HasAddress {
    property address -> str;
}

type User extending Named, HasAddress {
    # define some user-specific properties and a link
    multi link friends -> User;

    # define an index for User based on name
    index on (__subject__.name);
}

Introducing abstract types opens up the possibility of polymorphic queries.

Define a new object type corresponding to the more explicit DDL commands.

[abstract] type TypeName [extending supertype [, ...] ]
[ "{"
    [ annotation-declarations ]
    [ property-declarations ]
    [ link-declarations ]
    [ constraint-declarations ]
    [ index-declarations ]
    ...
  "}" ]

This declaration defines a new object type with the following options:

abstract

If specified, the created type will be abstract.

TypeName

The name (optionally module-qualified) of the new type.

extending supertype [, ...]

Optional clause specifying the supertypes of the new type.

Use of extending creates a persistent type relationship between the new subtype and its supertype(s). Schema modifications to the supertype(s) propagate to the subtype.

References to supertypes in queries will also include objects of the subtype.

If the same link name exists in more than one supertype, or is explicitly defined in the subtype and at least one supertype, then the data types of the link targets must be compatible. If there is no conflict, the links are merged to form a single link in the new type.

These sub-declarations are allowed in the Type block:

annotation-declarations

Set object type annotation to a given value.

property-declarations

Define a concrete property for this object type.

link-declarations

Define a concrete link for this object type.

constraint-declarations

Define a concrete constraint for this object type.

index-declarations

Define an index for this object type.

Light
Dark
System