-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathschema.js
85 lines (70 loc) · 2.1 KB
/
schema.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
const TerminusClient = require("@terminusdb/terminusdb-client");
// TODO: Change teamname and username
const teamName = "yourTeam"
const username = "yourUser"
const client = new TerminusClient.WOQLClient(
`https://cloud.terminusdb.com/${teamName}/`,
{ user: username, organization: teamName }
);
// If you are using TerminusCMS you need to generate you api key
// https://terminusdb.com/docs/terminuscms/get-api-key here the documentation
client.setApiKey(process.env.TERMINUSDB_ACCESS_TOKEN);
const address_schema = {
"@id": "Address",
"@key": {
"@type": "ValueHash"
},
"@subdocument": [],
"@type": "Class",
"postcode": "xsd:string",
"street": "xsd:string",
"street_num": "xsd:integer",
"town": "xsd:string"
};
const employee_schema = {
"@id": "Employee",
"@key": {
"@type": "Lexical",
"@fields": ["employee_id"]
},
"@type": "Class",
"employee_id": "xsd:string",
"address": "Address",
"contact_number": "xsd:string",
"manager": {
"@class": "Employee",
"@type": "Optional"
},
"name": "xsd:string",
"team": "Team",
"title": "xsd:string"
};
const team_schema = {
"@id": "Team",
"@type": "Enum",
"@value": [
"Marketing",
"IT"
]
};
const createDatabaseAndSchema = async () => {
await client.createDatabase("GettingStartedDB", {
label: "GettingStartedDB",
comment: "Created new GettingStartedDB",
});
console.log("Database created successfully!");
client.db("GettingStartedDB");
// insert all the schema documents
const schemas = [address_schema, team_schema, employee_schema];
await client.addDocument(schemas, { graph_type: "schema" },"","Inserting schema");
console.log("Schema inserted successfully!");
// Get commit history
const woqlLib = TerminusClient.WOQL;
const commitQuery = woqlLib.lib().commits();
const response= await client.query(commitQuery);
console.log(response.bindings);
// Get all schema documents
const result = await client.getDocument({"graph_type":"schema","as_list":true});
console.log(result);
};
createDatabaseAndSchema();