Computables

Links and properties may be declared as computable.

The values of computable properties and links are not persisted in the database and are computed using the specified expression every time they are referenced in a query. The type of the property or link is determined from the expression. Other than that computables behave exactly like their non-computable counterparts.

Links and properties have a source and one or more targets. The source is always the object on which the link is defined. Targets are either the objects to which the link points or the property values. The computable expressions define one or more targets and can refer to the source as __source__.

Computables are useful in the situations where there is a frequent need for some value that is derived from the values of existing properties and links.

For example, here we define the User type to contain the fullname computable property that is derived from user’s first and last name:

type User {
    required property firstname -> str;
    required property lastname -> str;
    property fullname :=
        (__source__.firstname ++ ' ' ++
         __source__.lastname);
}

If the computable expression is simple (i.e. not a subquery), shortcut paths may also be used instead of explicit references to __source__:

type User {
    required property firstname -> str;
    required property lastname -> str;
    property fullname := (
        .firstname ++ ' ' ++ .lastname);
}

Computables are also often used in views. For example, using the User from the above example, a UserView can be defined with a lastname_first computable which lists the full name in the format which is often used in formal alphabetized lists:

view UserView := User {
    lastname_first := (
        .lastname ++ ', ' ++ .firstname)
}

Computables can be used in shapes, too:

SELECT User {
    lastname_first := (
        .lastname ++ ', ' ++ .firstname)
};

Computable link SDL, link DDL, property SDL, and property DDL.