Search
ctrl/
Ask AI
Light
Dark
System

Properties

This section describes the DDL commands pertaining to properties.

Define a new property.

[ with with-item [, ...] ]
{create|alter} {type|link} SourceName "{"
  [ ... ]
  create [{required | optional}] [{single | multi}]
    property name
    [ extending base [, ...] ] -> type
    [ "{" subcommand; [...] "}" ] ;
  [ ... ]
"}"

Computed property form:

[ with with-item [, ...] ]
{create|alter} {type|link} SourceName "{"
  [ ... ]
  create [{required | optional}] [{single | multi}]
    property name := expression;
  [ ... ]
"}"

Abstract property form:

[ with with-item [, ...] ]
create abstract property [module::]name [extending base [, ...]]
[ "{" subcommand; [...] "}" ]

where subcommand is one of

  set default := expression
  set readonly := {true | false}
  create annotation annotation-name := value
  create constraint constraint-name ...

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.

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.

Define a new link address on the User object type:

Copy
alter type User {
    create property address -> str
};

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

Copy
alter type User {
    create property number_of_connections :=
        count(.interests)
};

Define a new abstract link orderable with weight property:

Copy
create abstract link orderable {
    create property weight -> std::int64
};

Change the definition of a property.

[ with with-item [, ...] ]
{create | alter} {type | link} source "{"
  [ ... ]
  alter property name
  [ "{" ] subcommand; [...] [ "}" ];
  [ ... ]
"}"


[ with with-item [, ...] ]
alter abstract property [module::]name
[ "{" ] subcommand; [...] [ "}" ];

where subcommand is one of

  set default := expression
  reset default
  set readonly := {true | false}
  reset readonly
  rename to newname
  extending ...
  set required [using (<conversion-expr)]
  set optional
  reset optionality
  set single [using (<conversion-expr)]
  set multi
  reset cardinality [using (<conversion-expr)]
  set type typename [using (<conversion-expr)]
  reset type
  using (computed-expr)
  create annotation annotation-name := value
  alter annotation annotation-name := value
  drop annotation annotation-name
  create constraint constraint-name ...
  alter constraint constraint-name ...
  drop constraint constraint-name ...

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.

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:

extending name [, ...]
   [ 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 [using (<conversion-expr)]

Make the property required.

set optional

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

reset optionality

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 [using (<conversion-expr)]

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 [using (<conversion-expr)]

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.

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

Copy
alter type User {
    alter property address
        create annotation title := "Home address";
};

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

Copy
alter type User {
    alter property address {
        create constraint max_len_value(500);
    };
};

Rename the property weight of link orderable to sort_by:

Copy
alter abstract link orderable {
    alter property weight rename to sort_by;
};

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

Copy
alter type User {
    alter property number_of_connections using (
        count(.friends)
    )
};

Remove a property from the schema.

[ with with-item [, ...] ]
{create|alter} type TypeName "{"
  [ ... ]
  drop link name
  [ ... ]
"}"


[ with with-item [, ...] ]
drop abstract property name ;

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.

Remove property address from type User:

Copy
alter type User {
    drop property address;
};