Closed alexgleason closed 6 months ago
It also reserves a single connection. The transaction object passed to the callback is bound to that single connection. begin
and commit
/rollback
is called on that connection automatically.
As long as you use the object passed to the callback, queries are run inside the transaction. If you use another transaction object or the "global" db
object, you run things outside the transaction.
Kysely has a transaction API that wraps a block of code in a callback. But from what I can tell, it just sends a
begin
query at the start, and acommit
query at the end. Does it do anything else to keep queries in a transaction together? What prevents async code from putting queries in the wrong transaction?I am using a custom SQLite adapter (kysely-deno-sqlite) I modified from the stock SQLite adapter, and I now need to extend it to use a worker pool. How can I detect that queries are part of a transaction in my adapter and ensure I send them to the right worker?