query-sqlite-db

Use when needing to inspect SQLite database directly, when debugging data issues, when environment variable expansion fails with APPDATA or similar paths, or when sqlite3 query returns "unable to open

SKILL.md

GitHub

Query SQLite Database

Overview

Direct SQLite queries for debugging data state. The app is a container with one /data volume (ADR-030), so the database is a plain file on the host. Query that file.

Database Paths

kniha-jazd-web resolves the path at src-tauri/web/src/main.rs:24-30: DATABASE_PATH, else $KNIHA_JAZD_DATA_DIR/kniha-jazd.db, else /data/kniha-jazd.db.

Context Path
Docker (compose or docker run) ./data/kniha-jazd.db on the host - the bind mount of /data, see docker-compose.web.yml
Local dev $KNIHA_JAZD_DATA_DIR/kniha-jazd.db, falling back to /data when unset
Explicit override $DATABASE_PATH
Integration tests (spawned mode) a fresh mkdtemp directory, deleted after the run - see onPrepare in wdio.server.conf.ts

To ask the running server instead of deducing, call the get_db_location RPC command. It reports the path the process actually opened.

Quick Reference

# Query (Docker default)
sqlite3 ./data/kniha-jazd.db "SELECT * FROM vehicles;"

# Schema
sqlite3 ./data/kniha-jazd.db ".schema paperless_trip_links"

# Tables
sqlite3 ./data/kniha-jazd.db ".tables"

docker exec does not work

The runtime stage of Dockerfile.web installs only ca-certificates and curl. There is no sqlite3 binary in the image. Query the bind-mounted file on the host.

Key Tables

Table Key Columns
vehicles id, name, tp_consumption
trips id, vehicle_id, start_datetime, end_datetime, fuel_liters
paperless_trip_links paperless_document_id, trip_id, assignment_type, amount_eur, applied_amount_cents, mismatch_override

Common Mistakes

Error Fix
sqlite3: command not found sudo apt install sqlite3
sqlite3 inside the container fails The image has no sqlite3. Query the host bind mount.
Guessing which file the server opened Call the get_db_location RPC command.
Column date not found Use receipt_datetime or start_datetime
"unable to open database" Check the path for typos. Confirm the file exists.