This section describes the SDL declarations pertaining to object types.
Consider a User
type with a few properties:
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:
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:
If specified, the created type will be abstract.
The name (optionally module-qualified) of the new type.
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:
Set object type annotation to a given value.
Define a concrete property for this object type.
Define a concrete link for this object type.
Define a concrete constraint for this object type.
Define an index for this object type.