-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathupdate_data.js
More file actions
51 lines (40 loc) · 1.46 KB
/
update_data.js
File metadata and controls
51 lines (40 loc) · 1.46 KB
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
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 , db:"GettingStartedDB" }
);
//Assign your key to environment variable TERMINUSDB_ACCESS_TOKEN
client.setApiKey(process.env.TERMINUSDB_ACCESS_TOKEN);
const updateAndLinkData = async () => {
const destiny = await client.getDocument({"id":"Employee/001"});
// have to delete "@id" because database will create a new one
delete destiny.address['@id'];
destiny.address.postcode = "PH12 3RP";
destiny.address.street = "Lairg Road";
destiny.address.street_num = 73;
destiny.address.town = "Newbigging";
await client.updateDocument(destiny,{},"","updating 001");
const ethan = {
"@type": "Employee",
"employee_id": "005",
name: "Ethan Abbott",
title: "Backend Developer",
team: "IT",
contact_number: "070 7796 8035",
address: {
"@type": "Address",
postcode: "IV27 2TG",
street: "Shore Street",
street_num: 84,
town: "Stoer"
},
manager: "Employee/004",
}
await client.addDocument(ethan,{},"","Adding ethan");
const result = await client.getDocument({"as_list":true});
console.log(result);
}
updateAndLinkData();