Skip to content

Commit 26e6024

Browse files
author
Francesca Bitto
committed
review doc
1 parent 6e7091c commit 26e6024

File tree

5 files changed

+62
-157
lines changed

5 files changed

+62
-157
lines changed

README.md

Lines changed: 30 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Promise based terminus client for the browser and node.js
88
## Requirements
99

1010
- [TerminusDB](https://github.com/terminusdb/terminusdb-server)
11-
- [NodeJS 8.1.4+](https://nodejs.org/en/)
11+
- [NodeJS 10+](https://nodejs.org/en/)
1212

1313
## Installation
1414

@@ -56,52 +56,40 @@ const port = 3000;
5656
const TerminusClient = require("@terminusdb/terminusdb-client");
5757

5858
// Connect and configure the TerminusClient
59-
const client = new TerminusClient.WOQLClient("https://127.0.0.1:6363/", {
60-
dbid: "banker",
59+
60+
// Connect and configure the TerminusClient
61+
const client = new TerminusClient.WOQLClient("http://127.0.0.1:6363/", {
6162
user: "admin",
6263
key: "root",
64+
db:"mydb",
6365
});
66+
67+
//change database, set the banker database
6468
client.db("banker");
65-
client.organization("admin");
66-
67-
async function postAccount() {
68-
try {
69-
const WOQL = TerminusClient.WOQL;
70-
const query = WOQL.using("admin/banker").and(
71-
WOQL.add_triple("doc:smog", "type", "scm:BankAccount"),
72-
WOQL.add_triple("doc:smog", "owner", "smog"),
73-
WOQL.add_triple("doc:smog", "balance", 999)
74-
);
75-
await client.connect();
76-
client
77-
.query(query, "adding smog's bank account")
78-
.then((response) => {
79-
return response;
80-
})
81-
.catch((err) => {
82-
console.log("error", err);
83-
});
84-
} catch (err) {
85-
console.error(err);
86-
}
87-
}
88-
89-
app.post("/account", (req, res) => {
90-
postAccount().then((dbres) => res.send(JSON.stringify(dbres)));
91-
});
69+
70+
//we are insert the data in the banker db
71+
app.post("/account", async(req, res) => {
72+
try{
73+
const owner = req.body.owner
74+
const balance = req.body.balance
75+
const accountObj = {'@type':'BankAccount',
76+
'owner':owner,
77+
'balance':balance}
78+
79+
80+
await client.connect()
81+
const response = await client.addDocument(accountObj)
82+
res.json({message:'account added'})
83+
84+
}catch(err){
85+
console.error(err.message)
86+
const status=err.status || 500
87+
res.status(status).send({message: 'Failed to add a new account','err':err.message});
88+
}
89+
})
9290

9391
app.listen(port, () => {
9492
console.log(`Backend Server listening at http://localhost:${port}`);
95-
client
96-
.connect()
97-
.then(function (response) {
98-
// handle success
99-
console.log(response);
100-
})
101-
.catch(function (error) {
102-
// handle error
103-
console.log(error);
104-
});
10593
});
10694
```
10795

@@ -114,8 +102,8 @@ To initialize `TerminusDB client` with custom options use
114102
```js
115103
const TerminusClient = require("@terminusdb/terminusdb-client");
116104

117-
const client = new TerminusClient.WOQLClient("https://127.0.0.1:6363/", {
118-
dbid: "test_db",
105+
const client = new TerminusClient.WOQLClient("http://127.0.0.1:6363/", {
106+
db: "test_db",
119107
user: "admin",
120108
key: "my_secret_key",
121109
});

docs/README.md

Lines changed: 30 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Promise based terminus client for the browser and node.js
88
## Requirements
99

1010
- [TerminusDB](https://github.com/terminusdb/terminusdb-server)
11-
- [NodeJS 8.1.4+](https://nodejs.org/en/)
11+
- [NodeJS 10+](https://nodejs.org/en/)
1212

1313
## Installation
1414

@@ -56,52 +56,40 @@ const port = 3000;
5656
const TerminusClient = require("@terminusdb/terminusdb-client");
5757

5858
// Connect and configure the TerminusClient
59-
const client = new TerminusClient.WOQLClient("https://127.0.0.1:6363/", {
60-
dbid: "banker",
59+
60+
// Connect and configure the TerminusClient
61+
const client = new TerminusClient.WOQLClient("http://127.0.0.1:6363/", {
6162
user: "admin",
6263
key: "root",
64+
db:"mydb",
6365
});
66+
67+
//change database, set the banker database
6468
client.db("banker");
65-
client.organization("admin");
66-
67-
async function postAccount() {
68-
try {
69-
const WOQL = TerminusClient.WOQL;
70-
const query = WOQL.using("admin/banker").and(
71-
WOQL.add_triple("doc:smog", "type", "scm:BankAccount"),
72-
WOQL.add_triple("doc:smog", "owner", "smog"),
73-
WOQL.add_triple("doc:smog", "balance", 999)
74-
);
75-
await client.connect();
76-
client
77-
.query(query, "adding smog's bank account")
78-
.then((response) => {
79-
return response;
80-
})
81-
.catch((err) => {
82-
console.log("error", err);
83-
});
84-
} catch (err) {
85-
console.error(err);
86-
}
87-
}
88-
89-
app.post("/account", (req, res) => {
90-
postAccount().then((dbres) => res.send(JSON.stringify(dbres)));
91-
});
69+
70+
//we are insert the data in the banker db
71+
app.post("/account", async(req, res) => {
72+
try{
73+
const owner = req.body.owner
74+
const balance = req.body.balance
75+
const accountObj = {'@type':'BankAccount',
76+
'owner':owner,
77+
'balance':balance}
78+
79+
80+
await client.connect()
81+
const response = await client.addDocument(accountObj)
82+
res.json({message:'account added'})
83+
84+
}catch(err){
85+
console.error(err.message)
86+
const status=err.status || 500
87+
res.status(status).send({message: 'Failed to add a new account','err':err.message});
88+
}
89+
})
9290

9391
app.listen(port, () => {
9492
console.log(`Backend Server listening at http://localhost:${port}`);
95-
client
96-
.connect()
97-
.then(function (response) {
98-
// handle success
99-
console.log(response);
100-
})
101-
.catch(function (error) {
102-
// handle error
103-
console.log(error);
104-
});
10593
});
10694
```
10795

@@ -114,8 +102,8 @@ To initialize `TerminusDB client` with custom options use
114102
```js
115103
const TerminusClient = require("@terminusdb/terminusdb-client");
116104

117-
const client = new TerminusClient.WOQLClient("https://127.0.0.1:6363/", {
118-
dbid: "test_db",
105+
const client = new TerminusClient.WOQLClient("http://127.0.0.1:6363/", {
106+
db: "test_db",
119107
user: "admin",
120108
key: "my_secret_key",
121109
});

docs/_sidebar.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,4 +176,5 @@
176176
- [DbDetails](api/typedef.js?id=DbDetails)
177177
- [RemoteRepoDetails](api/typedef.js?id=RemoteRepoDetails)
178178
- [CloneSourceDetails](api/typedef.js?id=CloneSourceDetails)
179+
- [ParamType](api/typedef.js?id=typedef)
179180

docs/api/typedef.js.md

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,5 @@
11
## Typedefs
22

3-
<dl>
4-
<dt><a href="#DocParamsGet">DocParamsGet</a> : <code>Object</code></dt>
5-
<dd><p>the GET document interface query parameters</p>
6-
</dd>
7-
<dt><a href="#DocParamsPost">DocParamsPost</a> : <code>Object</code></dt>
8-
<dd><p>the POST document interface query parameters</p>
9-
</dd>
10-
<dt><a href="#DocParamsPut">DocParamsPut</a> : <code>Object</code></dt>
11-
<dd><p>the PUT document interface query parameters</p>
12-
</dd>
13-
<dt><a href="#DocParamsDelete">DocParamsDelete</a> : <code>Object</code></dt>
14-
<dd><p>the DELETE document interface query parameters</p>
15-
</dd>
16-
<dt><a href="#GraphRef">GraphRef</a> : <code>&quot;schema/main&quot;</code> | <code>&quot;schema/*&quot;</code> | <code>&quot;instance/main&quot;</code> | <code>&quot;instance/*&quot;</code> | <code>&quot;inference/main&quot;</code> | <code>&quot;inference/*&quot;</code> | <code>string</code></dt>
17-
<dd></dd>
18-
<dt><a href="#DataFormatObj">DataFormatObj</a> : <code>Object</code></dt>
19-
<dd><p>(export/import)</p>
20-
</dd>
21-
<dt><a href="#FuntionType">FuntionType</a> : <code>&quot;add_quad&quot;</code> | <code>&quot;delete_quad&quot;</code> | <code>&quot;add_triple&quot;</code> | <code>&quot;delete_triple&quot;</code> | <code>&quot;quad&quot;</code> | <code>&quot;triple&quot;</code></dt>
22-
<dd></dd>
23-
<dt><a href="#ClassObj">ClassObj</a> : <code>Object</code></dt>
24-
<dd><p>the class details object</p>
25-
</dd>
26-
<dt><a href="#PropertyObj">PropertyObj</a> : <code>Object</code></dt>
27-
<dd><p>an object that describe a property element</p>
28-
</dd>
29-
<dt><a href="#ResourceType">ResourceType</a> : <code>&quot;commits&quot;</code> | <code>&quot;meta&quot;</code> | <code>&quot;branch&quot;</code> | <code>&quot;ref&quot;</code> | <code>&quot;repo&quot;</code> | <code>&quot;db&quot;</code></dt>
30-
<dd></dd>
31-
<dt><a href="#GraphType">GraphType</a> : <code>&quot;inference&quot;</code> | <code>&quot;schema&quot;</code> | <code>&quot;instance&quot;</code></dt>
32-
<dd></dd>
33-
<dt><a href="#CredentialObj">CredentialObj</a> : <code>Object</code></dt>
34-
<dd></dd>
35-
<dt><a href="#ActionType">ActionType</a> : <code>&#x27;graph&#x27;</code> | <code>&#x27;db&#x27;</code> | <code>&#x27;clone&#x27;</code> | <code>&#x27;triples&#x27;</code> | <code>&#x27;woql&#x27;</code> | <code>&#x27;frame&#x27;</code> | <code>&#x27;fetch&#x27;</code> | <code>&#x27;pull&#x27;</code> | <code>&#x27;rebase&#x27;</code> | <code>&#x27;csv&#x27;</code> | <code>&#x27;branch&#x27;</code> | <code>&#x27;reset&#x27;</code> | <code>&#x27;push&#x27;</code> | <code>&#x27;squash&#x27;</code></dt>
36-
<dd></dd>
37-
<dt><a href="#ParamsObj">ParamsObj</a> : <code>Object</code></dt>
38-
<dd></dd>
39-
<dt><a href="#RolesObj">RolesObj</a> : <code>Object</code></dt>
40-
<dd></dd>
41-
<dt><a href="#RepoType">RepoType</a> : <code>&quot;local&quot;</code> | <code>&quot;remote&quot;</code></dt>
42-
<dd></dd>
43-
<dt><a href="#DbDetails">DbDetails</a> : <code>Object</code></dt>
44-
<dd></dd>
45-
<dt><a href="#RemoteRepoDetails">RemoteRepoDetails</a> : <code>Object</code></dt>
46-
<dd><p>{remote: &quot;origin&quot;, &quot;remote_branch&quot;: &quot;main&quot;, &quot;author&quot;: &quot;admin&quot;, &quot;message&quot;: &quot;message&quot;}</p>
47-
</dd>
48-
<dt><a href="#CloneSourceDetails">CloneSourceDetails</a> : <code>Object</code></dt>
49-
<dd></dd>
50-
</dl>
51-
52-
533
## DocParamsGet
544
#### DocParamsGet : <code>Object</code>
555
the GET document interface query parameters

lib/typedef.js

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434

3535
/**
36-
* @typedef {"schema/main" | "schema/*" | "instance/main" | "instance/*" | "inference/main" | "inference/*" | string} GraphRef
36+
* @typedef {"schema" | "instance" } GraphRef
3737
*/
3838
/**
3939
* @typedef {Object} DataFormatObj (export/import)
@@ -45,28 +45,6 @@
4545
* @typedef {"add_quad" | "delete_quad" | "add_triple" | "delete_triple" | "quad" | "triple"} FuntionType
4646
*/
4747

48-
/**
49-
* @typedef {Object} ClassObj - the class details object
50-
* @property {string} id - IRI or variable containing IRI of the class to be inserted
51-
* @property {string} [label]
52-
* @property {string} [description]
53-
* @property {boolean} [abstract]
54-
* @property {array|string} [parent] -if not parent the new class will be a class ObjectW
55-
* @property {any} [{k:string}] - properties
56-
*/
57-
58-
/**
59-
* @typedef {Object} PropertyObj - an object that describe a property element
60-
* @property {string} id
61-
* @property {string} range - the type of property (class id or a native type xsd:number etc.. )
62-
* @property {string} [label]
63-
* @property {string} [description]
64-
* @property {string} domain - the ID of the class to which the property belongs
65-
* @property {string} [max] - the max property's cardinality
66-
* @property {string} [min] - the min property's cardinality
67-
* @property {string} [cardinality] - the property cardinality (max and min value)
68-
*/
69-
7048
/**
7149
* @typedef {"commits"|"meta"|"branch"|"ref"|"repo"|"db"} ResourceType
7250
*/

0 commit comments

Comments
 (0)