xormguard

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 9, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package xormguard integrates sqlguard with xorm (xorm.io/xorm).

Analysis is driven by the single shared sqlguard core (middleware.Guard), so redaction-by-default, stable fingerprints, the pluggable real-grammar parser, slow-query timing and N+1 detection behave identically to the database/sql driver wrapper, pgxguard, gormguard and bunguard. There is no parallel option surface — configure with the standard middleware options:

engine, _ := xorm.NewEngine("postgres", dsn)
engine.AddHook(xormguard.New(
    middleware.WithSlowQueryThreshold(500*time.Millisecond),
    middleware.WithN1Detection(10, time.Second),
))

xorm's contexts.Hook exposes the rendered SQL and the measured execution time on the ContextHook in AfterProcess, so this uses the explicit Check+CheckLatency pair (matching gormguard): static rules run on every query, latency is reported only on success.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Hook

type Hook struct {
	// contains filtered or unexported fields
}

Hook implements xorm's contexts.Hook and drives every traced statement through the shared sqlguard analysis core.

func New

func New(opts ...middleware.Option) *Hook

New creates a new sqlguard xorm hook. It accepts the standard sqlguard middleware options (WithAnalyzer, WithReporter, WithSlowQueryThreshold, WithParser, WithN1Detection, …) — the same option set every other sqlguard surface uses, so there is no parallel configuration surface to drift.

func (*Hook) AfterProcess

func (h *Hook) AfterProcess(c *contexts.ContextHook) error

AfterProcess implements contexts.Hook. c.SQL holds the rendered SQL, c.ExecuteTime the measured latency, and c.Err the query error (which is returned unchanged so the hook never swallows it).

func (*Hook) BeforeProcess

func (h *Hook) BeforeProcess(c *contexts.ContextHook) (context.Context, error)

BeforeProcess implements contexts.Hook. xorm stamps the start time itself and reports the elapsed duration as ContextHook.ExecuteTime in AfterProcess, so there is nothing to do here but pass the context through.

func (*Hook) ResetN1

func (h *Hook) ResetN1()

ResetN1 clears N+1 tracker state. Call it at a per-request boundary (e.g. end of an HTTP handler) to scope N+1 detection to one unit of work. No-op unless WithN1Detection was passed to New.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL