MohamedAbdeen21/niwid-db
MohamedAbdeen21/niwid-db has 46 GitHub stars and 4 forks. GitHot measured 0 stars in 24 hours, 0 in 7 days, and 0 in 15 days. Last checked 2026-11-10 03:38 UTC. Last push 2026-08-02.
A toy, ACID compliant, and Relational-ish DBMS built from scratch
What you can do
- ACID Compliance via Shadow Paging: Ensures Atomicity, Consistency, Isolation (read-committed), and Durability by implementing shadow paging, maintaining a stable, crash-resistant state. Shadow paging allows a table to have only a single writer for simplified concurrency control.
- Transaction Management: Supports commits and rollbacks to execute or discard changes within a transaction block to ensure transactional atomicity and isolation.
- Custom Execution Engine: A simple query engine that processes SQL statements, validates the query and datatypes, and performs basic DDL, TCL, and DML operations. Also supports EXPLAIN and EXPLAIN ANALYZE. Unoptimized logical plans are executed directly, without physical plan generation or optimizations yet.
- SQL Parsing: The only part not written from scratch. Leverages the sqlparser-rs crate for SQL syntax parsing.
Measured star growth
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- 0
- in 1 month
- Collecting history
Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.
README.md
Originalniwid-db
niwid-db is a toy database management system built from scratch, designed to explore fundamental database concepts, including memory and disk management, ACID properties, basic transaction handling, indexing, and query execution.
Table of Contents
Features
ACID Compliance via Shadow Paging: Ensures Atomicity, Consistency, Isolation (read-committed), and Durability by implementing shadow paging, maintaining a stable, crash-resistant state. Shadow paging allows a table to have only a single writer for simplified concurrency control.
Transaction Management: Supports commits and rollbacks to execute or discard changes within a transaction block to ensure transactional atomicity and isolation.
Custom Execution Engine: A simple query engine that processes SQL statements, validates the query and datatypes, and performs basic DDL, TCL, and DML operations. Also supports
EXPLAINandEXPLAIN ANALYZE. Unoptimized logical plans are executed directly, without physical plan generation or optimizations yet.SQL Parsing: The only part not written from scratch. Leverages the
sqlparser-rscrate for SQL syntax parsing.B+ Tree Indexing: Implements a B+ Tree index to ensure uniqueness, enabling efficient lookups and range queries for unique columns. Since there is no optimizer yet, you can force an index lookup using the
PREWHEREclause. Check outindex.sltfor more examples.Constraints: Supports
NOT NULLandUNIQUEconstraints to enforce data integrity, although primary keys and foreign keys (referential integrity) are not supported.Joins: Performs basic nested loop join operations between tables, allowing for relational queries.
Getting Started
Prerequisites
- Rust: niwid-db is written in Rust.
Installation
Clone the repository:
git clone https://github.com/MohamedAbdeen21/niwid-db.git cd niwid-dbRun the server:
cargo run --release --bin idk-serverConnect to the server from a different terminal:
nc localhost 8080
Usage
niwid-db can execute SQL queries for managing tables, running transactions, and executing basic SQL commands.
Example:
CREATE TABLE users (
id INT PRIMARY KEY,
name TEXT NOT NULL,
email TEXT
);
INSERT INTO users VALUES (1, 'Alice', '[email protected]');
You can also use transactions to batch operations:
BEGIN;
UPDATE users SET email = '[email protected]' WHERE id = 1;
ROLLBACK; -- Discards the update
Examples
For more examples, check out:
- the sqllogictests. If you're not familiar with slt files, check out how to read sqllogictests
- Examples panel in the demo website
Some implementation details
- Slotted pages, with string indirection and a B+ Tree Index.
- LRU page eviction policy
- Shadow-Paging for ACID. No MVCC, OCC, 2PL, or WAL.
- Simple query engine, directly executes the raw logical plan. No optimizer, or physical plan builder. The project focused on exploring the internals of the database, not the query engine.
- Catalog as a read-only Table, check it out using
SELECT * FROM __CATALOG__; Usingsqlparser.rsis the only part not written from scratch. I wrote my fair share of parsers (and contributed some to sqlparser-rs), but again, this was not the main focus of the project. - Demo website made with HTMX and Askama.
Contributing
Contributions are always welcome! Feel free to submit issues or pull requests.
Explore related projects
Asabeneh/30-Days-Of-Python
The 30 Days of Python programming challenge is a step-by-step guide to learn the Python programming language in 30 days. This challenge may take more than 100 days. Follow your own pace. These videos may help too: https://www.youtube.com/channel/UC7PNRuno1rzYPb1xLa4yktw
78,486 starsgrafana/grafana
The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
77,790 starsredis/redis
For developers, who are building real-time data-driven applications, Redis is the preferred, fastest, and most feature-rich cache, data structure server, and document and vector query engine.
77,332 starsapache/superset
Apache Superset is a Data Visualization and Data Exploration Platform
75,455 stars