ENAPSO Graph Database Client for Node.js
npm install @innotrade/enapso-graphdb-clientuseQleverBinding option that provides total count information even when using LIMIT and OFFSET clauses
setAccessToken() method for runtime token updates (QLever-only feature)
npm i @innotrade/enapso-graphdb-client --save
`
Create the connection with graph database
`javascript
const { EnapsoGraphDBClient } = require('@innotrade/enapso-graphdb-client');
let graphDBEndpoint = new EnapsoGraphDBClient.Endpoint({
baseURL: 'http://localhost:7200',
repository: 'Test',
triplestore: 'graphdb', // 'graphdb' or 'fuseki' or 'stardog' or 'qlever'
prefixes: [
{
prefix: 'entest',
iri: 'http://ont.enapso.com/test#'
}
],
transform: 'toCSV'
});
`
$3
| Parameter | Type | Description | Values |
| --------------------- | ---------------- | ---------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------- |
| baseURL(required) | String | Pass the URL in which graph database is running. | |
| repository(required) | String | Pass the name of the repository or database of the graph databases with which you want to create a connection. | |
| prefixes(required) | Array of objects | Pass the prefix and its IRI as an object which will be used in the SPARQL query to perform crud operations. | |
| triplestore(optional) | String | Pass the name of the graph database with which you want to create a connection by default it creates a connection with Ontotext GraphDB. | ('graphdb' , 'stardog' , 'fuseki' , 'qlever') |
| transform(optional) | String | Pass the type in which you want to show the result of SPARQL query by default it shows the result in JSON format. | ('toJSON', 'toCSV' , 'toTSV') |
📋 Features
| Feature | Description | Ontotext GraphDB | Apache Jena Fuseki | Stardog | QLever |
| -------------------- | ------------------------------------------------------------------ | ---------------- | ------------------ | ------- | ------ |
| Login | Authenticate user against the graph database | ✔ | ✘ | ✔ | ✘* |
| Query | To retrieve the information from graph database using SPARQL query | ✔ | ✔ | ✔ | ✔ |
| Update | To update the triples in the graph database | ✔ | ✔ | ✔ | ✔** |
| setAccessToken | Set access token to perform update. | ✘ | ✘ | ✘ | ✔ |
*QLever uses access tokens instead of traditional login
**Requires access token for update operations
Authentication
Authenticate against the graph database :
`
graphDBEndpoint.login('admin','root').then((result) => {
console.log(result);
})
.catch((err) => {
console.log(err);
});
`
Query
Query the graph database:
`
graphDBEndpoint
.query(
'select *
where {
?class rdf:type owl:Class
filter(regex(str(?class), "http://ont.enapso.com/test#TestClass", "i")) .
}',
{ transform: 'toJSON' }
)
.then((result) => {
console.log(
'Read the classes name:\n' + JSON.stringify(result, null, 2)
);
})
.catch((err) => {
console.log(err);
});
`
Update
Update the graph database:
`
graphDBEndpoint
.update(
insert data {
)
.then((result) => {
console.log('inserted a class :\n' + JSON.stringify(result, null, 2));
})
.catch((err) => {
console.log(err);
setAccessToken
Set or update access token dynamically (QLever only):
`javascript
// Set or update access token dynamically
qleverEndpoint.setAccessToken('your-new-access-token');
// Now you can perform operations with the new token
qleverEndpoint
.query('SELECT * WHERE { ?s ?p ?o } LIMIT 5')
.then((result) => {
console.log('Query with new token:', JSON.stringify(result, null, 2));
});
`
$3
QLever's unique
useQleverBinding feature allows you to get the total count of results even when using LIMIT and OFFSET:
`javascript
qleverEndpoint
.query(
SELECT ?subject ?predicate ?object WHERE {
,
{
transform: 'toJSON',
useQleverBinding: true // Get total count with pagination
}
)
.then((result) => {
console.log('Query results:', JSON.stringify(result, null, 2));
// Result will include both the limited results and total count
})
.catch((err) => {
console.log(err);
});
``