Lesson 4: Writing data
Inserting simple data
-
Insert queries are used to insert data. They comprise either an
insert
clause only, or amatch
clause and aninsert
clause. Insert queries are run using a data session and write transaction.insert # insert clause
match # match clause insert # insert clause
-
All attributes are multivalued, allowing an entity or relation to own any number of attributes of the same type, as long as they each have different values.
-
An Insert query without a
match
clause inserts data once. An Insert query with amatch
clause inserts data multiple times, once for each match found.
Inserting polymorphic data
-
A polymorphic insert can be performed by using a polymorphic pattern in the
match
clause of an Insert query. -
When inserting a relation, the roles can be omitted if they can be inferred unambiguously.
Deleting data
-
Delete queries are used to delete data. They comprise a
match
clause and adelete
clause. Delete queries are run using a data session and write transaction.match # match clause delete # delete clause
-
Delete queries delete data per statement.
-
A
has
statement is used to delete an entity or relation’s attribute.$entity has $deleted-attribute;
-
An
isa
statement is used to delete an entity or relation.$deleted-entity isa entity-type;
-
When deleting a roleplayer in a relation, the relation must also be deleted manually if required. A relation is only deleted automatically if all of its roleplayers are deleted.
Updating data
-
Update queries are used to update data. They comprise a
match
clause, adelete
clause, and aninsert
clause. Update queries are run using a data session and write transaction.match # match clause delete # delete clause insert # insert clause
Data validation
-
All inserted data is validated against the schema.
-
Inserting data that does not conform to the schema will cause an exception to be thrown.
-
An exception will also be thrown if deleting or updating data leads to an invalid state.