feat(tx): run websocketspec and mqttspec operations in per-message transactions

Reads and deletes run in one transaction; create and update write in one
and re-fetch plus After hooks in a second. OnTxBegin fires first in each.
This commit is contained in:
2026-09-30 22:46:46 +02:00
parent 97bcb44fdc
commit ed457eb14a
8 changed files with 611 additions and 227 deletions
+10
View File
@@ -64,6 +64,13 @@ 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 for a
// read/create/update/delete message (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 context information for hook execution
@@ -128,6 +135,9 @@ type HookContext struct {
Metadata map[string]interface{}
}
// SetTx points the context at the transaction in use (common.TxContext).
func (c *HookContext) SetTx(tx common.Database) { c.Tx = tx }
// HookFunc is a function that processes a hook
type HookFunc func(*HookContext) error