A study of how a database works by implementing one.
The database now has the following functions:
- Select all Rows
- Insert a Row
- Create a table
- Get table information
The code aims to be readable, so to undestand the code, you can start by reading the main.c
file.
Right now the implementation supports one row per file. The table and its information is persisted in a file that is passed to the program as an argument.
The persistence of the database is done by writing the table information in a file. The file has a header in the start of the file, then the header is structured as follows:
header_size: size_t
col_count: uint8_t
table_name_size: size_t
table_name: char[table_name_size]
# For each Column
...
col_type: uint8_t
col_name_size: size_t
col_name: char[col_name_size]
...
The rest of the file consists of the rows of the table. That are saved one in order.
CREATE TABLE <table_name> (<column_name>:<column_type>, ...)
: Creates a table with the given name and column. The column type can beREAL
,TEXT
andINTEGER
. TheID
column is automatically created in the table.INSERT (<value>, ...)
: Inserts a row with the given values. The program checks the number of values and the types of the columns to insert the row.SELECT
: Selects all rows from the table.
.exit
: Exits and saves the program..info
: Shows the table information..help
: Shows the help message.
To run the program, you need to have the gcc
compiler and make
installed. Then, you can run the following commands:
make run
To run the tests, you need to install:
- Ruby
- bundle
Then, you can run the following commands:
make rspec
- Implement the B-Tree
- Implement the Schema Table, so that more tables can be stored in a single file
- Rust API to use the database
- Implement the DELETE query
- Implement the SELECT options, like
WHERE
,ORDER BY
,LIMIT
- Implement the UPDATE query
- Implement the INSERT query with the column names
- Implement better String representation