如何通过 typeorm 中的原始查询进行批量更新?
例如,我们有带有属性名称的模型用户
如何在一笔交易中更改少数用户的姓名?
typeorm 版本: 0.2.7
数据库:发表后
最佳答案
要批量更新,您可以使用 set 方法更新,当您可以使用 orm 函数时,始终建议不要使用原始查询。
import {getConnection, In} from "typeorm";
const userIds = [1,2,3];
await getConnection()
.createQueryBuilder()
.update(User)
.set({ isaSeniorCitizen: true })
.where({ id: In(userIds) })
.execute();
关于node.js - 通过 typeorm 中的原始查询批量更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53790994/