Skip to content

Commit 0851a1c

Browse files
Adding create-a-schema HOWTO
1 parent 92b260c commit 0851a1c

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

docs/howto/Create_A_Schema.md

+24-6
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,19 @@ client = WOQLClient(server_url)
2121
client.connect(user=user,account=account,key=key,db=dbid)
2222
```
2323

24+
If you haven't already created the database, you can do so with the
25+
following query:
26+
27+
```python
28+
client.create_database(dbid, label=label, description=description)
29+
```
30+
2431
Once we have a client object, we can proceed with adding a schema to
2532
the database.
2633

2734
```python
28-
address = WQ().doctype("Address")
35+
address = WQ().woql_and(
36+
WQ().doctype("Address")
2937
.label("An address record")
3038
.description("Record holding address information")
3139
.property("street", "xsd:string")
@@ -36,21 +44,31 @@ address = WQ().doctype("Address")
3644
.cardinality(1)
3745
.property("post_code", "xsd:string")
3846
.label("post code")
39-
.max_cardinality(1)
47+
.max(1)
4048

41-
client.query(person).execute(client, "Adding Address documents to the database")
49+
client.query(address, "Adding Address documents to the database")
4250
```
4351

4452
We now have a schema description of what constitutes an address,
4553
replete with documentation of the elements, and information about the
4654
cardinalities of edges in the database.
4755

48-
We can now use this document type to connect it to other elements in
56+
The `label` groups with the current schema object we are creating and
57+
gives it a human readable name. We can also use `description` to give
58+
a lengthier destription to any of the created schema objects.
59+
60+
When we use `property` we group it with the current class. This
61+
current class is its domain. It comes together with its range as the
62+
second argument after the name. If we have more complex properties
63+
with overlapping ranges it is necessary to create them seperately.
64+
65+
We can use this document type to connect it to other elements in
4966
the graph. For instance, we can create a new person document type as
5067
follows:
5168

5269
```python
53-
person = WQ().doctype("Person")
70+
person = WQ().woql_and(
71+
WQ().doctype("Person")
5472
.label("A digital human twin")
5573
.description("Record holding information on an individual")
5674
.property("forename", "xsd:string")
@@ -60,7 +78,7 @@ person = WQ().doctype("Person")
6078
.label("surname")
6179
.cardinality(1)
6280
.property("address", "Address")
63-
.label("The address(es) associated with an individual")
81+
.label("The address(es) associated with an individual"))
6482

6583
client.query(person, "Adding Person record")
6684
```

0 commit comments

Comments
 (0)