Skip to content

feat(sdk): add proc/func/tvf to the transaction handle - #115

Merged
damusix merged 1 commit into
masterfrom
sdk-transaction-routines
Oct 26, 2026
Merged

damusix merged 1 commit into
masterfrom
sdk-transaction-routines

Conversation

@damusix

@damusix damusix commented Oct 26, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • ctx.transaction(fn) hands fn a TransactionScope: the Kysely Transaction<DB> plus typed proc/func/tvf on the transaction's connection. scope.transaction(fn) inside impersonate() gets the same handle type.
  • A routine call now runs under transaction-scoped settings, e.g. SET LOCAL statement_timeout = '8s' followed by trx.tvf(...), and rolls back with the transaction.
  • Postgres trx.proc picks CALL or SELECT * FROM from a pg_proc lookup instead of try-and-fall-back. A failed CALL aborts 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_timeout forced raw sql. The issue's per-call { statementTimeout } option is not built; SET LOCAL on 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.tvf reaches the function. Documented in the reference and dev guide.

ImpersonatedScope.proc now also falls back to SELECT for a Postgres function (it threw before).

Closes #106

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
@damusix
damusix merged commit a043454 into master Oct 26, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sdk: tvf/proc/func inside a transaction, or a per-call statement timeout

1 participant