Mini Database

Introduction

There are many types of databases that are used around the world to hold and grab data; some popular types are SQL, NoSQL, and Graph. Each of them keeps data differently; for example, SQLs hold data in tables, NoSQLs in** collections, and Graphs in **nodes, edges. They might store the data as files in a hard drive, as objects in RAM or both. Your task is to implement a minimal SQL-like database which stores data as files in hard drive.

Definitions

Database Table

Just like a regular table, it consists of columns (fields) and rows (objects) where columns show the structure of the table, and each row is a piece of information that conforms to that structure. Each column has a name, a type, and a fixed size, and at least one of these columns must be a primary key.

A table is similar to a class in Object-Oriented programming where each column is a field of that class, and each row is an object of it.

Primary Key

A primary key of each table is a specific column that uniquely identifies each row. It is usually an incremental integer; for example, the primary key of the first row of the table will be 1, the second row will be 2, and so on.

Schema

the schema contains The definition of the columns of each table. Mainly, it defines the name, type, and size of each column; for example, a “User” table with columns “id” of type Integer (4 bytes), “full_name” of type String (100 bytes or characters), “email” of type String (100 bytes or characters), “gender” of type String (10 bytes or characters) and “current_age” of type Integer (4 bytes). The schema of a table, as a result, can also show the size of rows of a table (by adding up all the column sizes); for example, the size of the rows of the table above will be 4 + 100 + 100 + 10 + 4 = 218 bytes. A visual example of this schema is shown in figure 1. A sample of the resulting table of this example schema is shown in figure 2.

Database Schema Example Database Table Example
Figure 1 Figure 2

Components

Your program needs to have the following components:

Engine

The central part of your database, also called the engine, must be able to create tables with a specific schema and insert, update, delete, and search data in a particular table. It should create a file schemas to store each table’s schema. The way you’re going to store the schemas in the file is up to you.

Functionality Details

User Interface

just receive commands and print results Commands are JSON strings, so your program needs to parse JSON to understand what the user wants.

Different types of commands are described below:

Schema

The user gives a table name and a schema definition and expects a table with the given name and schema to be created, and the status message printed

Insert *

The user gives a table name and some data and expects one object with the given data to be created in that table, and the status message printed

Update *

The user gives a table name, a primary key, and some data and expects one object of that table, which has the given primary key, to be updated with the given data, and the status message printed

Delete

The user gives a table name and a primary key and expects one object of that table, which has the given primary key, to be deleted.

The user gives a table name and range or an array of primary keys If given a primary key, the user expects *one object of that table, which has the given primary key, to be printed in the terminal in a JSON object format.

Submission Details

This exercise consists of two phases, each with their own deadline, and you should submit different components of this task in each of them.

Phase 1:

Phase 2:

⏳ Deadline

Phase 1

May 12th, 2020

Phase 2

May 16th, 2020

Bonus Task