Delete stage
A delete stage deletes data from the database. Deletable data includes instances of types, ownerships of attributes, and role players of relations.
Syntax
The body of a delete stage is a sequence of delete statements.
delete
( <variable> | has <variable> of <variable> | links ( <variable> [ , ... ] ) of <variable> );
[ ... ]
Behavior
-
Bare variables delete the instances they refer to from the database.
-
Delete has statements delete ownerships of attributes.
-
Delete links statements delete role players from relations.
Execution
The delete stage must be preceded by other stages. The body of the delete stage is executed once for each input row. The output is then a stream of input rows with the deleted concepts removed.
Example
Schema for the following examples
#!test[schema, commit]
define
entity content owns id;
entity page sub content,
owns page-id,
owns name;
entity profile sub page,
owns username;
entity user sub profile,
owns phone,
owns karma;
attribute id value string;
attribute page-id sub id;
attribute username sub page-id;
attribute name value string;
attribute phone value string;
attribute karma value double;
attribute group-id sub id;
attribute rank, value string @values("admin", "member");
attribute tag value string;
relation group-membership, relates group, relates member, owns rank;
entity group, owns name, owns group-id, owns tag, plays group-membership:group;
user, plays group-membership:member;
#!test[write]
match
$user isa user, has name "<name>";
$group isa group, has group-id "<group id>";
$membership isa group-membership(group: $group, member: $user), has rank $rank;
$rank == "member";
delete
has $rank of $membership;
links ($user) of $membership;
$group;