1- = Read data using TypeDB
1+ = Common patterns of read queries
22:keywords: typedb, typeql, tutorial, console
33:pageTitle:
44:summary:
@@ -14,9 +14,9 @@ This tutorial covers the common patterns of read queries in TypeQL.
1414
1515This tutorial assumes you have access to a running TypeDB instance, as well as a TypeDB Console.
1616
17- See xref:{page-version}@home:install/index .adoc[the Install page] for setup instructions based on your needs .
17+ We recommend xref:{page-version}@home:: install/ce .adoc[installing TypeDB Community Edition] as it is distributed bundled with Console for easy setup .
1818
19- == Schema
19+ == Example schema and data
2020
2121IMPORTANT: TODO PERMALINKS TO `typedb/typedb-examples`
2222
@@ -28,7 +28,7 @@ You can load the example into your TypeDB instance using the following Console c
2828database create-init bookstore http://github.com/typedb/typedb-examples/releases/latest/download/bookstore-schema.tql http://github.com/typedb/typedb-examples/releases/latest/download/bookstore-data.tql
2929----
3030
31- .Schema and data for the following examples
31+ .Full schema and data queries
3232[%collapsible]
3333====
3434[,typeql]
@@ -50,7 +50,7 @@ statement:
5050
5151[,typeql]
5252----
53- #!test[read, count = 21, ]
53+ #!test[read, count = 21]
5454match $book isa book;
5555----
5656
@@ -70,12 +70,12 @@ Finished. Total answers: 21
7070----
7171
7272These are the values the variable `$book` takes that can be used further down in the pipeline.
73- This output isn't very useful for displaying a list of books to the user , however.
73+ This output isn't very useful for displaying a list of books to the customer , however.
7474Instead, most read queries end with a `fetch` clause that allows you to format the query result into a JSON-like document:
7575
7676[,typeql]
7777----
78- #!test[read, documents, count = 21]
78+ #!test[read, count = 21]
7979match
8080 $book isa book;
8181fetch {
@@ -103,7 +103,7 @@ This is the simplest `fetch` stage there is, and it simply retrieves all attribu
103103Finished. Total answers: 21
104104----
105105
106- == Additional patterns
106+ == Retrieve the author of each book using additional constraints
107107
108108Some data we'd like to display is still missing, however, such as the book's author.
109109Let's look back at the schema and find out how the author is associated to the book.
@@ -149,7 +149,7 @@ We'll adjust the query.
149149
150150[,typeql]
151151----
152- #!test[read, documents, count = 23]
152+ #!test[read, count = 23]
153153match
154154 $book isa book;
155155 authoring (author: $author, work: $book);
@@ -189,7 +189,7 @@ If we want to clean up the output to only fetch the attributes we want to displa
189189
190190[,typeql]
191191----
192- #!test[read, documents, count = 23]
192+ #!test[read, count = 23]
193193match
194194 $book isa book;
195195 authoring (author: $author, work: $book);
@@ -221,7 +221,7 @@ fetch {
221221Finished. Total answers: 23
222222----
223223
224- == Subqueries
224+ == Fetch list of authors using a subquery
225225
226226Have you noticed?
227227The last query we ran returned two more answers, 23 total, compared to the 21 answers to the query before.
@@ -235,7 +235,7 @@ We can do this by using a subquery in the `fetch`:
235235
236236[,typeql]
237237----
238- #!test[read, documents, count = 21]
238+ #!test[read, count = 21]
239239match
240240 $book isa book;
241241fetch {
@@ -282,7 +282,7 @@ You can read more about using functions in xref:{page-version}@core-concepts::ty
282282Finished. Total answers: 21
283283----
284284
285- == Optionals
285+ == Fetch discounted price with optionals
286286
287287Sometimes the data we want to display is optional, and we'd like to display it if it exists, but not require it to match for the query to succeed.
288288
@@ -291,7 +291,7 @@ If we try to add a pattern to the query that matches a `promotion-inclusion` rel
291291
292292[,typeql]
293293----
294- #!test[read, documents, count = 5]
294+ #!test[read, count = 5]
295295match
296296 $book isa book, has price $book-price;
297297 promotion-inclusion (item: $book), has discount $discount;
@@ -324,7 +324,7 @@ We can do this by using a `try` pattern:
324324
325325[,typeql]
326326----
327- #!test[read, documents, count = 21]
327+ #!test[read, count = 21]
328328match
329329 $book isa book, has price $book-price;
330330 try {
@@ -362,7 +362,7 @@ The previous query could be equivalently written as:
362362
363363[,typeql]
364364----
365- #!test[read, documents, count = 21]
365+ #!test[read, count = 21]
366366match
367367 $book isa book, has price $book-price;
368368fetch {
@@ -380,6 +380,23 @@ fetch {
380380
381381== Further reading
382382
383- * xref:{page-version}@tutorials::pipelines-crud.adoc[Learn how to modify data in the next tutorial]
384- * xref:{page-version}@core-concepts::typeql/index.adoc[TypeQL core concepts]
385- * xref:{page-version}@typeql-reference::index.adoc[TypeQL reference manual]
383+ [cols-2]
384+ --
385+ .xref:{page-version}@tutorials::pipelines-crud.adoc[]
386+ [.clickable]
387+ ****
388+ Learn how to modify data in the next tutorial
389+ ****
390+
391+ .xref:{page-version}@core-concepts::typeql/index.adoc[]
392+ [.clickable]
393+ ****
394+ TypeQL core concepts
395+ ****
396+
397+ .xref:{page-version}@typeql-reference::index.adoc[]
398+ [.clickable]
399+ ****
400+ TypeQL reference manual
401+ ****
402+ --
0 commit comments