JavaScript Client

v12.0.5

The official TerminusDB JavaScript client library for browser and Node.js applications. Build powerful data-driven applications with type-safe database operations.

$npm install terminusdb

WOQLClient

action(actionName, payload)

Sends an action to the server

Parameters
actionNamestringstructure of the action
payloadobjecta request body call
Returns
PromiseA promise that returns the call response object, or an Error if rejected.

addDocument(json, params, dbId, string, lastDataVersion, getDataVersion)

to add a new document or a list of new documents into the instance or the schema graph.

Parameters
jsonobject—
paramstypedef.DocParamsPostthe post parameters {@link #typedef.DocParamsPost}
dbIdstringthe dbid
stringmessagethe insert commit message
lastDataVersionstringthe last data version tracking id.
getDataVersionbooleanIf true the function will return object having result and dataVersion.
Returns
PromiseA promise that returns the call response object or object having *result* and *dataVersion* object if ***getDataVersion*** parameter is true, or an Error if rejected.
Example: JavaScript
const json = [{ "@type" : "Class",
             "@id" : "Coordinate",
             "@key" : { '@type' : 'Hash',
             '@fields' : ['x','y'] },
             "x" : "xsd:decimal",
             "y" : "xsd:decimal" },
             { "@type" : "Class",
             "@id" : "Country",
             "@key" : { '@type' : 'Lexical',
                         '@fields' : [name] },
             "name" : "xsd:string",
             "perimeter" : { "@type" : "List",
                             "@class" : "Coordinate" } }]
client.addDocument(json,{"graph_type":"schema"},"mydb","add new schema documents")

//if we would like to override the entire schema
const json = [
{"@base": "terminusdb:///data/",
      "@schema": "terminusdb:///schema#",
      "@type": "@context"
  },
  {
      "@id": "Person",
       "@key": {
          "@type": "Random"
      },
      "@type": "Class",
      "name": {
          "@class": "xsd:string",
          "@type": "Optional"
      }
  }]

// client.addDocument(json,{"graph_type":"schema","full_replace:true"},
      "mydb","update the all schema");

// Here we will pass true to show how to get dataVersion

const response = await client.addDocument(json, {"graph_type": "schema"},
  "mydb",
  "add new schema", '',
  true
)
console.log(response);

 // This will output:
 // {
 //   result: [ ...... ],
 //   dataVersion: 'branch:5fs681tlycnn6jh0ceiqcq4qs89pdfs'
 // }

 // Now we can use the data version we recieved as a response in previous
 // function call and used it is next function call as lastDataVersion

const response1 = await client.addDocument(json, {"graph_type": "schema"},
  "mydb",
  "add new schema", response.dataVersion,
)

addPrefix(prefixName, uri, dbId)

Add a new prefix mapping

Parameters
prefixNamestringThe prefix name to create
uri