database

package
v0.0.0-...-c157d14 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ForceVersion

func ForceVersion(db *sql.DB, migrationsPath string, version int, logger *log.Logger) error

ForceVersion sets the migration version without running migrations WARNING: Only use this to recover from a failed migration

func MigrateDown

func MigrateDown(db *sql.DB, migrationsPath string, logger *log.Logger) error

MigrateDown rolls back the most recent migration

func MigrateTo

func MigrateTo(db *sql.DB, migrationsPath string, targetVersion uint, logger *log.Logger) error

MigrateTo migrates to a specific version

func MigrateUp

func MigrateUp(db *sql.DB, migrationsPath string, logger *log.Logger) error

MigrateUp runs all pending migrations

func MigrateVersion

func MigrateVersion(db *sql.DB, migrationsPath string) (uint, bool, error)

MigrateVersion returns the current migration version

Types

type Config

type Config struct {
	Host     string
	Port     string
	User     string
	Password string
	DBName   string
	SSLMode  string
}

Config holds database connection configuration

type DB

type DB struct {
	*sql.DB
	// contains filtered or unexported fields
}

DB wraps sql.DB with additional functionality

func New

func New(cfg Config, logger zerolog.Logger) (*DB, error)

New creates a new database connection pool

func (*DB) Close

func (db *DB) Close() error

Close gracefully closes the database connection pool

func (*DB) GetPoolStats

func (db *DB) GetPoolStats() PoolStats

GetPoolStats returns formatted pool statistics with configuration

func (*DB) GetStats

func (db *DB) GetStats() sql.DBStats

GetStats returns database connection pool statistics

func (*DB) HealthCheck

func (db *DB) HealthCheck() error

HealthCheck verifies database connectivity and returns an error if unhealthy

type PoolStats

type PoolStats struct {
	OpenConnections int   // Currently open connections
	InUse           int   // Connections currently in use
	Idle            int   // Idle connections ready for use
	WaitCount       int64 // Total number of connections waited for
	WaitDuration    int64 // Total time waited for connections (nanoseconds)
	MaxOpenConns    int   // Maximum allowed open connections
	MaxIdleConns    int   // Maximum allowed idle connections
	MaxLifetime     int64 // Maximum connection lifetime (seconds)
	MaxIdleTime     int64 // Maximum connection idle time (seconds)
}

PoolStats returns formatted connection pool statistics for monitoring

Jump to

Keyboard shortcuts

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