Skip to content

Conversation

art049
Copy link
Member

@art049 art049 commented Sep 29, 2025

Summary

This PR replaces the in-memory slice-based album storage with a persistent SQLite database implementation.

Changes

Database Setup

  • Added SQLite driver dependency (github.com/mattn/go-sqlite3)
  • Created initDB() function to initialize SQLite database with schema
  • Database file albums.db stores persistent album data
  • Automatic seeding with initial album data on first run

Data Model

  • Changed album ID from string to int64 to support auto-increment primary keys
  • Added proper database schema with NOT NULL constraints

API Handlers

  • GET /albums: Updated to query all albums from database with proper error handling
  • POST /albums: Now inserts albums into database and returns generated ID
  • GET /albums/:id: Replaced slice iteration with SQL query by ID

Testing

  • Updated benchmark tests to work with database-generated IDs
  • Removed hard-coded ID from POST benchmark test
  • Fixed invalid JSON test case

Error Handling

  • Added proper error responses for database operations
  • Distinguish between "not found" (404) and internal errors (500)

Test Plan

  • All API endpoints work with SQLite backend
  • Database is created and seeded on first run
  • Benchmark tests pass with new implementation

🤖 Generated with Claude Code

Co-Authored-By: Claude [email protected]

Copy link

codspeed-hq bot commented Sep 29, 2025

CodSpeed Performance Report

Merging #1 will degrade performances by 85.89%

Comparing feature/sqlite-database (3c7d0e9) with main (769218c)

Summary

❌ 3 regressions
✅ 3 untouched

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark BASE HEAD Change
BenchmarkGetAlbumByIDExists 10.9 µs 77.6 µs -85.89%
BenchmarkGetAlbumByIDNotFound 10.1 µs 66.8 µs -84.81%
BenchmarkGetAlbums 15.7 µs 92.5 µs -83.01%

@art049 art049 force-pushed the feature/sqlite-database branch from a3e9857 to 192578c Compare September 30, 2025 13:09
- Add SQLite driver dependency (github.com/mattn/go-sqlite3)
- Create initDB() function to initialize SQLite database with schema
- Update all API handlers to use SQL queries instead of in-memory slice
- Seed database with initial album data on first run
- Update benchmark setup to initialize database for testing
- Database file: albums.db stores persistent album data

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@art049 art049 force-pushed the feature/sqlite-database branch from 192578c to 3c7d0e9 Compare September 30, 2025 13:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant