Documentation
¶
Index ¶
- type Store
- func (s *Store) Close() error
- func (s *Store) DeleteState(key string) error
- func (s *Store) DeleteUserBooksByStatus(status model.Status) error
- func (s *Store) GetBookByID(id int) (*model.Book, error)
- func (s *Store) GetDailyActivity(from, to time.Time) ([]model.DayActivity, error)
- func (s *Store) GetLatestRead(userBookID int) (*model.UserBookRead, error)
- func (s *Store) GetState(key string) (string, error)
- func (s *Store) GetUserBookByBookID(bookID int) (*model.UserBook, error)
- func (s *Store) GetWeeklyStats(from, to time.Time) (model.WeeklyStats, error)
- func (s *Store) InsertSession(session model.ReadingSession) (int, error)
- func (s *Store) ListSessions(limit int) ([]model.ReadingSession, error)
- func (s *Store) ListUserBooks(status model.Status) ([]model.UserBook, error)
- func (s *Store) PruneOrphanBooks(maxAgeDays int) error
- func (s *Store) SetState(key, value string) error
- func (s *Store) UpsertBook(b model.Book) error
- func (s *Store) UpsertUserBook(ub model.UserBook) error
- func (s *Store) UpsertUserBookRead(r model.UserBookRead) error
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 ¶
New opens (or creates) the SQLite database at dbPath, runs migrations, and returns a ready-to-use Store.
func (*Store) DeleteState ¶
DeleteState removes a key from the state table.
func (*Store) DeleteUserBooksByStatus ¶
DeleteUserBooksByStatus removes all user_books rows for a status and their reads.
func (*Store) GetBookByID ¶
GetBookByID retrieves a single book by its ID. Returns nil, nil when the book is not found.
func (*Store) GetDailyActivity ¶
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 ¶
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 ¶
GetUserBookByBookID retrieves a single user_book by its book_id, joined with the books table. Returns nil, nil when not found.
func (*Store) GetWeeklyStats ¶
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 ¶
ListUserBooks returns all user_books matching the given status, joined with the books table to populate the embedded Book struct.
func (*Store) PruneOrphanBooks ¶
PruneOrphanBooks removes cached books not referenced by user_books and older than maxAgeDays.
func (*Store) UpsertBook ¶
UpsertBook inserts or replaces a book record. Authors are stored as a comma-separated string.
func (*Store) UpsertUserBook ¶
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.