首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用NodeJS查询Stardog时的承诺错误

使用NodeJS查询Stardog时的承诺错误
EN

Stack Overflow用户
提问于 2018-02-20 17:38:08
回答 3查看 144关注 0票数 2

试图从Node应用程序查询本地运行的Stardog数据库。

查询在Stardog接口中运行时返回结果。

当在Node中运行它时,某些东西会破坏返回null和错误的承诺。

代码语言:javascript
复制
(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中运行的代码是:

代码语言:javascript
复制
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);
});
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2018-02-20 17:43:00

你不能在承诺中处理错误。

代码语言:javascript
复制
query.execute(conn, 'hospital_db', q, {
}).then(({ body }) => {
  console.log(body.results.bindings);
}).catch((err) => {
  console.log(err);
})
票数 1
EN

Stack Overflow用户

发布于 2018-02-20 17:49:04

你应该在你的承诺链上加一个陷阱。

代码语言:javascript
复制
 query.execute(conn, 'hospital_db', q, {
    }).then(({ body }) => {
        console.log(body.results.bindings);
    }).catch( (err) => {
        console.log(err);
    })
票数 1
EN

Stack Overflow用户

发布于 2018-02-20 18:37:37

‘s的连接对象接受端点、用户名、密码和元对象,而您有一个auth对象。您可以在https://github.com/stardog-union/stardog.js#connectionoptions的文档中看到这一点。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48891159

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档