Repository navigation
feat(sdk): add proc/func/tvf to the transaction handle - #115
Merged
Merged
Conversation
ctx.transaction(fn) hands fn a Kysely Transaction carrying typed proc/func/tvf on the transaction's connection, so a routine call runs under SET LOCAL settings such as statement_timeout and rolls back with the transaction. Inside a transaction, postgres proc picks CALL or SELECT from a pg_proc lookup: a failed CALL aborts the transaction, and a savepoint retry would roll back sibling statements run on the same handle. Closes #106
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ctx.transaction(fn)handsfnaTransactionScope: the KyselyTransaction<DB>plus typedproc/func/tvfon the transaction's connection.scope.transaction(fn)insideimpersonate()gets the same handle type.SET LOCAL statement_timeout = '8s'followed bytrx.tvf(...), and rolls back with the transaction.trx.procpicksCALLorSELECT * FROMfrom apg_proclookup instead of try-and-fall-back. A failedCALLaborts the transaction, and a savepoint retry would silently roll back sibling statements on the same handle (reproduced live, 2 of 3 rows committed).What this solves
Typed routine calls were unavailable inside a transaction, so a per-call
statement_timeoutforced rawsql. The issue's per-call{ statementTimeout }option is not built;SET LOCALon the handle covers it and every other transaction-scoped setting.Known edge: a name that is both a procedure and a function routes to
CALL, which fails if Postgres resolves it to the function;trx.tvfreaches the function. Documented in the reference and dev guide.ImpersonatedScope.procnow also falls back toSELECTfor a Postgres function (it threw before).Closes #106