Coding
PromptBeginner5 minmarkdown
Nano Banana Pro
Agent skill for nano-banana-pro
6
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Sign in to like and favorite skills
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is a Go library providing database persistence for Reddit data fetched via
go-reddit-api-wrapper. It supports both PostgreSQL and SQLite backends with identical interfaces.
# Run all tests go test -v ./... # Run specific package tests go test -v ./sqlite go test -v ./postgres # Run PostgreSQL tests (requires DATABASE_URL) export TEST_POSTGRES_URL="postgres://user:pass@localhost/reddit_test?sslmode=disable" go test -v ./postgres # Start test PostgreSQL with Docker docker run -d --name test-postgres \ -e POSTGRES_PASSWORD=test \ -e POSTGRES_DB=reddit_test \ -p 5432:5432 \ postgres:15
# Build CLI tool go build -o reddit-archiver ./cmd/reddit-archiver # Install CLI globally go install github.com/jamesprial/go-reddit-storage/cmd/reddit-archiver@latest
# Set required environment variables export REDDIT_CLIENT_ID="your-client-id" export REDDIT_CLIENT_SECRET="your-client-secret" # Run examples go run examples/basic/main.go go run examples/continuous/main.go go run examples/backfill/main.go # Run CLI tool ./reddit-archiver -subreddit golang -limit 100 -comments
The codebase uses an interface-based design (storage.go) that allows multiple backend implementations. Both PostgreSQL and SQLite implement the same
Storage interface, providing:
The
Archiver type (archiver.go) combines a Reddit API client with a storage backend to provide high-level operations:
ArchiveSubreddit - Fetch and store posts from a subredditArchivePost - Fetch and store a single post with commentsContinuousArchive - Monitor and archive new content continuouslyBackfillSubreddit - Archive historical posts with paginationUpdateScores - Refresh scores for recently archived postsgo:embed (schema/schema.go)schema_version tableNNN_description.sql where NNN is the version numberAll save operations use UPSERT patterns:
INSERT ... ON CONFLICT DO UPDATEINSERT OR REPLACE
This ensures re-archiving the same content is safe and updates existing records.SavePosts and SaveComments use transactions and prepared statementsdepth field and parent_id referencesEach backend (postgres/, sqlite/) is organized into:
<backend>.go - Connection, migrations, close, subreddit operationsposts.go - Post-specific CRUD operationscomments.go - Comment-specific CRUD operations<backend>_test.go - Backend-specific testsThe codebase uses
StorageError type (storage.go) for all storage-related errors. This wraps underlying errors with operation context.
Storage interface in storage.gopostgres_test.go and sqlite_test.go00X_description.sql in both schema/migrations/postgres/ and schema/migrations/sqlite/RunMigrations() callTEST_POSTGRES_URL environment variableraw_json columns for future schema evolutionsslmode parameter