databaser

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2025 License: MIT Imports: 10 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package databaser provides SQLite database connection and operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InTransaction

func InTransaction(ctx context.Context, db *DB, f func(tx *sqlx.Tx) error) error

InTransaction executes the given function within a database transaction.

func SaveManyEventsTx

func SaveManyEventsTx(ctx context.Context, tx *sqlx.Tx, events []*Event) error

SaveManyEventsTx stores multiple events in the database within a transaction.

Types

type DB

type DB struct {
	*sqlx.DB
}

DB wraps sqlx.DB for database operations.

func New

func New(ctx context.Context, path string) (*DB, error)

New creates a new database connection.

func (*DB) Close

func (db *DB) Close() error

Close closes the database connection.

func (*DB) GetEvents

func (db *DB) GetEvents(ctx context.Context, period time.Duration, location *time.Location) ([]Event, error)

GetEvents retrieves events to the current time minus the given period.

func (*DB) Init

func (db *DB) Init(ctx context.Context) error

Init initializes the database schema.

func (*DB) SaveEvent

func (db *DB) SaveEvent(ctx context.Context, event Event) error

SaveEvent stores an event in the database.

func (*DB) SaveManyEvents

func (db *DB) SaveManyEvents(ctx context.Context, events []Event) error

SaveManyEvents stores multiple events in the database.

type Event

type Event struct {
	Timestamp time.Time `db:"timestamp"`
	Load      uint8     `db:"load"`
}

Event represents a load event with a timestamp and load percentage.

func NewEventFromCSVRecord

func NewEventFromCSVRecord(record []string, location *time.Location) (*Event, error)

NewEventFromCSVRecord creates an Event from a CSV record.

func (Event) LogValue

func (e Event) LogValue() slog.Value

LogValue implements slog.LogValuer for Event.

Jump to

Keyboard shortcuts

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