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
Copy file name to clipboardExpand all lines: src/app/docs/schema-reference-guide/page.md
+29-68Lines changed: 29 additions & 68 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,57 +15,16 @@ The TerminusDB schema language enables documents and their relationships to be s
15
15
16
16
## Schema Objects
17
17
18
-
A JSON object in TerminusDB schema is composed of **key-value** pairs.
18
+
A JSON object in TerminusDB schema is composed of **key-value** pairs. There are two main types of schema objects, one `@context` typed schema object, and different kinds of structures, including the following:
19
19
20
-
#### Key
20
+
***Class**:definitions for document and subdocument instances
21
+
***Enum**: definitions for enum values
22
+
***Foreign**: definitions for foreign IRI references (arbitrary IRIs)
23
+
***TaggedUnion**: definitions for tagged union types (one of property definitions)
21
24
22
-
A key is one of two values, **keyword** or **property**, described in the table below. The full schema definition is a stream or list of these values or JSON objects.
23
-
24
-
#### Table: Types of keys
25
-
26
-
{%table%}
27
-
28
-
- Key type
29
-
- Example
30
-
- Description
31
-
32
-
---
33
-
34
-
-**keyword**
35
-
-`@id`
36
-
- Starts with `@`, has a value with a special meaning.
37
-
---
38
-
39
-
-**property**
40
-
-`name`
41
-
- Does not start with `@`, has a value with a **range** type.
42
-
43
-
{%/table%}
25
+
Each of the above types of schema objects has a `@type` property with the value of the type, and several other definition keywords as described next.
44
26
45
-
### Class definition
46
-
47
-
The basic unit of specification is a **class**. A class definition is a schema object with the keyword `@type` with type value `Class`. The keyword `@id` specifies the name of the class. The example below define a class named `Person` with a property `name` of type `xsd:string`. Search XSD definitions for more information about types.
The TerminusDB schema language enables documents and their relationships to be specified using simple JSON syntax. This syntax makes it as easy as possible to specify a JSON object to automatically convert to a graph. This approach enables data to be viewed as collections of documents or as knowledge graphs of interconnected objects.
63
-
64
-
## Schema Objects
65
-
66
-
A JSON object in TerminusDB schema is composed of **key-value** pairs.
67
-
68
-
#### Key
27
+
### Key
69
28
70
29
A key is one of two values, **keyword** or **property**, described in the table below. The full schema definition is a stream or list of these values or JSON objects.
71
30
@@ -90,7 +49,7 @@ A key is one of two values, **keyword** or **property**, described in the table
90
49
91
50
{%/table%}
92
51
93
-
###Class definition
52
+
## Class definition
94
53
95
54
The basic unit of specification is a **class**. A class definition is a schema object with the keyword `@type` with type value `Class`. The keyword `@id` specifies the name of the class. The example below define a class named `Person` with a property `name` of type `xsd:string`. Search XSD definitions for more information about types.
96
55
@@ -104,7 +63,7 @@ The basic unit of specification is a **class**. A class definition is a schema o
104
63
}
105
64
```
106
65
107
-
###Context object
66
+
## Context object
108
67
109
68
The **context object** is a special schema object affecting the entire schema. The context object is specified by the special `@type` value `@context`. An example:
110
69
@@ -139,7 +98,7 @@ This example does the following:
139
98
*`@authors`
140
99
*`@description`
141
100
142
-
####Context Prefixes
101
+
### Context Prefixes
143
102
144
103
All properties in the context object that do not start with `@`, such as `xsd`, are URI definitions. They must be of the form shown below. Prefix and URI are defined by their respective regular expressions. That is, a prefix has an identifier starting with an alphabetic character followed by alphanumeric characters. The URI has a protocol followed by valid URI characters. Each prefix is paired with a URI.
145
104
@@ -152,11 +111,11 @@ URI := ":alpha:alphaNum:*://:uriChar:*"
152
111
... }
153
112
```
154
113
155
-
## Context keywords
114
+
###Context keywords
156
115
157
116
A list of keywords used in the context object.
158
117
159
-
### @schema
118
+
####@schema
160
119
161
120
The `@schema` keyword specifies the default URI expansion to use for all elements of the schema. In the example below, the class name `NamedQuery` expands to `http://terminusdb.com/schema/woql#NamedQuery`.
162
121
@@ -199,7 +158,7 @@ The `@schema` keyword specifies the default URI expansion to use for all element
199
158
}
200
159
```
201
160
202
-
### @documentation
161
+
####@documentation
203
162
204
163
`@documentation` specifies documentation global to the entire schema. See the `@documentation` section in the previous context object example. The `@documentation` tag can be a single value, or it can be a list with each element having an additional `@langugage` tag. The `@language` tag must have an IANA language code, and this will be used to select appropriate descriptions when internationalising the schema.
205
164
@@ -255,7 +214,7 @@ An example of the `@language` tag for a context is as follows:
255
214
}
256
215
```
257
216
258
-
## Document definition keywords
217
+
## Document structure definition keywords
259
218
260
219
A document definition includes several properties, and the keywords, prefixed `@`, describing class behavior.
261
220
@@ -322,7 +281,7 @@ You can specify the order of properties within your schema so that it is display
322
281
...
323
282
```
324
283
325
-
### Class schema type
284
+
## Class schema type
326
285
327
286
`Class` designates a standard class document. It contains the definition of several properties and keywords describing various class attributes. An example of a class, and an instance of the class:
328
287
@@ -343,7 +302,7 @@ You can specify the order of properties within your schema so that it is display
343
302
}
344
303
```
345
304
346
-
#### Code: An example of a class instance
305
+
### Code: An example of a class instance
347
306
348
307
```json
349
308
{
@@ -359,11 +318,11 @@ You can specify the order of properties within your schema so that it is display
359
318
}
360
319
```
361
320
362
-
### Enum schema type
321
+
## Enum schema type
363
322
364
323
An `Enum` is a non-standard class in which each instance is a simple URI with no additional structure. To be a member of the class, you must be one of the referent URIs. An `Enum` example with an extension `Blue` is s shown below. In the database, the actual URI for an Enum is expanded with the preceding type name, so the `blue` extension becomes `http://s#PrimaryColour/blue`
365
324
366
-
#### Code: An example of an enum class
325
+
### Code: An example of an enum class
367
326
368
327
```json
369
328
{
@@ -378,13 +337,13 @@ An `Enum` is a non-standard class in which each instance is a simple URI with no
378
337
}
379
338
```
380
339
381
-
### TaggedUnion schema type
340
+
## TaggedUnion schema type
382
341
383
342
A `TaggedUnion` specifies mutually exclusive properties. This is useful when there is a disjoint choice between options.
384
343
385
344
Examples below of a schema with a TaggedUnion and a concrete TaggedUnion class extension. In these examples, the `BinaryTree` class specifies a `TaggedUnion` enabling a choice between a `leaf` (with no value), or a `node` class with a value and branches.
386
345
387
-
#### Code: An example schema with a TaggedUnion
346
+
### Code: An example schema with a TaggedUnion
388
347
389
348
```json
390
349
{
@@ -416,7 +375,7 @@ Examples below of a schema with a TaggedUnion and a concrete TaggedUnion class e
416
375
}
417
376
```
418
377
419
-
#### Code: An example TaggedUnion class extension
378
+
### Code: An example TaggedUnion class extension
420
379
421
380
```json
422
381
{
@@ -435,13 +394,13 @@ Examples below of a schema with a TaggedUnion and a concrete TaggedUnion class e
435
394
}
436
395
```
437
396
438
-
### @oneOf
397
+
## @oneOf in a Class definition
439
398
440
399
The `TaggedUnion` is a special case and syntactic sugar for the more general case of collections of disjoint properties. These more complex cases can be represented by inheriting from a number of `TaggedUnion`s, but they may also be given explicitly using the `@oneOf` field, together with a Class.
441
400
442
401
The value of the `@oneOf` field is a set, so can be any number of documents all of which have mutually disjoint properties, but which can coexist. Examples with more than one disjoint property are given below.
443
402
444
-
#### Code: An example schema with @oneOf
403
+
### Code: An example schema with @oneOf
445
404
446
405
```json
447
406
{
@@ -495,7 +454,7 @@ The value of the `@oneOf` field is a set, so can be any number of documents all
495
454
}
496
455
```
497
456
498
-
#### Code: Examples of `@oneOf` class extensions
457
+
### Code: Examples of `@oneOf` class extensions
499
458
500
459
```json
501
460
{
@@ -554,6 +513,8 @@ But not:
554
513
555
514
The `Unit` type has a single extension `[]`. This is used when only the presence of the property is interesting, but it has no interesting value. See the `BinaryTree` in the [TaggedUnion class extension](#codeanexampletaggedunionclassextension) example above.
556
515
516
+
## Class definition details
517
+
557
518
### @id
558
519
559
520
The `@id` key of a class defines the class name and identifier. The name uniquely defines the class, enabling the class to be updated, retrieved, and deleted. In the example below, the class is named `NamedQuery`. It does not have a fully qualified URL or prefix, so it is implicitly based on the URI given for `@schema`.
@@ -1015,7 +976,7 @@ An example of inheritance of properties and an object meeting this specification
1015
976
}
1016
977
```
1017
978
1018
-
## @unfoldable
979
+
### @unfoldable
1019
980
1020
981
The `@unfoldable` key is present with the value `[]` or it is not present.
1021
982
@@ -1025,7 +986,7 @@ The `@unfoldable` option can only be set on a class which does not directly or i
1025
986
1026
987
The purpose of `@unfoldable` is to be able to treat linked (top-level) documents as subdocuments in representation. Subdocuments can only be linked by one document, its owner, whereas normal documents can be linked by any number of other documents. If the desired result is to have a document linked by several other documents, but still have it fully unfolded on retrieval like a subdocument, use this option.
1027
988
1028
-
### Code: An example unfoldable
989
+
#### Code: An example unfoldable
1029
990
1030
991
```json
1031
992
{
@@ -1102,7 +1063,7 @@ The above example shows both Doug and Phil using the same address document. On r
1102
1063
1103
1064
The address is fully unfolded in both documents despite not being a subdocument.
1104
1065
1105
-
## Class properties
1066
+
### Class properties
1106
1067
1107
1068
All non-keywords are treated as properties of the class, with the form:
0 commit comments