egg-mysql 执行任何查询都不返回结果,日志里也不报错

Created on 25 Mar 2017  ·  18Comments  ·  Source: eggjs/egg

  • Node Version: 7.7.4
  • Egg Version: 1.0.0
  • Plugin Name: egg-mysql
  • Plugin Version: 2.0.0
  • Platform: windows 7 sp1 x64

Most helpful comment

已经在 ali-rds 层做了改造,支持直接 await 调用了

All 18 comments

请给出具体代码

async getUserByName(username) {
const user = await app.mysql.get('admin_user', {
user_id: 1,
});
console.log(username);
console.log(user);
return user;
}

let test = await app.mysql.query('select * from admin_user where user_name = ?', [username]);

我发现不管SQL语句是对的还是错的,都不报错,实际上没有执行?

另外如果把MYSQL配置文件注释掉,会报错

host改成一个不存在的地址,也不报错

控制台看不到任何信息

请问如何开始trace?

544

参考这个问题
原因是: egg-mysql包装了ali-rds
后者不支持promise所以不能使用async/await

一个解决方法是 用co包装

// app.js
const co = require('co');
module.exports = app => {
  app.beforeStart(async () => {
      ['insert', 'get', 'select', 'update', 'delete', 'query'].forEach(func => {
        app.mysql[func] = co.wrap(app.mysql[func]);
      });
    });
};

好的,明白了。

多谢!

@dead-horse since more and more user will use async, should we wrap promise or add description at README?

我也是怎么也调不到mysql,原来是用了async/await的原因,这问题应该在文档中特别强调或者修正下!!

mysql 的文档我也加一下

已经在 ali-rds 层做了改造,支持直接 await 调用了

重新安装依赖即可

上面那个文档要干掉么

@dead-horse 效率真高!

文档先别干掉,肯定还有其他插件有 generator function 的接口的,看到再改吧

报错信息或者可复现代码提供一下。 @justinli0709

@justinli0709 知道了,稍等我修复一下

Was this page helpful?
0 / 5 - 0 ratings

Related issues

whlsxl picture whlsxl  ·  3Comments

Ailein picture Ailein  ·  3Comments

yuu2lee4 picture yuu2lee4  ·  3Comments

popomore picture popomore  ·  3Comments

wujianling picture wujianling  ·  3Comments