This section describes the DDL commands pertaining to links.
Define a new link.
[ WITH with-item [, ...] ]
{CREATE|ALTER} TYPE TypeName "{"
[ ... ]
CREATE [{REQUIRED | OPTIONAL}] [{SINGLE | MULTI}]
LINK name
[ EXTENDING base [, ...] ] -> type
[ "{" subcommand; [...] "}" ] ;
[ ... ]
"}"
Computable link form:
[ WITH with-item [, ...] ]
{CREATE|ALTER} TYPE TypeName "{"
[ ... ]
CREATE [{REQUIRED | OPTIONAL}] [{SINGLE | MULTI}]
LINK name := expression;
[ ... ]
"}"
Abstract link form:
[ WITH with-item [, ...] ]
CREATE ABSTRACT LINK [module::]name [EXTENDING base [, ...]]
[ "{" subcommand; [...] "}" ]
where subcommand is one of
SET default := expression
SET readonly := {true | false}
CREATE ANNOTATION annotation-name := value
CREATE PROPERTY property-name ...
CREATE CONSTRAINT constraint-name ...
ON TARGET DELETE action
CREATE INDEX ON index-expr
CREATE TYPE ... CREATE LINK
and ALTER TYPE ... CREATE LINK
define
a new concrete link for a given object type.
There are three forms of CREATE LINK
, 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 link, and the third is a
form to define an abstract link item. The abstract form allows creating
the link in the specified module. Concrete link forms
are always created in the same module as the containing object type.
Most sub-commands and options of this command are identical to the
SDL link declaration. The following
subcommands are allowed in the CREATE LINK
block:
Specifies the default value for the link as an EdgeQL expression. Other than a slight syntactical difference this is the same as the corresponding SDL declaration.
Specifies whether the link is considered read-only. Other than a slight syntactical difference this is the same as the corresponding SDL declaration.
Add an annotation annotation-name set to value to the type.
See CREATE ANNOTATION
for details.
Define a concrete property item for this link. See
CREATE PROPERTY
for details.
Define a concrete constraint for this link. See
CREATE CONSTRAINT
for details.
Valid values for action are: RESTRICT
, DELETE
SOURCE
, ALLOW
, and DEFERRED RESTRICT
. The details of
what ON TARGET DELETE
options mean are described in
this section.
Define a new index
using index-expr for this link. See
CREATE INDEX
for details.
Define a new link interests
on the User
object type:
ALTER TYPE User {
CREATE MULTI LINK friends -> User
};
Define a new link special_group
as a
computable on the User
object type, which contains all the friends from the same town:
ALTER TYPE User {
CREATE LINK special_group := (
SELECT __source__.friends
FILTER .town = __source__.town
)
};
Define a new abstract link orderable
, and then a concrete link
interests
that extends it, inheriting the weight
property:
CREATE ABSTRACT LINK orderable {
CREATE PROPERTY weight -> std::int64
};
ALTER TYPE User {
CREATE MULTI LINK interests EXTENDING orderable -> Interest
};
Change the definition of a link.
[ WITH with-item [, ...] ]
{CREATE|ALTER} TYPE TypeName "{"
[ ... ]
ALTER LINK name
[ "{" ] subcommand; [...] [ "}" ];
[ ... ]
"}"
[ WITH with-item [, ...] ]
ALTER ABSTRACT LINK [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 PROPERTY property-name ...
ALTER PROPERTY property-name ...
DROP PROPERTY property-name ...
CREATE CONSTRAINT constraint-name ...
ALTER CONSTRAINT constraint-name ...
DROP CONSTRAINT constraint-name ...
ON TARGET DELETE action
CREATE INDEX ON index-expr
DROP INDEX ON index-expr
CREATE TYPE ... ALTER LINK
and ALTER TYPE ... ALTER LINK
change
the definition of a concrete link for a given object type.
ALTER ABSTRACT LINK
changes the definition of an abstract link item.
name must be a name of an existing abstract link, optionally qualified
with a module name.
The following subcommands are allowed in the ALTER LINK
block:
Change the name of the link item to newname. All concrete links inheriting from this links are also renamed.
Alter the link parent list. The full syntax of this subcommand is:
EXTENDING name [, ...]
[ FIRST | LAST | BEFORE parent | AFTER parent ]
This subcommand makes the link a child of the specified list of parent links. The requirements for the parent-child relationship are the same as when creating a link.
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 link required.
Make the link no longer required (i.e. make it optional).
Reset the optionality of the link to the default value (OPTIONAL
),
or, if the link is inherited, to the value inherited from links in
supertypes.
Change the maximum cardinality of the link set to one. Only valid for concrete links.
Change the maximum cardinality of the link set to greater than one. Only valid for concrete links;
Reset the maximum cardinality of the link to the default value
(SINGLE
), or, if the link is inherited, to the value inherited
from links in supertypes.
Change the type of the link to the specified
typename. The optional USING
clause specifies
a conversion expression that computes the new link value from the old.
The conversion expression must return a singleton set and is evaluated
on each element of MULTI
links. A USING
clause must be provided
if there is no implicit or assignment cast from old to new type.
Reset the type of the link to the type inherited from links of the same
name in supertypes. It is an error to RESET TYPE
on a link that is
not inherited.
Change the expression of a computable link. Only valid for concrete links.
Alter link annotation annotation-name.
See ALTER ANNOTATION
for details.
Remove link item’s annotation annotation-name.
See DROP ANNOTATION
for details.
Alter the definition of a property item for this link. See
ALTER PROPERTY
for details.
Remove a property item from this link. See
DROP PROPERTY
for details.
Alter the definition of a constraint for this link. See
ALTER CONSTRAINT
for details.
Remove a constraint from this link. See
DROP CONSTRAINT
for details.
Remove an index defined on index-expr
from this link. See DROP INDEX
for details.
Remove the default value from this link, or reset it to the value inherited from a supertype, if the link is inherited.
Set link writability to the default value (writable), or, if the link is inherited, to the value inherited from links in supertypes.
All the subcommands allowed in the CREATE LINK
block are also
valid subcommands for ALTER LINK
block.
Set the title
annotation of link friends
of object type User
to
"Friends"
:
ALTER TYPE User {
ALTER LINK interests CREATE ANNOTATION title := "Interests";
};
Rename the abstract link orderable
to sorted
:
ALTER ABSTRACT LINK orderable RENAME TO sorted;
Redefine the computable link
special_group
to be those who have some shared interests:
ALTER TYPE User {
CREATE LINK special_group := (
SELECT __source__.friends
# at least one of the friend's interests
# must match the user's
FILTER .interests IN __source__.interests
)
};
Remove the specified link from the schema.
[ WITH with-item [, ...] ]
{CREATE|ALTER} TYPE TypeName "{"
[ ... ]
DROP LINK name
[ ... ]
"}"
[ WITH with-item [, ...] ]
DROP ABSTRACT LINK [module]::name
DROP ABSTRACT LINK
removes an existing link item from the database
schema. All subordinate schema items defined on this link, such
as link properties and constraints, are removed as well.
DROP LINK
removes the specified link from its
containing object type. All links that inherit from this link
are also removed.