sqlstats

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package sqlstats wraps database/sql drivers with a measuring proxy and aggregates every query into an in-memory table. Works with any driver (MySQL/MariaDB via go-sql-driver, PostgreSQL via pgx stdlib or lib/pq).

Index

Constants

View Source
const DriverSuffix = ":isutools"

DriverSuffix is appended to the original driver name on registration: Register("mysql") makes "mysql:isutools" available.

Variables

Default is the generation-scoped store all proxied drivers report into.

Functions

func FirstConn added in v0.2.0

func FirstConn() (driverName, dsn string, ok bool)

FirstConn returns the base driver name and DSN of the first connection opened through a wrapped driver. dbinspect uses it to open its own raw connection for schema inspection without any extra integration code.

func Register

func Register(names ...string) error

Register wraps each named, already-registered driver and registers the measuring variant under name+DriverSuffix. Calling it again for the same name is a no-op.

Types

type Frozen added in v0.2.0

type Frozen struct {
	Generation int64
	Entries    []agg.Entry
}

Frozen is a completed SQL generation.

type Store added in v0.2.0

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

Store owns generation-scoped SQL aggregation tables.

func NewStore added in v0.2.0

func NewStore(maxKeys int) *Store

NewStore constructs a generation-scoped SQL store.

func (*Store) CurrentGeneration added in v0.2.0

func (s *Store) CurrentGeneration() int64

CurrentGeneration identifies the generation accepting new observations.

func (*Store) Observe added in v0.2.0

func (s *Store) Observe(query string, duration time.Duration)

Observe adds an already-normalized query to the current generation.

func (*Store) ObserveResult added in v0.2.0

func (s *Store) ObserveResult(query string, duration time.Duration, failed bool)

ObserveResult adds an already-normalized query result to the current generation.

func (*Store) Reset added in v0.2.0

func (s *Store) Reset()

Reset starts a new generation and discards the frozen data. Prefer Rotate when the caller needs to retain the previous generation.

func (*Store) Rotate added in v0.2.0

func (s *Store) Rotate() Frozen

Rotate publishes a new empty generation and freezes the previous one after all observations that started there have completed.

func (*Store) Snapshot added in v0.2.0

func (s *Store) Snapshot() []agg.Entry

Snapshot returns the current generation's SQL aggregates.

Jump to

Keyboard shortcuts

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