egg-mysql 在查询时如何使用 where in

2026-06-05 84 浏览 0 评论

egg-mysql 插件是基于 ali-rds 实现一个简单的链接插件,官方推荐的 MySQL 数据库连接器,今天要在更新的时候批量操作,要实现原生的 where in 查询功能,去查找相关的文档,发现 egg.js 和 egg-mysql 文档中均为提及如果实现 where in​ 的写法。

翻阅 ali-rds 源码, https://github.com/ali-sdk/ali-rds/blob/master/lib/operator.js 在 318 行处,有如下代码

wheres.push('?? IN (?)');

通过源码得知,in 的实现方式如下

let ids = [50, 15, 15];
let result = await this.app.mysql.update("table", rows, { where: { id: ids ​}});

也就是说,如果 where 条件传递的是数组,那么就会使用 where in 来拼合 sql。


发布评论

发布评论前请先 登录
取消
0 评论
点赞
收藏

评论列表 0

暂无评论