make buildOr 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 dbmake testInteractive line-editing enhancements (history, arrow-key navigation, and tab
completion) are enabled automatically when libreadline is available at
runtime.
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
At a high level, SQLyt is organized into six layers:
- Application entry layer (
src/app.c)
- Defines
main(). - Initializes session/root path and drives the input/execute loop.
- CLI layer (
src/cli.c)
- Reads input, normalizes commands, handles meta-commands.
- Dispatches parsed SQL statements to execution paths.
- Readline runtime layer (
src/readline_runtime.c)
- Dynamically loads readline when available.
- Provides history and tab-completion integration.
- Parsing and row-shaping layer (
src/parser.c)
- Parses SQL text into
SqlStatementstructures. - Encodes schema metadata and row payloads.
- B+ tree layer (
src/btree.c)
- Navigates and mutates table/index nodes.
- Handles node split, merge, and rebalancing.
- 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
Default root folder is ./data:
./dbOptional custom root folder:
./db /path/to/root- Exit CLI
.exit
- Use an existing database (must already be created)
.usedatabase <db_name>
- List all database folders under root
.showdatabases
- List tables in active database with root pages
.showtables
- Print B+ tree structure for a table
.btree <table_name>
- Print storage constants
.constants
- Create a database folder
create database app- Create a table
- first column must be
id int(optionallyprimary key) - remaining columns can be
intortext textvalues 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
)- 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")- Select all rows
select * from user- Delete a row
delete from user where id = 1select * from usercreate 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