mirror of
https://github.com/bitechdev/ResolveSpec.git
synced 2026-10-05 04:51:58 +00:00
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:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user