Gavin Wyant

← Back to work

Database Engine

A persistent CLI SQLite clone in C, written to internalize how databases actually lay out memory and files.

2025 · Systems · in progress


A from-scratch SQLite clone in C. The goal isn't a production database — it's a forcing function to understand the parts of a relational engine you normally take for granted: pagers, B-trees, fixed-size records, the on-disk format, the REPL.

Why build it

"I use SQLite" and "I understand SQLite" are different sentences. Reading Cstack's Let's Build a Simple Database tutorial got me to the first one; extending past it — adding persistence semantics, growing the page cache, debugging the corruption that comes with off-by-one in a file header — got me to the second.

What's there

A C program that opens a .db file, accepts insert/select statements at a REPL, serializes records to fixed-size cells, and reads them back across restarts. The page layout, the cursor abstraction, and the file-position math are mine; the SQLite grammar is a deliberately tiny subset.

Status

In progress. Open work is mostly on the index side — implementing a real B-tree (currently a sorted page) and supporting deletes without fragmenting the file.

CSQLitedatabasessqlitememoryfile-format