vikrant69g blog

Someone built a time machine for SQLite queries with zero dependencies

A developer built a tool that lets you rewind SQLite databases to any point in their history, no external dependencies required.

Code editor showing SQLite WAL file parser implementation in Python

I came across a SQLite time machine on Hacker News this morning. The entire thing is written in pure Python with no external libraries. You point it at a SQLite database and it lets you query the database as it existed at any point in its history. The trick is that SQLite keeps a write-ahead log by default. Every transaction writes to the WAL before committing to the main database file. Most tools discard this after checkpointing. This one keeps it and builds an index of every state the database has ever been in. What makes this interesting is the zero-dependency constraint. Most database time travel tools lean on Postgres logical replication or MySQL binlogs, which means middleware and a replication slot. This is just a Python script reading SQLite files directly. No server, no daemon, no config. I can see this being useful for debugging race conditions in test suites. If a test fails intermittently, you could replay the database state leading up to the failure without adding instrumentation to the application. The WAL already contains every write in order. The repository is 400 lines of code. It parses the WAL format by hand, which is documented in the SQLite source but not many people implement it from scratch. The author notes that SQLite WAL files are append-only until checkpoint, so you can treat them as an event log if you intercept the checkpoint trigger. I have not tested this on a production database yet. The README warns that large WAL files will eat memory because it loads the entire history into a dictionary. But for local development databases under a few hundred megabytes, this could replace a lot of ad-hoc snapshotting scripts. The fact that someone built this without reaching for any libraries is the real story. Most Python database tools import six or seven dependencies before writing a single line of logic. This one reads raw bytes and builds B-tree indexes in pure Python. That clarity matters when you are debugging data corruption.


Source: A zero-dependency, ultra-lightweight database time machine for SQLite