cache

package
v0.0.0-...-5f277d8 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package cache maintains a local SQLite database of health/activity samples for trend analysis. Agents can query it directly with SQL via `garmin cache query`; the schema is intentionally narrow (one JSON payload column per sample) so new metrics need no migrations.

Index

Constants

This section is empty.

Variables

View Source
var ErrReadOnly = fmt.Errorf("only SELECT/WITH queries are allowed")

ErrReadOnly is returned when a query is not a read-only statement.

Functions

func Open

func Open(path string) (*sql.DB, error)

Open creates/opens the cache database and ensures the schema.

func Query

func Query(db *sql.DB, sqlText string) ([]string, [][]any, error)

Query executes a single read-only SQL statement and returns columns and rows. Values keep their SQLite types (int64/float64/string/[]byte/nil).

func UpsertActivity

func UpsertActivity(db *sql.DB, a ActivityRow) error

UpsertActivity stores (or replaces) one cached activity.

func UpsertSample

func UpsertSample(db *sql.DB, s Sample) error

UpsertSample stores (or replaces) the payload for one profile/metric/date.

Types

type ActivityRow

type ActivityRow struct {
	Profile         string
	ActivityID      int64
	StartTimeLocal  string
	Type            string
	Name            string
	DistanceMeters  float64
	DurationSeconds float64
	Calories        int
	AvgHR           int
	Weather         string
	Payload         any
	FetchedAt       time.Time
}

ActivityRow is one activity cached for SQL analysis. Weather is the raw JSON from the activity weather endpoint (empty when unavailable, e.g. indoor activities).

type MetricStatus

type MetricStatus struct {
	Metric   string `json:"metric"`
	Count    int    `json:"count"`
	FirstDay string `json:"first_day"`
	LastDay  string `json:"last_day"`
}

MetricStatus describes the cached coverage of one metric.

func Status

func Status(db *sql.DB, profile string) ([]MetricStatus, error)

Status returns per-metric coverage for a profile.

type Sample

type Sample struct {
	Profile   string
	Region    string
	Metric    string
	Date      string
	Payload   any // marshaled to JSON
	FetchedAt time.Time
}

Sample is one metric/date row of the samples table.

Jump to

Keyboard shortcuts

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