Mining/pkg/database/interface.go
Claude 43e4b447ac
ax(batch): remove banned import references from comment examples
Replace all fmt.Println, fmt.Sprintf, log.Printf, log.Println, and
json.Unmarshal references in doc comments with logging.Info/logging.Warn
or direct value access patterns. Comments are examples that agents
learn from -- they must not demonstrate banned imports.

Co-Authored-By: Charon <charon@lethean.io>
2026-04-02 18:07:35 +01:00

95 lines
3 KiB
Go

package database
import (
"context"
"time"
)
// var store database.HashrateStore = database.DefaultStore()
// store.InsertHashratePoint(ctx, "xmrig", "xmrig", point, database.ResolutionHigh)
// store.Cleanup(30)
type HashrateStore interface {
// store.InsertHashratePoint(ctx, "xmrig", "xmrig", HashratePoint{Timestamp: time.Now(), Hashrate: 1234}, ResolutionHigh)
InsertHashratePoint(ctx context.Context, minerName, minerType string, point HashratePoint, resolution Resolution) error
// points, err := store.GetHashrateHistory("xmrig", ResolutionHigh, time.Now().Add(-time.Hour), time.Now())
GetHashrateHistory(minerName string, resolution Resolution, since, until time.Time) ([]HashratePoint, error)
// stats, err := store.GetHashrateStats("xmrig")
// if stats != nil { logging.Info("stats", logging.Fields{"average": stats.AverageRate}) }
GetHashrateStats(minerName string) (*HashrateStats, error)
// allStats, err := store.GetAllMinerStats()
// for _, stats := range allStats { logging.Info("stats", logging.Fields{"miner": stats.MinerName}) }
GetAllMinerStats() ([]HashrateStats, error)
// store.Cleanup(30) // remove data older than 30 days
Cleanup(retentionDays int) error
// store.Close()
Close() error
}
// store := database.DefaultStore() // wraps the global database connection
type defaultStore struct{}
// store := database.DefaultStore()
// store.GetHashrateStats("xmrig")
func DefaultStore() HashrateStore {
return &defaultStore{}
}
func (s *defaultStore) InsertHashratePoint(ctx context.Context, minerName, minerType string, point HashratePoint, resolution Resolution) error {
return InsertHashratePoint(ctx, minerName, minerType, point, resolution)
}
func (s *defaultStore) GetHashrateHistory(minerName string, resolution Resolution, since, until time.Time) ([]HashratePoint, error) {
return GetHashrateHistory(minerName, resolution, since, until)
}
func (s *defaultStore) GetHashrateStats(minerName string) (*HashrateStats, error) {
return GetHashrateStats(minerName)
}
func (s *defaultStore) GetAllMinerStats() ([]HashrateStats, error) {
return GetAllMinerStats()
}
func (s *defaultStore) Cleanup(retentionDays int) error {
return Cleanup(retentionDays)
}
func (s *defaultStore) Close() error {
return Close()
}
// store := database.NopStore() // all methods are no-ops; use when database is disabled
func NopStore() HashrateStore {
return &nopStore{}
}
type nopStore struct{}
func (s *nopStore) InsertHashratePoint(ctx context.Context, minerName, minerType string, point HashratePoint, resolution Resolution) error {
return nil
}
func (s *nopStore) GetHashrateHistory(minerName string, resolution Resolution, since, until time.Time) ([]HashratePoint, error) {
return nil, nil
}
func (s *nopStore) GetHashrateStats(minerName string) (*HashrateStats, error) {
return nil, nil
}
func (s *nopStore) GetAllMinerStats() ([]HashrateStats, error) {
return nil, nil
}
func (s *nopStore) Cleanup(retentionDays int) error {
return nil
}
func (s *nopStore) Close() error {
return nil
}