Object types​

Define an abstract type:


1. abstract type HasImage {
2. # just a URL to the image
3. required property image -> str;
4. index on (.image);
5. }

Define a type extending from the abstract:


1. type User extending HasImage {
2. required property name -> str {
3. # Ensure unique name for each User.
4. constraint exclusive;
5. }
6. }

Define a type with constraints and defaults for properties:


1. type Review {
2. required property body -> str;
3. required property rating -> int64 {
4. constraint min_value(0);
5. constraint max_value(5);
6. }
7. required property flag -> bool {
8. default := False;
9. }

11. required link author -> User;
12. required link movie -> Movie;

14. required property creation_time -> datetime {
15. default := datetime_current();
16. }
17. }

Define a type with a property that is computed from the combination of the other properties:


1. type Person extending HasImage {
2. required property first_name -> str {
3. default := '';
4. }
5. required property middle_name -> str {
6. default := '';
7. }
8. required property last_name -> str;
9. property full_name :=
10. (
11. (
12. (.first_name ++ ' ')
13. if .first_name != '' else
14. ''
15. ) ++
16. (
17. (.middle_name ++ ' ')
18. if .middle_name != '' else
19. ''
20. ) ++
21. .last_name
22. );
23. property bio -> str;
24. }

Define an abstract links:


1. abstract link crew {
2. # Provide a way to specify some "natural"
3. # ordering, as relevant to the movie. This
4. # may be order of importance, appearance, etc.
5. property list_order -> int64;
6. }

8. abstract link directors extending crew;

10. abstract link actors extending crew;

Define a type using abstract links and a computed property that aggregates values from another linked type:


1. type Movie extending HasImage {
2. required property title -> str;
3. required property year -> int64;

5. # Add an index for accessing movies by title and year,
6. # separately and in combination.
7. index on (.title);
8. index on (.year);
9. index on ((.title, .year));

11. property description -> str;

13. multi link directors extending crew -> Person;
14. multi link actors extending crew -> Person;

16. property avg_rating := math::mean(.<movie[is Review].rating);
17. }

Define an auto-incrementing scalar type and an object type using it as a property:


1. scalar type TicketNo extending sequence;

3. type Ticket {
4. property number -> TicketNo {
5. constraint exclusive;
6. }
7. }

See also
Schema > Object types
SDL > Object types
DDL > Object types
Introspection > Object types