How can I do bulk update via raw query in TypeORM?
For example we have model User with property name
How can I change names of few users in one transaction?
typeorm version: 0.2.7
database: postgress
To bulk update, you can use update with set method, it is always recommended to not use raw queries when you can use orm functions.
TypeORM is an Object Relational Mapper library running in node. js and written in TypeScript. TypeScript is an improvement to JavaScript with optional typing. TypeScript is a compiled language. It is not interpreted at run-time.
To bulk update, you can use update with set method, it is always recommended to not use raw queries when you can use orm functions.
import {getConnection, In} from "typeorm";
const userIds = [1,2,3];
await getConnection()
.createQueryBuilder()
.update(User)
.set({ isaSeniorCitizen: true })
.where({ id: In(userIds) })
.execute();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With