This project is a simple in-memory database implemented in C++ using a Binary Search Tree (BST). Each node in the BST stores a record as a hash map (key-value pairs). The database supports custom schemas, type checking, and persistence to a text file.
- Custom Schema: Define your own fields and types (int, string, bool, filepath).
- Type Checking: Ensures data matches the schema.
- BST Storage: Fast in-memory operations for insert, search, update, and delete.
- Persistence: Save and load the database (including schema) to/from a file.
- Purge: Delete all records from the file.
- Console Interface: All operations are performed via the console.
database/
├── files/
│ └── text.txt # Data file for persistence
├── headers/
│ └── read.h # Main header file (BSTNode, function declarations)
├── src/
│ ├── core.cpp # BST logic (insert, delete, update, search, inorder)
│ ├── main.cpp # Entry point and example usage
│ ├── read.cpp # Map input, type checking, and schema logic
│ ├── save.cpp # File save/load (commit/retrieve) and purge
│ └── schema.cpp # Schema creation logic
└── scripts/
├── main.sh # Build and run script (Linux/macOS)
└── main.ps1 # Build and run script (Windows PowerShell)
You need both CMake and a C++ toolchain (compiler + build tool).
On Windows, install one of these options first:
- MSYS2 + MinGW-w64 (
g++,mingw32-make) - Visual Studio Build Tools (MSVC compiler)
- Ninja + GCC/Clang
Then run from project root:
cmake -S . -B build
cmake --build build
./build/database.exeIf you are using MinGW explicitly:
cmake -S . -B build -G "MinGW Makefiles" -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++
cmake --build build
./build/database.exe./scripts/main.sh./scripts/main.ps1-
Run the program:
The program will prompt you to create a schema and insert records. -
Insert/Update/Delete/Search:
Use the console interface to manage records. -
Save to file:
Use thecommitfunction to save the schema and all records. -
Retrieve from file:
Use theretrievefunction to load schema and records from file. -
Purge file:
Use thepurgefunction to delete all records from the file.
int— Integer valuesstring— Any value not matching int, bool, or filepathbool— Accepts "true" or "false" (case-insensitive)filepath— Any string containing/or\
-- schema --
age int
name string
-- Hash Map 1 --
age 21
name Abhay
-- Hash Map 2 --
age 22
name Aryan
- Add a menu-driven interface.
- Support for JSON or CSV file formats.
- Add search by any field, not just key.
- Implement undo/redo and backup/restore features.
- Add unit tests and better error handling.
- for testing run
./scripts/setup_example.sh
This project is for educational purposes.