A developer has taken a strange but working idea further: a program's own executable file can double as a live, queryable database, and this second post shows the program using that same file to store its own data while it runs. It is a genuinely different way to think about how software holds its code and its state, and it is the kind of idea that can reshape how he thinks about build systems and file formats even if he never ships this exact format himself.
The starting idea, from an earlier post, is a format called SELF: a program that is, physically, a SQLite file (SQLite is a full database packed into a single ordinary file, no separate server needed). A Linux feature called binfmt_misc, which lets the operating system hand off unfamiliar file types to a custom helper program instead of refusing to run them, hands a SELF file to a small interpreter. That interpreter reads a table inside the database listing the program's code segments, loads them into memory, and jumps to the program's starting point. Once that works, a lot of the usual tools for inspecting a compiled program, listing its symbols, checking its structure, collapse into a single skill: writing a SQL query (the standard language for asking a database questions).
The new twist in this post: if the executable is already a database, and a database is something you write to as well as read, the running program can store its own data back into that same file. That erases the usual need for separate storage locations operating systems normally use to hold a program's logs, settings, and files. Everything, code and data both, lives in one file, and because it is a database, every update can be a transaction (a guarantee that a batch of changes either fully happens or does not happen at all).
The author built a working demo to prove it: a tiny web server, one file. That file is simultaneously the running program, the website it serves, the list of page routes, and a log of every visitor, stored in tables including routes (the web page content) and visits (who requested what, with a timestamp). Running the file starts a real web server; a plain sqlite3 command against that same running file shows the visitor count updating live, because the server is writing its own logs into itself as it runs.
This builds on an existing idea: Justine Tunney's redbean, a web server also packed into one file, built as an Actually Portable Executable (a program built to run unmodified across different operating systems) glued to a self-extracting ZIP archive. Redbean lets you customize behavior with the Lua scripting language. SELF's equivalent is simpler: to add a new page behavior, you just insert a new row into a "handlers" table containing the SQL query that should answer that request, for example one that counts visits grouped by page and returns the busiest five. Where redbean is, in the author's phrase, an Actually Portable Executable, this is an Actually Queryable Executable: one runs anywhere, the other you can run a SELECT (a database read command) against directly.
The trickiest engineering problem is how a running program gets access to its own file to read and write it, when an interpreter is the one that loaded it in the first place. The workaround: the interpreter releases its own connection to the database before the program starts, freeing the program to open that same file itself, with one line of code opening its own executable as a database connection.
Building one is unglamorous by design. You compile an ordinary program the normal way, producing an ordinary Linux executable, then run a converter tool that turns that file into the queryable format, then run plain SQL commands to create tables and literally insert the website's HTML as rows of data into the routes table.
Who this is for: developers building small, self-contained tools or services who like the idea of a single file that never needs a separate config store, log directory, or asset bundle, and who are comfortable trading some raw performance for that simplicity. What it replaces, at least in this proof-of-concept, is the usual stack of a compiled binary plus a separate database plus a filesystem for state plus an archive format for bundling assets, all folded into one file you can inspect with tools he almost certainly already has installed.