sl

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AlgorithmLogger

type AlgorithmLogger struct {
	DbHelper     *DBHelper
	CleanupRules []CleanupRule
}

AlgorithmLogger 算法数据记录器

func NewAlgorithmLogger

func NewAlgorithmLogger(dbPath string) (*AlgorithmLogger, error)

NewAlgorithmLogger 创建新的算法记录器

func (*AlgorithmLogger) AddCleanupRule

func (al *AlgorithmLogger) AddCleanupRule(tableName, timestampColumn string, retentionPeriod time.Duration)

AddCleanupRule 添加清理规则

func (*AlgorithmLogger) CleanupOldRecords

func (al *AlgorithmLogger) CleanupOldRecords() error

cleanupOldRecords 根据配置的规则清理旧记录

func (*AlgorithmLogger) Close

func (al *AlgorithmLogger) Close() error

Close 关闭数据库连接

func (*AlgorithmLogger) GetCleanupRules

func (al *AlgorithmLogger) GetCleanupRules() []CleanupRule

GetCleanupRules 获取所有清理规则

func (*AlgorithmLogger) GetStatistics

func (al *AlgorithmLogger) GetStatistics(start, end time.Time) (*Statistics, error)

GetStatistics 获取统计信息

func (*AlgorithmLogger) RemoveCleanupRule

func (al *AlgorithmLogger) RemoveCleanupRule(tableName string)

RemoveCleanupRule 移除清理规则

func (*AlgorithmLogger) SetCleanupRuleEnabled

func (al *AlgorithmLogger) SetCleanupRuleEnabled(tableName string, enabled bool)

SetCleanupRuleEnabled 启用/禁用清理规则

type CleanupRule

type CleanupRule struct {
	TableName       string        `json:"table_name"`
	TimestampColumn string        `json:"timestamp_column"`
	RetentionPeriod time.Duration `json:"retention_period"`
	Enabled         bool          `json:"enabled"`
}

CleanupRule 清理规则

type DBHelper

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

DBHelper 通用数据库操作辅助类

func NewDBHelper

func NewDBHelper(dbPath string) (*DBHelper, error)

NewDBHelper 创建新的数据库辅助实例

func (*DBHelper) BatchInsert

func (h *DBHelper) BatchInsert(tableName string, data interface{}) error

BatchInsert 批量插入记录

func (*DBHelper) Close

func (h *DBHelper) Close() error

Close 关闭数据库连接

func (*DBHelper) CreateTableFromStruct

func (h *DBHelper) CreateTableFromStruct(tableName string, structType interface{}) error

CreateTableFromStruct 根据结构体自动创建表. 使用 GORM-style 的 db 标签来定义字段属性. 标签格式: `db:"column_name;option1;option2:value;..."` 支持的选项: - primaryKey: 主键 - autoIncrement: 自增 - not null: 非空 - unique: 唯一 - index: 创建索引 - size:255: 字段大小 (用于 VARCHAR) - default:'some_value': 默认值

func (*DBHelper) Insert

func (h *DBHelper) Insert(tableName string, data interface{}) error

Insert 插入记录

func (*DBHelper) Query

func (h *DBHelper) Query(query string, result interface{}, args ...interface{}) error

Query 通用查询方法

func (*DBHelper) QueryMap

func (h *DBHelper) QueryMap(query string, args ...interface{}) (map[string]interface{}, error)

QueryOneToMap 查询单行记录并将其作为 map[string]interface{} 返回

func (*DBHelper) QueryMaps

func (h *DBHelper) QueryMaps(query string, args ...interface{}) ([]map[string]interface{}, error)

QueryToMaps 执行查询并返回一个 map 切片 ([]map[string]interface{})

func (*DBHelper) QueryOne

func (h *DBHelper) QueryOne(query string, result interface{}, args ...interface{}) error

QueryOne 查询单个记录

func (*DBHelper) QueryRaw

func (h *DBHelper) QueryRaw(query string, args ...interface{}) ([]map[string]interface{}, error)

QueryRaw 执行原始SQL查询并返回 []map[string]interface{}

type Statistics

type Statistics struct {
	TotalCount  int64   `db:"total_count"`
	AvgDuration float64 `db:"avg_duration"`
	MinDuration int64   `db:"min_duration"`
	MaxDuration int64   `db:"max_duration"`
}

Statistics 统计信息

Jump to

Keyboard shortcuts

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