database

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Host     string `json:"host" yaml:"host"`
	Port     int    `json:"port" yaml:"port"`
	Database string `json:"database" yaml:"database"`
	Username string `json:"username" yaml:"username"`
	Password string `json:"password" yaml:"password"`
	SSLMode  string `json:"ssl_mode" yaml:"ssl_mode"`
}

Config holds database connection configuration

func (*Config) DSN

func (c *Config) DSN() string

DSN returns the PostgreSQL data source name

func (*Config) Validate

func (c *Config) Validate() error

Validate validates the database configuration

type ConnectionPool

type ConnectionPool struct {
	Config          *Config
	DB              *gorm.DB
	MaxOpenConns    int
	MaxIdleConns    int
	ConnMaxLifetime time.Duration
}

ConnectionPool manages database connections

func NewConnectionPool

func NewConnectionPool(config *Config) *ConnectionPool

NewConnectionPool creates a new connection pool

func (*ConnectionPool) Close

func (p *ConnectionPool) Close() error

Close closes the database connection

func (*ConnectionPool) Connect

func (p *ConnectionPool) Connect() error

Connect establishes a connection to the database

type HealthCheck

type HealthCheck struct {
	Pool    *ConnectionPool
	Timeout time.Duration
}

HealthCheck provides database health checking functionality

func NewHealthCheck

func NewHealthCheck(pool *ConnectionPool) *HealthCheck

NewHealthCheck creates a new health check

func (*HealthCheck) Check

func (h *HealthCheck) Check(ctx context.Context) *core.HealthStatus

Check performs a health check on the database

type Repository

type Repository struct {
	DB *gorm.DB
}

Repository provides base repository functionality

func NewRepository

func NewRepository(db *gorm.DB) *Repository

NewRepository creates a new repository

func (*Repository) Migrate

func (r *Repository) Migrate(models ...interface{}) error

Migrate runs database migrations for the given models

func (*Repository) Transaction

func (r *Repository) Transaction(fn func(*gorm.DB) error) error

Transaction executes a function within a database transaction

Jump to

Keyboard shortcuts

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