Skip to content

Storage Module

SQLite-based persistence for processed posts and pipeline run tracking. Uses Bun's built-in bun:sqlite driver with WAL mode for concurrent reads.

StorageService

Pipeline Runs

MethodDescription
insertRun(id)Create new run record (status=running)
updateRun(id, updates)Update run stage, status, timestamps
getRun(id)Fetch single run
getRecentRuns(limit)Fetch N most recent runs
getTodayCompletedCount()Count successful runs today
getStats()Aggregate statistics

Processed Posts

MethodDescription
markProcessed(postId, subreddit, title, score)Record processed post
isProcessed(postId)Check if already processed
getRecentProcessedPosts(limit)List recent posts

Database Schema

sql
CREATE TABLE processed_posts (
  id TEXT PRIMARY KEY,
  subreddit TEXT NOT NULL,
  processed_at TEXT NOT NULL,
  title TEXT,
  score INTEGER
);

CREATE TABLE pipeline_runs (
  id TEXT PRIMARY KEY,
  status TEXT NOT NULL,      -- running | complete | failed
  stage TEXT NOT NULL,       -- PipelineStage value
  started_at TEXT NOT NULL,
  completed_at TEXT,
  post_id TEXT,
  post_title TEXT,
  tiktok_url TEXT,
  error_message TEXT,
  duration_ms INTEGER
);

PipelineStats

typescript
interface PipelineStats {
  totalRuns: number;
  successCount: number;
  failureCount: number;
  successRate: number;
  avgDurationMs: number;
  todayCompleted: number;
  todayFailed: number;
}

Performance

  • Prepared statements for all queries
  • WAL (Write-Ahead Logging) enabled for concurrent reads
  • OnModuleInit / OnModuleDestroy manage database lifecycle

Built with VitePress