database

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package database provides database connection management and migration utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunMigrations

func RunMigrations(db *sql.DB, migrationsPath string, schemaName, tableName string) error

RunMigrations executes SQL migrations at startup schemaName: schema where the migrations table will be created (e.g., "public", "etl_migrations") tableName: name of the migrations tracking table (e.g., "schema_migrations")

Types

type Manager

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

Manager manages connections to the database and provides utility methods for health checks and stats

func NewManager

func NewManager(cfg *config.PostgresDatabase, opts ...ManagerOption) (*Manager, error)

NewManager creates a new database manager

func (*Manager) Close

func (dm *Manager) Close() error

Close closes all connections

func (*Manager) GetConfig

func (dm *Manager) GetConfig() *config.PostgresDatabase

GetConfig returns the database configuration

func (*Manager) GetDB

func (dm *Manager) GetDB() *sql.DB

GetDB returns the *sql.DB instance

func (*Manager) GetPool

func (dm *Manager) GetPool() *pgxpool.Pool

GetPool returns the *pgxpool.Pool instance for advanced operations

func (*Manager) Health

func (dm *Manager) Health(ctx context.Context) error

Health checks the health status of the database

func (*Manager) Ping

func (dm *Manager) Ping(ctx context.Context) error

Ping tests the connection to the database

func (*Manager) PublicConnectionString

func (dm *Manager) PublicConnectionString() string

PublicConnectionString returns the configuration information as a string without the password

func (*Manager) Stats

func (dm *Manager) Stats() sql.DBStats

Stats returns the connection pool statistics

type ManagerOption

type ManagerOption func(*Manager) error

ManagerOption is a configuration function

func WithMigrations

func WithMigrations(migrationsPath string) ManagerOption

WithMigrations is an option to automatically run migrations

func WithMigrationsCustomSchema

func WithMigrationsCustomSchema(migrationsPath, schemaName, tableName string) ManagerOption

WithMigrationsCustomSchema is an option to run migrations with custom schema and table

Jump to

Keyboard shortcuts

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