feat(hooks): add OnTxBegin and runInTx for resolvespec and restheadspec

Every transaction the handlers open now fires OnTxBegin first, with the
transaction in hookCtx.Tx, via common.RunRequestTx.
This commit is contained in:
2026-09-30 22:40:06 +02:00
parent cd96404cdd
commit f2dbe2561c
8 changed files with 313 additions and 51 deletions
+9
View File
@@ -41,6 +41,12 @@ const (
// Unlike BeforeHandle, which fires once before operation dispatch, BeforeOp fires at each
// individual SQL-operation hook point, so it runs once per statement executed.
BeforeOp HookType = "before_op"
// OnTxBegin fires once, first, inside every transaction the handler opens
// (including the second short transaction for post-commit work). hookCtx.Tx
// is the transaction; use it to stamp transaction-local state such as RLS
// settings. An error or abort rolls the transaction back.
OnTxBegin HookType = common.TxHookName
)
// HookContext contains all the data available to a hook
@@ -76,6 +82,9 @@ type HookContext struct {
Tx common.Database
}
// SetTx points the context at the transaction in use (common.TxContext).
func (c *HookContext) SetTx(tx common.Database) { c.Tx = tx }
// HookFunc is the signature for hook functions
// It receives a HookContext and can modify it or return an error
// If an error is returned, the operation will be aborted