Documentation
¶
Overview ¶
Package entguard integrates sqlguard with ent (entgo.io/ent).
ent runs on database/sql, so the simplest coverage is already available by pointing entsql at a *sql.DB obtained from sqlguard.Register / OpenDB. This package is the dedicated alternative: it decorates ent's own dialect.Driver seam, so it works regardless of how the underlying *sql.DB was opened (including ent's dialect.DebugDriver chain) and mirrors ent's built-in dialect.Debug wrapper.
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 every other sqlguard surface. There is no parallel option surface — configure with the standard middleware options:
drv, _ := entsql.Open(dialect.Postgres, dsn)
guarded := entguard.Wrap(drv,
middleware.WithSlowQueryThreshold(500*time.Millisecond),
middleware.WithN1Detection(10, time.Second),
)
client := ent.NewClient(ent.Driver(guarded))
Every Exec/Query — on the driver and on transactions it opens — flows through middleware.Guard.Observe: static rules run on every call, latency is recorded only on success.
Index ¶
- type Driver
- func (d *Driver) BeginTx(ctx context.Context, opts *sql.TxOptions) (dialect.Tx, error)
- func (d *Driver) Exec(ctx context.Context, query string, args, v any) error
- func (d *Driver) Query(ctx context.Context, query string, args, v any) error
- func (d *Driver) ResetN1()
- func (d *Driver) Tx(ctx context.Context) (dialect.Tx, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Driver ¶
Driver decorates an ent dialect.Driver, routing every statement through the shared sqlguard analysis core.
func Wrap ¶
func Wrap(d dialect.Driver, opts ...middleware.Option) *Driver
Wrap decorates an ent dialect.Driver. 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 (*Driver) BeginTx ¶
BeginTx forwards to the wrapped driver's BeginTx when it implements one (entsql.Driver does — this is how ent honours read-only / isolation options), and wraps the resulting transaction. It degrades to Tx when the base driver has no BeginTx, matching ent's own fallback.