store

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2026 License: MIT Imports: 14 Imported by: 0 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 store provides persistence for scheduling state.

Index

Constants

This section is empty.

Variables

View Source
var ErrConflict = errors.New("conflict")

ErrConflict indicates a uniqueness constraint was violated (e.g. duplicate name).

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

ErrNotFound indicates the requested record does not exist.

Functions

This section is empty.

Types

type BlockRecord

type BlockRecord struct {
	ID        string // uuid string
	Name      string // unique
	Enabled   bool
	Spec      scheduler.Block // full block definition
	CreatedAt time.Time
	UpdatedAt time.Time
}

BlockRecord is the persisted representation of a scheduling block. Blocks are the API-editable source of truth for scheduling, replacing the static blocks previously defined in scheduler.yaml.

type Store

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

Store implements the persistence layer for Schedularr.

func New

func New(dsn string) (*Store, error)

New creates a new Store instance connected to the specified SQLite database. dsn is augmented with sqliteDSNParams -- see its doc comment.

func (*Store) Backup

func (s *Store) Backup(ctx context.Context, destPath string) error

Backup creates a safe backup of the database to the specified path using VACUUM INTO.

func (*Store) CleanupScheduleHistory

func (s *Store) CleanupScheduleHistory(ctx context.Context, window time.Duration) (int64, error)

CleanupScheduleHistory removes schedule history entries older than the window.

func (*Store) Close

func (s *Store) Close() error

Close closes the database connection.

func (*Store) CountBlocks

func (s *Store) CountBlocks(ctx context.Context) (int64, error)

CountBlocks returns the total number of blocks.

func (*Store) CreateBlock

func (s *Store) CreateBlock(ctx context.Context, rec *BlockRecord) error

CreateBlock inserts a new block, setting CreatedAt/UpdatedAt. Returns ErrConflict if a block with the same name already exists.

func (*Store) DeleteBlock

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

DeleteBlock removes a block by ID. Returns ErrNotFound if it does not exist.

func (*Store) ExportAllSeriesStates

func (s *Store) ExportAllSeriesStates(ctx context.Context) ([]scheduler.SeriesState, error)

ExportAllSeriesStates exports all series states to a slice for backup/export.

func (*Store) GetBlock

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

GetBlock retrieves a block by ID. Returns ErrNotFound if it does not exist.

func (*Store) GetPersistedSeriesState

func (s *Store) GetPersistedSeriesState(ctx context.Context, showTitle string) (*scheduler.SeriesState, error)

GetPersistedSeriesState retrieves the tracking state for a given show, returning ErrNotFound if no row is persisted for it. This is the existence-aware counterpart to GetSeriesState: GetSeriesState always succeeds with a fabricated S01E01 default for an untracked show (useful for the scheduler engine, which needs a starting point regardless), which makes it unsuitable for callers that must map "unknown show" to a 404 -- currently the state API's PatchSeriesState handler (internal/api/state.go).

func (*Store) GetSeriesState

func (s *Store) GetSeriesState(ctx context.Context, showTitle string) (*scheduler.SeriesState, error)

GetSeriesState retrieves the tracking state for a given show. If no state exists, it returns a default starting state (S01E01).

func (*Store) ImportSeriesStates

func (s *Store) ImportSeriesStates(ctx context.Context, states []scheduler.SeriesState) error

ImportSeriesStates imports series states from a slice, replacing existing states.

func (*Store) ListBlocks

func (s *Store) ListBlocks(ctx context.Context) ([]BlockRecord, error)

ListBlocks returns all blocks ordered by name.

func (*Store) ListScheduleHistory

func (s *Store) ListScheduleHistory(ctx context.Context, since time.Time) ([]scheduler.ScheduleHistoryEntry, error)

ListScheduleHistory returns schedule history entries scheduled at or after since, ordered by scheduled_at DESC (most recent first). This backs the GET /history API endpoint (internal/api/history.go), which maps a caller-supplied days window to since = now - days.

func (*Store) Ping

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

Ping verifies the database connection is live by executing a trivial `SELECT 1` round-trip, rather than sql.DB's own PingContext (which some drivers implement as a no-op connection check rather than an actual query). Used by the API server's /readyz endpoint (internal/api/router.go) to report readiness -- distinct from process liveness, which /healthz reports without touching the store at all.

func (*Store) RecordScheduleHistory

func (s *Store) RecordScheduleHistory(ctx context.Context, entries []scheduler.ScheduleHistoryEntry) error

RecordScheduleHistory persists schedule history entries for future filtering.

func (*Store) ResetSeriesState

func (s *Store) ResetSeriesState(ctx context.Context, showTitle string) error

ResetSeriesState resets a series to its starting state (S01E01, not completed).

func (*Store) SetSeriesState

func (s *Store) SetSeriesState(ctx context.Context, showTitle string, season, episode int) error

SetSeriesState sets a series to a specific season and episode. If the series doesn't exist, it creates a new entry.

func (*Store) UpdateBlock

func (s *Store) UpdateBlock(ctx context.Context, rec *BlockRecord) error

UpdateBlock updates an existing block's fields and bumps UpdatedAt. Returns ErrNotFound if no block with the given ID exists, or ErrConflict if the update would violate the unique name constraint.

func (*Store) UpdateSeriesState

func (s *Store) UpdateSeriesState(ctx context.Context, state *scheduler.SeriesState) error

UpdateSeriesState updates or inserts the tracking state for a show.

func (*Store) WasRecentlyScheduled

func (s *Store) WasRecentlyScheduled(ctx context.Context, programID, channelID string, window time.Duration) (bool, error)

WasRecentlyScheduled returns true if a program was scheduled within the provided window.

Jump to

Keyboard shortcuts

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