sqlpool

package
v2.4.6 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: AGPL-3.0 Imports: 2 Imported by: 0

Documentation

Overview

Package sqlpool applies connection-pool limits to a database/sql handle. Go's default MaxIdleConns of 2 causes connection churn under bursts.

Index

Constants

View Source
const (
	// DefaultConnMaxLifetime recycles connections so they do not pin to a failed-over server.
	DefaultConnMaxLifetime = 5 * time.Minute
	// DefaultConnMaxIdleTime returns capacity to the server when the process goes quiet.
	DefaultConnMaxIdleTime = time.Minute
)

Variables

This section is empty.

Functions

func Apply

func Apply(db *sql.DB, c Config)

Apply configures db in place. nil db is a no-op.

func DefaultMaxOpenConns

func DefaultMaxOpenConns(driver string) int

DefaultMaxOpenConns returns the open-connection limit for a driver name ("mysql" | "postgres" | "sqlite"). Unrecognised names get the MySQL value.

Types

type Config

type Config struct {
	// Driver selects the per-driver default for MaxOpenConns: "mysql" |
	// "postgres" | "sqlite".
	Driver string
	// MaxOpenConns caps total connections (in use plus idle); 0 is unlimited.
	MaxOpenConns *int
	// MaxIdleConns caps retained idle connections; nil mirrors MaxOpenConns,
	// 0 keeps none.
	MaxIdleConns *int
	// ConnMaxLifetimeSeconds recycles a connection after this age; 0 never.
	ConnMaxLifetimeSeconds *int
	// ConnMaxIdleTimeSeconds closes a connection idle this long; 0 never.
	ConnMaxIdleTimeSeconds *int
}

Config carries pool limits. nil takes the default; 0 lifts the limit.

Jump to

Keyboard shortcuts

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