store

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Store

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

Store wraps a SQLite database connection for local book data.

func New

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

New opens (or creates) the SQLite database at dbPath, runs migrations, and returns a ready-to-use Store.

func (*Store) Close

func (s *Store) Close() error

Close closes the underlying database connection.

func (*Store) DeleteState

func (s *Store) DeleteState(key string) error

DeleteState removes a key from the state table.

func (*Store) DeleteUserBooksByStatus

func (s *Store) DeleteUserBooksByStatus(status model.Status) error

DeleteUserBooksByStatus removes all user_books rows for a status and their reads.

func (*Store) GetBookByID

func (s *Store) GetBookByID(id int) (*model.Book, error)

GetBookByID retrieves a single book by its ID. Returns nil, nil when the book is not found.

func (*Store) GetBooksPerMonth added in v0.6.0

func (s *Store) GetBooksPerMonth(year int) ([12]int, error)

GetBooksPerMonth returns books finished per month (Jan=0) for one year.

func (*Store) GetBooksPerYear added in v0.6.0

func (s *Store) GetBooksPerYear() ([]model.LabelCount, error)

GetBooksPerYear returns books finished per year, ascending.

func (*Store) GetDailyActivity

func (s *Store) GetDailyActivity(from, to time.Time) ([]model.DayActivity, error)

GetDailyActivity returns total reading minutes per day in the given range. Only completed sessions (ended_at IS NOT NULL) are counted.

func (*Store) GetGenreBreakdown added in v0.6.0

func (s *Store) GetGenreBreakdown(limit int) ([]model.LabelCount, error)

GetGenreBreakdown returns the most common genres across the user's finished books, descending, limited to `limit` entries.

func (*Store) GetJournalDays added in v0.6.0

func (s *Store) GetJournalDays(from, to time.Time) ([]time.Time, error)

GetJournalDays returns the distinct calendar days with at least one journal entry in the given range. Date-only timestamps (midnight) are taken as-is; timestamps with a time component are converted to local time first.

func (*Store) GetLatestRead

func (s *Store) GetLatestRead(userBookID int) (*model.UserBookRead, error)

GetLatestRead returns the most recent user_book_reads row for the given user_book_id, ordered by started_at descending. Returns nil, nil when no reads exist.

func (*Store) GetRatingsDistribution added in v0.6.0

func (s *Store) GetRatingsDistribution() ([10]int, error)

GetRatingsDistribution returns counts per half-star bucket: index i holds books rated (i+1)*0.5 stars.

func (*Store) GetState

func (s *Store) GetState(key string) (string, error)

GetState retrieves a value from the state key-value table. Returns an empty string (and no error) when the key is not found.

func (*Store) GetUserBookByBookID

func (s *Store) GetUserBookByBookID(bookID int) (*model.UserBook, error)

GetUserBookByBookID retrieves a single user_book by its book_id, joined with the books table. Returns nil, nil when not found.

func (*Store) GetWeeklyStats

func (s *Store) GetWeeklyStats(from, to time.Time) (model.WeeklyStats, error)

GetWeeklyStats returns aggregated stats for completed sessions in the given range.

func (*Store) GetYearSummary added in v0.6.0

func (s *Store) GetYearSummary(year int) (model.YearSummary, error)

GetYearSummary aggregates finished books, pages read, and the user's average rating for one calendar year. Finished dates from Hardcover are date-only, so bucketing uses the stored date verbatim (no timezone conversion).

func (*Store) InsertLocalJournal added in v0.6.0

func (s *Store) InsertLocalJournal(actionAt time.Time, event string) error

InsertLocalJournal records an optimistic local journal entry (negative ID) so the heatmap reflects activity immediately, before the next sync pulls the server-side entry. Duplicate days are harmless: activity is counted per day.

func (*Store) InsertSession

func (s *Store) InsertSession(session model.ReadingSession) (int, error)

InsertSession inserts a completed reading session and returns its ID.

func (*Store) ListGoals added in v0.6.0

func (s *Store) ListGoals() ([]model.Goal, error)

ListGoals returns all cached reading goals.

func (*Store) ListSessions

func (s *Store) ListSessions(limit int) ([]model.ReadingSession, error)

ListSessions returns the most recent reading sessions, limited to `limit`. Sessions are joined with books to populate BookTitle when available.

func (*Store) ListUserBooks

func (s *Store) ListUserBooks(status model.Status) ([]model.UserBook, error)

ListUserBooks returns all user_books matching the given status, joined with the books table to populate the embedded Book struct.

func (*Store) PruneOrphanBooks

func (s *Store) PruneOrphanBooks(maxAgeDays int) error

PruneOrphanBooks removes cached books not referenced by user_books and older than maxAgeDays.

func (*Store) ReplaceGoals added in v0.6.0

func (s *Store) ReplaceGoals(goals []model.Goal) error

ReplaceGoals atomically swaps the cached reading goals.

func (*Store) ReplaceReadingJournals added in v0.6.0

func (s *Store) ReplaceReadingJournals(entries []model.JournalEntry) error

ReplaceReadingJournals atomically swaps the cached server journal entries with the given set. Local optimistic rows (negative IDs) are kept, except those old enough that a sync would long since have covered them.

func (*Store) ReplaceUserBooksForStatus added in v0.4.4

func (s *Store) ReplaceUserBooksForStatus(status model.Status, books []model.UserBook) error

ReplaceUserBooksForStatus atomically swaps all cached rows for a status with the given books (and their reads). A failure mid-way rolls back, leaving the previous cache intact.

func (*Store) SetState

func (s *Store) SetState(key, value string) error

SetState inserts or replaces a key-value pair in the state table.

func (*Store) UpsertBook

func (s *Store) UpsertBook(b model.Book) error

UpsertBook inserts or replaces a book record. Authors are stored as a comma-separated string.

func (*Store) UpsertUserBook

func (s *Store) UpsertUserBook(ub model.UserBook) error

UpsertUserBook inserts or replaces a user_book record and also upserts the associated book so the local books table stays in sync.

func (*Store) UpsertUserBookRead

func (s *Store) UpsertUserBookRead(r model.UserBookRead) error

UpsertUserBookRead inserts or replaces a user_book_reads record.

Jump to

Keyboard shortcuts

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