JavaScript Client
v12.0.0The official TerminusDB JavaScript client library for browser and Node.js applications. Build powerful data-driven applications with type-safe database operations.
npm install @terminusdb/terminusdb-clientQuick 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. |
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,
)Retrieve the URL of the server’s API base that we are currently connected to
Returns
| string | the URL of the TerminusDB server api endpoint we are connected to (typically server() + “api/”) |
let api_url = client.api()Diff two different commits and apply changes on the current branch/commit. If you would like to change branch or commit before apply use client.checkout("branchName")
Parameters
beforeVersion | string | Before branch/commit to compare |
afterVersion | string | After branch/commit to compare |
message | string | apply commit message |
matchFinalState | boolean | the default value is false |
options | object | {keep:{}} Options to send to the apply endpoint |
client.checkout("mybranch")
client.apply("mybranch","mybranch_new","merge main").then(result=>{
console.log(result)
})Creates a new branch with a TerminusDB database, starting from the current context of the client (branch / ref)
Parameters
newBranchId | string | local identifier of the new branch the ID of the new branch to be created |
isEmpty | boolean | if isEmpty is true it will create a empty branch. |
Returns
| Promise | A promise that returns the call response object, or an Error if rejected. |
client.branch("dev")Gets/Sets the client’s internal branch context value (defaults to ‘main’)
Parameters
branchId | string | the branch id to set the context to |
Returns
| string | the current branch id within the client context |
Clones a remote repo and creates a local copy
Parameters
cloneSource | typedef.CloneSourceDetails | object describing the source branch to be used as a base |
newDbId | string | id of the new cloned database on the local server |
orgId | string | id of the local organization that the new cloned database will be created in (in desktop mode this is always “admin”) |
Returns
| Promise | A promise that returns the call response object, or an Error if rejected. |
client.clonedb({remote_url: "https://my.terminusdb.com/myorg/mydb", label "Cloned DB", comment: "Cloned from mydb"}, newid: "mydb")You can call this to get the server info or override the start params configuration, this.connectionConfig.server will be used if present, or the promise will be rejected.
Parameters
params | typedef.ParamsObj | TerminusDB Server connection parameters |
Returns
| Promise | the connection capabilities response object or an error object |
client.connect()creates a copy of the client with identical internal state and context useful if we want to change context for a particular API call without changing the current client context
Returns
| WOQLClient | new client object with identical state to original but which can be manipulated independently |
let newClient = client.copy()Creates a new database in TerminusDB server
Parameters
dbId | string | The id of the new database to be created |
dbDetails | typedef.DbDetails | object containing details about the database to be created |
orgId | string | optional organization id - if absent default local organization id is used |
Returns
| Promise | A promise that returns the call response object, or an Error if rejected. |
//remember set schema:true if you need to add a schema graph
client.createDatabase("mydb", {label: "My Database", comment: "Testing", schema: true})Creates a new remote connection for the database
Parameters
remoteName | string | The name of the remote to create |
remoteLocation | string | The URL of the remote repository |
Returns
| Promise | A promise that returns the call response object, or an Error if rejected. |
client.createRemote("origin", "http://remote.server.com/org/db")add extra headers to your request
Parameters
customHeaders | object | — |
Returns
| object |
Gets the database's details
Parameters
dbName | string | the datbase name |
Returns
| object | the database description object |
Set/Get the organization's databases list (id, label, comment) that the current user has access to on the server.
Parameters
dbList | array | a list of databases the user has access to on the server, each having: |
Returns
| array | the organization's databases list |
//to get the list of all organization's databases
async function callGetDatabases(){
await client.getDatabases()
console.log(client.databases())
}Sets / Gets the current database
Parameters
dbId | string | the database id to set the context to |
Returns
| string|boolean | - the current database or false |
client.db("mydb")Deletes a branch from database
Parameters
branchId | string | local identifier of the branch |
Returns
| Promise | A promise that returns the call response object, or an Error if rejected. |
Deletes a database from a TerminusDB server
Parameters
dbId | string | The id of the database to be deleted |
orgId | string | the id of the organization to which the database belongs (in desktop use, this will always be “admin”) |
force | boolean | — |
Returns
| Promise | A promise that returns the call response object, or an Error if rejected. |
client.deleteDatabase("mydb")to delete the document
Parameters
params | typedef.DocParamsDelete | — |
dbId | string | the database id |
message | string | the delete 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. |
client.deleteDocument({"graph_type":"schema",id:['Country','Coordinate']})
// Here we will pass true to show how to get dataVersion
const response = await client.deleteDocument({"graph_type":"schema",id:['Country','Coordinate']},
"",
"",
"",
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.deleteDocument({"graph_type":"schema",
id:['Country','Coordinate']},
"",
"",
response.dataVersion,
)Deletes a remote connection
Parameters
remoteName | string | The name of the remote to delete |
Returns
| Promise | A promise that returns the call response object, or an Error if rejected. |
client.deleteRemote("origin")Common request dispatch function
Returns
| Promise | A promise that returns the call response object, or an Error if rejected. |
Fetch updates to a remote database to a remote repository with the local database
Parameters
remoteId | string | if of the remote to fetch (eg: 'origin') |
Returns
| Promise | A promise that returns the call response object, or an Error if rejected. |
Generates the json structure for commit descriptor
Parameters
commitId | string | a valid commit id o |
Generates the json structure for commit messages
Parameters
msg | string | textual string describing reason for the change |
author | string | optional author id string - if absent current user id will be used |
Returns
| object |
get the database collections list
Parameters
dbId | string | the database id |
Returns
| Promise | A promise that returns the call response object, or an Error if rejected. |
client.getBranches()get all the Document Classes (no abstract or subdocument)
Parameters
dbId | string | — |
Returns
| Promise | A promise that returns the call response object, or an Error if rejected. |
client.getClassDocuments()get all the schema classes (documents,subdocuments,abstracts)
Parameters
dbId | string | the database id |
Returns
| Promise | A promise that returns the call response object, or an Error if rejected. |
client.getClasses()get the database collections list
Parameters
start | number | where to start printing the commit information in the log (starting from the head of the current branch) |
count | number | The number of total commit log records to return |
Returns
| Promise | A promise that returns the call response object, or an Error if rejected. |
client.getCommitsLog(count=10)Gets the organization's databases list. If no organization has been set up, the function throws an exception
Returns
| Promise |
async function callGetDatabases(){
const dbList = await client.getDatabases()
console.log(dbList)
}Parameters
params | typedef.DocParamsGet | the get parameters, you can pass document query search template with the params |
dbId | string | the database id |
branch | string | the database branch |
lastDataVersion | string | the last data version tracking id. |
getDataVersion | boolean | If true the function will return object having result and dataVersion. |
query | object | document query search template |
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. |
//return the schema graph as a json array
client.getDocument({"graph_type":"schema","as_list":true}).then(result={
console.log(result)
})
//retutn the Country class document from the schema graph
client.getDocument({"graph_type":"schema","as_list":true,"id":"Country"}).then(result={
console.log(result)
})
//pass a document query template to query the document interface
const queryTemplate = { "name": "Ireland"}
client.getDocument({"as_list":true, "@type":"Country"
query:queryTemplate}).then(result=>{
console.log(result)
})
// Here we will pass true to show how to get dataVersion
const response = await client.getDocument({"graph_type":"schema","as_list":true},
"",
"",
"",
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.getDocument({"graph_type":"schema","as_list":true},
"",
"",
response.dataVersion,
)Get the document's history for a specific database or branch
Parameters
id | string | id of document to report history of |
historyParams | typedef.DocHistoryParams | — |
//this will return the last 5 commits for the Person/Anna document
client.checkout("mybranch")
client.docHistory("Person/Anna",{start:0,count:5}).then(result=>{
console.log(result)
})
//this will return the last and the first commit for the Person/Anna document
client.docHistory("Person/Anna",{updated:true,created:true}).then(result=>{
console.log(result)
})get all the Enum Objects
Parameters
dbId | string | — |
Returns
| Promise | A promise that returns the call response object, or an Error if rejected. |
client.getEnums()Get the patch of difference between two documents.
Parameters
before | object | The current state of JSON document |
after | object | The updated state of JSON document |
options | object | {keep:{}} Options to send to the diff endpoint. The diff api outputs the changes between the input, in options you can list the properties that you would like to see in the diff result in any case. |
Returns
| Promise | A promise that returns the call response object, or an Error if rejected. |
client.getJSONDiff(
{ "@id": "Person/Jane", "@type": "Person", name: "Jane" },
{ "@id": "Person/Jane", "@type": "Person", name: "Janine" }
).then(diffResult=>{
console.log(diffResult)
})
//result example
//{'@id': 'Person/Jane',
// name: { '@after': 'Janine', '@before': 'Jane', '@op': 'SwapValue' }}get the database prefixes object
Parameters
dbId | string | the database id |
Returns
| Promise | A promise that returns the call response object, or an Error if rejected. |
client.getPrefixes()
//return object example
{
'@base': 'terminusdb:///data/',
'@schema': 'terminusdb:///schema#',
'@type': 'Context'}Gets information about a remote connection
Parameters
remoteName | string | The name of the remote to retrieve |
Returns
| Promise | A promise that returns the remote details, or an Error if rejected. |
const remote = await client.getRemote("origin")get the database schema in json format
Parameters
dbId | string | the database id |
branch | string | specific a branch/collection |
Returns
| Promise | A promise that returns the call response object, or an Error if rejected. |
client.getSchema()The purpose of this method is to quickly discover the supported fields of a particular type.
Parameters
type | string | If given, the type to get information for. If omitted, information for all types is returned |
dbId | string | the database id |
Returns
| Promise | A promise that returns the call response object, or an Error if rejected. |
client.getSchemaFrame("Country")Retrieve the contents of a graph within a TerminusDB as triples, encoded in the turtle (ttl) format
Parameters
graphType | typedef.GraphType | type of graph to get triples from, either “instance” or “schema” |
Returns
| Promise | A promise that returns the call response object (with the contents being a string representing a set of triples in turtle (ttl) format), or an Error if rejected. |
const turtle = await client.getTriples("schema", "alt")Get the list of the user's organizations and the database related
Returns
| Promise | A promise that returns the call response object, or an Error if rejected. |
async funtion callGetUserOrganizations(){
await getUserOrganizations()
console.log(client.userOrganizations())
}Get the patch of difference between branches or commits.
Parameters
beforeVersion | string | Before branch/commit to compare |
afterVersion | string | After branch/commit to compare |
id | string | The document id to be diffed, if it is omitted all the documents will be compared |
options | typedef.DiffObject | {keep:{},count:10,start:0} Options to send to the diff endpoint. The diff api outputs the changes between the input (branches or commits), in options you can list the properties that you would like to see in the diff result in any case. |
Returns
| Promise | A promise that returns the call response object, or an Error if rejected. |
//This is to view all the changes between two commits
const beforeCommit = "a73ssscfx0kke7z76083cgswszdxy6l"
const afterCommit = "73rqpooz65kbsheuno5dsayh71x7wf4"
client.getVersionDiff( beforeCommit, afterCommit).then(diffResult=>{
console.log(diffResult)
})
//This is to view the changes between two commits but only for the given document
client.getVersionDiff( beforeCommit, afterCommit, "Person/Tom").then(diffResult=>{
console.log(diffResult)
})
//This is to view the changes between a branch (head) and a commit for the given document
client.getVersionDiff("main", afterCommit, "Person/Tom" ).then(diffResult=>{
console.log(diffResult)
})
//This is to view the changes between two branches with the keep options
const options = {"keep":{"@id":true, "name": true}, start:0, count:10}
client.getVersionDiff("main","mybranch",options).then(diffResult=>{
console.log(diffResult)
})Get the patch of difference between two documents.
Parameters
dataVersion | string | The version from which to compare the object |
jsonObject | object | The updated state of JSON document |
id | string | The document id to be diffed |
options | object | {keep:{}} Options to send to the diff endpoint the diff api outputs the changes between the input, but you can list the properties that you would like to see in the diff result in any case. |
Returns
| Promise | A promise that returns the call response object, or an Error if rejected. |
const jsonObj = { "@id": "Person/Jane", "@type": "Person", name: "Janine" }
client.getVersionObjectDiff("main",jsonObj
"Person/Jane").then(diffResp=>{
console.log(diffResp)
})Checks if a database exists Returns true if a DB exists and false if it doesn't. Other results throw an exception.
Parameters
orgName | string | the organization id to set the context to |
dbName | string | the db name to set the context to |
Returns
| Promise |
async function executeIfDatabaseExists(f){
const hasDB = await client.hasDatabase("admin", "testdb")
if (hasDB) {
f()
}
}Gets TerminusDB Server Information
Returns
| Promise | A promise that returns the call response object, or an Error if rejected. |
client.info()Appends the passed turtle to the contents of a graph
Parameters
graphType | string | type of graph |instance|schema|inference| |
turtle | string | is a valid set of triples in turtle format (OWL) |
commitMsg | string | Textual message describing the reason for the update |
Returns
| Promise | A promise that returns the call response object, or an Error if rejected. |
Sets/Gets set the database basic connection credential
Parameters
newCredential | typedef.CredentialObj | — |
Returns
| typedef.CredentialObj|boolean |
client.localAuth({user:"admin","key":"mykey","type":"basic"})Sends a message to the server
Parameters
message | string | textual string |
pathname | string | a server path to send the message to |
Returns
| Promise | A promise that returns the call response object, or an Error if rejected. |
Optimize db branch
Parameters
branchId | string | local identifier of the new branch |
Returns
| Promise | A promise that returns the call response object, or an Error if rejected. |
Gets/Sets the client’s internal organization context value, if you change the organization name the databases list will be set to empty
Parameters
orgId | string|boolean | the organization id to set the context to |
Returns
| string|boolean |
client.organization("admin")Apply a patch object to another object
Parameters
before | object | The current state of JSON document |
patch | object | The patch object |
Returns
| Promise | A promise that returns the call response object, or an Error if rejected. |
client.patch(
{ "@id" : "Person/Jane", "@type" : "Person", "name" : "Jane"},
{ "name" : { "@op" : "ValueSwap", "@before" : "Jane", "@after": "Janine" }}
).then(patchResult=>{
console.log(patchResult)
})
//result example
//{ "@id" : "Person/Jane", "@type" : "Person", "name" : "Jannet"}Apply a patch object to the current resource
Parameters
patch | array | The patch object |
message | string | The commit message |
Returns
| Promise | A promise that returns the call response object, or an Error if rejected. |
const patch = [
{
"@id": "Obj/id1",
"name": {
"@op": "SwapValue",
"@before": "foo",
"@after": "bar"
}
},
{
"@id": "Obj/id2",
"name": {
"@op": "SwapValue",
"@before": "foo",
"@after": "bar"
}
}
]
client.db("mydb")
client.checkout("mybranch")
client.patchResource(patch,"apply patch to mybranch").then(patchResult=>{
console.log(patchResult)
})
// result example
// ["Obj/id1",
// "Obj/id2"]
// or conflict error 409
// {
// "@type": "api:PatchError",
// "api:status": "api:conflict",
// "api:witnesses": [
// {
// "@op": "InsertConflict",
// "@id_already_exists": "Person/Jane"
// }
//]
//}Adds an author string (from the user object returned by connect) to the commit message.
Parameters
rc_args | object | — |
Returns
| object|boolean |
Pull changes from a branch on a remote database to a branch on a local database
Parameters
remoteSourceRepo | typedef.RemoteRepoDetails | an object describing the source of the pull |
Returns
| Promise | A promise that returns the call response object, or an Error if rejected. |
client.pull({remote: "origin", remote_branch: "main", message: "Pulling from remote"})Push changes from a branch on a local database to a branch on a remote database
Parameters
remoteTargetRepo | typedef.RemoteRepoDetails | an object describing the target of the push {remote: "origin", "remote_branch": "main", "author": "admin", "message": "message"} |
Returns
| Promise | A promise that returns the call response object, or an Error if rejected. |
client.push({remote: "origin", remote_branch: "main", message: "Pulling from remote"})Executes a WOQL query on the specified database and returns the results
Parameters
woql | WOQLQuery | an instance of the WOQLQuery class |
commitMsg | string | a message describing the reason for the change that will be written into the commit log (only relevant if the query contains an update) |
allWitnesses | boolean | — |
lastDataVersion | string | the last data version tracking id. |
getDataVersion | boolean | If true the function will return object having result and dataVersion. |
resources | Array.<NamedResourceData> | csv resources supplied as strings |
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. |
const result = await client.query(WOQL.star())Use {@link #getDocument} instead.
Parameters
query | object | the query template |
params | typedef.DocParamsGet | the get parameters |
dbId | string | the database id |
branch | string | the database branch |
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. |
const query = {
"type": "Person",
"query": { "age": 42 },
}
client.queryDocument(query, {"as_list":true})
// Here we will pass true to show how to get dataVersion
const query = {
"type": "Person",
"query": { "age": 42 },
}
const response = await client.queryDocument(query, {"as_list": true}, '', '','',true);
console.log(response);
// This will output:
// {
// result: [
// {
// '@id': 'Person/052d60ffbd114bf5e7331b03f07fcb7',
// '@type': 'Person',
// age: 42,
// name: 'John',
// },
// ],
// dataVersion: 'branch:5fs681tlycnn6jh0ceiqcq4qs89pdfs'
// }
// Now we can use the data version we recieved as a response in previous
// query and used it is next query as lastDataVersion
const query = {
"type": "Person",
"query": { "age": 18 },
}
const response1 = await client.queryDocument(query, {"as_list": true}, '',
'',
response.dataVersion
);Merges the passed branch into the current one using the rebase operation
Parameters
rebaseSource | object | json describing the source branch to be used as a base |
Returns
| Promise | A promise that returns the call response object, or an Error if rejected. |
//from the branch head
client.rebase({rebase_from: "admin/db_name/local/branch/branch_name", message:
"Merging from dev")
//or from a commit id
client.rebase({rebase_from: "admin/db_name/local/commit/9w8hk3y6rb8tjdy961de3i536ntkqd8",
message: "Merging from dev")Sets / gets the current ref pointer (pointer to a commit within a branch) Reference ID or Commit ID are unique hashes that are created whenever a new commit is recorded
Parameters
commitId | string | the reference ID or commit ID |
Returns
| string|boolean | the current commit id within the client context |
client.ref("mkz98k2h3j8cqjwi3wxxzuyn7cr6cw7")Sets/Gets the jwt token for authentication we need this to connect 2 terminusdb server to each other for push, pull, clone actions
Parameters
newCredential | typedef.CredentialObj | — |
Returns
| typedef.CredentialObj|boolean |
client.remoteAuth({"key":"dhfmnmjglkrelgkptohkn","type":"jwt"})Gets / Sets the client’s internal repository context value (defaults to ‘local’)
Parameters
repoId | typedef.RepoType|string | default value is local |
Returns
| string | the current repository id within the client context |
client.repo("origin")Reset the current branch HEAD to the specified commit path
Parameters
commitPath | string | The commit path to set the current branch to |
Returns
| Promise | A promise that returns the call response object, or an Error if rejected. |
Reset branch to a commit id, Reference ID or Commit ID are unique hashes that are created whenever a new commit is recorded
Parameters
branchId | string | local identifier of the new branch |
commitId | string | Reference ID or Commit ID |
Returns
| Promise | A promise that returns the call response object, or an Error if rejected. |
Generates a resource string for the required context of the current context for "commits" "meta" "branch" and "ref" special resources
Parameters
resourceType | typedef.ResourceType | the type of resource string that is required - one of “db”, “meta”, “repo”, “commits”, “branch”, “ref” |
resourceId | string | can be used to specify a specific branch / ref - if not supplied the current context will be used |
Returns
| string | a resource string for the desired context |
const branch_resource = client.resource("branch")Call a custom Api endpoit
Parameters
requestType | string | The current state of JSON document |
customRequestURL | string | The patch object |
payload | object | the request payload |
Returns
| Promise | A promise that returns the call response object, or an Error if rejected. |
client.sendCustomRequest("GET", "http://localhost:3030/changes/").then(result=>{
console.log(result)
})Gets the current connected server url it can only be set creating a new WOQLCLient instance
Returns
| string |
Parameters
params | typedef.ParamsObj | a object with connection params |
sets several of the internal state values in a single call
(similar to connect, but only sets internal client state, does not communicate with server)
client.set({key: "mypass", branch: "dev", repo: "origin"})Sets the internal client context to allow it to talk to the server’s internal system database
Squash branch commits
Parameters
branchId | string | local identifier of the new branch |
commitMsg | string | Textual message describing the reason for the update |
Returns
| Promise | A promise that returns the call response object, or an Error if rejected. |
Update a database in TerminusDB server
Parameters
dbDoc | typedef.DbDoc | object containing details about the database to be updated |
Returns
| Promise | A promise that returns the call response object, or an Error if rejected. |
client.updateDatabase({id: "mydb", label: "My Database", comment: "Testing"})Parameters
json | object | — |
params | typedef.DocParamsPut | the Put parameters {@link #typedef.DocParamsPut} |
dbId | * | the database id |
message | * | the update commit message |
lastDataVersion | string | the last data version tracking id. |
getDataVersion | boolean | If true the function will return object having result and dataVersion. |
compress | boolean | If true, the function will create a new document if it doesn't exist. |
create | boolean | Perform an *upsert* which inserts if the document is not present (also works on nested documents) |
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. |
client.updateDocument(
{
"@id": "Person",
"@key": {
"@type": "Random",
},
"@type": "Class",
label: "xsd:string",
},
{ graph_type: "schema" }
);
// Here we will pass true to show how to get dataVersion
const response = await client.updateDocument(
{
"@id": "Person",
"@key": {
"@type": "Random",
},
"@type": "Class",
label: "xsd:string",
},
{ graph_type: "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.updateDocument(
{
"@id": "Person",
"@key": {
"@type": "Random",
},
"@type": "Class",
label: "xsd:string",
},
{ graph_type: "schema" },
"",
"",
response.dataVersion
);
// update a document and create the linked document together
// we are update the document "Person/Person01"
// and create a new document {"@type": "Person","name": "child01"} at the same time
const response1 = await client.updateDocument(
{
"@id": "Person/Person01",
"@type": "Person",
"name": "Person01"
"children":[{"@type": "Person","name": "child01"}]
},{create:true})Updates an existing remote connection
Parameters
remoteName | string | The name of the remote to update |
remoteLocation | string | The new URL for the remote repository |
Returns
| Promise | A promise that returns the call response object, or an Error if rejected. |
client.updateRemote("origin", "http://new.remote.server.com/org/db")Replace the contents of the specified graph with the passed triples encoded in the turtle (ttl) format
Parameters
graphType | string | type of graph |instance|schema|inference| |
turtle | string | string encoding triples in turtle (ttl) format |
commitMsg | string | Textual message describing the reason for the update |
Returns
| Promise | A promise that returns the call response object, or an Error if rejected. |
client.updateTriples("schema", "alt", turtle_string, "dumping triples to graph alt")Gets the current user object as returned by the connect capabilities response user has fields: [id, name, notes, author]
Returns
| Object |
Get/Set the list of the user's organizations (id, organization, label, comment).
Parameters
orgList | array | a list of user's Organization |
Returns
| array | the user Organizations list |
async funtion callGetUserOrganizations(){
await client.getUserOrganizations()
console.log(client.userOrganizations())
}WOQL
The WOQL object is a wrapper around the WOQLQuery object
Adds quads according to the pattern [S,P,O,G]
Parameters
subject | string|Var | The IRI of a triple’s subject or a variable |
predicate | string|Var | The IRI of a property or a variable |
object | string|Var | The IRI of a node or a variable, or a literal |
graphRef- | typedef.GraphRef | A valid graph resource identifier string |
Returns
| WOQLQuery |
Adds triples according to the the pattern [subject,predicate,object]
Parameters
subject | string|Var | The IRI of a triple’s subject or a variable |
predicate | string|Var | The IRI of a property or a variable |
object | string|Var | The IRI of a node or a variable, or a literal |
Returns
| WOQLQuery |
Creates a pattern matching rule for the quad [S, P, O, G] (Subject, Predicate, Object, Graph) removed from the current commit
Parameters
subject | string|Var | The IRI of a triple’s subject or a variable |
predicate | string|Var | The IRI of a property or a variable |
object | string|Var | The IRI of a node or a variable, or a literal |
graphRef- | typedef.GraphRef | A valid graph resource identifier string |
Returns
| WOQLQuery |
Creates a triple pattern matching rule for the triple [S, P, O] (Subject, Predicate, Object) added in the current layer
Parameters
subject | string|Var | The IRI of a triple’s subject or a variable |
predicate | string|Var | The IRI of a property or a variable |
object | string|Var | The IRI of a node or a variable, or a literal |
Returns
| WOQLQuery |
Generates a query that by default matches all triples in a graph - identical to star() except for order of arguments
Parameters
subject | string|Var | The IRI of a triple’s subject or a variable |
predicate | string|Var | The IRI of a property or a variable |
object | string|Var | The IRI of a node or a variable, or a literal |
graphRef | typedef.GraphRef | the resource identifier of a graph possible value are schema/{main - myschema - *} | instance/{main - myschema - *} | inference/{main - myschema - *} |
Returns
| WOQLQuery | - A WOQLQuery which contains the pattern matching expression all("mydoc") //will return every triple in the instance/main graph that has "doc:mydoc" as its subject |
Logical conjunction of the contained queries - all queries must match or the entire clause fails
Parameters
subqueries | WOQLQuery | A list of one or more woql queries to execute as a conjunction |
Returns
| WOQLQuery | - A WOQLQuery object containing the conjunction of queries |
//find triples that are of type scm:Journey, and have
//a start_station Start, and that start_station is labeled Start_Label
let [Journey, Start, Start_Label] = vars("Journey", "Start", "Start_Label")
WOQL.and(
WOQL.triple(Journey, "rdf:type", "@schema:Journey"),
WOQL.triple(Journey, "start_station", Start),
WOQL.triple(Start, "label", Start_Label))Imports the value identified by Source to a Target variable
Parameters
source | string|number|Var | Source |
target | string|Var | Target |
type | string | type to cast value to string|number etc... |
Returns
| WOQLQuery |
let [First_Var, Second_Var] = vars('First_Var', 'Second_Var')
WOQL.as("first var", First_Var, "string").as("second var", Second_Var)
WOQL.as(["first var", First_Var, "string"], ["second var", Second_Var])Generates explicitly a JSON-LD literal boolean from the input
Parameters
bool | boolean | true | false |
Returns
| object | - A JSON-LD literal boolean |
boolean(true)
//returns { "@type": "xsd:boolean", "@value": true }Use instead to run your query woqlclient.query('myWOQLQuery')
Parameters
client | WOQLClient | — |
Returns
| WOQLClient |
Adds a text comment to a query - can also be used to wrap any part of a query to turn it off
Parameters
comment | string | text comment |
subquery | WOQLQuery | query that is "commented out" |
Returns
| WOQLQuery |
takes a variable number of string arguments and concatenates them into a single string
Parameters
varList | array|string|Var | a variable representing a list or a list of variables or strings - variables can be embedded in the string if they do not contain spaces |
resultVarName | string|Var | A variable or string containing the output string |
Returns
| WOQLQuery | A WOQLQuery which contains the Concatenation pattern matching expression |
let [first_name, last_name, full_name] = vars("first_name", "last_name", "full_name")
concat([first_name, " ", last_name], full_name)Creates a count of the results of the query
Parameters
countVarName | string|number|Var | variable or integer count |
subquery | WOQLQuery | — |
Returns
| WOQLQuery | A WOQLQuery object containing the count sub Query |
let [count, Person] = vars("count", "Person")
WOQL.count(count).triple(Person, "rdf:type", "@schema:Person")Generates explicitly a JSON-LD literal date from the imput
Parameters
date | string | any date format string (YYYY-MM-DD) |
Returns
| object | - A JSON-LD literal date |
date("2022-10-02")
//returns { "@type": "xsd:date", "@value": "2022-10-02" }Generates explicitly a JSON-LD literal datetime from the imput
Parameters
datetime | string | any datetime format string (YYYY-MM-DDThh-mm-ssZ) |
Returns
| object | - A JSON-LD literal datetime |
datetime("2022-10-19T14:17:12Z")
//returns { "@type": "xsd:dateTime", "@value": "2022-10-19T14:17:12Z" }Delete a document from the graph.
Parameters
IRI | string | The document id or a variable |
Returns
| object | WOQLQuery |
Deletes a single triple from the graph [Subject, Predicate, Object, Graph]
Parameters
subject | string|Var | The IRI of a triple’s subject or a variable |
predicate | string|Var | The IRI of a property or a variable |
object | string|Var | The IRI of a node or a variable, or a literal |
graphRef | typedef.GraphRef | A valid graph resource identifier string |
Returns
| WOQLQuery | - A WOQLQuery which contains the Delete Quad Statement |
remove the class Person from the schema graph
WOQL.delete_quad("Person", "rdf:type", "sys:Class", "schema")Deletes a single triple from the default graph of the database
Parameters
subject | string|Var | The IRI of a triple’s subject or a variable |
predicate | string|Var | The IRI of a property or a variable |
object | string|Var | The IRI of a node or a variable, or a literal |
Returns
| WOQLQuery | - A WOQLQuery which contains the Triple Deletion statement |
delete_triple("john", "age", 42)Filter the query to return only results that are distinct in the given variables
Parameters
varNames | string|Var | these variables are guaranteed to be unique as a tuple |
Returns
| WOQLQuery |
Division - integer division - args are divided left to right
Parameters
args | string|number|Var | numbers for division |
Returns
| WOQLQuery | A WOQLQuery which contains the division expression |
let [result] = vars("result")
evaluate(div(10, 3), result)
//result contains 3Divides numbers N1...Nn by each other left, to right precedence
Parameters
args | string|number|Var | numbers to tbe divided |
Returns
| WOQLQuery | A WOQLQuery which contains the division expression let [result] = vars("result") evaluate(divide(times(10, minus(2.1, plus(0.2, 1))), 10), result) //result contains 0.9000000000000001 |
Produces an encoded form of a document that can be used by a WOQL operation such as `WOQL.insert_document`.
Parameters
object | object | Document to encode |
Returns
| object | The encoded document |
const doc = WOQL.doc({ "@type": "Person", name: "Newperson" })Extract the value of a key in a bound document.
Parameters
document | string|Var | Document which is being accessed. |
field | string|Var | The field from which the document which is being accessed. |
value | string|Var | The value for the document and field. |
Returns
| WOQLQuery | A WOQLQuery which contains the a dot Statement |
query module allow you to use WOQL words as top level functions
Parameters
auto_eval | * | — |
Matches if a is equal to b
Parameters
varName | string|Var | literal, variable or id |
varValue | string|Var | literal, variable or id |
Returns
| WOQLQuery |
Evaluates the passed arithmetic expression and generates or matches the result value
Parameters
arithExp | object|WOQLQuery|string | A WOQL query containing a valid WOQL Arithmetic Expression, which is evaluated by the function |
resultVarName | string|number|Var | Either a variable, in which the result of the expression will be stored, or a numeric literal which will be used as a test of result of the evaluated expression |
Returns
| WOQLQuery | A WOQLQuery which contains the Arithmetic function |
let [result] = vars("result")
eval(plus(2, minus(3, 1)), result)Evaluates the passed arithmetic expression and generates or matches the result value
Parameters
arithExp | object|WOQLQuery|string | A WOQL query containing a valid WOQL Arithmetic Expression, which is evaluated by the function |
resultVarName | string|number|Var | Either a variable, in which the result of the expression will be stored, or a numeric literal which will be used as a test of result of the evaluated expression |
Returns
| WOQLQuery | A WOQLQuery which contains the Arithmetic function |
let [result] = vars("result")
evaluate(plus(2, minus(3, 1)), result)Exponent - raises varNum01 to the power of varNum02
Parameters
varNum | string|number|Var | a variable or numeric containing the number to be raised to the power of the second number |
expNum | number | a variable or numeric containing the exponent |
Returns
| WOQLQuery | A WOQLQuery which contains the exponent expression |
let [result] = vars("result")
evaluate(exp(3, 2), result)
//result contains 9Generates the nearest lower integer to the passed number
Parameters
varNum | string|number|Var | Variable or numeric containing the number to be floored |
Returns
| WOQLQuery | A WOQLQuery which contains the floor expression |
let [result] = vars("result")
evaluate(divide(floor(times(10, minus(2.1, plus(0.2, 1)))), 10), result)
//result contains 0.9 - floating point error removedSpecifies the database URL that will be the default database for the enclosed query
Parameters
graphRef- | typedef.GraphRef | A valid graph resource identifier string |
query | WOQLQuery | The query |
Returns
| WOQLQuery | A WOQLQuery object containing the from expression |
Use the document inteface to import documents
Parameters
asvars | Vars|array.<Var> | an array of AsVar variable mappings (see as for format below) |
queryResource | WOQLQuery | an external resource (remote, file, post) to query |
Returns
| WOQLQuery | A WOQLQuery which contains the get expression |
let [a, b] = vars("a", "b")
get(as("a", a).as("b", b)).remote("http://my.url.com/x.csv")
//copies the values from column headed "a" into a variable a and from column
//"b" into a variable b from remote CSVSets the graph resource ID that will be used for subsequent chained function calls
Parameters
graphRef | typedef.GraphRef | Resource String identifying the graph which will be used for subsequent chained schema calls |
Returns
| WOQLQuery | A WOQLQuery which contains the partial Graph pattern matching expression |
WOQL.graph("schema")
//equivalent to add_quad("MyClass", "label", "My Class Label", "schema/main")Compares the value of v1 against v2 and returns true if v1 is greater than v2
Parameters
varNum01 | string|number|Var | a variable or numeric containing the number to be compared |
varNum02 | string|number|Var | a variable or numeric containing the second comporator |
Returns
| WOQLQuery | A WOQLQuery which contains the comparison expression |
let [result] = vars("result")
greater(1.2, 1.1).eq(result, literal(true, "boolean"))
//result contains trueGroups the results of the contained subquery on the basis of identical values for Groupvars, extracts the patterns defined in PatternVars and stores the results in GroupedVar
Parameters
varList | array|string|Var | Either a single variable or an array of variables |
patternVars | array|string|Var | Either a single variable or an array of variables |
resultVarName | string|Var | output variable name |
subquery | WOQLQuery | The query whose results will be grouped |
Returns
| WOQLQuery | A WOQLQuery which contains the grouping expression |
//subquery is an argument or a chained query
let [age, last_name, first_name, age_group, person] = vars("age", "last name", "first name",
"age group", "person")
group_by(age, [last_name, first_name], age_group)
.triple(person, "first_name", first_name)
.triple(person, "last_name", last_name)
.triple(person, "age", age)Generate a new IRI from the prefix and concatention of the variables
Parameters
prefix | string | A prefix for the IRI - typically formed of the doc prefix and the classtype of the entity (“doc:Person”) |
inputVarList | array|string|Var | An array of variables and / or strings from which the unique hash will be generated |
resultVarName | string|Var | Variable in which the unique ID is stored |
Returns
| WOQLQuery | A WOQLQuery object containing the ID generating function |
let [newid] = vars("newid")
idgen("doc:Person", ["John", "Smith"], newid)Generates a random ID with a specified prefix
Parameters
prefix | string | prefix for the generated ID |
resultVarName | string | variable that stores the generated ID |
Returns
| WOQLQuery | A WOQLQuery object containing the random ID generation function |
let [newid] = vars("newid")
idgen_random("Person/", newid)Runs the query without backtracking on side-effects
Parameters
subquery | string|WOQLQuery | WOQL Query objects |
Returns
| WOQLQuery | A WOQLQuery object containing the immediately sub Query |
Inserts a single triple into the database declaring the Node to have type Type, optionally into the specified graph
Parameters
classId | string|Var | IRI string or variable containing the IRI of the node to be inserted |
classType | string|Var | IRI string or variable containing the IRI of the type of the node (class/document name) |
graphRef | typedef.GraphRef | Optional Graph resource identifier |
Returns
| WOQLQuery | A WOQLQuery which contains the insert expression |
insert("mydoc", "MyType")
//equivalent to add_triple("mydoc", "rdf:type", "@schema:MyType")Insert a document in the graph.
Parameters
docjson | object | The document to insert. Must either have an '@id' or have a class specified key. |
IRI | string | An optional identifier specifying the document location. |
Returns
| object | WOQLQuery |
const res = await client.query(
WOQL.insert_document(WOQL.doc({ "@type" : "Person", "label": "John" }))
)Specifies the graph resource to write the contained query into
Parameters
graphRef- | typedef.GraphRef | A valid graph resource identifier string |
subquery | WOQLQuery | The query which will be written into the graph |
Returns
| WOQLQuery | A WOQLQuery which will be written into the graph in question |
//Subq is an argument or a chained query
using("admin/minecraft").into("instance/main").add_triple("a", "rdf:type", "@schema:X")
//writes a single tripe (doc:a, rdf:type, scm:X) into the main instance graphExplicitly sets a value to be an IRI - avoiding automatic type marshalling
Parameters
val | string | string which will be treated as an IRI |
Returns
| object | - A JSON-LD IRI value |
Tests whether a given instance IRI has type Class, according to the current state of the DB
Parameters
instanceIRI | string|Var | A string IRI or a variable that identify the class instance |
classId | string|Var | A Class IRI or a variable |
Returns
| WOQLQuery | A WOQLQuery object containing the type test |
let [subject] = vars("subject")
isa(subject, "Person")Joins a list variable together (Input) into a string variable (Output) by glueing the strings together with Glue
Parameters
varList | string|array|Var | a variable representing a list or a list of strings and / or variables |
glue | string|Var | A variable (v:glue) or (glue) string representing the characters to put in between the joined strings in input |
resultVarName | string|Var | A variable or string containing the output string |
Returns
| WOQLQuery | A WOQLQuery which contains the Join pattern matching expression |
let [sentence] = vars("sentence")
join(["joe", "has", "a", "hat", " ", sentence)Generates a WOQLQuery object from the passed WOQL JSON - if an argument is passed, the query object is created from it, if none is passed, the current state is returned as a JSON-LD
Parameters
JSON_LD | object | JSON-LD woql document encoding a query |
Returns
| WOQLQuery|object | either a JSON-LD or a WOQLQuery object json version of query for passing to api |
Calculates the length of the list in va and stores it in vb
Parameters
inputVarList | string|array | Either a variable representing a list or a list of variables or literals |
resultVarName | string|Var | A variable in which the length of the list is stored or the length of the list as a non-negative integer |
Returns
| WOQLQuery | A WOQLQuery which contains the Length pattern matching expression |
let [count] = vars("count")
length(["john", "joe", "frank"], count)Compares the value of v1 against v2 and returns true if v1 is less than v2
Parameters
varNum01 | string|number|Var | a variable or numeric containing the number to be compared |
varNum02 | string|number|Var | a variable or numeric containing the second comporator |
Returns
| WOQLQuery | A WOQLQuery which contains the comparison expression |
let [result] = vars("result")
less(1, 1.1).eq(result, literal(true, "boolean"))
//result contains trueget the predefined library query [WOQLLibrary](/api/woqlLibrary.js?id=WOQLLibrary)
Returns
| WOQLQuery | WOQLQuery object |
//get commits older than the specified commit id
const query = WOQL.lib().previousCommits('m8vpxewh2aovfauebfkbzwmj4qwr5lb')
//return the commits of a specific branch starting from the head
//you can add the limit (how many results to return.) and the start point
//if a timestamp is given, gets the commits before the specified timestamp
//WOQL.lib().commits(branch='main',limit=0,start=0,timestamp=0)
const query = WOQL.lib().commits('main',10,2,1630683082.9278786)
//return the branches list with the timestamp and commits id
const query = WOQL.lib().branches()Generates a string Leverstein distance measure between stringA and stringB
Parameters
stringA | string|Var | string literal or variable representing a string to be compared |
stringB | string|Var | string literal or variable representing the other string to be compared |
distance | number|string|Var | variable representing the distance between the variables |
Returns
| WOQLQuery | A WOQLQuery which contains the Like pattern matching expression |
let [dist] = vars('dist')
like("hello", "hallo", dist)
//dist contains 0.7265420560747664Specifies a maximum number of results that will be returned from the subquery
Parameters
limit | number|string | A variable that refers to an non-negative integer or a non-negative integer |
subquery | WOQLQuery | A subquery whose results will be limited |
Returns
| WOQLQuery | A WOQLQuery whose results will be returned starting from the specified offset |
let [a, b, c] = vars("a", "b", "c")
limit(100).triple(a, b, c)
//subquery is an argument or a chained query
limit(100,triple(a, b, c))Creates a pattern matching rule for a triple [Subject, Predicate, Object]
Parameters
subject | string|Var | The IRI of a triple’s subject or a variable |
predicate | string|Var | The IRI of a property or a variable |
object | string|Var | The IRI of a node or a variable, or a literal |
Returns
| WOQLQuery | A WOQLQuery which contains the a quad or a triple Statement |
Generates explicitly a JSON-LD string literal from the input
Parameters
val | string | any literal type |
type | string | an xsd or xdd type |
Returns
| object | - A JSON-LD literal |
literal(1, "nonNegativeInteger")
//returns { "@type": "xsd:nonNegativeInteger", "@value": 1 }Changes a string to lower-case
Parameters
inputVarName | string|Var | string or variable representing the non-lowercased string |
resultVarName | string|Var | variable that stores the lowercased string output |
Returns
| WOQLQuery | A WOQLQuery which contains the Lower case pattern matching expression |
let [lower] = var("l")
lower("aBCe", lower)
//lower contains "abce"Matches if List includes Element
Parameters
element | string|object|Var | Either a variable, IRI or any simple datatype |
list | string|array|Var | List ([string, literal] or string*) Either a variable representing a list or a list of variables or literals |
Returns
| WOQLQuery | A WOQLQuery which contains the List inclusion pattern matching expression |
let [name] = vars("name")
member(name, ["john", "joe", "frank"])Subtracts Numbers N1..Nn
Parameters
args | string|number|Var | variable or numeric containing the value that will be subtracted from |
Returns
| WOQLQuery | A WOQLQuery which contains the subtraction expression |
let [result] = vars("result")
evaluate(minus(2.1, plus(0.2, 1)), result)Specifies the identity of a node that can then be used in subsequent builder functions. Note that node() requires subsequent chained functions to complete the triples / quads that it produces - by itself it only generates the subject.
Parameters
nodeid | string|Var | The IRI of a node or a variable containing an IRI which will be the subject of the builder functions |
chainType | typedef.FuntionType | Optional type of builder function to build (default is triple) |
Returns
| WOQLQuery | - A WOQLQuery which contains the partial Node pattern matching expression |
node("mydoc").label("my label")
//equivalent to triple("mydoc", "label", "my label")Logical negation of the contained subquery - if the subquery matches, the query will fail to match
Parameters
subquery | string|WOQLQuery | A subquery which will be negated |
Returns
| WOQLQuery | A WOQLQuery object containing the negated sub Query |
let [subject, label] = vars("subject", "label")
not().triple(subject, 'label', label)Deletes all triples in the passed graph (defaults to instance/main)
Parameters
graphRef | typedef.GraphRef | Resource String identifying the graph from which all triples will be removed |
Returns
| WOQLQuery | - A WOQLQuery which contains the deletion expression |
nuke("schema/main")
//will delete everything from the schema/main graphResults in one solution of the subqueries
Parameters
subquery | string|WOQLQuery | WOQL Query objects |
Returns
| WOQLQuery | A WOQLQuery object containing the once sub Query |
Specifies that the Subquery is optional - if it does not match the query will not fail
Parameters
subquery | WOQLQuery | A subquery which will be optionally matched |
Returns
| WOQLQuery | A WOQLQuery object containing the optional sub Query |
let [subject] = vars("subject")
opt(triple(subject, 'label', "A"))
//Subq is an argument or a chained query
opt().triple(subject, 'label', "A")Creates a logical OR of the arguments
Parameters
subqueries | WOQLQuery | A list of one or more woql queries to execute as alternatives |
Returns
| WOQLQuery | - A WOQLQuery object containing the logical Or of the subqueries |
let [Subject] = vars("Subject")
or(
triple(Subject, 'label', "A"),
triple(Subject, "label", "a")
)Orders the results of the contained subquery by a precedence list of variables
Parameters
varNames | string|Var|array | A sequence of variables, by which to order the results, each optionally followed by either “asc” or “desc” to represent order as a list, by default it will sort the variable in ascending order |
Returns
| WOQLQuery | A WOQLQuery which contains the ordering expression |
let [A, B, C] = vars("A", "B", "C")
WOQL.order_by(A, [B, "asc"], [C, "desc"]).triple(A, B, C);Pads out the string input to be exactly len long by appending the pad character pad to form output
Parameters
inputVarName | string|Var | The input string or variable in unpadded state |
pad | string|Var | The characters to use to pad the string or a variable representing them |
len | number|string|Var | The variable or integer value representing the length of the output string |
resultVarName | string|Var | stores output |
Returns
| WOQLQuery | A WOQLQuery which contains the Pad pattern matching expression |
let [fixed] = vars("fixed length")
pad("joe", " ", 8, fixed)
//fixed contains "joe "Performs a path regular expression match on the graph
Parameters
subject | string|Var | An IRI or variable that refers to an IRI representing the subject, i.e. the starting point of the path |
pattern | string | (string) - A path regular expression describing a pattern through multiple edges of the graph (see: https://terminusdb.com/docs/path-query-reference-guide) |
object | string|Var | An IRI or variable that refers to an IRI representing the object, i.e. ending point of the path |
resultVarName | string|Var | A variable in which the actual paths traversed will be stored |
Returns
| WOQLQuery | - A WOQLQuery which contains the path regular expression matching expression |
let [person, grand_uncle, lineage] = vars("person", "grand uncle", "lineage")
path(person, "((father|mother) {2,2}), brother)", grand_uncle, lineage)Adds the numbers together
Parameters
args | string|number|Var | a variable or numeric containing the values to add |
Returns
| WOQLQuery | A WOQLQuery which contains the addition expression |
let [result] = vars("result")
evaluate(plus(2, plus(3, 1)), result)Identifies a resource as a local path on the client, to be sent to the server through a HTTP POST request, with the format defined through the options
Parameters
url | string | The Path on the server at which the file resource can be accessed |
formatObj | typedef.DataFormatObj | imput options, optional |
source | string | It defines the source of the file, it can be 'url','post' |
Returns
| WOQLQuery | A WOQLQuery which contains the Post resource identifier |
post("/.../.../", {type:'csv'})Use the document inteface to import documents
Parameters
varsToExp | Vars|array.<Var> | an array of AsVar variable mappings (see as for format below) |
query | WOQLQuery | The query which will be executed to produce the results |
fileResource | string | an file resource local to the server |
Returns
| WOQLQuery | A WOQLQuery which contains the put expression |
Creates a pattern matching rule for the quad [S, P, O, G] (Subject, Predicate, Object, Graph)
Parameters
subject | string|Var | The IRI of a triple’s subject or a variable |
predicate | string|Var | The IRI of a property or a variable |
object | string|Var | The IRI of a node or a variable, or a literal |
graphRef | typedef.GraphRef | A valid graph resource identifier string |
Returns
| WOQLQuery |
Generates an empty WOQLQuery object
Returns
| WOQLQuery |
let q = query()
//then q.triple(1, 1) ...Backward-compatible alias for idgen_random
Parameters
prefix | string | prefix for the generated ID |
resultVarName | string | variable that stores the generated ID |
Returns
| WOQLQuery | A WOQLQuery object containing the random ID generation function |
Matches the regular expression defined in Patern against the Test string, to produce the matched patterns in Matches
Parameters
pattern | string | string or variable using normal PCRE regular expression syntax with the exception that special characters have to be escaped twice (to enable transport in JSONLD) |
inputVarName | string|Var | string or variable containing the string to be tested for patterns with the regex |
resultVarList | string|array|object|Var | variable representing the list of matches or a list of strings or variables |
Returns
| WOQLQuery | A WOQLQuery which contains the Regular Expression pattern matching expression |
let [All, Sub] = vars("All", "Sub")
WOQL.re("h(.).*", "hello", [All, Sub])
//e contains 'e', llo contains 'llo'
//p is a regex pattern (.*) using normal regular expression syntax, the only unusual
thing is that special characters have to be escaped twice, s is the string to be matched
and m is a list of matches:Read a node identified by an IRI as a JSON-LD document
Parameters
IRI | string | The document id or a variable to read |
output | string | Variable which will be bound to the document. |
Returns
| object | WOQLQuery |
let [person] = vars("Person")
const query = WOQL.read_document(
"Person/0b4feda109d9d13c9da809090b342ad9e4d8185545ce05f7cd20b97fe458f547",
person
);
const res = await client.query(query);Identifies a remote resource by URL and specifies the format of the resource through the options
Parameters
remoteObj | object | The URL at which the remote resource can be accessed |
formatObj | typedef.DataFormatObj | The format of the resource data {} |
Returns
| WOQLQuery | A WOQLQuery which contains the remote resource identifier |
remote({url:"http://url.of.resource"}, {type: "csv"})Creates a pattern matching rule for the quad [S, P, O, G] (Subject, Predicate, Object, Graph) removed from the current commit
Parameters
subject | string|Var | The IRI of a triple’s subject or a variable |
predicate | string|Var | The IRI of a property or a variable |
object | string|Var | The IRI of a node or a variable, or a literal |
graphRef- | typedef.GraphRef | A valid graph resource identifier string |
Returns
| WOQLQuery |
Creates a triple pattern matching rule for the triple [S, P, O] (Subject, Predicate, Object) added in the current commit
Parameters
subject | string|Var | The IRI of a triple’s subject or a variable |
predicate | string|Var | The IRI of a property or a variable |
object | string|Var | The IRI of a node or a variable, or a literal |
Returns
| WOQLQuery |
Parameters
varNames | string|Var | only these variables are returned |
Returns
| WOQLQuery |
let [a, b, c] = vars("a", "b", "c")
WOQL.select(a, triple(a, b, c))
Filters the query so that only the variables included in [V1...Vn] are returned in the bindingsCalculates the size in bytes of the contents of the resource identified in ResourceID
Parameters
resourceId | string|Var | A valid resource identifier string (can refer to any graph / branch / commit / db) |
resultVarName | string|Var | The variable name |
let [varSize] = vars("varSize")
size("admin/minecraft/local/branch/main/instance/main", varSize)
//returns the number of bytes in the main instance graph on the main branchExtracts a contiguous subsequence from a list, following JavaScript's slice() semantics
Parameters
inputList | string|array|Var | Either a variable representing a list or a list of variables or literals |
resultVarName | string|Var | A variable in which the sliced list is stored |
start | number|string|Var | The start index (0-based, supports negative indices) |
end | number|string|Var | The end index (exclusive, optional - defaults to list length) |
Returns
| WOQLQuery | A WOQLQuery which contains the Slice pattern matching expression |
let [result] = vars("result")
slice(["a", "b", "c", "d"], result, 1, 3) // result = ["b", "c"]
slice(["a", "b", "c", "d"], result, -2) // result = ["c", "d"]Splits a string (Input) into a list strings (Output) by removing separator
Parameters
inputVarName | string|Var | A string or variable representing the unsplit string |
separator | string|Var | A string or variable containing a sequence of charatcters to use as a separator |
resultVarName | string|Var | variable that stores output list |
Returns
| WOQLQuery | A WOQLQuery which contains the Split pattern matching expression |
let [words] = vars("words")
split("joe has a hat", " ", words)Generates a query that by default matches all triples in a graph identified by "graph" or in all the current terminusDB's graph
Parameters
graph | string|boolean | false or the resource identifier of a graph possible value are schema/{main - myschema - *} | instance/{main - myschema - *} | inference/{main - myschema - *} |
subject | string|Var | The IRI of a triple’s subject or a variable, default value "v:Subject" |
predicate | string|Var | The IRI of a property or a variable, default value "v:Predicate" |
object | string|Var | The IRI of a node or a variable, or a literal, default value "v:Object" |
Returns
| WOQLQuery | A WOQLQuery which contains the pattern matching expression |
star("schema/main")
//will return every triple in schema/main graphSpecifies an offset position in the results to start listing results from
Parameters
start | number|string|Var | A variable that refers to an interger or an integer literal |
subquery | WOQLQuery | WOQL Query object, you can pass a subquery as an argument or a chained query |
Returns
| WOQLQuery | A WOQLQuery whose results will be returned starting from the specified offset |
let [a, b, c] = vars("a", "b", "c")
start(100).triple(a, b, c)Generates explicitly a JSON-LD string literal from the input
Parameters
val | string|boolean|number | any primitive literal type |
Returns
| object | - A JSON-LD string literal |
string(1)
//returns { "@type": "xsd:string", "@value": "1" }Returns true if ClassA subsumes ClassB, according to the current DB schema
Parameters
classA | string | ClassA |
classB | string | ClassB |
Returns
| boolean | WOQLQuery |
Substring of string
Parameters
string | string|Var | String or variable |
before | number|Var | integer or variable (characters from start to begin) |
length | number|Var | integer or variable (length of substring) |
after | number|Var | integer or variable (number of characters after substring) |
substring | string|Var | String or variable |
Returns
| WOQLQuery |
let [after, result] = vars("after", "result")
substr("joe", 1, 2, after, result)
//result is "oe", after is 2computes the sum of the List of values passed. In contrast to other arithmetic functions, sum self-evaluates - it does not have to be passed to evaluate()
Parameters
subquery | WOQLQuery | a subquery or ([string or numeric]) - a list variable, or a list of variables or numeric literals |
total | string|Var | the variable name with the sum result of the values in List |
Returns
| WOQLQuery | - A WOQLQuery which contains the Sum expression |
let [total] = vars("total")
sum([2, 3, 4, 5], total)Multiplies numbers N1...Nn together
Parameters
args | string|number|Var | a variable or numeric containing the value |
Returns
| WOQLQuery | A WOQLQuery which contains the multiplication expression |
let [result] = vars("result")
evaluate(times(10, minus(2.1, plus(0.2, 1))), result)
//result contains 9.000000000000002yRemove whitespace from both sides of a string:
Parameters
inputStr | string|Var | A string or variable containing the untrimmed version of the string |
resultVarName | string|Var | A string or variable containing the trimmed version of the string |
Returns
| WOQLQuery | A WOQLQuery which contains the Trim pattern matching expression |
let [trimmed] = vars("trimmed")
trim("hello ", trimmed)
//trimmed contains "hello"Creates a triple pattern matching rule for the triple [S, P, O] (Subject, Predicate, Object)
Parameters
subject | string|Var | The IRI of a triple’s subject or a variable |
predicate | string|Var | The IRI of a property or a variable |
object | string|Var | The IRI of a node or a variable, or a literal |
Returns
| WOQLQuery |
Calculates the number of triples of the contents of the resource identified in ResourceID
Parameters
resourceId | string|Var | A valid resource identifier string (can refer to any graph / branch / commit / db) |
tripleCount | string|number|Var | An integer literal with the size in bytes or a variable containing that integer |
Returns
| WOQLQuery | A WOQLQuery which contains the size expression |
let [count] = vars("count")
triple_count("admin/minecraft/local/_commits", count)
//returns the number of bytes in the local commit graphA function that always matches, always returns true
Returns
| WOQLQuery | A WOQLQuery object containing the true value that will match any pattern |
when(true()).triple("a", "b", "c")Returns true if 'elementId' is of type 'elementType', according to the current DB schema
Parameters
elementId | string|Var | the id of a schema graph element |
elementType | string|Var | the element type |
Returns
| WOQLQuery | A WOQLQuery object containing the type_of pattern matching rule |
Casts the value of Input to a new value of type Type and stores the result in CastVar
Parameters
varName | string|number|object|Var | Either a single variable or a literal of any basic type |
varType | string|Var | Either a variable or a basic datatype (xsd / xdd) |
resultVarName | string|Var | save the return variable |
Returns
| WOQLQuery | A WOQLQuery which contains the casting expression |
let [time] = vars("time")
cast("22/3/98", "xsd:dateTime", time)Generate a new IRI from the prefix and a hash of the variables which will be unique for any given combination of variables
Parameters
prefix | string | A prefix for the IRI - typically formed of the doc prefix and the classtype of the entity (“doc:Person”) |
inputVarList | array|string|Var | An array of variables and / or strings from which the unique hash will be generated |
resultVarName | string|Var | Variable in which the unique ID is stored |
Returns
| WOQLQuery | A WOQLQuery object containing the unique ID generating function |
let [newid] = vars("newid")
unique("doc:Person", ["John", "Smith"], newid)Update a document identified by an IRI
Parameters
docjson | object | The document to update. Must either have an '@id' or have a class specified key. |
IRI | string | An optional identifier specifying the document location. |
Returns
| object | WOQLQuery |
Update a pattern matching rule for the quad [S, P, O, G] (Subject, Predicate, Object, Graph)
Parameters
subject | string|Var | The IRI of a triple’s subject or a variable |
predicate | string|Var | The IRI of a property or a variable |
newObject | string|Var | The value to update or a literal |
graphRef | typedef.GraphRef | A valid graph resource identifier string |
Returns
| WOQLQuery | A WOQLQuery which contains the a Update Quad Statement |
Update a pattern matching rule for the triple (Subject, Predicate, oldObjValue) with the new one (Subject, Predicate, newObjValue)
Parameters
subject | string|Var | The IRI of a triple’s subject or a variable |
predicate | string|Var | The IRI of a property or a variable |
newObjValue | string|Var | The value to update or a literal |
oldObjValue | string|Var | The old value of the object |
Returns
| WOQLQuery | A WOQLQuery which contains the a Update Triple Statement |
Changes a string to upper-case
Parameters
inputVarName | string|Var | string or variable representing the uncapitalized string |
resultVarName | string|Var | variable that stores the capitalized string output |
Returns
| WOQLQuery | A WOQLQuery which contains the Upper case pattern matching expression |
let [allcaps] = vars("allcaps")
upper("aBCe", allcaps)
//upper contains "ABCE"Query running against any specific commit Id
Parameters
refPath | string | path to specific reference Id or commit Id |
subquery | WOQLQuery | subquery for the specific commit point |
Returns
| WOQLQuery |
let [a, b, c] = vars("a", "b", "c")
WOQL.using("userName/dbName/local/commit|branch/commitID").triple(a, b, c)Creates a pattern matching rule for a triple [Subject, Predicate, Object] add extra information about the type of the value object
Parameters
subject | string|Var | The IRI of a triple’s subject or a variable |
predicate | string|Var | The IRI of a property or a variable |
objValue | string|number|boolean|Var | an specific value |
Returns
| WOQLQuery | A WOQLQuery which contains the a quad or a triple Statement |
Generates javascript variables for use as WOQL variables within a query
Parameters
varNames | string | — |
Returns
| Array.<Var> | an array of javascript variables which can be dereferenced using the array destructuring operation |
const [a, b, c] = WOQL.vars("a", "b", "c")
//a, b, c are javascript variables which can be used as WOQL variables in subsequent queriesParameters
varNames | string | — |
Returns
| object.<Var> |
const v = WOQL.Vars('var01', 'var02', 'var03');
triple(v.var01, v.var02, v.var03)Generates unique javascript variables for use as WOQL variables within a query
Parameters
varNames | string | — |
Returns
| Array.<Var> | an array of javascript variables which can be dereferenced using the array destructuring operation |
const [a, b, c] = WOQL.vars("a", "b", "c")
//a, b, c are javascript variables that are unique WOQL variablesSets the unique variable counter to a specific value This is particularly useful together with select() for locally scoped variables
Parameters
start | number | starting value |
Produces variables with unique names by appending an incrementing counter to each variable name. This is particularly useful together with select() for locally scoped variables
Parameters
varNames | string | — |
Returns
| object.<Var> |
// Creates variables like "a_4", "b_5" - unique even with same input names
const v = WOQL.VarsUnique('var01', 'var02', 'var03');
triple(v.var01, v.var02, v.var03) // locally scopedWOQLLibrary
Library Functions to manage the commits graph
General Pattern 4: Retrieves Branches, Their ID, Head Commit ID, Head Commit Time (if present, new branches have no commits)
get all the commits of a specific branch if a timestamp is given, gets all the commits before the specified timestamp
Parameters
branch | string | the branch name |
limit | number | the max number of result |
start | number | the start of the pagination |
timestamp | number | Unix timestamp in seconds |
Finds the id of the very first commit in a database's history This is useful for finding information about when, by who and why the database was created The first commit is the only commit in the database that does not have a parent commit
AccessControl
The AccessControl is a driver to work with
-- TerminusX API -- Get all the access request list for a specify organization
Parameters
orgName | string | The organization name. |
Returns
| Promise | A promise that returns the call response object, or an Error if rejected. |
accessControl.accessRequestsList().then(result=>{
console.log(result)
})-- TerminusDB API --- This end point works in basic authentication, admin user Create an organization
Parameters
orgName | string | The organization name to create |
Returns
| Promise | A promise that returns the call response object, or an Error if rejected. |
accessControl.createOrganization("my_org_name").then(result=>{
console.log(result)
})-- TerminusX API --- IMPORTANT This does not work with the API-TOKEN. Create an organization
Parameters
orgName | string | The organization name to create |
Returns
| Promise | A promise that returns the call response object, or an Error if rejected. |
accessControl.createOrganization("my_org_name").then(result=>{
console.log(result)
})--TerminusDB API --- basic authentication, admin user. Create a new role in the system database.
Parameters
name | string | The role name. |
actions | typedef.RolesActions | A list of actions |
Returns
| Promise | A promise that returns the call response object, or an Error if rejected. |
accessControl.createRole("Reader",[ACTIONS.INSTANCE_READ_ACCESS]).then(result=>{
console.log(result)
})-- TerminusdDB API --- basic Authentication, admin user. Add the user into the system database
Parameters
name | string | the user name |
password | string | you need the password for basic authentication |
Returns
| Promise | A promise that returns the call response object, or an Error if rejected. |
accessControl.deleteUser(userId).then(result=>{
console.log(result)
})-- TerminusX API -- Create a user's a role for a resource (organization/database)
Parameters
userId | string | The user's id. |
scope | string | The resource name/id. |
role | string | The user role to be assigned. |
orgName | string | The organization name. |
Returns
| Promise | A promise that returns the call response object, or an Error if rejected. |
const dbId = "UserDatabase/acfcc2db02b83792sssb15239ccdf586fc5b176846ffe4878b1aea6a36c8f"
accessControl.assignUserRole('User/auth0%7C61790e11a3966d006906596a',dbId,
"Role/collaborator").then(result=>{
console.log(result)
})add extra headers to your request
Parameters
customHeaders | object | — |
Returns
| object |
-- TerminusX API -- Delete an access request to join your team, only an admin user can delete it
Parameters
orgName | string | The organization name. |
Returns
| Promise | A promise that returns the call response object, or an Error if rejected. |
accessControl.deleteAccessRequest("djjdshhsuuwewueueuiHYHYYW.......").then(result=>{
console.log(result)
})-- TerminusDB API --- Delete an Organization
Parameters
orgName | string | The organization name to delete |
Returns
| Promise | A promise that returns the call response object, or an Error if rejected. |
accessControl.deleteOrganization("my_org_name").then(result=>{
console.log(result)
})-- TerminusX API --- Delete an invitation
Parameters
inviteId | string | The invite id to delete. |
orgName | string | The organization name. |
Returns
| Promise | A promise that returns the call response object, or an Error if rejected. |
const fullInviteId="Organization/my_team_name/invitations/Invitation/7ad0c9eb82b6175bcda9
c0dfc2ac51161ef5ba7cb0988d992c4bce82b3fa5d25"
accessControl.deleteOrgInvite(fullInviteId).then(result=>{
console.log(result)
})-- TerminusdDB API --- basic Authentication, admin user. Delete role in the system database, (this api is enabled only in the local installation)
Parameters
name | string | The role name. |
Returns
| Promise | A promise that returns the call response object, or an Error if rejected. |
accessControl.deleteRole("Reader").then(result=>{
console.log(result)
})-- TerminusdDB API --- basic Authentication, admin user. Remove the user from the system database.
Parameters
userId | string | the document user id |
Returns
| Promise | A promise that returns the call response object, or an Error if rejected. |
accessControl.deleteUser(userId).then(result=>{
console.log(result)
})--TerminusX and TerminusDB API --- Get all the system database roles types.
Returns
| Promise | A promise that returns the call response object, or an Error if rejected. |
-- TerminusDB API --- This end point works in basic authentication, admin user Get list of organizations
Returns
| Promise | A promise that returns the call response object, or an Error if rejected. |
-- TerminusdDB API --- basic Authentication, admin user. Return the list of all the users (this api is enabled only in the local installation)
Returns
| Promise | A promise that returns the call response object, or an Error if rejected. |
accessControl.getAllUsers().then(result=>{
console.log(result)
})Get a API url from cloudAPIUrl
Parameters
cloudAPIUrl | string | The base url for cloud |
Returns
| string | apiUrl |
-- TerminusX API -- Get the user's role for every databases under the organization
Parameters
userId | string | The user's id. |
orgName | string | The organization name. |
Returns
| Promise | A promise that returns the call response object, or an Error if rejected. |
accessControl.getDatabaseRolesOfUser('User/auth0%7C61790e366377Yu6596a').then(result=>{
console.log(result)
})
//this is a capabilities list of databases and roles
//[ {capability: "Capability/b395e8523d509dec6b33aefc9baed3b2e2bfadbd4c79d4ff9b20dce2b14e2edc"
//if there is an id we have a user specific capabality for this database
// name: {@type: "xsd:string", @value: "profiles_test"}
// role: "Role/dataUpdater"
// scope: "UserDatabase/7ebdfae5a02bc7e8f6d79sjjjsa4e179b1df9d4576a3b1d2e5ff3b4859"
// user: "User/auth0%7C61790e11a3966d006906596a"},
//{ capability: null
// if the capability id is null the user level of access for this database is the
same of the team
//name: {@type: "xsd:string", @value: "Collab002"}
//role: "Role/dataReader"
// scope: "UserDatabase/acfcc2db02b83792sssb15239ccdf586fc5b176846ffe4878b1aea6a36c8f"
//user: "User/auth0%7C61790e11a3966d006906596a"}]Get a organization from parameters.
Parameters
params | object | The parameters |
Returns
| string|undefined | - organization |
-- TerminusDB API --- Get an organization from the TerminusDB API.
Parameters
organization | string | The organization |
Returns
| object | - organization |
-- TerminusX API --- Get the invitation info
Parameters
inviteId | string | The invite id to retrieve. |
orgName | string | The organization name. |
Returns
| Promise | A promise that returns the call response object, or an Error if rejected. |
const fullInviteId="Organization/my_team_name/invitations/Invitation/7ad0c9eb82b6175bcda9c0dfc
2ac51161ef5ba7cb0988d992c4bce82b3fa5d25"
accessControl.getOrgInvite(fullInviteId).then(result=>{
console.log(result)
})-- TerminusX and TerminusDB API -- Get all the organization's users and roles,
Parameters
orgName | string | The organization name. |
Returns
| Promise | A promise that returns the call response object, or an Error if rejected. |
accessControl.getOrgUsers().then(result=>{
console.log(result)
})
//this function will return an array of capabilities with users and roles
//-- TerminusX -- response array example
//[{capability: "Capability/3ea26e1d698821c570afe9cb4fe81a3......"
// email: {@type: "xsd:string", @value: "user@terminusdb.com"}
// picture: {@type: "xsd:string",…}
// role: "Role/dataReader"
// scope: "Organization/my_org_name"
// user: "User/auth0%7C613f5dnndjdjkTTT"}]
//
//
// -- Local Installation -- response array example
//[{ "@id":"User/auth0%7C615462f8ab33f4006a6bee0c",
// "capability": [{
// "@id":"Capability/c52af34b71f6f8916ac0115ecb5fe0e31248ead8b1e3d100852015...",
// "@type":"Capability",
// "role": [{
// "@id":"Role/admin",
// "@type":"Role",
// "action": ["instance_read_access"],
// "name":"Admin Role"
// }],
// "scope":"Organization/@team"}]]-- TerminusX API --- Get the pending invitations list.
Parameters
orgName | string | The organization name. |
Returns
| Promise | A promise that returns the call response object, or an Error if rejected. |
const invitationList = accessControl.getPendingOrgInvites().then(result=>{
console.log(invitationList)
})
//this will return an array of invitations object like this
//[{@id: "Organization/my_team_name/invitations/Invitation/7ad0c9eb82b6175bcda9c0dfc2ac51161ef5ba
cb0988d992c4bce82b3fa5d25"
// @type: "Invitation"
// creation_date: "2021-10-22T11:13:28.762Z"
// email_to: "new_user@terminusdb.com"
// invited_by: "User/auth0%7C6162f8ab33567406a6bee0c"
// role: "Role/dataReader"
// status: "needs_invite"}]-- TerminusX API --- Get the user role for a given organization or the default organization The user is identified by the jwt or the access token
Parameters
orgName | string | The organization name. |
Returns
| Promise | A promise that returns the call response object, or an Error if rejected. |
accessControl.getTeamUserRole().then(result=>{
console.log(result)
})
//response object example
{"userRole":"Role/admin"}-- TerminusX and TerminusDB API -- Get the user roles for a given organization or the default organization,
Parameters
userName | string | The organization name. |
orgName | string | The organization name. |
Returns
| Promise | A promise that returns the call response object, or an Error if rejected. |
accessControl.getTeamUserRole("myUser").then(result=>{
console.log(result)
})
//response object example
{
"@id": "User/myUser",
"capability": [
{
"@id":"Capability/server_access",
"@type":"Capability",
"role": [{
"@id":"Role/reader",
"@type":"Role",
"action": [
"instance_read_access",
],
"name":"reader"
}],
"scope":"Organization/myteam"
}
],
"name": "myUser"
}-- TerminusX API -- Get the userinfo teams ownership and subscription
Parameters
orgName | string | The organization name. |
Returns
| Promise | A promise that returns the call response object, or an Error if rejected. |
accessControl.getUserInfo().then(result=>{
console.log(result)
})-- TerminusX API --- Check if the organization exists. it is a Head call . IMPORTANT This does not work with the API-TOKEN.
Parameters
orgName | string | The organization name to check if exists. |
Returns
| Promise | A promise that returns the call status object, 200: if the organization exists and 404: if the organization does not exist |
-- TerminusdDB API --- Grant/Revoke Capability
Parameters
userName | string | the document user id |
resourceName | string | the name of a (database or team) |
rolesArr | array | the roles name list |
operation | typedef.CapabilityCommand | grant/revoke operation |
scopeType | typedef.ScopeType | the resource type (database or organization) |
Returns
| Promise | A promise that returns the call response object, or an Error if rejected. |
//we add an user to an organization and manage users' access
//the user myUser can access the Organization and all the database under the organization with "reader" Role
client.manageCapability(myUser,myteam,[reader],"grant","organization").then(result=>{
consol.log(result)
})
//the user myUser can access the database db__001 under the organization myteam
//with "writer" Role
client.manageCapability(myUser,myteam/db__001,[writer],"grant","database").then(result=>{
consol.log(result)
})-- TerminusX API -- Remove an user from an organization, only an admin user can remove an user from an organization
Parameters
userId | string | The id of the user to be removed. (this is the document user's @id) |
orgName | string | The organization name in which the user is to be removed. |
Returns
| Promise | A promise that returns the call response object, or an Error if rejected. |
accessControl.removeUserFromOrg("User/auth0%7C613f5dnndjdjkTTT","my_org_name").then(result=>{
console.log(result)
})-- TerminusX API -- Get all the access request list for a specify organization
Parameters
email | string | the user email. |
affiliation | string | the user affiliation, company, university etc.. |
note | string | the message for the team admin |
orgName | string | The organization name. |
Returns
| Promise | A promise that returns the call response object, or an Error if rejected. |
accessControl.sendAccessRequest("myemail@terminusdb.com",
"my_company",
"please add me to your team"
).then(result=>{
console.log(result)
})-- TerminusX API --- Send a new invitation
Parameters
userEmail | string | The email of user. |
role | string | The role for user. (the document @id role like Role/collaborator) |
note | string | The note to send with the invitation. |
orgName | string | The organization name. |
Returns
| Promise | A promise that returns the call response object, or an Error if rejected. |
accessControl.sendOrgInvite("new_user@terminusdb.com","Role/admin",
"please join myteam").then(result=>{
console.log(result)
})Sets the API token for the object, to request a token create an account in https://terminusdb.com/
Parameters
atokenpi | string | The API token to use to connect with TerminusX |
Sets the API token for the object, to request a token create an account in https://terminusdb.com/
Parameters
atokenpi | string | The API token to use to connect with TerminusX |
-- TerminusX API --- Accept /Reject invitation. if the invitation has been accepted we add the current user to the organization. the only user that can accept this invitation is the user registered with the invitation email, we indentify the user with the jwt token
Parameters
inviteId | string | The invite id to updated. |
accepted | boolean | The status of the invitation. |
orgName | string | The organization name. |
Returns
| Promise | A promise that returns the call response object, or an Error if rejected. |
const fullInviteId="Organization/my_team_name/invitations/Invitation/7ad0c9eb82b6175bcda9
c0dfc2ac51161ef5ba7cb0988d992c4bce82b3fa5d25"
accessControl.updateOrgInviteStatus(fullInviteId,true).then(result=>{
console.log(result)
})-- TerminusX API -- Update user's a role for a resource (organization/database), (this api works only in terminusX)
Parameters
userId | string | The user's id. |
capabilityId | string | The capability id. |
scope | string | The resource name/id. |
role | string | The user role to be updated. |
orgName | string | The organization name. |
Returns
| Promise | A promise that returns the call response object, or an Error if rejected. |
const dbId = "UserDatabase/acfcc2db02b83792sssb15239ccdf586fc5b176846ffe4878b1aea6a36c8f"
const capId= "Capability/b395e8523d509dec6b33aefc9baed3b2e2bfadbd4c79d4ff9b20dce2b14e2edc"
accessControl.updateUserRole('User/auth0%7C61790e11a3966d006906596a',capId,dbId,
"Role/dataUpdater").then(result=>{
console.log(result)
})View
We bundle the useful functions in a View object and just export that for ease of consumption
Called to test whether a specific cell is matched by a set of rules returns array of rules that matched
Called to test whether an entire column of results is matched by a set of rules returns array of rules that matched
Called to test whether a specific edge (source -> target) is matched by a set of rules returns array of rules that matched
Called to test whether a specific node is matched by a set of rules returns array of rules that matched
Called to match an entire row of results is matched by a set of rules returns array of rules that matched
WOQLQuery
defines the internal functions of the woql query object - the
Adds quads according to the pattern [S,P,O,G]
Parameters
subject | string|Var | The IRI of a triple’s subject or a variable |
predicate | string|Var | The IRI of a property or a variable |
object | string|Var | The IRI of a node or a variable, or a literal |
graphRef | typedef.GraphRef | A valid graph resource identifier string |
Returns
| WOQLQuery |
Adds triples according to the the pattern [subject,predicate,object]
Parameters
subject | string|Var | The IRI of a triple’s subject or a variable |
predicate | string|Var | The IRI of a property or a variable |
object | string|Var | The IRI of a node or a variable, or a literal |
Returns
| WOQLQuery |
Creates a pattern matching rule for the quad [S, P, O, G] (Subject, Predicate, Object, Graph) removed from the current commit
Parameters
subject | string|Var | The IRI of a triple’s subject or a variable |
predicate | string|Var | The IRI of a property or a variable |
object | string|Var | The IRI of a node or a variable, or a literal |
graphRef- | typedef.GraphRef | A valid graph resource identifier string |
Returns
| WOQLQuery |
Creates a triple pattern matching rule for the triple [S, P, O] (Subject, Predicate, Object) added in the current layer
Parameters
subject | string|Var | The IRI of a triple’s subject or a variable |
predicate | string|Var | The IRI of a property or a variable |
object | string|Var | The IRI of a node or a variable, or a literal |
Returns
| WOQLQuery |
Parameters
Subj | string|Var | The IRI of a triple’s subject or a variable |
Pred | string|Var | The IRI of a property or a variable |
Obj | string|Var | The IRI of a node or a variable, or a literal |
Graph | typedef.GraphRef | the resource identifier of a graph possible |
Returns
| WOQLQuery | - A WOQLQuery which contains the pattern matching expression |
Parameters
Subj | string|Var | The IRI of a triple’s subject or a variable |
Pred | string|Var | The IRI of a property or a variable |
Obj | string|Var | The IRI of a node or a variable, or a literal |
Graph | typedef.GraphRef | the resource identifier of a graph possible |
Returns
| WOQLQuery | - A WOQLQuery which contains the pattern matching expression |
Logical conjunction of the contained queries - all queries must match or the entire clause fails
Parameters
subqueries | WOQLQuery | A list of one or more woql queries to execute as a conjunction |
Returns
| WOQLQuery | - A WOQLQuery object containing the conjunction of queries |
Transforms whatever is passed in as the object of a triple into the appropriate json-ld form (variable, literal or id)
Transforms whatever is passed in as the predicate (id or variable) into the appropriate json-ld form
Transforms whatever is passed in as the subject into the appropriate json-ld for variable or id
Adds a text comment to a query - can also be used to wrap any part of a query to turn it off
Parameters
comment | string | text comment |
subquery | WOQLQuery | query that is "commented out" |
Returns
| WOQLQuery |
takes a variable number of string arguments and concatenates them into a single string
Parameters
varList | array|string|Var | a variable representing a list or a list of variables or strings - variables can be embedded in the string if they do not contain spaces |
resultVarName | string|Var | A variable or string containing the output string |
Returns
| WOQLQuery | A WOQLQuery which contains the Concatenation pattern matching expression |
Creates a count of the results of the query
Parameters
countVarName | string|number|Var | variable or integer count |
subquery | WOQLQuery | — |
Returns
| WOQLQuery | A WOQLQuery object containing the count sub Query |
takes input that can be either a string (variable name) or an array - each element of the array is a member of the list
Delete a document from the graph.
Parameters
IRI | string | The document id or a variable |
Returns
| WOQLQuery | WOQLQuery |
Deletes a single triple from the graph [Subject, Predicate, Object, Graph]
Parameters
subject | string|Var | The IRI of a triple’s subject or a variable |
predicate | string|Var | The IRI of a property or a variable |
object | string|Var | The IRI of a node or a variable, or a literal |
graphRef | typedef.GraphRef | A valid graph resource identifier string |
Returns
| WOQLQuery | - A WOQLQuery which contains the Delete Quad Statement |
Deletes a single triple from the default graph of the database
Parameters
subject | string|Var | The IRI of a triple’s subject or a variable |
predicate | string|Var | The IRI of a property or a variable |
object | string|Var | The IRI of a node or a variable, or a literal |
Returns
| WOQLQuery | - A WOQLQuery which contains the Triple Deletion statement |
Filter the query to return only results that are distinct in the given variables
Parameters
varNames | string|Var | these variables are guaranteed to be unique as a tuple |
Returns
| WOQLQuery |
Division - integer division - args are divided left to right
Parameters
args | string|number|Var | numbers for division |
Returns
| WOQLQuery | A WOQLQuery which contains the division expression |
Divides numbers N1...Nn by each other left, to right precedence
Parameters
args | string|number|Var | numbers to tbe divided |
Returns
| WOQLQuery | A WOQLQuery which contains the division expression |
Extract the value of a key in a bound document.
Parameters
document | string|Var | Document which is being accessed. |
field | string|Var | The field from which the document which is being accessed. |
value | string|Var | The value for the document and field. |
Returns
| WOQLQuery | A WOQLQuery which contains the a dot Statement |
Matches if a is equal to b
Parameters
varName | string|Var | literal, variable or id |
varValue | string|Var | literal, variable or id |
Returns
| WOQLQuery |
Evaluates the passed arithmetic expression and generates or matches the result value
Parameters
arithExp | object|WOQLQuery|string | query or JSON-LD representing the query |
resultVarName | string|Var | output variable |
Returns
| WOQLQuery |
Evaluates the passed arithmetic expression and generates or matches the result value. Alias for eval() to support both naming conventions in fluent/chained style.
Parameters
arithExp | object|WOQLQuery|string | A WOQL query containing a valid arithmetic expression |
resultVarName | string|number|Var | Either a variable to store the result, or a numeric literal to test against the evaluated expression |
Returns
| WOQLQuery |
Exponent - raises varNum01 to the power of varNum02
Parameters
varNum | string|number|Var | a variable or numeric containing the number to be raised to the power of the second number |
expNum | number | a variable or numeric containing the exponent |
Returns
| WOQLQuery | A WOQLQuery which contains the exponent expression |
Transforms strings that start with v: into variable json-ld structures
Parameters
varname | unknown | will be transformed if it starts with v: |
Finds the last woql element that has a subject in that is a property id used for triplebuilder to chain further calls - when they may be inside ands or ors or subqueries
Parameters
json | object | — |
Finds the last woql element that has a subject in it and returns the json for that used for triplebuilder to chain further calls - when they may be inside ands or ors or subqueries
Parameters
json | object | — |
Generates the nearest lower integer to the passed number
Parameters
varNum | string|number|Var | Variable or numeric containing the number to be floored |
Returns
| WOQLQuery | A WOQLQuery which contains the floor expression |
Specifies the database URL that will be the default database for the enclosed query
Parameters
graphRef- | typedef.GraphRef | A valid graph resource identifier string |
query | WOQLQuery | The query |
Returns
| WOQLQuery | A WOQLQuery object containing the from expression |
Use the document inteface to import documents
Parameters
asvars | Vars|array.<Var> | an array of AsVar variable mappings (see as for format below) |
queryResource | WOQLQuery | an external resource (remote, file, post) to query |
Returns
| WOQLQuery | A WOQLQuery which contains the get expression |
Sets the graph resource ID that will be used for subsequent chained function calls
Parameters
graphRef | typedef.GraphRef | Resource String identifying the graph which will be used for subsequent chained schema calls |
Returns
| WOQLQuery | A WOQLQuery which contains the partial Graph pattern matching expression |
Sets the graph resource ID that will be used for subsequent chained function calls
Parameters
graphRef | typedef.GraphRef | Resource String identifying the graph which will be used for subsequent chained schema calls |
Returns
| WOQLQuery | A WOQLQuery which contains the partial Graph pattern matching expression |
Compares the value of v1 against v2 and returns true if v1 is greater than v2
Parameters
varNum01 | string|number|Var | a variable or numeric containing the number to be compared |
varNum02 | string|number|Var | a variable or numeric containing the second comporator |
Returns
| WOQLQuery | A WOQLQuery which contains the comparison expression |
Groups the results of the contained subquery on the basis of identical values for Groupvars, extracts the patterns defined in PatternVars and stores the results in GroupedVar
Parameters
gvarlist | array|string|Var | Either a single variable or an array of variables |
groupedvar | array|string|Var | Either a single variable or an array of variables |
output | string|Var | output variable name |
groupquery | WOQLQuery | The query whose results will be grouped |
Returns
| WOQLQuery | A WOQLQuery which contains the grouping expression |
Generates the node's ID combined the variable list with a specific prefix (URL base). If the input variables's values are the same, the output value will be the same.
Parameters
prefix | string | — |
inputVarList | string|array | the variable input list for generate the id |
outputVar | string | the output variable name |
Generates a random ID with a specified prefix Uses cryptographically secure random base64 encoding to generate unique identifiers
Parameters
prefix | string | prefix for the generated ID |
outputVar | string | variable that stores the generated ID |
Returns
| WOQLQuery | A WOQLQuery which contains the random ID generation pattern idgen_random("Person/", "v:person_id") |
Runs the query without backtracking on side-effects
Parameters
subquery | string|WOQLQuery | WOQL Query objects |
Returns
| WOQLQuery | A WOQLQuery object containing the immediately sub Query |
Parameters
id | string|Var | IRI string or variable containing |
type | string|Var | IRI string or variable containing the IRI of the |
refGraph | typedef.GraphRef | Optional Graph resource identifier |
Returns
| WOQLQuery | A WOQLQuery which contains the insert expression |
Parameters
id | string|Var | IRI string or variable containing |
type | string|Var | IRI string or variable containing the IRI of the |
refGraph | typedef.GraphRef | Optional Graph resource identifier |
Returns
| WOQLQuery | A WOQLQuery which contains the insert expression |
Insert a document in the graph.
Parameters
docjson | object | The document to insert. Must either have an '@id' or have a class specified key. |
IRI | string | An optional identifier specifying the document location. |
Returns
| WOQLQuery | WOQLQuery |
Specifies the graph resource to write the contained query into
Parameters
graphRef- | typedef.GraphRef | A valid graph resource identifier string |
subquery | WOQLQuery | The query which will be written into the graph |
Returns
| WOQLQuery | A WOQLQuery which will be written into the graph in question |
Tests whether a given instance IRI has type Class, according to the current state of the DB
Parameters
instanceIRI | string|Var | A string IRI or a variable that identify the class instance |
classId | string|Var | A Class IRI or a variable |
Returns
| WOQLQuery | A WOQLQuery object containing the type test |
Joins a list variable together (Input) into a string variable (Output) by glueing the strings together with Glue
Parameters
varList | string|array|Var | a variable representing a list or a list of strings and / or variables |
glue | string|Var | A variable (v:glue) or (glue) string representing the characters to put in between the joined strings in input |
resultVarName | string|Var | A variable or string containing the output string |
Returns
| WOQLQuery | A WOQLQuery which contains the Join pattern matching expression |
converts back and forward from json if the argument is present, the current query is set to it, if the argument is not present, the current json version of this query is returned
Parameters
json | object | a query in json format |
Returns
| object |
Calculates the length of the list in va and stores it in vb
Parameters
inputVarList | string|array | Either a variable representing a list or a list of variables or literals |
resultVarName | string|Var | A variable in which the length of the list is stored or the length of the list as a non-negative integer |
Returns
| WOQLQuery | A WOQLQuery which contains the Length pattern matching expression |
Compares the value of v1 against v2 and returns true if v1 is less than v2
Parameters
varNum01 | string|number|Var | a variable or numeric containing the number to be compared |
varNum02 | string|number|Var | a variable or numeric containing the second comporator |
Returns
| WOQLQuery | A WOQLQuery which contains the comparison expression |
Generates a string Leverstein distance measure between stringA and stringB
Parameters
stringA | string|Var | string literal or variable representing a string to be compared |
stringB | string|Var | string literal or variable representing the other string to be compared |
distance | number|string|Var | variable representing the distance between the variables |
Returns
| WOQLQuery | A WOQLQuery which contains the Like pattern matching expression |
Specifies a maximum number of results that will be returned from the subquery
Parameters
limit | number|string | A variable that refers to an non-negative integer or a non-negative integer |
subquery | WOQLQuery | A subquery whose results will be limited |
Returns
| WOQLQuery | A WOQLQuery whose results will be returned starting from the specified offset |
Creates a pattern matching rule for triple [Subject, Predicate, Object]
Parameters
subject | string|Var | The IRI of a triple’s subject or a variable |
predicate | string|Var | The IRI of a property or a variable |
object | string|Var | The IRI of a node or a variable, or a literal |
Returns
| WOQLQuery | A WOQLQuery which contains the a quad or a triple Statement |
Parameters
s | any | the value of the literal |
t | string | the type of the literal, e.g. 'xsd:string', 'xsd:boolean' |
Returns
| object | - a WOQL DataValue object with the given type and value |
Changes a string to lower-case
Parameters
inputVarName | string|Var | string or variable representing the non-lowercased string |
resultVarName | string|Var | variable that stores the lowercased string output |
Returns
| WOQLQuery | A WOQLQuery which contains the Lower case pattern matching expression |
Matches if List includes Element
Parameters
element | string|object|Var | Either a variable, IRI or any simple datatype |
list | string|array|Var | List ([string, literal] or string*) Either a variable representing a list or a list of variables or literals |
Returns
| WOQLQuery | A WOQLQuery which contains the List inclusion pattern matching expression |
Subtracts Numbers N1..Nn
Parameters
args | string|number|Var | variable or numeric containing the value that will be subtracted from |
Returns
| WOQLQuery | A WOQLQuery which contains the subtraction expression |
Parameters
node | string|Var | The IRI of a node or a variable containing an IRI which will be the subject of the builder functions |
type | typedef.FuntionType | Optional type of builder function to build (default is triple) |
Returns
| WOQLQuery | - A WOQLQuery which contains the partial Node pattern matching expression |
Specifies the identity of a node that can then be used in subsequent builder functions. Note that node() requires subsequent chained functions to complete the triples / quads that it produces - by itself it only generates the subject.
Parameters
nodeid | string|Var | The IRI of a node or a variable containing an IRI which will be the subject of the builder functions |
chainType | typedef.FuntionType | Optional type of builder function to build (default is triple) |
Returns
| WOQLQuery | - A WOQLQuery which contains the partial Node pattern matching expression |
Logical negation of the contained subquery - if the subquery matches, the query will fail to match
Parameters
subquery | string|WOQLQuery | A subquery which will be negated |
Returns
| WOQLQuery | A WOQLQuery object containing the negated sub Query |
Deletes all triples in the passed graph (defaults to instance/main)
Parameters
graphRef | typedef.GraphRef | Resource String identifying the graph from which all triples will be removed |
Returns
| WOQLQuery | - A WOQLQuery which contains the deletion expression |
Deletes all triples in the passed graph (defaults to instance/main)
Parameters
graphRef | typedef.GraphRef | Resource String identifying the graph from which all triples will be removed |
Returns
| WOQLQuery | - A WOQLQuery which contains the deletion expression |
nuke("schema/main")
//will delete everything from the schema/main graphResults in one solution of the subqueries
Parameters
subquery | string|WOQLQuery | WOQL Query objects |
Returns
| WOQLQuery | A WOQLQuery object containing the once sub Query |
Specifies that the Subquery is optional - if it does not match the query will not fail
Parameters
subquery | WOQLQuery | A subquery which will be optionally matched |
Returns
| WOQLQuery | A WOQLQuery object containing the optional sub Query |
Creates a logical OR of the arguments
Parameters
subqueries | WOQLQuery | A list of one or more woql queries to execute as alternatives |
Returns
| WOQLQuery | - A WOQLQuery object containing the logical Or of the subqueries |
Orders the results of the contained subquery by a precedence list of variables
Parameters
orderedVarlist | string|Var|array | A sequence of variables, by which to order the results, each optionally followed by either “asc” or “desc” to represent order as a list, by default it will sort the variable in ascending order |
Returns
| WOQLQuery | A WOQLQuery which contains the ordering expression |
Pads out the string input to be exactly len long by appending the pad character pad to form output
Parameters
inputVarName | string|Var | The input string or variable in unpadded state |
pad | string|Var | The characters to use to pad the string or a variable representing them |
len | number|string|Var | The variable or integer value representing the length of the output string |
resultVarName | string|Var | stores output |
Returns
| WOQLQuery | A WOQLQuery which contains the Pad pattern matching expression |
Performs a path regular expression match on the graph
Parameters
subject | string|Var | An IRI or variable that refers to an IRI representing the subject, i.e. the starting point of the path |
pattern | string | (string) - A path regular expression describing a pattern through multiple edges of the graph (see: https://terminusdb.com/docs/path-query-reference-guide) |
object | string|Var | An IRI or variable that refers to an IRI representing the object, i.e. ending point of the path |
resultVarName | string|Var | A variable in which the actual paths traversed will be stored |
Returns
| WOQLQuery | - A WOQLQuery which contains the path regular expression matching expression |
Adds the numbers together
Parameters
args | string|number|Var | a variable or numeric containing the values to add |
Returns
| WOQLQuery | A WOQLQuery which contains the addition expression |
Identifies a resource as a local path on the client, to be sent to the server through a HTTP POST request, with the format defined through the options
Parameters
url | string | The Path on the server at which the file resource can be accessed |
formatObj | typedef.DataFormatObj | imput options, optional |
source | string | It defines the source of the file, it can be 'url','post' |
Returns
| WOQLQuery | A WOQLQuery which contains the Post resource identifier |
Use the document inteface to import documents
Parameters
varsToExp | Vars|array.<Var> | an array of AsVar variable mappings (see as for format below) |
query | WOQLQuery | The query which will be executed to produce the results |
fileResource | string | an file resource local to the server |
Returns
| WOQLQuery | A WOQLQuery which contains the put expression |
Creates a pattern matching rule for the quad [S, P, O, G] (Subject, Predicate, Object, Graph)
Parameters
subject | string|Var | The IRI of a triple’s subject or a variable |
predicate | string|Var | The IRI of a property or a variable |
object | string|Var | The IRI of a node or a variable, or a literal |
graphRef | typedef.GraphRef | A valid graph resource identifier string |
Returns
| WOQLQuery |
Matches the regular expression defined in Patern against the Test string, to produce the matched patterns in Matches
Parameters
pattern | string | string or variable using normal PCRE regular expression syntax with the exception that special characters have to be escaped twice (to enable transport in JSONLD) |
inputVarName | string|Var | string or variable containing the string to be tested for patterns with the regex |
resultVarList | string|array|object|Var | variable representing the list of matches or a list of strings or variables |
Returns
| WOQLQuery | A WOQLQuery which contains the Regular Expression pattern matching expression |
Read a node identified by an IRI as a JSON-LD document
Parameters
IRI | string | The document id or a variable to read |
output | string | Variable which will be bound to the document. |
Returns
| WOQLQuery | WOQLQuery |
Identifies a remote resource by URL and specifies the format of the resource through the options
Parameters
remoteObj | object | The URL at which the remote resource can be accessed |
formatObj | typedef.DataFormatObj | The format of the resource data {} |
Returns
| WOQLQuery | A WOQLQuery which contains the remote resource identifier |
Creates a pattern matching rule for the quad [S, P, O, G] (Subject, Predicate, Object, Graph) removed from the current commit
Parameters
subject | string|Var | The IRI of a triple’s subject or a variable |
predicate | string|Var | The IRI of a property or a variable |
object | string|Var | The IRI of a node or a variable, or a literal |
graphRef- | typedef.GraphRef | A valid graph resource identifier string |
Returns
| WOQLQuery |
Creates a triple pattern matching rule for the triple [S, P, O] (Subject, Predicate, Object) added in the current commit
Parameters
subject | string|Var | The IRI of a triple’s subject or a variable |
predicate | string|Var | The IRI of a property or a variable |
object | string|Var | The IRI of a node or a variable, or a literal |
Returns
| WOQLQuery |
Filters the query so that only the variables included in [V1...Vn] are returned in the bindings
Parameters
varNames | string|Var | only these variables are returned |
Returns
| WOQLQuery |
Provides the query with a 'vocabulary' a list of well known predicates that can be used without prefixes mapping: id: prefix:id ...
Calculates the size in bytes of the contents of the resource identified in ResourceID
Parameters
resourceId | string|Var | A valid resource identifier string (can refer to any graph / branch / commit / db) |
resultVarName | string|Var | The variable name |
Extracts a contiguous subsequence from a list, following JavaScript's slice() semantics
Parameters
inputList | string|array|Var | Either a variable representing a list or a list of variables or literals |
resultVarName | string|Var | A variable in which the sliced list is stored |
start | number|string|Var | The start index (0-based, supports negative indices) |
end | number|string|Var | The end index (exclusive, optional - defaults to list length) |
Returns
| WOQLQuery | A WOQLQuery which contains the Slice pattern matching expression let [result] = vars("result") slice(["a", "b", "c", "d"], result, 1, 3) // result = ["b", "c"] slice(["a", "b", "c", "d"], result, -2) // result = ["c", "d"] |
Splits a string (Input) into a list strings (Output) by removing separator
Parameters
inputVarName | string|Var | A string or variable representing the unsplit string |
separator | string|Var | A string or variable containing a sequence of charatcters to use as a separator |
resultVarName | string|Var | variable that stores output list |
Returns
| WOQLQuery | A WOQLQuery which contains the Split pattern matching expression |
Generates a query that by default matches all triples in a graph identified by "graph" or in all the current terminusDB's graph
Parameters
graph | string|boolean | false or the resource identifier of a graph possible value are schema/{main - myschema - *} | instance/{main - myschema - *} | inference/{main - myschema - *} |
subject | string|Var | The IRI of a triple’s subject or a variable, default value "v:Subject" |
predicate | string|Var | The IRI of a property or a variable, default value "v:Predicate" |
object | string|Var | The IRI of a node or a variable, or a literal, default value "v:Object" |
Returns
| WOQLQuery | A WOQLQuery which contains the pattern matching expression |
Specifies an offset position in the results to start listing results from
Parameters
start | number|string|Var | A variable that refers to an interger or an integer literal |
subquery | WOQLQuery | WOQL Query object, you can pass a subquery as an argument or a chained query |
Returns
| WOQLQuery | A WOQLQuery whose results will be returned starting from the specified offset |
Returns true if ClassA subsumes ClassB, according to the current DB schema
Parameters
classA | string | ClassA |
classB | string | ClassB |
Returns
| boolean | WOQLQuery |
Substring
Parameters
string | string|Var | String or variable |
before | number|Var | integer or variable (characters from start to begin) |
length | number|Var | integer or variable (length of substring) |
after | number|Var | integer or variable (number of characters after substring) |
subString | string|Var | String or variable |
Returns
| WOQLQuery |
computes the sum of the List of values passed. In contrast to other arithmetic functions, sum self-evaluates - it does not have to be passed to evaluate()
Parameters
subquery | WOQLQuery | a subquery or ([string or numeric]) - a list variable, or a list of variables or numeric literals |
total | string|Var | the variable name with the sum result of the values in List |
Returns
| WOQLQuery | - A WOQLQuery which contains the Sum expression |
Multiplies numbers N1...Nn together
Parameters
args | string|number|Var | a variable or numeric containing the value |
Returns
| WOQLQuery | A WOQLQuery which contains the multiplication expression |
Remove whitespace from both sides of a string:
Parameters
inputStr | string|Var | A string or variable containing the untrimmed version of the string |
resultVarName | string|Var | A string or variable containing the trimmed version of the string |
Returns
| WOQLQuery | A WOQLQuery which contains the Trim pattern matching expression |
Creates a triple pattern matching rule for the triple [S, P, O] (Subject, Predicate, Object)
Parameters
subject | string|Var | The IRI of a triple’s subject or a variable |
predicate | string|Var | The IRI of a property or a variable |
object | string|Var | The IRI of a node or a variable, or a literal |
Returns
| WOQLQuery |
Calculates the number of triples of the contents of the resource identified in ResourceID
Parameters
resourceId | string|Var | A valid resource identifier string (can refer to any graph / branch / commit / db) |
tripleCount | string|number|Var | An integer literal with the size in bytes or a variable containing that integer |
Returns
| WOQLQuery | A WOQLQuery which contains the size expression |
A function that always matches, always returns true
Returns
| WOQLQuery | A WOQLQuery object containing the true value that will match any pattern |
Returns true if 'elementId' is of type 'elementType', according to the current DB schema
Parameters
elementId | string|Var | the id of a schema graph element |
elementType | string|Var | the element type |
Returns
| WOQLQuery | A WOQLQuery object containing the type_of pattern matching rule |
Casts the value of Input to a new value of type Type and stores the result in CastVar
Parameters
varName | string|number|object|Var | Either a single variable or a literal of any basic type |
varType | string|Var | Either a variable or a basic datatype (xsd / xdd) |
resultVarName | string|Var | save the return variable |
Returns
| WOQLQuery | A WOQLQuery which contains the casting expression |
Generate a new IRI from the prefix and a hash of the variables which will be unique for any given combination of variables
Parameters
prefix | string | A prefix for the IRI - typically formed of the doc prefix and the classtype of the entity (“doc:Person”) |
inputVarList | array|string|Var | An array of variables and / or strings from which the unique hash will be generated |
resultVarName | string|Var | Variable in which the unique ID is stored |
Returns
| WOQLQuery | A WOQLQuery object containing the unique ID generating function |
Update a document identified by an IRI
Parameters
docjson | object | The document to update. Must either have an '@id' or have a class specified key. |
IRI | string | An optional identifier specifying the document location. |
Returns
| WOQLQuery | WOQLQuery |
Update a pattern matching rule for the quad [S, P, O, G] (Subject, Predicate, Object, Graph)
Parameters
subject | string | The IRI of a triple’s subject or a variable |
predicate | string | The IRI of a property or a variable |
newObject | string | The value to update or a literal |
graph | string | the resource identifier of a graph possible value are schema/{main - myschema - *} | instance/{main - myschema - *} | inference/{main - myschema - *} |
Returns
| WOQLQuery | A WOQLQuery which contains the a Update Quad Statement |
Update a pattern matching rule for the quad [S, P, O, G] (Subject, Predicate, Object, Graph)
Parameters
subject | string|Var | The IRI of a triple’s subject or a variable |
predicate | string|Var | The IRI of a property or a variable |
newObject | string|Var | The value to update or a literal |
graphRef | typedef.GraphRef | A valid graph resource identifier string |
Returns
| WOQLQuery | A WOQLQuery which contains the a Update Quad Statement |
Update a pattern matching rule for the triple (Subject, Predicate, oldObjValue) with the new one (Subject, Predicate, newObjValue)
Parameters
subject | string|Var | The IRI of a triple’s subject or a variable |
predicate | string|Var | The IRI of a property or a variable |
newObjValue | string|Var | The value to update or a literal |
oldObjValue | string|Var | The old value of the object |
Returns
| WOQLQuery | A WOQLQuery which contains the a Update Triple Statement |
Update a pattern matching rule for the triple (Subject, Predicate, oldObjValue) with the new one (Subject, Predicate, newObjValue)
Parameters
subject | string|Var | The IRI of a triple’s subject or a variable |
predicate | string|Var | The IRI of a property or a variable |
newObjValue | string|Var | The value to update or a literal |
oldObjValue | string|Var | The old value of the object |
Returns
| WOQLQuery | A WOQLQuery which contains the a Update Triple Statement |
Changes a string to upper-case
Parameters
inputVarName | string|Var | string or variable representing the uncapitalized string |
resultVarName | string|Var | variable that stores the capitalized string output |
Returns
| WOQLQuery | A WOQLQuery which contains the Upper case pattern matching expression |
Query running against any specific commit Id
Parameters
refPath | string | path to specific reference Id or commit Id |
subquery | WOQLQuery | subquery for the specific commit point |
Returns
| WOQLQuery |
Creates a pattern matching rule for triple [Subject, Predicate, Object] add extra information about the type of the value object
Parameters
subject | string|Var | The IRI of a triple’s subject or a variable |
predicate | string|Var | The IRI of a property or a variable |
objValue | string|number|boolean|Var | an specific value |
Returns
| WOQLQuery | A WOQLQuery which contains the a quad or a triple Statement |