store

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2026 License: MIT Imports: 6 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) 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) 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) 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) InsertSession

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

InsertSession inserts a completed reading session and returns its ID.

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) 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