querycollector

package
v0.19.917 Latest Latest
Warning

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

Go to latest
Published: May 6, 2026 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Collector

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

Collector accumulates query records in a fixed-size ring buffer.

func NewCollector

func NewCollector(maxSize int) *Collector

NewCollector creates a new collector with the given max buffer size.

func (*Collector) Add

func (c *Collector) Add(r QueryRecord)

Add inserts a record into the ring buffer.

func (*Collector) Clear

func (c *Collector) Clear()

Clear resets the collector.

func (*Collector) Records

func (c *Collector) Records() []QueryRecord

Records returns a snapshot of all collected records (newest first).

func (*Collector) Tables

func (c *Collector) Tables() []string

Tables returns the distinct table names seen in the buffer.

func (*Collector) Total

func (c *Collector) Total() int

Total returns the total number of queries captured (including evicted).

type Plugin

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

Plugin is a GORM plugin that records every query into a Collector.

func NewPlugin

func NewPlugin(collector *Collector, dbType string) *Plugin

NewPlugin creates a plugin that tags records with the given dbType ("psql" or "ch").

func (*Plugin) Initialize

func (p *Plugin) Initialize(db *gorm.DB) error

func (*Plugin) Name

func (p *Plugin) Name() string

type QueryRecord

type QueryRecord struct {
	Table        string        `json:"table"`
	Operation    string        `json:"operation"`
	SQL          string        `json:"sql"`
	Duration     time.Duration `json:"duration_ns"`
	DurationMS   float64       `json:"duration_ms"`
	RowsAffected int64         `json:"rows_affected"`
	ResponseSize int           `json:"response_size"`
	PreloadCount int           `json:"preload_count"`
	Timestamp    time.Time     `json:"timestamp"`
	Error        string        `json:"error,omitempty"`
	Caller       string        `json:"caller"`
	DBType       string        `json:"db_type"`
	Source       string        `json:"source"`
	Endpoint     string        `json:"endpoint"`
}

QueryRecord holds the captured data for a single query execution.

Jump to

Keyboard shortcuts

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