Properties

This section describes the DDL commands pertaining to properties.

Create property

Define a new property.

  1. [ with with-item [, ...] ]
  2. {create|alter} {type|link} SourceName "{"
  3. [ ... ]
  4. create [{required | optional}] [{single | multi}]
  5. property name
  6. [ extending base [, ...] ] -> type
  7. [ "{" subcommand; [...] "}" ] ;
  8. [ ... ]
  9. "}"
  10. Computed property form:
  11. [ with with-item [, ...] ]
  12. {create|alter} {type|link} SourceName "{"
  13. [ ... ]
  14. create [{required | optional}] [{single | multi}]
  15. property name := expression;
  16. [ ... ]
  17. "}"
  18. Abstract property form:
  19. [ with with-item [, ...] ]
  20. create abstract property [module::]name [extending base [, ...]]
  21. [ "{" subcommand; [...] "}" ]
  22. where subcommand is one of
  23. set default := expression
  24. set readonly := {true | false}
  25. create annotation annotation-name := value
  26. create constraint constraint-name ...

Description

The combination {create|alter} {type|link} … create property defines a new concrete property for a given object type or link.

There are three forms of create property, as shown in the syntax synopsis above. The first form is the canonical definition form, the second form is a syntax shorthand for defining a computed property, and the third is a form to define an abstract property item. The abstract form allows creating the property in the specified module. Concrete property forms are always created in the same module as the containing object or property.

Parameters

Most sub-commands and options of this command are identical to the SDL property declaration. The following subcommands are allowed in the create property block:

set default := expression

Specifies the default value for the property as an EdgeQL expression. Other than a slight syntactical difference this is the same as the corresponding SDL declaration.

set readonly := {true | false}

Specifies whether the property is considered read-only. Other than a slight syntactical difference this is the same as the corresponding SDL declaration.

create annotation annotation-name := value

Set property annotation-name to value.

See create annotation for details.

create constraint

Define a concrete constraint on the property. See create constraint for details.

Examples

Define a new link address on the User object type:

  1. alter type User {
  2. create property address -> str
  3. };

Define a new computed property number_of_connections on the User object type counting the number of interests:

  1. alter type User {
  2. create property number_of_connections :=
  3. count(.interests)
  4. };

Define a new abstract link orderable with weight property:

  1. create abstract link orderable {
  2. create property weight -> std::int64
  3. };

Alter property

Change the definition of a property.

  1. [ with with-item [, ...] ]
  2. {create | alter} {type | link} source "{"
  3. [ ... ]
  4. alter property name
  5. [ "{" ] subcommand; [...] [ "}" ];
  6. [ ... ]
  7. "}"
  8. [ with with-item [, ...] ]
  9. alter abstract property [module::]name
  10. [ "{" ] subcommand; [...] [ "}" ];
  11. where subcommand is one of
  12. set default := expression
  13. reset default
  14. set readonly := {true | false}
  15. reset readonly
  16. rename to newname
  17. extending ...
  18. set required
  19. set optional
  20. reset optionalily
  21. set single
  22. set multi
  23. reset cardinality
  24. set type typename [using (<conversion-expr)]
  25. reset type
  26. using (computed-expr)
  27. create annotation annotation-name := value
  28. alter annotation annotation-name := value
  29. drop annotation annotation-name
  30. create constraint constraint-name ...
  31. alter constraint constraint-name ...
  32. drop constraint constraint-name ...

Description

The combination {create|alter} {type|link} … create property defines a new concrete property for a given object type or link.

The command alter abstract property changes the definition of an abstract property item.

Parameters

source

The name of an object type or link on which the property is defined. May be optionally qualified with module.

name

The unqualified name of the property to modify.

module

Optional name of the module to create or alter the abstract property in. If not specified, the current module is used.

The following subcommands are allowed in the alter link block:

rename to newname

Change the name of the property to newname. All concrete properties inheriting from this property are also renamed.

extending …

Alter the property parent list. The full syntax of this subcommand is:

  1. extending name [, ...]
  2. [ first | last | before parent | after parent ]

This subcommand makes the property a child of the specified list of parent property items. The requirements for the parent-child relationship are the same as when creating a property.

It is possible to specify the position in the parent list using the following optional keywords:

  • first – insert parent(s) at the beginning of the parent list,

  • last – insert parent(s) at the end of the parent list,

  • before <parent> – insert parent(s) before an existing parent,

  • after <parent> – insert parent(s) after an existing parent.

set required

Make the property required.

set optional

Make the property no longer required (i.e. make it optional).

reset optionalily

Reset the optionality of the property to the default value (optional), or, if the property is inherited, to the value inherited from properties in supertypes.

set single

Change the maximum cardinality of the property set to one. Only valid for concrete properties.

set multi

Change the maximum cardinality of the property set to greater than one. Only valid for concrete properties.

reset cardinality

Reset the maximum cardinality of the property to the default value (single), or, if the property is inherited, to the value inherited from properties in supertypes.

set type typename [using (<conversion-expr)]

Change the type of the property to the specified typename. The optional using clause specifies a conversion expression that computes the new property value from the old. The conversion expression must return a singleton set and is evaluated on each element of multi properties. A using clause must be provided if there is no implicit or assignment cast from old to new type.

reset type

Reset the type of the property to the type inherited from properties of the same name in supertypes. It is an error to reset type on a property that is not inherited.

using (computed-expr)

Change the expression of a computed property. Only valid for concrete properties.

alter annotation annotation-name;

Alter property annotation annotation-name. See alter annotation for details.

drop annotation annotation-name;

Remove property annotation annotation-name. See drop annotation for details.

alter constraint constraint-name …

Alter the definition of a constraint for this property. See alter constraint for details.

drop constraint constraint-name;

Remove a constraint from this property. See drop constraint for details.

reset default

Remove the default value from this property, or reset it to the value inherited from a supertype, if the property is inherited.

reset readonly

Set property writability to the default value (writable), or, if the property is inherited, to the value inherited from properties in supertypes.

All the subcommands allowed in the create property block are also valid subcommands for alter property block.

Examples

Set the title annotation of property address of object type User to "Home address":

  1. alter type User {
  2. alter property address
  3. create annotation title := "Home address";
  4. };

Add a maximum-length constraint to property address of object type User:

  1. alter type User {
  2. alter property address {
  3. create constraint max_len_value(500);
  4. };
  5. };

Rename the property weight of link orderable to sort_by:

  1. alter abstract link orderable {
  2. alter property weight rename to sort_by;
  3. };

Redefine the computed property number_of_connections to be the number of friends:

  1. alter type User {
  2. alter property number_of_connections using (
  3. count(.friends)
  4. )
  5. };

Drop property

Remove a property from the schema.

  1. [ with with-item [, ...] ]
  2. {create|alter} type TypeName "{"
  3. [ ... ]
  4. drop link name
  5. [ ... ]
  6. "}"
  7. [ with with-item [, ...] ]
  8. drop abstract property name ;

Description

The combination alter {type|link} drop property removes the specified property from its containing object type or link. All properties that inherit from this property are also removed.

The command drop abstract property removes the specified abstract property item from the schema.

Example

Remove property address from type User:

  1. alter type User {
  2. drop property address;
  3. };

See also

Schema > Properties

SDL > Properties

Introspection > Object types