尝试从 Node JS 应用程序查询本地运行的 Stardog 数据库。
该查询在 Stardog 界面中运行时返回结果。
在 Node 中运行它时,返回 null 和错误的 promise 搞砸了。
(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.
我在 Node 中运行的代码是:
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);
});