gpt4 book ai didi

node.js - 通过 typeorm 中的原始查询批量更新

转载 作者:行者123 更新时间:2023-12-04 00:29:10 25 4
gpt4 key购买 nike

如何通过 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com