Documentation
¶
Index ¶
- type PoolConfig
- type PoolManager
- func (pm *PoolManager) Close() error
- func (pm *PoolManager) DB() *gorm.DB
- func (pm *PoolManager) GetStats() PoolStats
- func (pm *PoolManager) Ping(ctx context.Context) error
- func (pm *PoolManager) Stats() sql.DBStats
- func (pm *PoolManager) WithTransaction(ctx context.Context, fn TransactionFunc) error
- func (pm *PoolManager) WithTransactionRetry(ctx context.Context, maxRetries int, fn TransactionFunc) error
- type PoolStats
- type TransactionFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type PoolConfig ¶
type PoolConfig struct {
// 最大空闲连接数
MaxIdleConns int `yaml:"max_idle_conns" json:"max_idle_conns"`
// 最大打开连接数
MaxOpenConns int `yaml:"max_open_conns" json:"max_open_conns"`
// 连接最大生命周期
ConnMaxLifetime time.Duration `yaml:"conn_max_lifetime" json:"conn_max_lifetime"`
// 连接最大空闲时间
ConnMaxIdleTime time.Duration `yaml:"conn_max_idle_time" json:"conn_max_idle_time"`
// 健康检查间隔
HealthCheckInterval time.Duration `yaml:"health_check_interval" json:"health_check_interval"`
}
PoolConfig 连接池配置
type PoolManager ¶
type PoolManager struct {
// contains filtered or unexported fields
}
PoolManager 数据库连接池管理器
func NewPoolManager ¶
func NewPoolManager(db *gorm.DB, config PoolConfig, logger *zap.Logger) (*PoolManager, error)
NewPoolManager 创建连接池管理器
func (*PoolManager) WithTransaction ¶
func (pm *PoolManager) WithTransaction(ctx context.Context, fn TransactionFunc) error
WithTransaction 在事务中执行函数
func (*PoolManager) WithTransactionRetry ¶
func (pm *PoolManager) WithTransactionRetry(ctx context.Context, maxRetries int, fn TransactionFunc) error
WithTransactionRetry 在事务中执行函数(带重试)
type PoolStats ¶
type PoolStats struct {
MaxOpenConnections int `json:"max_open_connections"`
OpenConnections int `json:"open_connections"`
InUse int `json:"in_use"`
Idle int `json:"idle"`
WaitCount int64 `json:"wait_count"`
WaitDuration time.Duration `json:"wait_duration"`
MaxIdleClosed int64 `json:"max_idle_closed"`
MaxLifetimeClosed int64 `json:"max_lifetime_closed"`
}
PoolStats 连接池统计信息(更友好的格式)
Click to show internal directories.
Click to hide internal directories.