drizzle-team / drizzle-team/drizzle-orm
[FEATURE]: BATCH API in node-postgres
- Dominant language
- TypeScript
- Stars
- 35.8k
- Forks
- 1.6k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 4
Description
### Feature hasn't been suggested before.
- [X] I have verified this feature I'm about to request hasn't been suggested before.
### Describe the enhancement you want to request
Reopening https://github.com/drizzle-team/drizzle-orm/issues/2291
Saw this was closed, but wondering why. Assume the following code:
```ts
await db.transaction(async (tx) => {
await tx.update(...);
await tx.update(...);
});
```
This will perform 2 updates inside a transaction. If one fails, the transaction fails. We can speed this up by putting each update inside a Promise.all, but we are still making 3 trips to our database:
1. start transaction
2. update rows
3. end transaction
It would be much more efficient to do something like
```ts
db.batch([
db.update(...),
db.update(...)
]);
```
Under the hood this could produce a single SQL statement that does the following:
```sql
BEGIN;
UPDATE table1 SET column_name1 = 'new_value' WHERE condition1;
UPDATE table2 SET column_name2 = 'new_value' WHERE condition2;
COMMIT;
```
Now I only have one chunk of SQL being sent to the database rather than 3.
Contributor guide
Assessment
This issue has not been assessed yet.