HeadlinesBriefing favicon HeadlinesBriefing.com

Actually Queryable Executables: SQLite Database Programs

Hacker News •
×

I was pleasantly surprised to see my article 'Your executable is a SQLite database' resonated widely. SELF is a format where programs are SQLite databases. Using binfmt_misc to trigger a custom interpreter mapping rows in segments table to jump to entry point, binary tooling collapses into SQL.

The surprising insight: if the executable is a database writable at runtime, the running program can store its state transactionally in the same file. self-httpd demonstrates this—a single-file webserver containing program, website, routes, and visitor logs. All state updates occur in the same SQLite file as the program itself.

While redbean uses self-extracting ZIP archives with Lua hooks, SELF uses database rows as handlers. Instead of Lua scripts, handlers are SQL INSERT statements into a handlers table. The key difference: redbean provides scripting hooks, SELF provides queryable executables where you can SELECT from the running program.

The process accesses itself via argv[0] containing the executable path. The interpreter releases its SQLite connection before jumping to entry point, allowing the program to open its own file handle.