1. this.app.mysql.get("data_options", {value: "xxx"}); // 查询一个内容
  2. this.app.mysql.insert("i18n_config", [{...}]); // 批量添加
  3. this.app.mysql.select("i18n_config", {
  4. where: {
  5. id: 10000
  6. }
  7. });
  8. await this.app.mysql.update('i18n_comment', {
  9. id: i18nComment.id, // 修改时,一定需要id作为索引进行修改
  10. comment,
  11. en_unique_md5,
  12. cn_value: cnValue,
  13. });
  14. await this.app.mysql.select("select * from i18n_config_status_data where id = ?", [1000]),

事务

  1. const conn = yield app.mysql.beginTransaction();
  2. try {
  3. yield conn.insert(table, row1);
  4. yield conn.update(table, row2);
  5. yield conn.commit();
  6. } catch (err) {
  7. // error, rollback
  8. yield conn.rollback(); // rollback call won't throw err
  9. throw err;
  10. }
  11. const result = yield app.mysql.beginTransactionScope(function* (conn) {
  12. // don't commit or rollback by yourself
  13. yield conn.insert(table, row1);
  14. yield conn.update(table, row2);
  15. return { success: true };
  16. }, ctx); // ctx is the context of current request, access by `this.ctx`.
  17. // if error throw on scope, will auto rollback