Officially out now: The TypeDB 3.0 Roadmap >>

@values annotation

The @values annotation is used to specify a set of permitted values for attributes.

Syntax

Value annotation syntax
<type label> value <value type> @values(arg);
<type label> value <value type> @values(arg0, arg1, ..., argN);
Ownership annotation syntax
<type label> owns <attribute type label> @values(arg0);
<type label> owns <attribute type label> @values(arg0, arg1, ..., argN);

The @values annotation can be defined for either an attribute type’s value type or an ownership.

The @values annotation requires at least one argument. Multiple arguments can be specified, separated by commas. Arguments should be of the same value type as <attribute type label>. Please refer to Supported value types for the list of accepted value types.

Usage

The @values annotation adds a constraint on values of attributes of a given attribute type to be within the specified set of allowed values.

When defined for an attribute type’s value type, the annotation creates a constraint for any attribute of this attribute type.

define
  attribute gender value string @values("male", "female", "other");

When defined for an ownership, the annotation creates a constraint for any attribute of this attribute type owned by the owner type. In the following example, an instance of the emoji type can contain any value, but a reaction can have (has) only the emoji s with the suitable values.

define
  relation reaction owns emoji @values("like", "love", "funny", "surprise", "sad", "angry");
  attribute emoji value string;

Subtyping

The values constraint put on an attribute types' value type is inherited. This means that values of all subtypes of a constrained type are also constrained, and it cannot be changed.

A subtype can introduce an even stricter constraint to allow only a subset of the inherited set of allowed values.

Subtyping for ownerships

The values constraint put on an ownership should be respected by all the sub attribute types owned by this owner. This way, any instance of any subtype of the emoji owned by any instance of any subtype of the reaction should comply to the defined values.

Ownerships of these subtypes can have their own values constraints, and they will be respected similarly down the inheritance line.

Limitations

See Supported value types for the list of supported value types.

References

Supported value types

The @values annotation is applicable only to comparable value types, thus it is supported by all built-in TypeQL value types.

Table 1. Supported value types

Value type

Supported?

Comment

boolean

integer

double

decimal

string

date

datetime

datetime-tz

duration