在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ koa.js 中使用 knex.js 問題

koa.js 中使用 knex.js 問題

const { mysql } = require('../qcloud')

module.exports = async (ctx, next) => {
    mysql('cAppinfo').select('*').then(res => {
        ctx.state.code = 0
        ctx.state.data = res
    }).catch(err => {
        ctx.state.code = -1
        throw new Error(err)
    })
}

這段代碼放在app.js文件下可以打印出正確的數(shù)據(jù),卻在controllers文件夾下進(jìn)入不到then階段

項目克隆自:https://github.com/tencentyun...

卡在這里好久了,求指導(dǎo)?

回答
編輯回答
尛憇藌

const { mysql } = require('../qcloud')
module.exports = async (ctx, next) => {

await mysql('cAppinfo').select('*').then(res => {
    ctx.state.code = 0
    ctx.state.data = res
}).catch(err => {
    ctx.state.code = -1
    throw new Error(err)
})

}

改成這個樣子試試

2017年12月13日 04:02
編輯回答
北城荒

mysql('cAppinfo').select('*') 進(jìn)來了么

2017年10月2日 00:20
編輯回答
網(wǎng)妓

你的配置文件路徑有改嗎

2017年8月9日 06:24
編輯回答
離魂曲

因為查詢數(shù)據(jù)庫是異步,所以在mysql前面加await。

2017年9月9日 11:24
編輯回答
傻叼

在什么地方添加await,我的添加了直接上傳不了

2017年6月6日 10:09