sqlite

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package sqlite implements the firehose cache using the pure-Go (no cgo) SQLite driver, modernc.org/sqlite, for portability reasons across various Linux architectures. The cache holds dedupe keys, conditional-GET validators, retention data, and feed-health state — never read state.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

type DB struct {
	*sql.DB
	// contains filtered or unexported fields
}

DB wraps a *sql.DB with firehose-specific open/migrate behavior. It also carries the display *time.Location so times read back from the cache are interpreted consistently (SQLite has no native tz; we store UTC and present in the configured location at render time).

func NewDB

func NewDB(dsn string, loc *time.Location) *DB

NewDB constructs a DB for the SQLite file at dsn. loc is the display location used when scanning timestamps. Call Open to connect and migrate.

func (*DB) Open

func (db *DB) Open(ctx context.Context) error

Open connects to the database, applies pragmas, and runs migrations. It is safe to call once at startup.

type FeedService

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

FeedService is the SQLite-backed firehose.FeedService.

func NewFeedService

func NewFeedService(db *DB) *FeedService

NewFeedService constructs a FeedService over db.

func (*FeedService) FindFeedByURL

func (s *FeedService) FindFeedByURL(ctx context.Context, url string) (*firehose.Feed, error)

FindFeedByURL returns the feed with the given URL or an ENOTFOUND error.

func (*FeedService) FindFeeds

func (s *FeedService) FindFeeds(ctx context.Context, filter firehose.FeedFilter) ([]*firehose.Feed, int, error)

FindFeeds returns feeds matching filter and the total count (ignoring offset/limit).

func (*FeedService) SyncFeeds

func (s *FeedService) SyncFeeds(ctx context.Context, feeds []*firehose.Feed) error

SyncFeeds reconciles the configured feed set into the cache: inserts new feeds, updates categories/config on existing ones (matched by URL), and deletes feeds no longer configured (cascading their items). Fetch-state columns on existing feeds are preserved.

func (*FeedService) UpdateFeed

func (s *FeedService) UpdateFeed(ctx context.Context, id int64, upd firehose.FeedUpdate) (*firehose.Feed, error)

UpdateFeed applies fetch/health state. Nil fields in upd are left unchanged.

type ItemService

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

ItemService is the SQLite-backed firehose.ItemService.

func NewItemService

func NewItemService(db *DB) *ItemService

NewItemService constructs an ItemService over db.

func (*ItemService) FindItems

func (s *ItemService) FindItems(ctx context.Context, filter firehose.ItemFilter) ([]*firehose.Item, int, error)

FindItems returns items matching filter, newest-first (published desc, then id desc as a stable tiebreaker for deterministic output), and the total count before offset/limit.

Category selection joins feed.categories. Because categories are stored as a newline-joined TEXT column, category matching is done in Go after scanning; the display window is applied in SQL (it is the selective predicate).

func (*ItemService) ItemStats added in v0.2.0

func (s *ItemService) ItemStats(ctx context.Context) ([]firehose.ItemStat, error)

ItemStats implements firehose.ItemService.

func (*ItemService) PurgeExpired

func (s *ItemService) PurgeExpired(ctx context.Context, olderThan time.Time) (int, error)

PurgeExpired deletes items published before olderThan (the cache-retention cutoff, distinct from and older than the display window). Returns the count removed.

func (*ItemService) UpsertItems

func (s *ItemService) UpsertItems(ctx context.Context, items []*firehose.Item) error

UpsertItems inserts new items and updates changed ones, keyed by (feed_id, guid). Existing rows keep their kid.ID so IDs stay stable across runs (id.Time() and deterministic ordering both depend on this). Items with a zero ID are assigned a fresh kid.ID on insert.

Jump to

Keyboard shortcuts

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