Skip to content

feat: persist settings and scores in SQLite database#7

Merged
manuelmauro merged 1 commit into
mainfrom
feat/sqlite-persistence
Apr 4, 2026
Merged

feat: persist settings and scores in SQLite database#7
manuelmauro merged 1 commit into
mainfrom
feat/sqlite-persistence

Conversation

@manuelmauro
Copy link
Copy Markdown
Owner

Summary

Game settings and score history are now persisted in a SQLite database using rusqlite (bundled) and dirs for platform-appropriate storage paths.

Database location

Platform Path
macOS ~/Library/Application Support/nback/nback.db
Linux ~/.local/share/nback/nback.db
Windows C:\Users\<user>\AppData\Roaming\nback\nback.db

Falls back to ./nback/nback.db if no data directory is available.

Schema

-- Single-row settings (auto-created with defaults on first run)
CREATE TABLE settings (
    id, n, rounds, round_time, position, color, shape, sound
);

-- One row per completed game session
CREATE TABLE scores (
    id, played_at, n, total_rounds, round_duration,
    correct, wrong, f1_score_percent
);

Behavior

  • Startup: database is opened/created, settings and last 50 scores loaded
  • Settings change: PersistencePlugin watches GameSettings for changes and saves to DB in PostUpdate (covers both menu edits and end-of-game difficulty adjustments)
  • Game end: score is inserted into DB, full history reloaded (so played_at timestamps are populated by SQLite)
  • ScoreRecord gains a played_at: String field (ISO-8601, set by datetime('now') default)

Dependencies added

  • rusqlite 0.35 with bundled feature (statically links SQLite)
  • dirs 6.0 for platform data directories

Add a persistence layer using rusqlite + dirs:

- Database stored at `dirs::data_dir()/nback/nback.db`
  (e.g. ~/Library/Application Support/nback/nback.db on macOS)
- Settings table: single-row, loaded at startup, saved whenever
  GameSettings resource changes (via PersistencePlugin)
- Scores table: one row per completed game session with an
  auto-populated played_at timestamp
- ScoreRecord gains a played_at field (ISO-8601 string)
- On game end: score is inserted, full history reloaded from DB
- On startup: settings and score history loaded from DB

Dependencies added: rusqlite (bundled), dirs
@manuelmauro manuelmauro merged commit 91251c2 into main Apr 4, 2026
3 checks passed
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