Skip to content

Instantly share code, notes, and snippets.

View radarroark's full-sized avatar

radarroark

View GitHub Profile
@radarroark
radarroark / next-gen-sqlite.md
Last active January 22, 2026 13:54
The next-gen SQLite won't look like SQLite

SQLite was thought of as a toy for many years until we all realized it was actually nice to use a database as a library, even server-side. And yet...

  1. It's a big dependency, despite what you think. In no universe is 150,000 lines of C code "lightweight".
  2. Like with all SQL databases, you have an impedance mismatch: the way you store data in memory is completely different than the table structure a SQL database forces on you, leading to tons of glue code.
  3. It's mutable, so it can't undo or time travel, and it can't read while a write is happening (even in WAL mode...reads can't happen during checkpointing!).

To solve these problems, I'm building a database called xitdb. It has ports for several languages:

@radarroark
radarroark / datascript+xitdb.md
Last active January 16, 2026 12:49
Datascript + xitdb: your humble, single-file, mini Datomic

xitdb-clj is a new immutable database for Clojure. It can time travel like Datomic, and store data in a single file like SQLite. On its own, though, it has no query language. Enter Datascript...

Datascript is normally an in-memory database, but it lets you use anything as backing storage. What if we combined them?

Datascript's storage feature doesn't tell us exactly what changed, so I added one more trick: Editscript, the diffing library. I use it to figure out how to update the database with the minimal number of changes.

The end result is a sort of mini Datomic that writes to a single file. And yet, this setup can do something Datomic can't: it can branch off of any old copy of the database. The example below reverts to an older copy of the database.

Keep in mind that all reads and writes are incremental. The database is not being loaded into memory at once, so you can use it to