database

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FiltrWhere added in v0.0.4

func FiltrWhere(field field.Expr, value any) field.Expr

func QueryPaging added in v0.0.4

func QueryPaging(query any, page Paging) error

func SetDsn

func SetDsn(m *configs.GormDbConfig) string

Types

type Aggregator added in v0.0.4

type Aggregator struct {
	// contains filtered or unexported fields
}

Aggregator 聚合器结构体

func NewAggregator added in v0.0.4

func NewAggregator(batchProcessor BatchProcessFunc, optionFuncs ...SetAggregatorOptionFunc) (*Aggregator, error)

NewAggregator 创建新的聚合器实例

func (*Aggregator) Enqueue added in v0.0.4

func (agt *Aggregator) Enqueue(item interface{}) error

Enqueue 入队一个项目,会阻塞直到有空间

func (*Aggregator) EnqueueWithRetry added in v0.0.4

func (agt *Aggregator) EnqueueWithRetry(item interface{}, maxRetries int, backoff time.Duration) bool

EnqueueWithRetry 入队一个项目,会重试直到成功或者达到最大重试次数

func (*Aggregator) SafeStop added in v0.0.4

func (agt *Aggregator) SafeStop()

SafeStop 安全停止聚合器,确保所有项目都被处理

func (*Aggregator) Start added in v0.0.4

func (agt *Aggregator) Start()

Start 启动聚合器

func (*Aggregator) Stop added in v0.0.4

func (agt *Aggregator) Stop()

Stop 停止聚合器

func (*Aggregator) TryEnqueue added in v0.0.4

func (agt *Aggregator) TryEnqueue(item interface{}) bool

TryEnqueue 尝试入队一个项目,非阻塞

type AggregatorOption added in v0.0.4

type AggregatorOption struct {
	BatchSize         int
	Workers           int
	ChannelBufferSize int
	LingerTime        time.Duration
	ErrorHandler      ErrorHandlerFunc
	Logger            *log.Logger
}

AggregatorOption 聚合器选项

type BatchProcessFunc added in v0.0.4

type BatchProcessFunc func([]interface{}) error

BatchProcessFunc 批处理函数类型

type DBConfig

type DBConfig struct {
	Driver string
	DSN    string
	Config *gorm.Config
}

DBConfig 数据库配置结构体

type DBManager

type DBManager struct {
	// contains filtered or unexported fields
}

DBManager 数据库管理器

func GetDBManager

func GetDBManager() *DBManager

GetDBManager 获取数据库管理器单例

func GetGormDB

func GetGormDB(dbConfig *configs.GormDbConfig) (dbm *DBManager, err error)

GetGormDB 获取gorm.DB

func (*DBManager) GetDB

func (m *DBManager) GetDB() *gorm.DB

GetDB 获取数据库连接

func (*DBManager) InitDB

func (m *DBManager) InitDB(config DBConfig) error

InitDB 初始化数据库连接

func (*DBManager) ReconnectIfNeeded

func (m *DBManager) ReconnectIfNeeded() error

ReconnectIfNeeded 检查连接并在需要时重连

func (*DBManager) StartHealthCheck

func (m *DBManager) StartHealthCheck(interval time.Duration)

StartHealthCheck 启动健康检查

type ErrorHandlerFunc added in v0.0.4

type ErrorHandlerFunc func(err error, items []interface{}, batchProcessFunc BatchProcessFunc, aggregator *Aggregator)

ErrorHandlerFunc 错误处理函数类型

type Paging added in v0.0.4

type Paging interface {
	OrderBy() string
	SetTotal(int)
	GetTotal() int
	OffsetLimit() (offset, limit int)
}

func New added in v0.0.4

func New() Paging

type SetAggregatorOptionFunc added in v0.0.4

type SetAggregatorOptionFunc func(option *AggregatorOption)

SetAggregatorOptionFunc 聚合器选项设置函数类型

func WithBatchSize added in v0.0.4

func WithBatchSize(batchSize int) SetAggregatorOptionFunc

示例: 设置聚合器选项的函数

func WithChannelBufferSize added in v0.0.4

func WithChannelBufferSize(size int) SetAggregatorOptionFunc

func WithErrorHandler added in v0.0.4

func WithErrorHandler(handler ErrorHandlerFunc) SetAggregatorOptionFunc

func WithLingerTime added in v0.0.4

func WithLingerTime(duration time.Duration) SetAggregatorOptionFunc

func WithLogger added in v0.0.4

func WithLogger(logger *log.Logger) SetAggregatorOptionFunc

func WithWorkers added in v0.0.4

func WithWorkers(workers int) SetAggregatorOptionFunc

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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