saved
Actually Queryable Executables
gist
Farid Zakaria's follow-up to SELF shows that if the executable is a writable SQLite file, the running program can store its own state there transactionally. self-httpd is a single-file webserver whose code, routes, visitor log, and button presses live in one database; the live demo at selfdb.exe.xyz is that file. Against redbean's ZIP-plus-Lua portable executable, handlers are SQL rows, live edits are transactions, FTS5 indexes the site from inside itself, and a redeploy is INSERT...SELECT then scp of one file.
ideas
- The running program can store state in itself. Because SELF is a writable SQLite file, application state can live next to segments, collapsing /var, /tmp, and /home into one transactional file.
- self-httpd is program, site, and log. routes holds page bodies; visits and presses are written back while the server runs; the live selfdb.exe.xyz page queries its own segments and symbols on each request.
- Queryable versus portable. Redbean is an Actually Portable Executable (ZIP plus Lua); SELF is an Actually Queryable Executable—the container is the database, and a handler is a new row.
- Live edits and deploys are SQL. UPDATE routes changes the running site without reload; sqldiff audits a deploy; FTS5 indexes pages in-process; a redeploy migrates visits with INSERT...SELECT, then scp of one file.
- argv[0] is the database. binfmt_misc execs the interpreter, not the file, so /proc/self/exe is not usable yet; self-exec passes the path as argv[0] and drops its connection so the program can open itself.
quotes
“The program can store its own state in the same file it is running from, and it can do so transactionally.”
“If redbean is an Actually Portable Executable, this is an Actually Queryable Executable.”
“None of that is machinery I wrote. It is machinery SQLite already has, that a program inherits for free by being a database.”
“The program is the database, and the database is the program.”