storage

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TableNameMap = map[string]string{

	"heart-rate": "heart_rate",
	"heart_rate": "heart_rate",
	"steps":      "steps",
	"spo2":       "spo2",
	"vo2max":     "vo2_max",
	"vo2_max":    "vo2_max",
	"sleep":      "sleep",
	"workouts":   "workouts",

	"resting-heart-rate":  "resting_heart_rate",
	"resting_heart_rate":  "resting_heart_rate",
	"hrv":                 "hrv",
	"heart-rate-recovery": "heart_rate_recovery",
	"heart_rate_recovery": "heart_rate_recovery",
	"respiratory-rate":    "respiratory_rate",
	"respiratory_rate":    "respiratory_rate",
	"blood-pressure":      "blood_pressure",
	"blood_pressure":      "blood_pressure",

	"active-energy":   "active_energy",
	"active_energy":   "active_energy",
	"basal-energy":    "basal_energy",
	"basal_energy":    "basal_energy",
	"exercise-time":   "exercise_time",
	"exercise_time":   "exercise_time",
	"stand-time":      "stand_time",
	"stand_time":      "stand_time",
	"flights-climbed": "flights_climbed",
	"flights_climbed": "flights_climbed",

	"distance-walking-running": "distance_walking_running",
	"distance_walking_running": "distance_walking_running",
	"distance-cycling":         "distance_cycling",
	"distance_cycling":         "distance_cycling",

	"body-mass":       "body_mass",
	"body_mass":       "body_mass",
	"bmi":             "body_mass_index",
	"body-mass-index": "body_mass_index",
	"body_mass_index": "body_mass_index",
	"height":          "height",

	"walking-speed":          "walking_speed",
	"walking_speed":          "walking_speed",
	"walking-step-length":    "walking_step_length",
	"walking_step_length":    "walking_step_length",
	"walking-asymmetry":      "walking_asymmetry",
	"walking_asymmetry":      "walking_asymmetry",
	"walking-double-support": "walking_double_support",
	"walking_double_support": "walking_double_support",
	"walking-steadiness":     "walking_steadiness",
	"walking_steadiness":     "walking_steadiness",
	"stair-ascent-speed":     "stair_ascent_speed",
	"stair_ascent_speed":     "stair_ascent_speed",
	"stair-descent-speed":    "stair_descent_speed",
	"stair_descent_speed":    "stair_descent_speed",
	"six-minute-walk":        "six_minute_walk",
	"six_minute_walk":        "six_minute_walk",

	"running-speed":                "running_speed",
	"running_speed":                "running_speed",
	"running-power":                "running_power",
	"running_power":                "running_power",
	"running-stride-length":        "running_stride_length",
	"running_stride_length":        "running_stride_length",
	"running-ground-contact-time":  "running_ground_contact_time",
	"running_ground_contact_time":  "running_ground_contact_time",
	"running-vertical-oscillation": "running_vertical_oscillation",
	"running_vertical_oscillation": "running_vertical_oscillation",

	"wrist-temperature":  "wrist_temperature",
	"wrist_temperature":  "wrist_temperature",
	"time-in-daylight":   "time_in_daylight",
	"time_in_daylight":   "time_in_daylight",
	"dietary-water":      "dietary_water",
	"dietary_water":      "dietary_water",
	"physical-effort":    "physical_effort",
	"physical_effort":    "physical_effort",
	"walking-heart-rate": "walking_heart_rate",
	"walking_heart_rate": "walking_heart_rate",

	"mindful-sessions": "mindful_sessions",
	"mindful_sessions": "mindful_sessions",
	"stand-hours":      "stand_hours",
	"stand_hours":      "stand_hours",
}

TableNameMap maps CLI-friendly names to actual table names.

Functions

func DefaultDBPath

func DefaultDBPath() string

DefaultDBPath returns ~/.healthsync/healthsync.db

func ValidTableNames

func ValidTableNames() []string

ValidTableNames returns the list of valid CLI table names.

Types

type DB

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

DB wraps the sql.DB connection and provides health data operations.

func Open

func Open(dbPath string) (*DB, error)

Open opens (or creates) the SQLite database at the given path.

func (*DB) BatchInsertRecords

func (db *DB) BatchInsertRecords(table string, columns []string, records [][]interface{}) (*InsertStats, error)

BatchInsertRecords inserts health records in batches using INSERT OR IGNORE. records should be a slice of []interface{} where each element is a row's values.

func (*DB) Close

func (db *DB) Close() error

Close closes the database connection.

func (*DB) Conn

func (db *DB) Conn() *sql.DB

Conn returns the underlying *sql.DB for direct access.

func (*DB) CountRows

func (db *DB) CountRows(table string) (int64, error)

CountRows returns the total row count for a table.

func (*DB) GetDBInfo added in v0.5.0

func (db *DB) GetDBInfo(dbPath string) (*DBInfo, error)

GetDBInfo returns statistics about the database at dbPath.

func (*DB) QueryActiveEnergyDailyTotal added in v0.4.0

func (db *DB) QueryActiveEnergyDailyTotal(params QueryParams) ([]map[string]interface{}, error)

QueryActiveEnergyDailyTotal returns deduplicated daily active energy totals aggregated by calendar day.

func (*DB) QueryBasalEnergyDailyTotal added in v0.4.0

func (db *DB) QueryBasalEnergyDailyTotal(params QueryParams) ([]map[string]interface{}, error)

QueryBasalEnergyDailyTotal returns deduplicated daily basal energy totals aggregated by calendar day.

func (*DB) QueryRows

func (db *DB) QueryRows(params QueryParams) ([]map[string]interface{}, error)

QueryRows executes a query against the specified table and returns rows as maps.

func (*DB) QueryStepsDailyTotal added in v0.2.0

func (db *DB) QueryStepsDailyTotal(params QueryParams) ([]map[string]interface{}, error)

QueryStepsDailyTotal returns deduplicated step totals aggregated by calendar day.

type DBInfo added in v0.5.0

type DBInfo struct {
	Path       string
	FileSizeMB float64
	Tables     []TableInfo // only non-empty tables, sorted by row count desc
	TotalRows  int64
}

DBInfo holds overall database statistics.

type InsertStats

type InsertStats struct {
	Table    string
	Inserted int64
	Skipped  int64
}

InsertStats tracks how many rows were inserted vs skipped (duplicates).

type QueryParams

type QueryParams struct {
	Table  string
	From   string // start date filter (inclusive)
	To     string // end date filter (inclusive)
	Limit  int
	Offset int
}

QueryParams holds filters for querying health data.

type TableInfo added in v0.5.0

type TableInfo struct {
	Name     string
	RowCount int64
	LastDate string // MAX(start_date)
}

TableInfo holds per-table stats for db info output.

Jump to

Keyboard shortcuts

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