Skip to content

Commit b34fc69

Browse files
Test TypeDB core concepts (#988)
## Goal Test TypeDB core concepts
1 parent 5e71234 commit b34fc69

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

core-concepts/modules/ROOT/pages/typedb/crud.adoc

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
= CRUD
22
:page-aliases: {page-version}@manual::CRUD.adoc, {page-version}@manual::CRUD/inserting.adoc, {page-version}@manual::CRUD/reading.adoc
3+
:test-typeql: linear
34

45
CRUD operations create, read, update, and delete data in the TypeDB database.
56

@@ -16,14 +17,25 @@ For these examples, consider the following schema:
1617
[,typeql]
1718
.Sample schema
1819
----
20+
#!test[schema]
1921
define
2022
entity person,
2123
owns name @card(1),
22-
plays friendship:friend;
23-
relation friendship,
24-
relates friend;
24+
plays friendship:friend,
25+
plays parentship:parent,
26+
plays parentship:child;
2527
attribute name,
2628
value string;
29+
relation friendship,
30+
relates friend @card(2);
31+
relation parentship,
32+
relates parent,
33+
relates child;
34+
35+
entity user sub person,
36+
owns username @key;
37+
attribute username,
38+
value string;
2739
----
2840

2941
If `insert` is the first stage in a pipeline, it runs just once and outputs a single row containing the newly created instances.
@@ -33,6 +45,7 @@ An example command to insert two people and a friendship between them would be:
3345
[,typeql]
3446
.Alice 🤝 Bob
3547
----
48+
#!test[write]
3649
insert
3750
$a-name isa name "Alice";
3851
$b-name isa name "Bob";
@@ -61,6 +74,7 @@ In this example, Alice and Bob are already in the database, and we want to creat
6174
[,typeql]
6275
.Alice 🤝 Bob, v2
6376
----
77+
#!test[write]
6478
match
6579
$a isa person, has name "Alice";
6680
$b isa person, has name "Bob";
@@ -76,6 +90,7 @@ The `put` stage represents an "insert if does not exist" operation and provides
7690

7791
[,typeql]
7892
----
93+
#!test[write]
7994
put
8095
$a isa person, has name "Alice";
8196
$b isa person, has name "Bob";
@@ -118,10 +133,11 @@ For further explanation, see the drivers xref:{page-version}@core-concepts::driv
118133
A concern when loading large amounts of data is duplication. In most cases, it can be avoided by using the `put` stage:
119134

120135
[,typeql]
121-
.Insert a new user if there isn't already a user named `"john1"`
136+
.Insert a new user if there isn't already a user with username `"john1"`
122137
----
138+
#!test[write, count = 1]
123139
put
124-
$x isa user, has username "john_1";
140+
$x isa user, has username "john_1", has name "John";
125141
----
126142

127143
An issue may arise during parallel loading, however, where concurrent workers ensure the same user exists, inadvertently creating two
@@ -160,6 +176,7 @@ This allows structuring the output of the query to map precisely to the structur
160176

161177
[,typeql]
162178
----
179+
#!test[read, documents]
163180
match
164181
$p isa person;
165182
fetch {
@@ -206,6 +223,7 @@ Similar to ``put``, an `update` stage represents a "set if does not exist" opera
206223
[,typeql]
207224
.Simple attribute update
208225
----
226+
#!test[write]
209227
match
210228
$a isa person, has name "Alice";
211229
update
@@ -217,6 +235,7 @@ This is the expected way to "change" the value of an attribute that is owned. At
217235
[,typeql]
218236
.Fixing a data entry error by switching roleplayers
219237
----
238+
#!test[write]
220239
match
221240
$parentship isa parentship, links (parent: $p, child: $c);
222241
update
@@ -226,6 +245,7 @@ update
226245
[,typeql]
227246
.Multiple unrelated statements can be updated at a time
228247
----
248+
#!test[write]
229249
match
230250
$a isa person, has username "white-rabbit";
231251
$b isa person, has username "mad-hatter";
@@ -243,6 +263,7 @@ The same roleplayer switch from the previous section can be expressed as follows
243263
[,typeql]
244264
.Fixing a data entry error by switching roleplayers, v2
245265
----
266+
#!test[write]
246267
match
247268
$parentship isa parentship, links (parent: $p, child: $c);
248269
delete
@@ -257,6 +278,7 @@ Similarly, the common operation of replacing an owned attribute can be done like
257278

258279
[,typeql]
259280
----
281+
#!test[write]
260282
match
261283
$a isa person, has name $name;
262284
$name == "Alice";
@@ -276,6 +298,7 @@ The most straightforward deletion is to remove an entire instance (an entity, re
276298

277299
[,typeql]
278300
----
301+
#!test[write]
279302
match
280303
$a isa person, has name "Alice";
281304
delete
@@ -298,8 +321,10 @@ Connections between instances, that is ownerships and roleplayers, can be delete
298321

299322
[,typeql]
300323
----
324+
#!test[write]
301325
match
302-
$a isa person, has name $name == "Alice";
326+
$a isa person, has name $name;
327+
$name == "Alice";
303328
$f isa friendship, links (friend: $a);
304329
delete
305330
has $name of $a;

core-concepts/modules/ROOT/pages/typedb/databases.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
= Databases
22
:page-aliases: {page-version}@manual::databases.adoc, {page-version}@manual::databases/creating.adoc
3+
:test-typeql: linear
34

45
This section covers the management of databases and the definition of the schema, which provides the structural foundation for your data.
56

@@ -50,6 +51,7 @@ Here is an example of a simple schema definition:
5051

5152
[,typeql]
5253
----
54+
#!test[schema]
5355
define
5456
entity person,
5557
owns name,

0 commit comments

Comments
 (0)