@terminusdb/terminusdb-client

TerminusDB client library

Usage no npm install needed!

<script type="module">
  import terminusdbTerminusdbClient from 'https://cdn.skypack.dev/@terminusdb/terminusdb-client';
</script>

README

TerminusDB JavaScript Client


Discord Discourse Twitter

npm version npm downloads

This repository is for the JavaScript client for TerminusDB and TerminusX. The JavaScript client runs in the browser and on Node.js.

TerminusDB is an open-source graph database and document store. It allows you to link JSON documents in a powerful knowledge graph all through a simple document API.

TerminusX is a self-service data platform that allows you to build, deploy, execute, monitor, and share versioned data products. It is built on TerminusDB. TerminusX is in public beta and you can sign up now.

Requirements

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.
NodeJS version 10.X or higher is required. NodeJS version 14.X is recommended.

Installation is done using the npm install command:

Using npm:

$ npm install --save @terminusdb/terminusdb-client

Minified Script

Using cdn:

<script src="https://unpkg.com/@terminusdb/terminusdb-client/dist/terminusdb-client.min.js"></script>

Downloading:

Download the terminusdb-client.min.js file from the /dist directory and save it to your location of choice, then:

<script src="http://my.saved.location/terminusdb-client.min.js"></script>

Usage

This example creates a simple dataProduct, starting to create a database model the schema and insert a simple document

For the full Documentation

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

// Connect and configure the TerminusClient
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.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)
    }
  }

Options

connections options.

To initialize TerminusDB client with custom options use

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

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

API

The TerminusDB API can be found at the TerminusDB Documentation.

Report Issues

If you have encounter any issues, please report it with your os and environment setup, version that you are using and a simple reproducible case.

If you encounter other questions, you can ask in our Discord Server.

Contribute

It will be nice, if you open an issue first so that we can know what is going on, then, fork this repo and push in your ideas. Do not forget to add a bit of test(s) of what value you adding.

Please check Contributing.md for more information.

Licence

The APACHE 2.0 License

Copyright (c) 2019