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; [...] "}" ] ;
[ ... ]
"}"
Computable 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 ...
{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
computable 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:
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.
Specifies whether the property is considered read-only. Other than a slight syntactical difference this is the same as the corresponding SDL declaration.
Set property annotation-name to value.
See CREATE ANNOTATION
for details.
Define a concrete constraint on the property.
See CREATE CONSTRAINT
for details.
Define a new link address
on the User
object type:
ALTER TYPE User {
CREATE PROPERTY address -> str
};
Define a new property number_of_connections
as a
computable on the User
object type counting the number of interests:
ALTER TYPE User {
CREATE PROPERTY number_of_connections :=
count(.interests)
};
Define a new abstract link orderable
with weight
property:
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
SET OPTIONAL
RESET OPTIONALITY
SET SINGLE
SET MULTI
RESET CARDINALITY
SET TYPE typename [USING (<conversion-expr)]
RESET TYPE
USING (computable-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 ...
{CREATE|ALTER} {TYPE|LINK} ... CREATE PROPERTY defines a new concrete property for a given object type or link.
ALTER ABSTRACT PROPERTY changes the definition of an abstract property item.
The name of an object type or link on which the property is defined. May be optionally qualified with module.
The unqualified name of the property to modify.
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:
Change the name of the property to newname. All concrete properties inheriting from this property are also renamed.
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.
Make the property required.
Make the property no longer required (i.e. make it optional).
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.
Change the maximum cardinality of the property set to one. Only valid for concrete properties.
Change the maximum cardinality of the property set to greater than one. Only valid for concrete properties;
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.
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 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.
Change the expression of a computable property. Only valid for concrete properties.
Alter property annotation annotation-name.
See ALTER ANNOTATION
for details.
Remove property annotation-name.
See DROP ANNOTATION
for details.
Alter the definition of a constraint for this property. See
ALTER CONSTRAINT
for details.
Remove a constraint from this property. See
DROP CONSTRAINT
for details.
Remove the default value from this property, or reset it to the value inherited from a supertype, if the property is inherited.
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"
:
ALTER TYPE User {
ALTER PROPERTY address
CREATE ANNOTATION title := "Home address";
};
Add a maximum-length constraint to property address
of object type
User
:
ALTER TYPE User {
ALTER PROPERTY address {
CREATE CONSTRAINT max_len_value(500);
};
};
Rename the property weight
of link orderable
to sort_by
:
ALTER ABSTRACT LINK orderable {
ALTER PROPERTY weight RENAME TO sort_by;
};
Redefine the computable property
number_of_connections
to be the number of friends:
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 ;