Skip to content

Commit 1674611

Browse files
Add TypeQL guides (#1006)
## Goal We add three new language guides in Guides : TypeQL and move what was previously Tutorials under Guides : Integrations. We also move the TypeQL vs SQL comparison page under Guides : TypeQL. ## Implementation
1 parent 0a15d00 commit 1674611

File tree

24 files changed

+1854
-56
lines changed

24 files changed

+1854
-56
lines changed

core-concepts/modules/ROOT/pages/typeql/index.adoc

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,4 @@ A deeper look at invalid patterns involving disjoint variable reuse
6767
****
6868
Short definitions of terms used throughout the guide, with links to the section which introduces them.
6969
****
70-
71-
.xref:{page-version}@core-concepts::typeql/sql-vs-typeql.adoc[]
72-
[.clickable]
73-
****
74-
A guide of relational constructs in SQL compared to similar concepts in TypeQL.
75-
****
7670
--

core-concepts/modules/ROOT/partials/nav.adoc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
** xref:{page-version}@core-concepts::typeql/invalid-patterns.adoc[]
2323
// ** xref:{page-version}@core-concepts::typeql/best-practices.adoc[]
2424
** xref:{page-version}@core-concepts::typeql/glossary.adoc[]
25-
** xref:{page-version}@core-concepts::typeql/sql-vs-typeql.adoc[]
2625
2726
2827
* xref:{page-version}@core-concepts::drivers/index.adoc[]
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
name: tutorials
2-
title: Tutorials
1+
name: guides
2+
title: Guides
33
version: '3.x'
44
nav:
55
- modules/ROOT/nav.adoc

guides/modules/ROOT/attachments/bookstore-data.tql

Lines changed: 545 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 300 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,300 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
#
19+
20+
define
21+
22+
entity book @abstract,
23+
owns isbn @card(0..2),
24+
owns isbn-13 @key,
25+
owns isbn-10 @unique,
26+
owns title,
27+
owns page-count,
28+
owns genre @card(0..),
29+
owns price,
30+
plays contribution:work,
31+
plays publishing:published,
32+
plays promotion-inclusion:item,
33+
plays order-line:item,
34+
plays rating:rated,
35+
plays recommendation:recommended;
36+
37+
entity hardback sub book,
38+
owns stock;
39+
40+
entity paperback sub book,
41+
owns stock;
42+
43+
entity ebook sub book;
44+
45+
entity contributor,
46+
owns name,
47+
plays contribution:contributor,
48+
plays authoring:author,
49+
plays editing:editor,
50+
plays illustrating:illustrator;
51+
52+
entity company @abstract,
53+
owns name;
54+
55+
entity publisher sub company,
56+
plays publishing:publisher;
57+
58+
entity courier sub company,
59+
plays delivery:deliverer;
60+
61+
entity publication,
62+
owns year,
63+
plays publishing:publication,
64+
plays locating:located;
65+
66+
entity user,
67+
owns id @key,
68+
owns name,
69+
owns birth-date,
70+
owns total-spending,
71+
owns loyalty-tier,
72+
plays action-execution:executor,
73+
plays locating:located,
74+
plays recommendation:recipient;
75+
76+
entity order,
77+
owns id @key,
78+
owns status,
79+
plays order-line:order,
80+
plays action-execution:action,
81+
plays delivery:delivered;
82+
83+
entity promotion,
84+
owns code @key,
85+
owns name,
86+
owns start-timestamp,
87+
owns end-timestamp,
88+
plays promotion-inclusion:promotion;
89+
90+
entity review,
91+
owns id @key,
92+
owns score,
93+
owns verified,
94+
plays rating:review,
95+
plays action-execution:action;
96+
97+
entity login,
98+
owns success,
99+
plays action-execution:action;
100+
101+
entity address,
102+
owns street,
103+
plays delivery:destination,
104+
plays locating:located;
105+
106+
entity place @abstract,
107+
owns name,
108+
plays locating:located,
109+
plays locating:location;
110+
111+
entity city sub place;
112+
113+
entity state sub place;
114+
115+
entity country sub place;
116+
117+
relation contribution,
118+
relates contributor,
119+
relates work;
120+
121+
relation authoring sub contribution,
122+
relates author as contributor;
123+
124+
relation editing sub contribution,
125+
relates editor as contributor;
126+
127+
relation illustrating sub contribution,
128+
relates illustrator as contributor;
129+
130+
relation publishing,
131+
relates publisher,
132+
relates published,
133+
relates publication;
134+
135+
relation promotion-inclusion,
136+
relates promotion,
137+
relates item,
138+
owns discount;
139+
140+
relation order-line,
141+
relates order,
142+
relates item,
143+
owns quantity;
144+
145+
relation rating,
146+
relates review,
147+
relates rated;
148+
149+
relation action-execution,
150+
relates action,
151+
relates executor,
152+
owns timestamp;
153+
154+
relation delivery,
155+
relates deliverer,
156+
relates delivered,
157+
relates destination;
158+
159+
relation locating,
160+
relates located,
161+
relates location;
162+
163+
relation recommendation,
164+
relates recommended,
165+
relates recipient;
166+
167+
attribute isbn @abstract, value string;
168+
attribute isbn-13 sub isbn;
169+
attribute isbn-10 sub isbn;
170+
attribute title, value string;
171+
attribute page-count, value integer;
172+
attribute genre, value string;
173+
attribute stock, value integer;
174+
attribute price, value double;
175+
attribute discount, value double;
176+
attribute id, value string;
177+
attribute code, value string;
178+
attribute name, value string;
179+
attribute birth-date, value datetime;
180+
attribute street, value string;
181+
attribute year, value integer;
182+
attribute quantity, value integer;
183+
attribute score, value integer;
184+
attribute verified, value boolean;
185+
attribute timestamp, value datetime;
186+
attribute start-timestamp, value datetime;
187+
attribute end-timestamp, value datetime;
188+
attribute status, value string @values("invalid", "pending", "paid", "dispatched", "delivered", "returned", "canceled");
189+
attribute success, value boolean;
190+
attribute total-spending, value double;
191+
attribute loyalty-tier, value integer @range(0..5);
192+
193+
# TODO: Change to check
194+
fun is_review_verified_by_purchase($review: review) -> { order }:
195+
match
196+
($review, $product) isa rating;
197+
($order, $product) isa order-line;
198+
($user, $review) isa action-execution, has timestamp $review-time;
199+
($user, $order) isa action-execution, has timestamp $order-time;
200+
$review-time > $order-time;
201+
return { $order };
202+
203+
fun book_recommendations_for($user: user) -> {book}:
204+
match
205+
$new-book isa book;
206+
{
207+
let $new-book in book_recommendations_by_author($user);
208+
} or {
209+
let $new-book in book_recommendations_by_genre($user);
210+
};
211+
return { $new-book };
212+
213+
fun book_recommendations_by_genre($user: user) -> { book }:
214+
match
215+
$user isa user;
216+
$liked-book isa book;
217+
{
218+
($user, $order-for-liked) isa action-execution;
219+
($order-for-liked, $liked-book) isa order-line;
220+
} or {
221+
($user, $review-for-liked) isa action-execution;
222+
($review-for-liked, $liked-book) isa rating;
223+
$review-for-liked has score >= 7;
224+
};
225+
$new-book isa book;
226+
not { {
227+
($user, $order-for-new) isa action-execution;
228+
($order-for-new, $new-book) isa order-line;
229+
} or {
230+
($user, $review-for-new) isa action-execution;
231+
($review-for-new, $new-book) isa rating;
232+
}; };
233+
$liked-book has genre $shared-genre;
234+
$new-book has genre $shared-genre;
235+
not { {
236+
$shared-genre == "fiction";
237+
} or {
238+
$shared-genre == "nonfiction";
239+
}; };
240+
return { $new-book };
241+
242+
fun book_recommendations_by_author($user: user) -> { book }:
243+
match
244+
$user isa user;
245+
$liked-book isa book;
246+
{
247+
($user, $order-for-liked) isa action-execution;
248+
($order-for-liked, $liked-book) isa order-line;
249+
} or {
250+
($user, $review-for-liked) isa action-execution;
251+
($review-for-liked, $liked-book) isa rating;
252+
$review-for-liked has score >= 7;
253+
};
254+
$new-book isa book;
255+
not { {
256+
($user, $order-for-new) isa action-execution;
257+
($order-for-new, $new-book) isa order-line;
258+
} or {
259+
($user, $review-for-new) isa action-execution;
260+
($review-for-new, $new-book) isa rating;
261+
}; };
262+
($liked-book, $shared-author) isa authoring;
263+
($new-book, $shared-author) isa authoring;
264+
return { $new-book };
265+
266+
fun order_line_best_price($line: order-line) -> { double }:
267+
match
268+
($order) isa action-execution, has timestamp $order-time;
269+
$line isa order-line, links ($order, $item);
270+
$item has price $retail-price;
271+
let $time_value = $order-time;
272+
let $best-discount = best_discount_for_item($item, $time_value);
273+
let $discounted-price = round(100 * $retail-price * (1 - $best-discount)) / 100;
274+
$line has quantity $quantity;
275+
let $line-total = $quantity * $discounted-price;
276+
return { $line-total };
277+
278+
fun best_discount_for_item($item: book, $order-time: datetime) -> double:
279+
match
280+
{
281+
$inclusion isa promotion-inclusion,
282+
links ($promotion, $item),
283+
has discount $discount-attr;
284+
$promotion has start-timestamp <= $order-time,
285+
has end-timestamp >= $order-time;
286+
let $discount = $discount-attr;
287+
} or {
288+
let $discount = 0.0; # default
289+
};
290+
return max($discount);
291+
292+
fun transitive_places($place: place) -> { place }:
293+
match
294+
{
295+
locating (located: $place, location: $parent);
296+
} or {
297+
locating (located: $place, location: $middle);
298+
let $parent in transitive_places($middle);
299+
};
300+
return { $parent };
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
// Tutorials
1+
// Guides
22

33
include::{page-version}@home::partial$nav-main.adoc[]
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
= Guides
2+
3+
In this section, you will find guides for accomplishing specific TypeDB tasks.
4+
5+
**New users** - We recommend new users begin with the xref:{page-version}@home::get-started/index.adoc[get started] guide
6+
in the home section.
7+
8+
[cols-2]
9+
--
10+
.xref:{page-version}@guides::integrations/index.adoc[]
11+
[.clickable]
12+
****
13+
Integrate TypeDB into your application or platform
14+
****
15+
16+
.xref:{page-version}@guides::typeql/index.adoc[]
17+
[.clickable]
18+
****
19+
Learn how to write TypeQL queries
20+
****
21+
--
22+
23+
Got other guides you'd like to see?
24+
Get in touch at link:mailto:[email protected]?subject=Request%20new%20guide[[email protected]]
25+
or link:https://typedb.com/discord[join our discord server].

tutorials/modules/ROOT/pages/deploy-through-api.adoc renamed to guides/modules/ROOT/pages/integrations/deploy-through-api.adoc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
= Deploy TypeDB via the Cloud API
2-
:keywords: typedb, typeql, tutorial, api, cloud, cluster, deploy
2+
:keywords: typedb, typeql, tutorial, guide, api, cloud, cluster, deploy
33
:pageTitle: Deploy TypeDB via the Cloud API
4-
:summary: A tutorial on deploying TypeDB through the API
4+
:summary: A guide on deploying TypeDB through the API
55
:page-toclevels: 2
66
:tabs-sync-option:
77

8-
This tutorial will walk you through the creation of a script
8+
This guide will walk you through the creation of a script
99
to automate deployment of a TypeDB cluster on TypeDB Cloud.
1010

1111
We're going to build a script that authenticates with the API,
@@ -653,7 +653,7 @@ If successful, TypeDB Cloud will deploy your cluster, and the script will poll i
653653

654654
== Conclusion
655655

656-
This tutorial has shown you how to set up a script to deploy TypeDB through the Cloud API.
656+
This guide has shown you how to set up a script to deploy TypeDB through the Cloud API.
657657

658658
Similar approaches can be used for other common actions,
659659
such as pausing or resuming your clusters when not in use.

0 commit comments

Comments
 (0)