A lightweight, SQLite-like database implemented from scratch in the Zig programming language. This project is for educational purposes to understand the internals of a simple database.
This project was greatly inspired by the guide in Let's Build a Simple Database.
To build the executable, run:
make buildTo start the database CLI, run:
make runThis will create a database file named test-db in the root directory if one doesn't exist.
The project has both unit tests and integration tests for the CLI.
To run the unit tests written in Zig, use:
make testTo run the RSpec tests for the command-line interface, use:
make test-cliTo run all tests, use:
make test-all.
├── Makefile
├── build.zig
├── spec
│ └── main_spec.rb
└── src
├── btree.zig
├── cmd_handler.zig
├── db.zig
├── input.zig
├── main.zig
├── pager.zig
├── playground.zig
├── row.zig
├── table.zig
├── tests.zig
└── utils.zig
src/: Contains the core source code for the database.main.zig: The main entry point for the CLI application.db.zig: Core database logic.btree.zig: B-tree implementation for indexing.pager.zig: Manages reading and writing of database pages.table.zig,row.zig: Data structures for tables and rows.tests.zig: Unit tests.
spec/: Contains the RSpec tests for the CLI.build.zig: The build script for the project.Makefile: Contains helper commands for building, running, and testing the project.