Executable Is a SQLite Database

fzakaria.com

321 points by setheron 12 hours ago


miketery - 2 minutes ago

As far as agent workflows are concerned whats needed is the other direction. Store the files wherever but let an agent interact with it as if its on local FS via bash or other languages using their file io.

Whats worked for others?

setheron - 14 minutes ago

(author) I'm enjoying the comments. When I published a short-paper with this idea in academic circles, the feedback wasn't so kind

andai - 3 hours ago

This whole article is fantastic, but already at the start, the SQLite virtual tables thing is blowing my mind.

https://www.sqlite.org/vtablist.html

You can "mount" your filesystem (or anything else) as a SQL database, wtf. That's amazing.

This sounds like it could be extremely useful.

djoldman - 3 hours ago

> The format itself is incredibly terse, designed for a world where disk space and network bandwidth was at an extreme premium. Modifying the format is hard, you often have to zero out sections and add new ones since it is packed so tightly. There is also no self-describing schema. ELF itself is a very generic format that supports sections of data that by convention are interpreted in specific ways but the format does not enforce it.

Sounds like a great use case for:

  1. ELF file to SELF file
  2. modify SELF file
  3. SELF file to ELF file
inigyou - 3 hours ago

> I realized something that bugged me. ELF is already a database.

Even more broadly applied: Every base of data is already a database (that's what the compound word means). Programs like sqlite and postgres used to be called by the more precise term "Relational Data Base Management Software" or "RDBMS" until their use became so widespread that they were colloquially called databases instead.

The very first data base structures were more like, each geometric sector of a hard drive is a record, and each head is a column. This was a straightforward translation of punch-card workflow onto a magnetic disk.

XJ6w9dTdM - 4 hours ago

Yes !

This has been on the back of my mind for a while. And, as other commenters have noted, it would be great for the file to contain the (self-modifiable) Lisp image, a builtin virtual file system, and whatever the application want to use as (runtime modifiable) extra tables.

I find SQLite dynamic linking being basically compatible with ELF dynamic linking to be very impressive, I can imagine that if well done, it cloud replace most uses of AppImages with a much more efficient format, like the author suggests.

How about an option for compressing section contents within the SQLite blobs, since the author mentioned you can't mmap directly the text pages and have to copy anyway ?

There are two extensions that I was thinking would make a SQLite executable truly unique.

First, a linking extension that would allow patching in functions and hooks more directly to allow for a very powerful plug-in system. Imagine the plug-in SQLite defining a BEFORE/AFTER/REPLACE hook for some symbol the host SQLite defines as extensible.

Second, re-linking at runtime. This would require application author cooperation because you won't be able to do that from anywhere, but imagine changing a dependency or loading a plugin at runtime through editing the db, and the interpreter just maps that on demand/automatically in the background, now next time your web server accept(), it calls the new version of the handling function.

garganzol - 4 hours ago

The copied vs. mapped memory situation is the only deal breaker in this experiment. Otherwise, file format unification would be a big step forward. The PE/COFF executable file format used by Windows (and some older Unix systems) is a relational database as well. The same goes to .NET assembly format - it's a relational database too. The wheel gets reinvented over and over again.

catlifeonmars - 3 hours ago

I can buy that an object file can be viewed as a relational db. Why SQLite though? Why not SQL query engine over the object file using a virtual table abstraction? I’m not seeing how most the SQLite features, with the exception of a subset of the query engine would translate over.

If the author wants to make a case for including schema metadata in an object file, again why SQLite? This strikes me a lot as someone who is trying to find uses for their favorite hammer (a very useful hammer I might say) rather than a serious exploration of what a new, improved object file format would look like.

(And that’s totally ok)

unified101 - 6 hours ago

I don't think this goes far enough! Make the actually app store be the same file itself. so it's a living application and the file is constantly updated to how you use it. Copy it around, and you carry your data wiht you as well.

Let's go deeper. it's a webserver app + the server code + application code + db, so pocketbase++ where it's also the deployment target.

Then combine it with APE liek system, and the same file loads and stores things on every platform. evil laugh

Very cool hacking! My hats off to the author.

skavi - 7 hours ago

This was super fun. Dude’s been on an absolute tear recently.

eqvinox - 2 hours ago

NB: ELF executables and libraries don't need to have sections, or a section header table. The program headers are what matters. You can use sstrip to remove the SHT.

JSR_FDED - 7 hours ago

I appreciate the inventiveness of this idea. But I don’t find myself thinking I must have this.

zcw100 - 2 hours ago

Reminds me of the DBOS, everything's a database, ethos. https://www.dbos.dev/

howerj - 2 hours ago

I've wanted to do something like this for quite a while! Of course I wanted to make my own OS, language and DB from scratch in order to do it, so naturally I've never gotten around to it. It goes to show that there is nothing new under the sun.

luciana1u - 3 hours ago

an executable that is also a database means my bugs get relational now. instead of a segfault i get a foreign key constraint violation.

didip - 4 hours ago

A lot of kernel filesystem features should be inside a database as well.

dcrazy - 2 hours ago

Congratulations, you’ve rediscovered mainframes.

dolmen - 6 hours ago

I wonder how flexible is the SQLite binary format to allow to design a tool that would take a SELF binary/db and rewrite it to make BLOB values more mmap-able (OS page aligned) in order to allow shortcuts in the self-exec loader.

cobbzilla - 3 hours ago

This is really creative and clever, nicely done!

The “Inception” graphic was hilarious and made me wonder if perhaps the site itself is served by some SELF binary (is it?? that would be insane)

kjuulh - 6 hours ago

Great read. I always find these turn a feature of a computer into a database an interesting read/idea. It certainly has upside, and downsides. For example having an entire filesystem as a sqlite database etc, or in this case an executable. It would be nice to have a structured way of talking to our utilities, rather than interpreting various commands as json through a few layers of tools to then get the output in a common format. That said I'd probably rather have a split up tool-set, than everything having to be in a single database for it to interoperate.

ale42 - 6 hours ago

I was thinking that someone managed to put an ELF header in an SQLite file while keeping it compatible with SQLite... but no, "just" a new binary format. Very interesting nevertheless!

mongol - 6 hours ago

So where does this lead to? Is it leading us towards SQLite as some kind of alternative container image format? Because the benefit seems to only occur when it incorporates dependencies

simonw - 7 hours ago

The word "Your" was dropped from the start of the title for some reason.

colinhb - 8 hours ago

The handling of dynamic libraries and closing over them into single dbs made this a fun read.

alex7o - 4 hours ago

What if, we put the sqlite driver in kernel space? So this is your only filesystem like a unikernel

__m - 3 hours ago

not sure if the people exploring binaries prefer sql over command line tools

HackerThemAll - 5 hours ago

Yeah, I have been amazed for an entire life how many tools the IT industry invented during last 50 years to just disguise a database.

OK, in '70s, '80s or '90s when compute and storage resources were limited and every bit counted, specialized formats did make sense.

But nowadays we'd save enormous efforts by just packaging stuff in SQLite databases. Microsoft's proprietary file formats (Office, Power BI etc.), OpenOffice/LibreOffice OpenDocument format, or almost everything else would fit perfectly.

Documents, files, are all data (called "data files", aren't they?), including executables, which as can be seen in this article are also databases.

https://sqlite.org/aff_short.html

https://sqlite.org/appfileformat.html

testemailfordg2 - 4 hours ago

[dead]

testemailfordg2 - 4 hours ago

[flagged]