|
|
|
|
|
by mattashii
1291 days ago
|
|
HTTP does not (easily) allow for using answers of earlier queries in the transaction. E.g. BEGIN;
INSERT INTO my_table (...) RETURNING (id);
SELECT count(\*) AS my_count FROM my_table;
INSERT INTO historical (new_id, value_derived_from_count, now());
COMMIT;
is difficult (or potentially impossible) to do transactionally using single HTTP queries. Sure, you can rewrite your queries to use single-statement queries if you're lucky, but for others that may take a lot of work. Keeping a transaction alive over WebSocket allows you to easily have transaction states that last longer than the lifetime of the first request, which allows for transactions of which state is processed in more than one place. |
|
But of course for the user of the driver it might be fine if that is 2 or more HTTP requests. I expect that is how PlanetScale does it in their transaction implementation, https://github.com/planetscale/database-js#transactions, and I know that is how Prisma Data Proxy handles it - the transaction is identified with an ID which is returned to the Client and then included in further requests for the same transaction.
It's valid tradeoff to make to prefer a persistent connection to keep the overhead for multiple queries in a transaction as low as possible - which seems what Neon has done here.