db

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package db provides database connection management.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewDatabase added in v0.0.4

func NewDatabase(cfg config.DatabaseConfig, logOutput io.Writer) (*gorm.DB, error)

NewDatabase creates a database connection with connection pooling. logOutput is the writer for SQL logs (use io.Discard to suppress).

func NewDialector added in v0.0.4

func NewDialector(cfg config.DatabaseConfig) (gorm.Dialector, error)

NewDialector creates a GORM dialector based on the driver type.

func NewMongoDB

func NewMongoDB(ctx context.Context, cfg config.MongoConfig) (*mongo.Database, error)

NewMongoDB creates a MongoDB connection. ctx is used for connection timeout.

func NewRedis

func NewRedis(cfg config.RedisConfig) *redis.Client

NewRedis creates a Redis client.

Types

type KafkaConfig

type KafkaConfig struct {
	config.KafkaConfig
	ClientID string `json:"client_id" yaml:"client_id" toml:"client_id"`
}

KafkaConfig extends the base config for Kafka.

type Manager

type Manager struct {
	DB      *gorm.DB // Generic database connection (MySQL/PostgreSQL)
	Redis   *redis.Client
	MongoDB *mongo.Database
	Config  *config.BaseConfig
}

Manager manages all database connections.

func NewManager

func NewManager(ctx context.Context, cfg config.BaseConfig) (*Manager, error)

NewManager creates a new database manager. ctx is used for connection timeouts during initialization.

func (*Manager) DBWithContext added in v0.0.4

func (m *Manager) DBWithContext(ctx context.Context) *gorm.DB

DBWithContext returns the database connection with context.

func (*Manager) Health

func (m *Manager) Health(ctx context.Context) map[string]error

Health returns health status of all components.

func (*Manager) IsEnabled

func (m *Manager) IsEnabled(component string) bool

IsEnabled checks if a component is enabled.

func (*Manager) Start

func (m *Manager) Start(ctx context.Context) error

Start checks connectivity of all databases.

func (*Manager) Stop

func (m *Manager) Stop(ctx context.Context) error

Stop closes all database connections.

Jump to

Keyboard shortcuts

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