SQLite file-format access in BrainFuck : an experiment in interacting with SQLite databases from Brainfuck using only standard Linux primitives.
The shell side only moves bytes. The BrainFuck side does the interesting work: header parsing, page reads, schema walking, table scans, limited column projection, narrow create-table demos, and small controlled writes.
This project is an intentionally absurd demonstration.
The point is not that BrainFuck is a sensible language for database work. The point is that a piece of software which would normally feel intractable can now be assembled surprisingly quickly with AI assistance. It's partly provoked by Matt Shumer's article Somthing Big is Happening.
In roughly a day of part-time work, this repo went from idea to a working demo that can:
- read the SQLite header
- walk schema pages
- scan a table
- project selected columns from the demo table
- create one new empty demo table
- perform small controlled writes
- Header read and validation
- Page reads
- Schema walk
- Table scan
- Limited
SELECT-style projection on the demouserstable:SELECT name FROM users;andSELECT name, sex FROM users; - Narrow
CREATE TABLEdemo:CREATE TABLE log (ts INT, value TEXT); INSERT,UPDATE, andDELETEon the tiny demo database
Add bin/ to your shell PATH for this checkout:
export PATH="$PWD/bin:$PATH"Build the toolchain from scratch:
build-imageRun the smallest demo:
run-bf-db examples/01_hello_header.bf tests/fixtures/tiny.dbScan the demo table:
run-bf-db ./sqlite_table_scan tests/fixtures/tiny.dbProject selected columns from the demo table:
run-bf-db ./sqlite_select_users_name tests/fixtures/tiny.db
run-bf-db ./sqlite_select_users_name_sex tests/fixtures/tiny.dbThese are the current SELECT equivalents:
SELECT name FROM users;
SELECT name, sex FROM users;Current scope is intentionally small: single-table projection on the demo
users table only, with no WHERE, ORDER BY, joins, or expressions.
Create a new empty demo table:
run-bf-db ./sqlite_create_log_table tests/fixtures/tiny.dbThis is the current CREATE TABLE equivalent:
CREATE TABLE log (ts INT, value TEXT);Current scope is intentionally small here too: one narrow empty-table create demo on the current 4096-byte fixture shape, with no indexes, constraints, page splits, journaling, or general SQL parsing.
Run the proof suite:
run-testsrun-bf-db will build missing demo binaries automatically and create tests/fixtures/tiny.db when sqlite3 is available.
run-tests will also reuse existing generated demo executables and only rebuild stale ones.
SQLite .db file
↑
│ dd / raw page bytes
│
Shell pager
↑
│ ASCII request/response
│
BrainFuck program
The protocol is intentionally small:
Hreads the 100-byte SQLite header as hexR <page_size> <page_no>reads a page as hexW <page_size> <page_no>writes a page back as hex
scripts/run_bf_db.shruns any.bffile or built demo executable against a databaseexamples/01_hello_header.bfis the minimal runnable demosqlite_select_users_nameandsqlite_select_users_name_sexare the builtSELECTequivalents in the demosqlite_create_log_tableis the builtCREATE TABLE log (ts INT, value TEXT);equivalent in the demotests/run_tests.shis the proof runner behindrun-testsdocs/USAGE.mdexplains the pager protocol and BF integration modeltests/TESTS.mdsummarizes what is verified
bf/contains the named SQLite demo programs and BF helper librariesexamples/contains the curated demo plus reference sketchesscripts/contains the pager, build, and run helperstools/contains the Dockerized toolchaindocs/archive/contains older planning and maintenance notes
With bin/ on your PATH, the top-level commands feel like a local toolchain:
build-imagebuild-bfrun-bf-dbrun-testsshell
For the non-Docker/manual toolchain path, see the appendix in docs/DETAILED_BUILD_PLAN.md.
This is a BrainFuck-driven SQLite file-format demo, not a full SQLite replacement or SQL engine.
