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; [...] "}" ] ;
[ ... ]
"}"
Computed 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
reset on target delete
create index on index-expr
The combinations of 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
computed 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.
Reset the delete policy to either the inherited value or to the
default 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 friends
on the User
object type:
alter type User {
create multi link friends -> User
};
Define a new computed link
special_group
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 a concrete link
interests
that extends it, inheriting its 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 (computed-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
The combinations of``create type … alter link`` and alter type ...
alter link
change the definition of a concrete link for a given
object type.
The command alter abstract link
changes the definition of an
abstract link item. name must be the identity 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 link set’s maximum cardinality to one. Only valid for concrete links.
Remove the upper limit on the link set’s cardinality. Only valid for concrete links.
Reset the link set’s maximum cardinality to the default value
(single
), or to the value inherited from the link’s 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 be strictly the inherited type. This only
has an effect on links that have been overloaded in order to change their inherited
type. It is an error to reset type
on a link that is not inherited.
Change the expression of a computed 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.
On the object type User
, set the title
annotation of its
friends
link to "Friends"
:
alter type User {
alter link friends create annotation title := "Friends";
};
Rename the abstract link orderable
to sorted
:
alter abstract link orderable rename to sorted;
Redefine the computed 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 [, ...] ]
alter type TypeName "{"
[ ... ]
drop link name
[ ... ]
"}"
[ with with-item [, ...] ]
drop abstract link [module]::name
The combination of alter type
and drop link
removes the
specified link from its containing object type. All links that
inherit from this link are also removed.
The command 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.
Remove link friends
from object type User
:
alter type User drop link friends;
Drop abstract link orderable
:
drop abstract link orderable;