Skip to content

Latest commit

 

History

12 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple C++ In-Memory Database with BST Persistence

Overview

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.

Features

  • 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.

Project Structure

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)

How to Build and Run

Using CMake (Recommended)

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.exe

If 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

On Linux/macOS

./scripts/main.sh

On Windows (PowerShell)

./scripts/main.ps1

Usage

  1. Run the program:
    The program will prompt you to create a schema and insert records.

  2. Insert/Update/Delete/Search:
    Use the console interface to manage records.

  3. Save to file:
    Use the commit function to save the schema and all records.

  4. Retrieve from file:
    Use the retrieve function to load schema and records from file.

  5. Purge file:
    Use the purge function to delete all records from the file.

Supported Field Types

  • int — Integer values
  • string — Any value not matching int, bool, or filepath
  • bool — Accepts "true" or "false" (case-insensitive)
  • filepath — Any string containing / or \

Example File Format

-- schema --
age int
name string

-- Hash Map 1 --
age 21
name Abhay

-- Hash Map 2 --
age 22
name Aryan

Possible Improvements

  • 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 testers

  • for testing run
./scripts/setup_example.sh

License

This project is for educational purposes.

About

this is in-memory database with BST persistent storge concurrency control and transaction control

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages