试图从Node应用程序查询本地运行的Stardog数据库。
查询在Stardog接口中运行时返回结果。
当在Node中运行它时,某些东西会破坏返回null和错误的承诺。
(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);
});发布于 2018-02-20 17:43:00
你不能在承诺中处理错误。
query.execute(conn, 'hospital_db', q, {
}).then(({ body }) => {
console.log(body.results.bindings);
}).catch((err) => {
console.log(err);
})发布于 2018-02-20 17:49:04
你应该在你的承诺链上加一个陷阱。
query.execute(conn, 'hospital_db', q, {
}).then(({ body }) => {
console.log(body.results.bindings);
}).catch( (err) => {
console.log(err);
})发布于 2018-02-20 18:37:37
‘s的连接对象接受端点、用户名、密码和元对象,而您有一个auth对象。您可以在https://github.com/stardog-union/stardog.js#connectionoptions的文档中看到这一点。
https://stackoverflow.com/questions/48891159
复制相似问题