You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## What is the goal of this PR?
As a part of my onboarding, I have prepared yet another example with
TypeDB. This one is in Python. Its purpose is to demonstrate how to use
Python client to TypeDB.
## What are the changes implemented in this PR?
Added a directory commerce/bookstore - with all files of the example.
The `README.md` file contains all necessary documentation for this
example.
---------
Co-authored-by: Alex Walker <alexjpwalker@gmail.com>
1. Checkout this repository: `git clone https://github.com/vaticle/typedb-examples && cd typedb-examples`
30
+
2. Start the [TypeDB Server](http://docs.vaticle.com/docs/running-typedb/install-and-run#start-the-typedb-server). Check that it's listening to address: `0.0.0.0:1729`.
31
+
3. Launch `typedb-examples/commerce/bookstore/python/load_data.py` Python script. It will load the bookstore schema and data into the DB.
32
+
4. Launch `typedb-examples/commerce/bookstore/python/requests.py` Python script and follow the instructions to explore example functions and data.
33
+
5. Use this simple example to learn the basics of using TypeDB! Explore source codes of the Python scripts and use TypeDB Studio to explore DB schema and content.
34
+
35
+
## How it works
36
+
37
+
### Files
38
+
39
+
This example is located in the `typedb-examples/commerce/bookstore/` directory and consists of the following main files:
40
+
- Python scripts
41
+
-`python/load_data.py` — used to load the bookstore DB schema and data
42
+
-`python/requests.py` — provides simple command line interface to execute requests on TypeDB database
43
+
-`python/loaders.py` — internal (imported) file with data loading classes and functions
44
+
-`python/config.py` — internal settings: database name and path to directory with imported csv files
45
+
-`schema.tql` — DB schema in TypeQL
46
+
-`README.md` — documentation for the bookstore example. You are reading it right now
47
+
-`tests.py` — a set of tests for the example
48
+
-`todo.md` — list of ideas for improvements in the future. If you want to contribute to this example, you can start with these ideas
49
+
- Bookstore dataset `data/`:
50
+
-`books.csv`
51
+
-`users.csv`
52
+
-`ratings.csv`
53
+
-`order.csv`
54
+
-`genres.csv`
55
+
-`request-examples/` — directory with examples of requests for the database. Files of `.tql` format can be used in Type DB Studio directly or to create a request for other TypeDB clients
56
+
-`requirements.txt` — list of major requirements for internal testing environment
57
+
58
+
### Schema
59
+
60
+
The schema stored in the `schema.tql` file and loaded by the `load_data.py` script.
61
+
62
+

63
+
64
+
#### Attributes
65
+
66
+
The bookstore schema has the following attributes:
67
+
68
+
- name (string)
69
+
- description (string)
70
+
- id (string)
71
+
- ISBN (string)
72
+
- book-author (string)
73
+
- publisher (string)
74
+
- foreign-user-id (string)
75
+
- status (string)
76
+
- delivery-address (string)
77
+
- payment-details (string)
78
+
- username (string)
79
+
- password (string)
80
+
- foreign-id (string)
81
+
- genre-tag (string)
82
+
83
+
- created-date (datetime)
84
+
85
+
- price (long)
86
+
- stock (long)
87
+
- rating (long)
88
+
- age (long)
89
+
90
+
#### Entities
91
+
92
+
The bookstore schema has the following entities:
93
+
94
+
- product
95
+
- book
96
+
- person
97
+
- user
98
+
99
+
#### Relations
100
+
101
+
The bookstore schema has the following relations:
102
+
103
+
- review
104
+
- order
105
+
- tag-hierarchy
106
+
107
+
#### Rules
108
+
109
+
The bookstore schema has two rules to demonstrate rules usability.
110
+
111
+
The first one works for genre tags, serves no real purpose but follows the following basic logic — a child (sub-tag) of my child is my child. The code for the first rule:
112
+
113
+
```
114
+
rule super-tag-hierarchy:
115
+
when {
116
+
(sup-tag: $p, sub-tag: $b) isa tag-hierarchy;
117
+
(sup-tag: $b, sub-tag: $bb) isa tag-hierarchy;
118
+
} then {
119
+
(sup-tag: $p, sub-tag: $bb) isa tag-hierarchy;
120
+
};
121
+
```
122
+
123
+
The second one works also for genre tags, used to improve tag searching experience. By assigning tag to a book you
124
+
are also assigning all sup-tags to the same book. So the book can be found not only by exact tag you have assigned
125
+
to it, but also by all the parent tags of this tag.
0 commit comments