【发布时间】:2019-07-30 07:43:09
【问题描述】:
我正在使用 KnexJS 承诺查询数据库。我能够在async/await 中获得结果,但是当我使用 Knex 承诺时,我无法访问承诺中的then 和catch 部分的ctx 对象。 console.log(results) 在控制台中显示结果。
这是我的代码:
router.get('/profile', async ctx => {
'http://localhost:8000/profile'
ctx.knex
.select().from('profile')
.then(results => {
console.error(results)
this.body = results
})
.catch(error => {
console.log(error)
this.throw(500, "Inside Error")
})
})
【问题讨论】:
-
为什么不想使用 Async/await?
-
因为为什么不呢? @technogeek1995