Skip to content

deysandip301/SQLyt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SQLyt

Build

make build

Or directly with gcc:

gcc -std=c11 -pthread -Iinclude src/app.c src/readline_runtime.c src/btree.c src/pager.c src/parser.c src/cli.c -ldl -o db

Test

make test

Interactive line-editing enhancements (history, arrow-key navigation, and tab completion) are enabled automatically when libreadline is available at runtime.

Project Structure

SQLyt/
├── include/
│   └── sqlyt.h        # shared types, constants, and cross-module interfaces
├── src/
│   ├── app.c          # program entrypoint (`main`) and startup loop
│   ├── readline_runtime.c
│   │                   # readline runtime integration and completion wiring
│   ├── btree.c        # B+ tree layout, cursor operations, insert/delete/rebalance
│   ├── pager.c        # pager, WAL, checkpointing, open/close lifecycle
│   ├── parser.c       # SQL parsing, schema encoding, row pack/unpack helpers
│   └── cli.c          # REPL helpers, meta-commands, and SQL execution routing
├── tests/
│   └── test_main.py   # end-to-end SQL and storage behavior tests
├── data/              # default runtime root path for databases
├── Makefile           # build/test/clean targets
└── README.md

Architecture

At a high level, SQLyt is organized into six layers:

  1. Application entry layer (src/app.c)
  • Defines main().
  • Initializes session/root path and drives the input/execute loop.
  1. CLI layer (src/cli.c)
  • Reads input, normalizes commands, handles meta-commands.
  • Dispatches parsed SQL statements to execution paths.
  1. Readline runtime layer (src/readline_runtime.c)
  • Dynamically loads readline when available.
  • Provides history and tab-completion integration.
  1. Parsing and row-shaping layer (src/parser.c)
  • Parses SQL text into SqlStatement structures.
  • Encodes schema metadata and row payloads.
  1. B+ tree layer (src/btree.c)
  • Navigates and mutates table/index nodes.
  • Handles node split, merge, and rebalancing.
  1. Pager and durability layer (src/pager.c)
  • Manages page cache and file I/O.
  • Implements WAL frame writes and checkpointing.

Shared contract layer (include/sqlyt.h)

  • Defines shared structs, enums, constants, and function contracts across modules.

Execution flow:

CLI input -> parser -> statement executor -> btree operations -> pager/WAL -> disk

Run

Default root folder is ./data:

./db

Optional custom root folder:

./db /path/to/root

Command Cheat Sheet

Meta commands

  1. Exit CLI
.exit
  1. Use an existing database (must already be created)
.usedatabase <db_name>
  1. List all database folders under root
.showdatabases
  1. List tables in active database with root pages
.showtables
  1. Print B+ tree structure for a table
.btree <table_name>
  1. Print storage constants
.constants

SQL commands

  1. Create a database folder
create database app
  1. Create a table
  • first column must be id int (optionally primary key)
  • remaining columns can be int or text
  • text values are capped at 64 characters; longer strings will be rejected
create table user (
  id int primary key,
  user_id int,
  user_name text,
  email text,
  city text
)
  1. Insert a row
  • first value is row key (id)
  • remaining values must match schema order
  • quoted strings are supported
insert into user values (1, 101, "Alice Doe", "alice@example.com", "New York")
  1. Select all rows
select * from user
  1. Delete a row
delete from user where id = 1
select * from user

Quick Session Example

create database app
.usedatabase app

create table user (id int primary key, user_id int, user_name text, email text)
insert into user values (1, 101, "Alice Doe", "alice@example.com")
insert into user values (2, 102, "Bob", "bob@example.com")

select * from user

delete from user where id = 1

select * from user

.showtables
.btree user
.exit

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors