Documentation
¶
Overview ¶
Package database provides database connection and ORM utilities for the application.
Package database provides database connection and ORM utilities for the application.
Index ¶
Constants ¶
View Source
const ( // DefaultPingTimeout is the default timeout for database ping operations DefaultPingTimeout = 5 * time.Second // MinArgsLength represents the minimum number of arguments needed for a query MinArgsLength = 2 // ConnectionPoolWarningThreshold is the percentage of max connections that triggers a warning ConnectionPoolWarningThreshold = 0.8 // ConnectionPoolPercentageMultiplier is used to convert ratio to percentage ConnectionPoolPercentageMultiplier = 100 )
Variables ¶
View Source
var TickerDuration = 1 * time.Minute
TickerDuration controls how often the connection pool is monitored
Functions ¶
This section is empty.
Types ¶
type DB ¶ added in v0.1.5
type DB interface {
// Close closes the database connection
Close() error
// MonitorConnectionPool monitors the database connection pool and logs metrics
MonitorConnectionPool(ctx context.Context)
// Ping pings the database to verify the connection
Ping(ctx context.Context) error
// GetDB returns the underlying GORM DB instance
GetDB() *gorm.DB
}
DB defines the interface for database operations
type GormDB ¶ added in v0.1.5
GormDB wraps the GORM database connection
func NewWithDB ¶ added in v0.1.5
NewWithDB creates a new GormDB instance with an existing DB connection
func (*GormDB) MonitorConnectionPool ¶ added in v0.1.5
MonitorConnectionPool monitors the database connection pool and logs metrics
type GormLogWriter ¶ added in v0.1.5
type GormLogWriter struct {
// contains filtered or unexported fields
}
GormLogWriter implements io.Writer for GORM logger
func (*GormLogWriter) Error ¶ added in v0.1.5
func (w *GormLogWriter) Error(msg string, err error)
Error implements logger.Writer interface
func (*GormLogWriter) Printf ¶ added in v0.1.5
func (w *GormLogWriter) Printf(format string, args ...any)
Printf implements logger.Writer interface
Click to show internal directories.
Click to hide internal directories.