Skip to content

Commit

Permalink
Merge branch 'rc'
Browse files Browse the repository at this point in the history
  • Loading branch information
rrooij committed Sep 10, 2021
2 parents eb20b29 + d860e90 commit ca4a7dd
Show file tree
Hide file tree
Showing 65 changed files with 15,378 additions and 8,366 deletions.
120 changes: 64 additions & 56 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ Promise based terminus client for the browser and node.js

## Requirements

- [TerminusDB](https://github.com/terminusdb/terminusdb)
- [NodeJS 10+](https://nodejs.org/en/)

## Installation
Expand All @@ -16,7 +15,8 @@ TerminusDB Client can be used as either a Node.js module available through the n

### NPM Module

Before installing, download and install Node.js. Node.js 0.10 or higher is required.
Before installing, download and install Node.js.<br>
NodeJS version 10.X or higher is required. NodeJS version 14.X is recommended.

Installation is done using the npm install command:

Expand Down Expand Up @@ -44,66 +44,74 @@ Download the terminusdb-client.min.js file from the /dist directory and save it

## Usage

This example creates a simple Express.js server that will post an account to
a database with the id "banker" and the default "admin" user with password "root"
For the [full Documentation](https://terminusdb.github.io/terminusdb-client-js)
This example creates a simple dataProduct, starting to create a database model the schema
and insert a simple document

```javascript
const express = require("express");
const app = express();
const port = 3000;
For the [full Documentation](https://terminusdb.com/docs/reference/js-client)

```javascript
const TerminusClient = require("@terminusdb/terminusdb-client");

// Connect and configure the TerminusClient
const client = new TerminusClient.WOQLClient("https://127.0.0.1:6363/", {
db: "banker",
user: "admin",
key: "root",
});
//to change the starting settings
client.db("banker");
client.organization("admin");

async function postAccount() {
try {
const WOQL = TerminusClient.WOQL;
const query = WOQL.using("admin/banker").and(
WOQL.add_triple("doc:smog", "type", "scm:BankAccount"),
WOQL.add_triple("doc:smog", "owner", "smog"),
WOQL.add_triple("doc:smog", "balance", 999)
);
await client.connect();
client
.query(query, "adding smog's bank account")
.then((response) => {
return response;
})
.catch((err) => {
console.log("error", err);
});
} catch (err) {
console.error(err);
const client = new TerminusClient.WOQLClient('SERVER_CLOUD_URL/mycloudTeam',
{user:"myemail@something.com", organization:'mycloudTeam'})

client.setApiKey(MY_ACCESS_TOKEN)

const bankerSchema = [
{
"@type":"Class",
"@id":"BankAccount",
"@key":{
"@type":"Hash",
"@fields":[
"account_id"
]
},
"account_id":"xsd:string",
"owner":"Person",
"balance":"xsd:decimal"
},
{
"@type":"Class",
"@id":"Person",
"@key":{
"@type":"Hash",
"@fields":[
"name"
]
},
"name":"xsd:string"
}
]

async function createDataProduct(){
try{
await client.connect()
await client.createDatabase("banker", {label: "Banker Account",
comment: "Testing", schema: true})
//add the schema documents
await client.addDocument(bankerSchema,{"graph_type":"schema"},null,"add new schema")

const accountObj = {"@type":"BankAccount",
"account_id":"DBZDFGET23456",
"owner":{
"@type":"Person",
"name":"Tom"
},
"balance":1000
}

//add a document instance
await client.addDocument(accountObj)

client.getDocument({"as_list":true,id:'Person/Tom'})

}catch(err){
console.error(err.message)
}
}
}

app.post("/account", (req, res) => {
postAccount().then((dbres) => res.send(JSON.stringify(dbres)));
});

app.listen(port, () => {
console.log(`Backend Server listening at http://localhost:${port}`);
client
.connect()
.then(function (response) {
// handle success
console.log(response);
})
.catch(function (error) {
// handle error
console.log(error);
});
});
```

## Options
Expand All @@ -115,7 +123,7 @@ To initialize `TerminusDB client` with custom options use
```js
const TerminusClient = require("@terminusdb/terminusdb-client");

const client = new TerminusClient.WOQLClient("https://127.0.0.1:6363/", {
const client = new TerminusClient.WOQLClient("http://127.0.0.1:6363/", {
db: "test_db",
user: "admin",
key: "my_secret_key",
Expand Down
121 changes: 65 additions & 56 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ Promise based terminus client for the browser and node.js

## Requirements

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

## Installation

TerminusDB Client can be used as either a Node.js module available through the npm registry, or directly included in web-sites by including the script tag below.

### NPM Module

Before installing, download and install Node.js. Node.js 0.10 or higher is required.
Before installing, download and install Node.js.<br>
NodeJS version 10.X or higher is required. NodeJS version 14.X is recommended.

Installation is done using the npm install command:

Expand Down Expand Up @@ -44,65 +44,74 @@ Download the terminusdb-client.min.js file from the /dist directory and save it

## Usage

This example creates a simple Express.js server that will post an account to
a database with the id "banker" and the default "admin" user with password "root"
This example creates a simple dataProduct, starting to create a database model the schema
and insert a simple document

For the [full Documentation](https://terminusdb.com/docs/reference/js-client)

```javascript
const express = require("express");
const app = express();
const port = 3000;

const TerminusClient = require("@terminusdb/terminusdb-client");

// Connect and configure the TerminusClient
const client = new TerminusClient.WOQLClient("https://127.0.0.1:6363/", {
dbid: "banker",
user: "admin",
key: "root",
});
client.db("banker");
client.organization("admin");

async function postAccount() {
try {
const WOQL = TerminusClient.WOQL;
const query = WOQL.using("admin/banker").and(
WOQL.add_triple("doc:smog", "type", "scm:BankAccount"),
WOQL.add_triple("doc:smog", "owner", "smog"),
WOQL.add_triple("doc:smog", "balance", 999)
);
await client.connect();
client
.query(query, "adding smog's bank account")
.then((response) => {
return response;
})
.catch((err) => {
console.log("error", err);
});
} catch (err) {
console.error(err);
const client = new TerminusClient.WOQLClient('SERVER_CLOUD_URL/mycloudTeam',
{user:"myemail@something.com", organization:'mycloudTeam'})

client.setApiKey(MY_ACCESS_TOKEN)

const bankerSchema = [
{
"@type":"Class",
"@id":"BankAccount",
"@key":{
"@type":"Hash",
"@fields":[
"account_id"
]
},
"account_id":"xsd:string",
"owner":"Person",
"balance":"xsd:decimal"
},
{
"@type":"Class",
"@id":"Person",
"@key":{
"@type":"Hash",
"@fields":[
"name"
]
},
"name":"xsd:string"
}
]

async function createDataProduct(){
try{
await client.connect()
await client.createDatabase("banker", {label: "Banker Account",
comment: "Testing", schema: true})
//add the schema documents
await client.addDocument(bankerSchema,{"graph_type":"schema"},null,"add new schema")

const accountObj = {"@type":"BankAccount",
"account_id":"DBZDFGET23456",
"owner":{
"@type":"Person",
"name":"Tom"
},
"balance":1000
}

//add a document instance
await client.addDocument(accountObj)

client.getDocument({"as_list":true,id:'Person/Tom'})

}catch(err){
console.error(err.message)
}
}
}

app.post("/account", (req, res) => {
postAccount().then((dbres) => res.send(JSON.stringify(dbres)));
});

app.listen(port, () => {
console.log(`Backend Server listening at http://localhost:${port}`);
client
.connect()
.then(function (response) {
// handle success
console.log(response);
})
.catch(function (error) {
// handle error
console.log(error);
});
});
```

## Options
Expand All @@ -114,8 +123,8 @@ To initialize `TerminusDB client` with custom options use
```js
const TerminusClient = require("@terminusdb/terminusdb-client");

const client = new TerminusClient.WOQLClient("https://127.0.0.1:6363/", {
dbid: "test_db",
const client = new TerminusClient.WOQLClient("http://127.0.0.1:6363/", {
db: "test_db",
user: "admin",
key: "my_secret_key",
});
Expand Down
Loading

0 comments on commit ca4a7dd

Please sign in to comment.