Storage Layer
Storage paths
Section titled “Storage paths”All paths follow the XDG Base Directory Specification:
| Path | Purpose |
|---|---|
$XDG_DATA_HOME/.stars/stars.db | SQLite database (main storage) |
$XDG_DATA_HOME/.stars/backups/ | Timestamped .db backup copies |
$XDG_DATA_HOME/.stars/exports/ | Export output files |
$XDG_CONFIG_HOME/stars/config.nu | NUON configuration file |
$XDG_DATA_HOME defaults to ~/.local/share and $XDG_CONFIG_HOME defaults to ~/.config.
Database schema
Section titled “Database schema”The stars.db file contains two tables:
stars table
Section titled “stars table”Created implicitly by Nushell’s into sqlite command. Columns mirror the normalized star schema from core/types.nu. See the SQLite Schema reference for the full column list.
sync_metadata table
Section titled “sync_metadata table”Tracks sync state for incremental sync:
CREATE TABLE sync_metadata ( key TEXT PRIMARY KEY, value TEXT);Currently stores:
| Key | Value | Description |
|---|---|---|
last_synced_at | ISO-8601 datetime | When any sync last completed |
last_full_sync_at | ISO-8601 datetime | When the last full sync completed |
Operations
Section titled “Operations”Loading data
Section titled “Loading data”load # → SELECT * FROM stars ORDER BY stargazers_count DESCReturns a standard Nushell table. All filtering, searching, and sorting happens in Nushell after loading.
Storing data
Section titled “Storing data”# Full replacement (used for first sync or --full)store $data --replace # deletes DB, writes fresh
# Upsert (used for incremental sync)upsert $data # merges by id, preserving existing recordsBackups
Section titled “Backups”backup # → copies stars.db to backups/stars_YYYYMMDD_HHMMSS.dbBackups are plain copies of the SQLite file. They can be restored by copying back:
let paths = get-pathscp $"($paths.backup_dir)/stars_20260223_150000.db" $paths.db_pathDirectory initialization
Section titled “Directory initialization”The ensure-storage function creates all required directories on first use:
- Base directory:
$XDG_DATA_HOME/.stars/ - Backup directory:
$XDG_DATA_HOME/.stars/backups/ - Export directory:
$XDG_DATA_HOME/.stars/exports/ - Runs
ALTER TABLE stars ADD COLUMN starred_at TEXTif the column is missing (for databases created before incremental sync support) - Creates the
sync_metadatatable if it doesn’t exist
Migration
Section titled “Migration”On first use, mod.nu checks for a legacy gh-stars database and migrates it:
- Old path:
$XDG_DATA_HOME/gh-stars/stars.db - New path:
$XDG_DATA_HOME/.stars/stars.db
The migration:
- Loads all records from the old database
- Adds
source: "github"andsynced_atcolumns if missing - Writes to the new location
- Preserves the old database (does not delete it)
See Migration from gh-stars for details.