Does drizzle support a way to make an array transaction?

In prisma, you can do something like this
await db.$transaction([query1, query2])
await db.$transaction([query1, query2])
Is there a way to do something analogous in drizzle? I know you can do something like
await db.$transaction(async (tx) => {
await query1;
await query2;
});
await db.$transaction(async (tx) => {
await query1;
await query2;
});
but this makes 2 db trips instead of 1.
4 Replies
jakeleventhal
jakeleventhalOP13mo ago
is this the same thing as https://orm.drizzle.team/docs/batch-api
Drizzle ORM - next gen TypeScript ORM
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
Angelelz
Angelelz13mo ago
The bacth API is only supported in some drivers Transactions are used to run queries serially. If the queries don't have relations between each other that you can run them parallel, you might as well just use promise.all outside a transaction
jakeleventhal
jakeleventhalOP13mo ago
why wont the batch api work in postgres for instance? it works in prisma if it is dependent, without the batch api it requires two trips to db
Angelelz
Angelelz13mo ago
because postgres.js doesn't support batches. Whatever prisma is doing, is not batching. It's probably promise.all under the hood (which will be crazy if they are calling it $transaction), or just running them sequentially for you.
Want results from more Discord servers?
Add your server