Documentation
¶
Overview ¶
Package database provides database connection management and migration utilities.
Index ¶
- func RunMigrations(db *sql.DB, migrationsPath string, schemaName, tableName string) error
- type Manager
- func (dm *Manager) Close() error
- func (dm *Manager) GetConfig() *config.PostgresDatabase
- func (dm *Manager) GetDB() *sql.DB
- func (dm *Manager) GetPool() *pgxpool.Pool
- func (dm *Manager) Health(ctx context.Context) error
- func (dm *Manager) Ping(ctx context.Context) error
- func (dm *Manager) PublicConnectionString() string
- func (dm *Manager) Stats() sql.DBStats
- type ManagerOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RunMigrations ¶
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) GetConfig ¶
func (dm *Manager) GetConfig() *config.PostgresDatabase
GetConfig returns the database configuration
func (*Manager) PublicConnectionString ¶
PublicConnectionString returns the configuration information as a string without the password
type ManagerOption ¶
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