Running concurrent queries

Hi so maybe this is more of a SQL question sorry if so. So I understand the benefit of transaction is to do all of those queries as a unit and you can roll back all the changes if one fails for example. I also understand you can add await inside the transaction requests if you need them to be dependant on each other. If I want to just send a bunch of non-dependant queries that get executed in parallel in one request to my DB for example updating a users name in the user table and there bio in the profiles table in one go, would it be best just to promise.all a bunch of normal queries or should I use transaction or batch in this case (I use supabase so not sure if batch is supported with drizzle for me) Essentially just wondering about what the best methods for scenarios like the above is performance wise. I'm also using serverless so I prefer to limit my number of connections to db where possible. And I assume promise.all approach might make multiple requests albeit in parallel? p.s. I also found this question unanswered before making this post https://discord.com/channels/1043890932593987624/1183316306552954960/1183316306552954960
2 Replies
Angelelz
Angelelz13mo ago
If your queries don't depend on each other, promise.all or promise.allSettled are good options If your driver/drizzle supports batching even better Transactions are suppose to run on a single connection, so even if you use promise.all they'll probably won't get parallelized
Sam
SamOP13mo ago
Thanks for the helpful answers as always @Angelelz !
Want results from more Discord servers?
Add your server