美文网首页
Egg MySQL 查 具体使用方法参数详解

Egg MySQL 查 具体使用方法参数详解

作者: 张思学 | 来源:发表于2020-05-19 16:15 被阅读0次

针对查询数据库返回数据的条件进行详细描述

代码
class UserList extends Service {
  async list() {
   // 查 mysql 数据 ( ' 表名 ', {条件})
    const users = await this.app.mysql.select('user', {
      columns: [ 'id', 'name' ], // 查询字段,全部查询则不写,相当于查询*
      where: {
        name: '张思学',
      }, // 查询条件
      orders: [
        [ 'id', 'desc' ],
      ], // 降序desc,升序asc
      limit: 10, // 查询条数
      offset: 0, // 数据偏移量(分页查询使用)
    });
    return { users };
  }
}

相关文章

网友评论

      本文标题:Egg MySQL 查 具体使用方法参数详解

      本文链接:https://www.haomeiwen.com/subject/gnmbohtx.html