db

package
v0.0.0-...-9ecc644 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

db.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DBMetric

type DBMetric struct {
	MetricName string
	Type       string
	Unit       string
	Value      float64
	ResetDaily bool
	LastReset  time.Time
}

DBMetric represents a metric stored in the database

type Database

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

Database encapsulates the SQLite connection and a mutex for thread safety

func NewDatabase

func NewDatabase(dbPath string) (*Database, error)

NewDatabase initializes a new Database instance

func (*Database) AddMetric

func (db *Database) AddMetric(metric DBMetric) error

AddMetric inserts a new metric into the database

func (*Database) DecrementMetric

func (db *Database) DecrementMetric(metricName string, decrement float64) error

DecrementMetric decreases the value of a metric by a specified amount

func (*Database) DeleteMetric

func (db *Database) DeleteMetric(metricName string) error

DeleteMetric removes a metric from the database by its name.

func (*Database) GetMetric

func (db *Database) GetMetric(metricName string) (*DBMetric, error)

GetMetric retrieves a single metric by its name

func (*Database) GetMetrics

func (db *Database) GetMetrics() ([]DBMetric, error)

GetMetrics retrieves all metrics from the database

func (*Database) IncrementMetric

func (db *Database) IncrementMetric(metricName string, increment float64) error

IncrementMetric increases the value of a metric by a specified amount

func (*Database) ResetDailyMetrics

func (db *Database) ResetDailyMetrics() error

ResetDailyMetrics resets all metrics that are marked to reset daily and haven't been reset today

func (*Database) StartDailyResetScheduler

func (db *Database) StartDailyResetScheduler(stopChan chan bool)

StartDailyResetScheduler starts a scheduler that resets daily metrics at midnight using Go channels.

func (*Database) UpdateMetric

func (db *Database) UpdateMetric(metricName string, newValue float64) error

UpdateMetric sets the value of a metric to a new specified value

Jump to

Keyboard shortcuts

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