A custom database engine built from scratch using NestJS and TypeScript. It is built around a custom SQL-like DSL: a hand-written tokenizer and parser that convert raw query strings into an AST, so the engine only understands a fixed, purpose-built set of commands rather than parsing a general-purpose language.
It stores data in .ndjson files and uses a custom indexing system to achieve high performance without relying on any external database software.
The engine performs direct file system access using byte offsets, allowing precise reads and writes without loading entire files into memory.
-
Custom SQL-like DSL A hand-written tokenizer and recursive-descent parser convert raw query strings into an AST (Abstract Syntax Tree) for safe and structured execution.
-
Smart Indexing Supports Primary Keys and Unique columns using index files that store:
valueoffsetlength
-
Direct File Access Uses
fs.FileHandleto jump directly to the required bytes in.ndjsonfiles. -
Metadata Management Automatically handles:
AUTO_INCREMENTTIMESTAMPNOW()logic (ISO format)
-
Soft Deletes Rows are marked as
deleted: trueinstead of being physically removed, preserving file offsets and index integrity.
The engine exposes two main endpoints to execute database operations.
DDL (Data Definition Language) Used to define and manage database structure.
Supported Commands
CREATE TABLECREATE DATABASEALTER TABLEDROP TABLEDROP DATABASE
Example
{
"query": "CREATE TABLE users (id SERIAL PRIMARY KEY, username TEXT, email VARCHAR(255) UNIQUE)"
}DML (Data Manipulation Language) Used to manage the data stored inside tables.
Supported Commands
SELECTINSERTUPDATEDELETE
Example
{
"query": "SELECT username, email FROM users WHERE id = 1;"
}