database

package
v0.0.0-20260608 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConfigurePool

func ConfigurePool(db *sql.DB, cfg PoolConfig)

ConfigurePool applies the given PoolConfig to a *sql.DB connection.

Types

type Connection

type Connection struct {
	DB      *sql.DB
	Dialect dialect.Dialect
}

Connection represents a database connection along with its dialect.

func NewConnection

func NewConnection(db *sql.DB, d dialect.Dialect) *Connection

NewConnection creates a new database connection wrapper.

type Manager

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

Manager handles multiple database connections.

func NewManager

func NewManager(cfg *config.Repository) *Manager

NewManager creates a new database connection manager.

func (*Manager) AddConnection

func (m *Manager) AddConnection(name string, conn *Connection)

AddConnection adds a pre-configured connection to the manager. It automatically applies connection pool settings from the config repository using PoolConfigFromEnv and ConfigurePool.

func (*Manager) Close

func (m *Manager) Close() error

Close closes all managed database connections.

func (*Manager) Connection

func (m *Manager) Connection(name string) (*Connection, error)

Connection gets a database connection by name.

func (*Manager) DB

func (m *Manager) DB() (*Connection, error)

DB gets the default database connection.

type PoolConfig

type PoolConfig struct {
	// MaxOpenConns is the maximum number of open connections to the database.
	// Default: 25. Set to 0 for unlimited.
	MaxOpenConns int

	// MaxIdleConns is the maximum number of idle connections in the pool.
	// Default: 5.
	MaxIdleConns int

	// ConnMaxLifetime is the maximum amount of time a connection may be reused.
	// Default: 5 minutes. Set to 0 for no limit.
	ConnMaxLifetime time.Duration

	// ConnMaxIdleTime is the maximum amount of time a connection may be idle.
	// Default: 3 minutes. Set to 0 for no limit.
	ConnMaxIdleTime time.Duration
}

PoolConfig holds connection pool settings for a database connection. These map directly to the Go standard library's database/sql pool controls.

func DefaultPoolConfig

func DefaultPoolConfig() PoolConfig

DefaultPoolConfig returns sensible default pool settings.

func PoolConfigFromEnv

func PoolConfigFromEnv(cfg *config.Repository) PoolConfig

PoolConfigFromEnv reads pool configuration from the config repository, falling back to sensible defaults for any unset values.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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