Hooks & Observability
Hooks & observability
Model hooks, query hooks, and statement logging — every seam where your code can observe or intercept execution.
fusion-orm gives you two hook systems and one logging surface. They answer different questions:
- Model hooks (
BeforeCreate,AfterFind, …) run inside the CRUD callback chains, per row, with access to the*DBsession. They mutate the model or veto the operation by returning an error. - Query hooks (
QueryHook) wrap every executed statement, once per I/O call. They observe SQL, duration, and errors — the seam for metrics, tracing, and audit logs. - The logger (
logger.Interface) traces completed statements with gorm-parity formatting: level gating, slow-query warnings, and optional parameter stripping.
All three are opt-in. A model without hook methods skips hook dispatch
entirely (the check happens at schema parse time); a *DB without query
hooks allocates nothing per statement; the default logger prints nothing
unless a query errors or runs slow.