Issuing multiple sql queries in order, but without waiting for round trips?

I need to run several commands to set up transaction variables for my use case. They need to be run in order, but I don't need the result of any of them. Is there a way to issue e.g. 3 sequential commands in a single query to the database so I don't have to wait for the round trip for each one, like happens now with await tx.execute(.....) 3 times in a row?
12 Replies
Angelelz
Angelelz9mo ago
Stack Overflow
Execute an Array of promises sequentially without using async/await
Lets say I have an array of promises. Each element of my array is a knex.js query builder and is ready to be executed and returns a promise. How can I run each element of this array sequentially. ...
Angelelz
Angelelz9mo ago
I've never tried it but it looks interesting The problem I see with this is that they will wait for the previous one The other think is sending the promise without awaiting, one after the other But then your synchronous code will probably run before the the first 3 resolves. I don't know how bad will it be Lastly, I believe that postgres-js has an API for this. But you'll need to use it directly without drizzle
francis
francis9mo ago
yeah, this is exactly the same as await 1; await 2; await 3
francis
francis9mo ago
hm I'm not sure postgres-js does this either. looks like it's a new postgres feature in 14 https://www.postgresql.org/docs/devel/libpq-pipeline-mode.html
PostgreSQL Documentation
33.5. Pipeline Mode
33.5. Pipeline Mode # 33.5.1. Using Pipeline Mode 33.5.2. Functions Associated with Pipeline Mode 33.5.3. When to Use Pipeline Mode libpq …
Angelelz
Angelelz9mo ago
Not Postgres, I meant postgres-js
Angelelz
Angelelz9mo ago
GitHub
GitHub - porsager/postgres: Postgres.js - The Fastest full featured...
Postgres.js - The Fastest full featured PostgreSQL client for Node.js, Deno, Bun and CloudFlare - GitHub - porsager/postgres: Postgres.js - The Fastest full featured PostgreSQL client for Node.js, ...
Angelelz
Angelelz9mo ago
There is an option to give the transaction an array of queries
francis
francis9mo ago
ah yes, that is the pipelining feature I was talking about hm is there any way to get access to the underlying postgres-js transaction instance from a drizzle transaction instance?
Angelelz
Angelelz9mo ago
No, if you want to go this route you'll need to export the same driver that you pass to drizzle so you can use it directly like this
francis
francis9mo ago
ah, the problem is that I want to issue these pipelined commands in the same transaction that I then use to do drizzle things in guess there is no way to do so
Angelelz
Angelelz9mo ago
This should be easy to implement because the driver supports it. Can you add a feature request? Now, I don't really know if postgres-js actually makes only one network round trip
francis
francis9mo ago
ah, it doesn't actually work, since you can't provide the array and also do normal transaction functional stuff. I didn't realize that at first. but thank you for looking!
Want results from more Discord servers?
Add your server