SQLiter is a fully functional, lightweight relational database engine written in C, designed as a from-scratch clone of SQLite. It implements core database components such as paging, B-tree indexing, serialization, and persistent file storage — all without external libraries. This project was built for learning low-level database internals and exploring how real databases like SQLite manage data structures, disk I/O, and queries.
- Custom Pager System — Handles reading and writing fixed-size pages to disk.
- B-Tree Storage Engine — Implements leaf and internal nodes for efficient data lookup.
- Row Serialization — Translates rows between in-memory and on-disk formats.
- Meta Commands — Includes debugging tools like
.btreeand.constants. - REPL Interface — Simple terminal interface for inserting and selecting data.
- Persistent Storage — All data is stored in a binary file (
*.db).
| Command | Description |
|---|---|
insert <id> <username> <email> |
Inserts a new record into the database |
select |
Displays all stored records |
| Command | Description |
|---|---|
.btree |
Prints the current B-tree structure |
.constants |
Displays internal memory and page constants |
.exit |
Safely closes the database and exits the program |
$ gcc main.c -o sqliter
$ ./sqliter mydata.db
mydata > insert 1 alice [email protected]
Executed.
mydata > insert 2 bob [email protected]
Executed.
mydata > select
(1, alice, [email protected])
(2, bob, [email protected])
mydata > .btree
- leaf (size 2)
- 1
- 2
mydata > .exit| File | Description |
|---|---|
main.c |
Core implementation of SQLiter |
test.db |
Example database file generated after running |
Makefile (optional) |
Can be added to simplify compilation |
- Page-based storage: Each page is 4096 bytes, mimicking SQLite’s pager.
- B+ Tree implementation: Uses internal nodes for indexing and leaf nodes for storing data.
- Binary Search: Efficient key lookups within leaf nodes.
- File-backed persistence: Changes are written directly to the
.dbfile. - Dynamic Splitting: Automatically handles leaf and internal node splits when full.
- Support for DDL commands (
CREATE TABLE,DROP TABLE, etc.) - Add UPDATE and DELETE statements.
- Implement multiple table support.
- Develop a Python-based TUI for visual interaction.
-
Clone the repository
git clone https://github.com/yourusername/sqliter.git cd sqliter -
Compile
gcc main.c pager.c btree.c table.c parser.c executor.c layout.c -o main
-
Run
./main mydata.db
- SQLiter currently supports a single table model for simplicity.
- The prompt automatically removes the
.dbextension giving a smooth experience. - This project is intended for educational purposes and database engine experimentation.