jackc / pgx

PostgreSQL driver and toolkit for Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Allow registering a callback after current transaction commits

mitar opened this issue · comments

commented

Is your feature request related to a problem? Please describe.

So I use nested transactions. And I would want that various parts of code do not have to compose well and do not have to worry if they are being called inside real transaction or inside nested transaction. But sometimes the code has to do some logic after the commit, for example, read committed values from the database and sync it into another system. This logic should be called only after the real transaction has been committed and data is persisted. But the code does not really know when is that. After commit this might not be true, because code might be inside a nested transaction.

Describe the solution you'd like

Ideally, Tx interface would have AfterCommit(fn func ()) method which would register fn to be called after a successful commit of the real (outer) transaction.

Describe alternatives you've considered

I have to wrap Tx with my own struct to do so, it seems.