db

package
v0.0.37 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrWorkoutNotFound = errors.New("workout not found")

ErrWorkoutNotFound indicates that the referenced workout does not exist.

Functions

This section is empty.

Types

type Exercise

type Exercise struct {
	ID          string    `json:"id"`                    // ID is the unique catalog identifier.
	Name        string    `json:"name"`                  // Name is the exercise label.
	OwnerUserID string    `json:"ownerUserId,omitempty"` // OwnerUserID is set for user-owned entries.
	IsCore      bool      `json:"isCore"`                // IsCore marks built-in exercises.
	CreatedAt   time.Time `json:"createdAt"`             // CreatedAt records when the entry was created.
}

Exercise represents a reusable exercise catalog entry.

type HealthChecker added in v0.0.20

type HealthChecker interface {
	Ping(ctx context.Context) error
}

HealthChecker is the minimal interface needed for health checks.

type PauseOptions

type PauseOptions struct {
	AutoAdvance bool `json:"autoAdvance,omitempty"` // AutoAdvance skips to the next step on completion.
}

PauseOptions captures optional behaviour for pause steps.

type Store

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

Store wraps all database access.

func New

func New(ctx context.Context, url string) (*Store, error)

New establishes a connection pool.

func (*Store) BackfillCoreExercises

func (s *Store) BackfillCoreExercises(ctx context.Context) error

BackfillCoreExercises creates core exercises from existing workout data and links them.

func (*Store) Close

func (s *Store) Close()

Close releases the underlying connection pool.

func (*Store) CreateExercise

func (s *Store) CreateExercise(ctx context.Context, name, ownerUserID string, isCore bool) (*Exercise, error)

CreateExercise inserts a new exercise entry.

func (*Store) CreateTemplateFromWorkout

func (s *Store) CreateTemplateFromWorkout(ctx context.Context, workoutID string, nameOverride string) (*Workout, error)

CreateTemplateFromWorkout clones an existing workout as a template.

func (*Store) CreateUser

func (s *Store) CreateUser(ctx context.Context, email, avatarURL, passwordHash string) (*User, error)

CreateUser inserts a new user with the provided password hash.

func (*Store) CreateWorkout

func (s *Store) CreateWorkout(ctx context.Context, w *Workout) (*Workout, error)

CreateWorkout inserts a workout and its steps for a user.

func (*Store) CreateWorkoutFromTemplate

func (s *Store) CreateWorkoutFromTemplate(ctx context.Context, templateID, userID, name string) (*Workout, error)

CreateWorkoutFromTemplate copies an existing template to a user.

func (*Store) DeleteExercise

func (s *Store) DeleteExercise(ctx context.Context, id string) error

DeleteExercise removes an exercise and clears linked workout rows.

func (*Store) DeleteWorkout

func (s *Store) DeleteWorkout(ctx context.Context, workoutID string) error

DeleteWorkout removes a workout and cascades its steps.

func (*Store) EnsureSchema

func (s *Store) EnsureSchema(ctx context.Context, logger *slog.Logger) error

EnsureSchema applies the baseline schema and any pending migrations.

func (*Store) GetExercise

func (s *Store) GetExercise(ctx context.Context, id string) (*Exercise, error)

GetExercise fetches a single exercise by id.

func (*Store) GetUser

func (s *Store) GetUser(ctx context.Context, id string) (*User, error)

GetUser fetches a single user by id.

func (*Store) GetUserWithPassword

func (s *Store) GetUserWithPassword(ctx context.Context, id string) (*User, string, error)

GetUserWithPassword fetches a user and password hash by id.

func (*Store) ListExercises

func (s *Store) ListExercises(ctx context.Context, userID string) ([]Exercise, error)

ListExercises returns core exercises plus user-owned exercises.

func (*Store) ListTemplates

func (s *Store) ListTemplates(ctx context.Context) ([]Workout, error)

ListTemplates returns all workout templates.

func (*Store) ListUsers

func (s *Store) ListUsers(ctx context.Context) ([]User, error)

ListUsers returns all users ordered by creation date.

func (*Store) Ping

func (s *Store) Ping(ctx context.Context) error

Ping validates the connection.

func (*Store) RecordTraining added in v0.0.28

func (s *Store) RecordTraining(ctx context.Context, log TrainingLog, steps []TrainingStepLog) error

RecordTraining stores a completed workout training and optional step timings. Duplicate IDs are ignored.

func (*Store) RenameExercise

func (s *Store) RenameExercise(ctx context.Context, id, name string) (*Exercise, error)

RenameExercise updates the catalog name and linked workout exercise names.

func (*Store) ReplaceExerciseForUser

func (s *Store) ReplaceExerciseForUser(ctx context.Context, userID, fromID, toID, toName string) error

ReplaceExerciseForUser swaps a user workout's exercise references to a new exercise id.

func (*Store) TrainingHistory added in v0.0.28

func (s *Store) TrainingHistory(ctx context.Context, userID string, limit int) ([]TrainingLog, error)

TrainingHistory returns recent trainings for a user.

func (*Store) TrainingStepTimings added in v0.0.28

func (s *Store) TrainingStepTimings(ctx context.Context, trainingID string) ([]TrainingStepLog, error)

TrainingStepTimings returns stored step durations for a training.

func (*Store) UpdateUserAdmin

func (s *Store) UpdateUserAdmin(ctx context.Context, userID string, isAdmin bool) error

UpdateUserAdmin sets the admin flag for a user.

func (*Store) UpdateUserName added in v0.0.18

func (s *Store) UpdateUserName(ctx context.Context, userID, name string) error

UpdateUserName changes the display name for a user.

func (*Store) UpdateUserPassword

func (s *Store) UpdateUserPassword(ctx context.Context, userID, passwordHash string) error

UpdateUserPassword sets the password hash for a user.

func (*Store) UpdateWorkout

func (s *Store) UpdateWorkout(ctx context.Context, w *Workout) (*Workout, error)

UpdateWorkout replaces the workout name and steps.

func (*Store) UpsertAdminUser

func (s *Store) UpsertAdminUser(ctx context.Context, email, passwordHash string) (*User, bool, error)

UpsertAdminUser ensures the admin user exists with the given password hash.

func (*Store) WorkoutSteps

func (s *Store) WorkoutSteps(ctx context.Context, workoutID string) ([]WorkoutStep, error)

WorkoutSteps fetches all steps for a workout ordered by step order.

func (*Store) WorkoutWithSteps

func (s *Store) WorkoutWithSteps(ctx context.Context, workoutID string) (*Workout, error)

WorkoutWithSteps retrieves a workout by id.

func (*Store) WorkoutsByUser

func (s *Store) WorkoutsByUser(ctx context.Context, userID string) ([]Workout, error)

WorkoutsByUser returns workouts for a user.

type SubsetExercise added in v0.0.20

type SubsetExercise struct {
	ID         string `json:"id"`         // ID is the unique exercise row identifier.
	SubsetID   string `json:"subsetId"`   // SubsetID links to the parent subset.
	Order      int    `json:"order"`      // Order is the exercise sequence within the subset.
	ExerciseID string `json:"exerciseId"` // ExerciseID links to the catalog entry.
	Name       string `json:"name"`       // Name is the exercise label.
	Type       string `json:"type"`       // Type is rep, stopwatch, or countdown.
	Reps       string `json:"reps"`       // Reps is the repetition text.
	Weight     string `json:"weight"`     // Weight is optional load text.
	Duration   string `json:"duration"`   // Duration is a stopwatch/countdown value.
	SoundKey   string `json:"soundKey"`   // SoundKey overrides the subset sound.
}

type TrainingLog added in v0.0.28

type TrainingLog struct {
	ID          string    `json:"id"`          // ID is the unique training identifier.
	WorkoutID   string    `json:"workoutId"`   // WorkoutID links to the workout.
	WorkoutName string    `json:"workoutName"` // WorkoutName is the display name at completion time.
	UserID      string    `json:"userId"`      // UserID owns the training.
	StartedAt   time.Time `json:"startedAt"`   // StartedAt is when the training began.
	CompletedAt time.Time `json:"completedAt"` // CompletedAt is when the training finished.
}

TrainingLog represents a completed workout training.

type TrainingStepLog added in v0.0.28

type TrainingStepLog struct {
	ID               string `json:"id"`               // ID is the unique log row identifier.
	TrainingID       string `json:"trainingId"`       // TrainingID links to the training.
	StepOrder        int    `json:"stepOrder"`        // StepOrder preserves training ordering.
	Type             string `json:"type"`             // Type is the step kind.
	Name             string `json:"name"`             // Name is the step label.
	EstimatedSeconds int    `json:"estimatedSeconds"` // EstimatedSeconds is the target duration.
	ElapsedMillis    int64  `json:"elapsedMillis"`    // ElapsedMillis is the observed duration.
}

TrainingStepLog captures actual timing for a completed step.

type User

type User struct {
	ID        string    `json:"id"`        // ID is the unique user identifier.
	Name      string    `json:"name"`      // Name is the display name.
	IsAdmin   bool      `json:"isAdmin"`   // IsAdmin marks admin privileges.
	AvatarURL string    `json:"avatarUrl"` // AvatarURL is the optional avatar image.
	CreatedAt time.Time `json:"createdAt"` // CreatedAt records when the user was created.
}

User represents an account owner.

type Workout

type Workout struct {
	ID         string        `json:"id"`         // ID is the unique workout identifier.
	UserID     string        `json:"userId"`     // UserID owns the workout.
	Name       string        `json:"name"`       // Name is the workout title.
	IsTemplate bool          `json:"isTemplate"` // IsTemplate marks shared templates.
	CreatedAt  time.Time     `json:"createdAt"`  // CreatedAt records when the workout was created.
	Steps      []WorkoutStep `json:"steps"`      // Steps defines the workout flow.
}

Workout groups stopwatch steps.

type WorkoutStep

type WorkoutStep struct {
	ID                    string          `json:"id"`                              // ID is the unique step identifier.
	WorkoutID             string          `json:"workoutId"`                       // WorkoutID links to the parent workout.
	Order                 int             `json:"order"`                           // Order defines the step sequence.
	Type                  string          `json:"type"`                            // Type is set or pause.
	Name                  string          `json:"name"`                            // Name is the step label.
	EstimatedSeconds      int             `json:"estimatedSeconds"`                // EstimatedSeconds is the target duration.
	SoundKey              string          `json:"soundKey"`                        // SoundKey plays on step completion.
	Subsets               []WorkoutSubset `json:"subsets"`                         // Subsets hold exercises for set steps.
	PauseOptions          PauseOptions    `json:"pauseOptions,omitempty"`          // PauseOptions configure pause behavior.
	RepeatCount           int             `json:"repeatCount,omitempty"`           // RepeatCount repeats the step group.
	RepeatRestSeconds     int             `json:"repeatRestSeconds,omitempty"`     // RepeatRestSeconds is rest between repeats.
	RepeatRestAfterLast   bool            `json:"repeatRestAfterLast,omitempty"`   // RepeatRestAfterLast includes rest after last repeat.
	RepeatRestSoundKey    string          `json:"repeatRestSoundKey,omitempty"`    // RepeatRestSoundKey plays during repeat rest.
	RepeatRestAutoAdvance bool            `json:"repeatRestAutoAdvance,omitempty"` // RepeatRestAutoAdvance skips repeat rest automatically.
	RepeatRestName        string          `json:"repeatRestName,omitempty"`        // RepeatRestName overrides the repeat pause label.

	CreatedAt time.Time `json:"createdAt"` // CreatedAt records when the step was created.
}

WorkoutStep defines a single part of the workout.

func (*WorkoutStep) NormalizeRepeatSettings added in v0.0.18

func (w *WorkoutStep) NormalizeRepeatSettings()

NormalizeRepeatSettings clamps and clears repeat rest settings for a step.

type WorkoutSubset added in v0.0.20

type WorkoutSubset struct {
	ID               string           `json:"id"`               // ID is the unique subset identifier.
	StepID           string           `json:"stepId"`           // StepID links to the parent step.
	Order            int              `json:"order"`            // Order is the subset sequence within the step.
	Name             string           `json:"name"`             // Name is the subset label.
	EstimatedSeconds int              `json:"estimatedSeconds"` // EstimatedSeconds is the subset target.
	SoundKey         string           `json:"soundKey"`         // SoundKey plays at the subset target.
	Superset         bool             `json:"superset"`         // Superset skips to the next subset on Next.
	Exercises        []SubsetExercise `json:"exercises"`        // Exercises belong to the subset.
	CreatedAt        time.Time        `json:"createdAt"`        // CreatedAt records when the subset was created.
}

Jump to

Keyboard shortcuts

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