Trying to query a locally run Stardog database from a Node JS application.
The query returns results when run in the Stardog interface.
When running it in Node, something gets messed up with the promise which returns null and an error.
(node:1248) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: Cannot read property 'results' of null
(node:1248) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
The code i'm running in Node is:
const { Connection, query } = require('stardog');
const conn = new Connection({
endpoint: 'http://localhost:5820',
auth: {
user: 'admin',
pass: 'admin'
}
});
var q = 'select distinct ?s where { ?s ?p ?o }'
query.execute(conn, 'hospital_db', q, {
}).then(({ body }) => {
console.log(body.results.bindings);
});
You are not handling error in promise.
query.execute(conn, 'hospital_db', q, {
}).then(({ body }) => {
console.log(body.results.bindings);
}).catch((err) => {
console.log(err);
})