Skip to content

nrthyrk/minidb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MiniDB: Mini Database Engine in C++

MiniDB is a simplified database engine implemented in C++, for the purpose of understanding the underlying details of database system. This database engine implements the most basic SQL operations as well as index on B+ tree.

Compile

To compile, you need two open source C++ libraries installed:

  • boost
  • readline

Use CMake to build the project.

mkdir build
cd build
cmake ..
make

The executable minidb will be created in the build directory.

To run it, you need to have the global environment variable "HOME" set. The database data will be stored at $HOME/MiniDBData. This directory will be created automatically on the first run.

Features

Database Management

  • Create Database
Syntax:		CREATE DATABASE database_name;
Example:	CREATE DATABASE abc;
  • Drop Database
Syntax:		DROP DATABASE database_name;
Example: 	DROP DATABASE abc;
  • Show Databases
Syntax:		SHOW DATABASES;
Example: 	SHOW DATABASES;
  • Use
Syntax:		USE database_name;
Example: 	USE abc;

Table Management

  • Create Table
Syntax:		CREATE TABLE table_name
			(
			column_name1 data_type(size),
			column_name2 data_type(size),
			column_name3 data_type(size),
			....,
			PRIMARY KEY (column_name)
			);
Example: 	CREATE TABLE aaa
			(
			col1 int,
			col2 float,
			col3 char(8),
			PRIMARY KEY (col1)
			);

Note: Available data types include int, float and char(N). Only one primary key could be created.

  • Drop Table
Syntax:		DROP TABLE table_name;
Example:	DROP TABLE aaa;
  • Show Tables
Syntax:		SHOW TABLES;
Example: 	SHOW TABLES;

Index Management

  • Create Index
Syntax:		CREATE INDEX index_name
			ON table_name (column_name);
Example: 	CREATE INDEX aaacol1 
			ON aaa (col1);

Note: Index can only be created on primary key. B+ tree manipulation is implemented in all data manipulation SQLs.

  • Drop Index
Syntax:		DROP INDEX index_name;
Example:	DROP INDEX aaacol1;

Data Manipulation

  • Insert
Syntax:		INSERT INTO table_name
			VALUES (value1, value2, value3, ...);
Example: 	INSERT INTO aaa
			VALUES (111, 222.2, 'xyz');
  • Select
Syntax:		SELECT * FROM table_name
			WHERE column1 = value1
			and column2 = value2
			and ...;
Example:	SELECT * FROM aaa
			WHERE col1 = 111;

Note: Only "and" logic is allowed. Only "*" is allowed.

  • Delete
Syntax:		DELETE FROM table_name 
			WHERE column1 = value1
			and column2 = value2
			and ...;
Example:	DELETE FROM aaa
			WHERE col1 = 111;

Note: Only "and" logic is allowed.

  • Update
Syntax:		UPDATE table_name
			SET column1 = value1, column2 = value2, ...
			WHERE column1 = value1
			and column2 = value2
			and ...;
Example:	UPDATE aaa
			SET col2 = 555.5
			WHERE col1 = 1;

Note: Only "and" logic is allowed.

Other Features Implemented

  • Help
Syntax:		HELP;
Example: 	HELP;
  • Quit
Syntax:		EXIT
			or
			QUIT
Example:	EXIT
			or
			QUIT
  • Exec
Syntax:		EXEC file_name;
Example: 	EXEC input.txt;

Unimplemented Features

  • Transaction Management
  • User Management
  • Authentication
  • Join
  • Foreign Keys
  • Views
  • Complex Select

Design & Implementation

For a detailed overview of the system architecture and modules, see docs/design-implementation.md.

Test Runs

For examples of SQL queries and expected output, see docs/test-run.md.

About

Mini Database Engine in C++

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors