eggjs / egg

🥚 Born to build better enterprise frameworks and apps with Node.js & Koa

Home Page:https://eggjs.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

egg-mysql插件查询问题

shinji3887 opened this issue · comments

commented

请详细告知你的新点子(Nice Ideas):

官方文档中查询是这么写的:

const results = await this.app.mysql.select('posts', { // 搜索 post 表
  where: { status: 'draft', author: ['author1', 'author2'] }, // WHERE 条件
  columns: ['author', 'title'], // 要查询的表字段
  orders: [['created_at','desc'], ['id','desc']], // 排序方式
  limit: 10, // 返回数据量
  offset: 0, // 数据偏移量
});

=> SELECT `author`, `title` FROM `posts`
  WHERE `status` = 'draft' AND `author` IN('author1','author2')
  ORDER BY `created_at` DESC, `id` DESC LIMIT 0, 10;

那么如何做sql中的大于、小于、between、count、distinct这些操作呢?

egg-mysql封装了ali-rds,ali-rds文档db.count()方法统计数量,其他操作应该可以直接query拼接sql去查询