Documentation
¶
Overview ¶
Package pool provides enhanced connection pool management utilities.
Index ¶
- func Configure(db *sql.DB, cfg *PoolConfig) error
- type Monitor
- type PoolConfig
- type Stats
- type TracedDB
- func (t *TracedDB) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
- func (t *TracedDB) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
- func (t *TracedDB) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row
- func (t *TracedDB) SetSlowQueryThreshold(threshold time.Duration)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Monitor ¶
type Monitor struct {
// contains filtered or unexported fields
}
Monitor provides continuous pool monitoring.
func NewMonitor ¶
NewMonitor creates a new pool monitor.
func (*Monitor) OnSlowQuery ¶
OnSlowQuery registers a callback for slow queries.
type PoolConfig ¶
type PoolConfig struct {
// MaxOpenConns is the maximum number of open connections to the database.
MaxOpenConns int
// MaxIdleConns is the maximum number of connections in the idle connection pool.
MaxIdleConns int
// ConnMaxLifetime is the maximum amount of time a connection may be reused.
ConnMaxLifetime time.Duration
// ConnMaxIdleTime is the maximum amount of time a connection may be idle.
ConnMaxIdleTime time.Duration
// ConnReqDurThreshold is the duration threshold for slow query logging.
ConnReqDurThreshold time.Duration
}
PoolConfig holds advanced pool configuration.
func DefaultPoolConfig ¶
func DefaultPoolConfig() *PoolConfig
DefaultPoolConfig returns sensible defaults.
func (*PoolConfig) Validate ¶
func (p *PoolConfig) Validate() error
Validate checks if the pool configuration is valid.
type Stats ¶
type Stats struct {
MaxOpenConnections int
OpenConnections int
InUse int
Idle int
WaitCount int64
WaitDuration time.Duration
MaxIdleClosed int64
MaxLifetimeClosed int64
}
Stats holds connection pool statistics.
type TracedDB ¶
type TracedDB struct {
DB *sql.DB
SlowLog func(query string, duration time.Duration)
// contains filtered or unexported fields
}
TracedDB wraps a sql.DB with query timing capabilities.
func NewTracedDB ¶
NewTracedDB creates a traced database wrapper.
func (*TracedDB) ExecContext ¶
func (t *TracedDB) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
ExecContext wraps ExecContext with timing.
func (*TracedDB) QueryContext ¶
func (t *TracedDB) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
QueryContext wraps QueryContext with timing.
func (*TracedDB) QueryRowContext ¶
QueryRowContext wraps QueryRowContext with timing.
func (*TracedDB) SetSlowQueryThreshold ¶
SetSlowQueryThreshold sets the threshold for slow query logging.