鍍金池/ 問答/HTML/ 小程序里knex操作騰訊云的云數(shù)據(jù)庫MySQL,總是出錯,求解

小程序里knex操作騰訊云的云數(shù)據(jù)庫MySQL,總是出錯,求解

如下,我自己單獨嘗試連接mysql和騰訊暴露的接口連接都不行,求大神幫忙指導(dǎo)下。
另外,我將后端代碼上傳到騰訊云上面了,如何查看后端代碼console.log的打印數(shù)據(jù)?

module.exports = async (ctx, next) => {

  if (ctx.state.$wxInfo.loginState === 1) {
  
    /*const { mysql: config } = require('../config');
    var knex = require('knex')({
      client: 'mysql',
      connection: {
        host: config.host,
        port: config.port,
        user: config.user,
        password: config.pass,
        database: config.db,
        charset: config.char,
        multipleStatements: true
      }
    });
    knex('question_sort').select('id').then(res => {
       console.log(res)
      ctx.state.data = res;
    })*/
    
    const { mysql } = require('../qcloud')
    mysql('question_sort').select('id').then(res => {
      ctx.state.data = res;
    })
    
  } else {
    ctx.state.code = -1
  }
}
回答
編輯回答
執(zhí)念

mysql查詢也是異步,前面加await就好了

2017年9月8日 11:15
編輯回答
還吻

樓主,你的問題解決了嗎?能交流一下你最后是怎么做的嗎?

2017年3月20日 15:00