go-auditGo Audit
ORM Adapters

ORM Adapters

go-audit ships first-class adapters for the three most popular Go ORMs. Pick the one matching your stack — installation is identical across all three.

Currently viewing the GORM adapter. Switch tabs above to see Bun and Ent installation flows.

Install the GORM adapter

Pull the adapter package alongside the core go-audit module. The adapter only depends on what you already have in your GORM project.

$ go get github.com/gopackx/go-audit/adapters/auditgorm

Register the plugin

Once installed, plug the adapter into your GORM database. It hooks into create, update, and delete callbacks automatically.

main.go
import "github.com/gopackx/go-audit/adapters/auditgorm"

// after auditor is initialised
_ = gormDB.Use(auditgorm.Plugin(auditor, auditgorm.Options{
    SkipUnchanged: true,
    IgnoreTables:  []string{"sessions"},
}))

What gets captured

The plugin records mutations driven through GORM. Raw SQL queries that bypass GORM's callbacks are not captured — use the API logging middleware for those.

OperationCaptured
INSERT
Full row + diff
UPDATE
Field-by-field diff
DELETE
Final row state
Bulk insert
Per-row entries
Soft delete
Tagged separately
Raw SQL
Not supported

Soft delete detection

GORM marks rows as soft-deleted when the model embeds gorm.DeletedAt. The adapter detects this convention automatically — you don't need to configure anything.

user.go
type User struct {
    ID        uint
    Email     string
    DeletedAt gorm.DeletedAt `gorm:"index"`
}
Will detect record as soft-deleted, since it has the corresponding framework hook applied.

Comparison: GORM vs Bun vs Ent

All three adapters expose the same auditing surface. Differences come down to how each ORM exposes hooks and metadata.

FeatureGORMBunEnt
Go 1.21+
Supported
Supported
Supported
Soft-delete detection
Auto
Not supported
Manual
Bulk insert capture
Supported
Supported
Supported
Field-level diff
Supported
Supported
Supported
Generated query API
Not supported
Not supported
Supported

On this page