Skip to content

Latest commit

 

History

History
92 lines (66 loc) · 2.07 KB

File metadata and controls

92 lines (66 loc) · 2.07 KB

Zig DB

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.

Getting Started

Prerequisites

Building the Project

To build the executable, run:

make build

Running the CLI

To start the database CLI, run:

make run

This will create a database file named test-db in the root directory if one doesn't exist.

Testing

The project has both unit tests and integration tests for the CLI.

Running Unit Tests

To run the unit tests written in Zig, use:

make test

Running CLI Tests

To run the RSpec tests for the command-line interface, use:

make test-cli

Running All Tests

To run all tests, use:

make test-all

Project Structure

.
├── 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.