JavaScript Client
v12.0.5The official TerminusDB JavaScript client library for browser and Node.js applications. Build powerful data-driven applications with type-safe database operations.
$
npm install terminusdbQuick Navigation
WOQLClient
Sends an action to the server
Parameters
actionName | string | structure of the action |
payload | object | a request body call |
Returns
| Promise | A promise that returns the call response object, or an Error if rejected. |
to add a new document or a list of new documents into the instance or the schema graph.
Parameters
json | object | — |
params | typedef.DocParamsPost | the post parameters {@link #typedef.DocParamsPost} |
dbId | string | the dbid |
string | message | the insert commit message |
lastDataVersion | string | the last data version tracking id. |
getDataVersion | boolean | If true the function will return object having result and dataVersion. |
Returns
| Promise | A 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,
)