close
Skip to content

sen-ltd/sqlite-stats

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sqlite-stats

A zero-config SQLite database inspector CLI. When you're handed an unknown .db file — a SaaS backup, old app data, a bundled fixture — the first thing you want is "what's in here?". sqlite-stats answers that in one command: tables, row counts, columns, indexes, foreign keys, file size, and EXPLAIN QUERY PLAN rendered as a tree.

Everything is done with standard SQLite PRAGMA calls. The binary is a static Alpine musl build with rusqlite's bundled feature, so there are no runtime dependencies on a system libsqlite3.

Usage

sqlite-stats mydata.db                                  # human-friendly summary
sqlite-stats mydata.db --format json                    # machine-readable
sqlite-stats mydata.db --format markdown > report.md    # good for PR comments
sqlite-stats mydata.db --verbose                        # + per-column type / nullability / default
sqlite-stats mydata.db --tables users,orders            # limit to a subset
sqlite-stats mydata.db --explain-query 'SELECT * FROM posts WHERE user_id = ?'

Sections in the default human report:

  • Database — file size, page size, page count, encoding, journal mode, user_version
  • Tables — one line per user table: name / rows / cols / indexes / approx bytes
  • Views — name list
  • Indexes — name, table, columns, unique / partial flags
  • Foreign keys — resolved pointers
  • Top 5 largest tables — by dbstat payload bytes where available, otherwise a row-count estimate

Flags

Flag Default Description
--format human|json|markdown human Output format
--verbose / -v off Include per-column info
--tables NAME,NAME all Limit to specific tables
--no-views off Exclude views
--no-system on Exclude sqlite_% tables
--explain-query 'SQL' - Wrap EXPLAIN QUERY PLAN and render as a tree

Exit codes: 0 success, 1 can't open DB or bad query, 2 bad args.

Build

cargo build --release
./target/release/sqlite-stats ./mydata.db

Docker

docker build -t sqlite-stats .
docker run --rm -v "$PWD":/work sqlite-stats /work/mydata.db

The final image is a non-root Alpine runtime with just the static binary.

Tests

cargo test

All tests use :memory: databases.

Why this exists

SQLite's PRAGMA interface is fantastic but impossible to remember. PRAGMA page_count, PRAGMA table_info(x), PRAGMA index_list(x), PRAGMA index_info(idx), PRAGMA foreign_key_list(x), the dbstat virtual table, EXPLAIN QUERY PLAN — each of these is one line of Rust through rusqlite, and walking them gives you a surprisingly complete picture of a database. This CLI is just a nice way to run all of them at once.

License

MIT.

Links

About

A zero-config SQLite database inspector CLI for the moment you're handed an unknown .db file — a SaaS export, a customer backup, a bundled fixture — and you want to know what's in it before opening a query shell.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors