This project is a light-weight SQLite-ish database written in C. It is a command-line interface (CLI) based database system that persists data to a file.
- Persistent Storage: Data is saved to a file and can be retrieved later.
- B-Tree Implementation: Uses a B-Tree to store data, which allows for efficient insertion and retrieval.
- Basic SQL Operations: Supports
insertandselectstatements. - Meta-commands: Provides meta-commands like
.exit,.btree, and.constantsfor interacting with the database. - Simple REPL: A simple Read-Eval-Print Loop for executing commands.
- A C compiler (like
gccorclang) - Ruby and Bundler for running the tests
You can compile the C code using gcc:
gcc -o main main.cTo start the database CLI, provide a filename as an argument:
./main mydatabase.dbIf the file does not exist, it will be created.
Once the CLI is running, you can enter SQL-like commands or meta-commands.
-
Insert a record:
db > insert <id> <username> <email>Example:
db > insert 1 jdoe john.doe@example.com -
Select all records:
db > select
.exit: Exit the CLI..btree: Display the structure of the B-Tree..constants: Show database constants likeROW_SIZEandPAGE_SIZE.
The tests are written in Ruby using RSpec. First, install the dependencies:
bundle installThen, run the tests:
bundle exec rspec