pgxsqlxconnector

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewCompositeHook

func NewCompositeHook(hooks ...sqlhooks.Hooks) sqlhooks.Hooks

func NewDB

func NewDB(cfg Config) (result *sqlx.DB, err error)

func NewLogHook

func NewLogHook(cfg *Config) *logHook

func NewMetricHook

func NewMetricHook(cfg *Extra, dbName string) *metricHook

Types

type CompositeHook

type CompositeHook struct {
	Hooks []sqlhooks.Hooks
}

func (*CompositeHook) After

func (ch *CompositeHook) After(ctx context.Context, query string, args ...interface{}) (context.Context, error)

func (*CompositeHook) Before

func (ch *CompositeHook) Before(ctx context.Context, query string, args ...interface{}) (context.Context, error)

type Config

type Config struct {
	Host     string `validate:"required" default:"localhost"`
	Port     string `validate:"required" default:"5432"`
	User     string `validate:"required" default:"postgres"`
	Password string `validate:"required" default:"password"`
	DBName   string `validate:"required"`
	SSLMode  string `validate:"required" default:"disable"`
	Settings Settings
	Extra    Extra

	// for backward compatibility. Use Extra instead of these three fields.
	LogQuery bool
	AppName  string
	HookFunc func(query string, took int64, appName string)
}

type Extra

type Extra struct {
	LogQuery      bool
	HookFunc      func(query string, took int64, appName string)
	EnableMetrics bool `default:"true"`
	Registry      prometheus.Registerer
}

type PgSqlxStatsCollector

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

PgSqlxStatsCollector is a Prometheus collector for sqlx metrics. It implements the prometheus.Collector interface.

func NewPgSqlxStatsCollector

func NewPgSqlxStatsCollector(db *sqlx.DB, dbName string) *PgSqlxStatsCollector

NewPgSqlxStatsCollector returns a new sqlxCollector. The dbName parameter is used to set the "db" label on the metrics. The db parameter is the sqlx.DB to collect metrics from. The db parameter must not be nil. The dbName parameter must not be empty.

func (PgSqlxStatsCollector) Collect

func (p PgSqlxStatsCollector) Collect(metrics chan<- prometheus.Metric)

Collect implements the prometheus.Collector interface.

func (PgSqlxStatsCollector) Describe

func (p PgSqlxStatsCollector) Describe(descs chan<- *prometheus.Desc)

Describe implements the prometheus.Collector interface.

type Settings

type Settings struct {
	MaxOpenConns    int           `validate:"required,min=1"`
	ConnMaxLifetime time.Duration `validate:"required,min=1"`
	MaxIdleConns    int           `validate:"required,min=1"`
	ConnMaxIdleTime time.Duration `validate:"required,min=1"`
}

Jump to

Keyboard shortcuts

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