https://github.com/p4zd4n/dbee
Authorial Relational Database Management System (RDBMS) created with C++20. DBee supports majority of SQL operations
https://github.com/p4zd4n/dbee
cmake cpp cpp20 database dbms dbms-project
Last synced: about 2 months ago
JSON representation
Authorial Relational Database Management System (RDBMS) created with C++20. DBee supports majority of SQL operations
- Host: GitHub
- URL: https://github.com/p4zd4n/dbee
- Owner: P4ZD4N
- Created: 2024-11-25T11:02:39.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-01-18T15:49:36.000Z (over 1 year ago)
- Last Synced: 2025-01-30T10:43:08.567Z (over 1 year ago)
- Topics: cmake, cpp, cpp20, database, dbms, dbms-project
- Language: C++
- Homepage:
- Size: 215 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 💻 DBee

## 👀 About
Simple **Relational Database Management System (RDBMS)** created with C++20. App is intended to serve as a storage, which enable to manage data with query language similar to SQL. User can create and manage multiple databases within the entire system.
Each database is represented by the `Database` class, which stores essential information such as the database name (`std::string`) and a collection of tables (`std::unordered_map`). Each table is modeled using the `Table` class, which contains:
- Table name (`std::string`)
- Column names (`std::vector`)
- Column types (`std::vector`)
- Column-level constraints (`std::vector>`
- Foreign key definitions (`std::vector>`) - Each foreign key pair links a local column (by position) to a specific column in another table, ensuring referential integrity.
- Stored data (`std::vector`)
Supported data types include `INTEGER`, `FLOAT`, and `TEXT`, all defined in the `ColumnType` enum. The system enforces type safety, preventing invalid inserts (e.g., adding text to an integer column). Constraints such as `PRIMARY KEY`, `FOREIGN KEY`, `UNIQUE`, and `NOT NULL` are also supported and represented via the `Constraint` enum.
While building this system, I learned how relational databases work under the hood - including how they handle schemas, data types, constraints, and foreign keys. This helped me better understand how higher-level tools work and how to connect application development with how databases are actually built.
## 🔧 Tech Stack
- C++20
- CMake
## 💡 Features
- Possibility to manage multiple independent databases in one environment.
- Support for creating and managing tables with the ability to define columns with precisely defined data types: `INTEGER`, `FLOAT`, and `TEXT`.
- Possibility to add important constraints on columns to ensure data integrity: `PRIMARY KEY`, `FOREIGN KEY`, `UNIQUE`, and `NOT NULL`.
- Parser, which has ability to interpret queries written in a **SQL-like syntax** and execute proper operations based on entered query.
- Possibility to save and read RDBMS data from file. Enable to restore the entire RDBMS structure including databases, tables, columns, constraints and data.
## 🔍 Query language
Implemented query language is similar to SQL but includes some key differences:
- **No semicolon required** – Queries do **not** need to end with a semicolon.
- **Case-sensitive syntax** – All clauses must be written in **uppercase**. Lowercase or mixed-case keywords will not be recognized. Example:
✅ DATABASE CREATE db
❌ Database Create db
### DDL
- **`DATABASE CREATE `**
Creates an empty database with no tables.
**Example:**
```DATABASE CREATE shop```
- **`DATABASE USE `**
Selects the database to work with.
**Example:**
``DATABASE USE shop``
- **`DATABASE DROP `**
Deletes the specified database.
**Example:**
``DATABASE DROP shop``
- **`TABLE CREATE WITH COLUMNS ()[]{}`**
Creates a new table with specified columns, types, constraints, and optional foreign key references. Constraints are written **without spaces**, separated by commas inside square brackets. The foreign key reference (inside `{}`) is **optional** and only required when the column should reference another table.
**Example:**
``TABLE CREATE watches WITH COLUMNS id(INTEGER)[PRIMARY_KEY], model(TEXT)[NOT_NULL], own_id(INTEGER)[FOREIGN_KEY]{users.id}``
- **`TABLE DROP `**
Removes a table from the current database.
**Example:**
``TABLE DROP watches``
- **`ALTER TABLE ADD COLUMN ()[]{}`**
Adds a new column with optional constraints and an optional foreign key reference.
**Example:**
``ALTER TABLE users ADD COLUMN id2(INTEGER)[PRIMARY_KEY]``
- **`ALTER TABLE DROP COLUMN `**
Removes a column from the table.
**Example:**
``ALTER TABLE users DROP COLUMN id2``
- **`ALTER TABLE ADD CONSTRAINT FOREIGN_KEY REFERENCES {.}`**
Adds a foreign key constraint to a column, referencing another table.
**Example:**
``ALTER TABLE pets ADD CONSTRAINT FOREIGN_KEY REFERENCES own_id{users.id}``
- **`ALTER TABLE ADD CONSTRAINT ON `**
Adds a general constraint (`PRIMARY_KEY`, `UNIQUE`, or `NOT_NULL`) to a column.
**Example:**
``ALTER TABLE users ADD CONSTRAINT UNIQUE ON pesel``
### DML
- **`INSERT INTO VALUES ...`**
Inserts a new row into the specified table. Commas between values are optional. Multi-word strings can be wrapped in single quotes (`'...'`).
**Examples:**
``INSERT INTO users VALUES 1 'Wiktor Chudy'``
``INSERT INTO users VALUES 1, Wiktor``
``INSERT INTO users VALUES 1 Wiktor``
- **`UPDATE SET = , ... WHERE `**
Updates records in a table based on optional filtering conditions. You can update **multiple columns** by separating them with commas after `SET`. The `WHERE` clause is **optional**. If omitted, all rows in the table will be updated. Logical operators supported: `&&` / `AND`, `||` / `OR`. Logical expressions are **evaluated left to right**, with **no precedence**, meaning parentheses are **not** supported.
**Example:**
``UPDATE users SET name = Wiktor, weight = 75 WHERE name = wiktor && weight > 100``
- **`DELETE FROM WHERE `**
Deletes rows from the specified table. The `WHERE` clause is **optional**. If omitted, **all data** in the table will be deleted. Logical operators and evaluation rules are the same as for `UPDATE`.
**Example:**
``DELETE FROM users WHERE id = 1``
### DQL
- **`SELECT , , ... FROM , , ... WHERE `**
Retrieves values from specified columns and tables. The `WHERE` clause is **optional**.
**Examples:**
``SELECT name, age FROM users``
``SELECT name, age FROM users, pets``
``SELECT name FROM users WHERE age > 25``
- **`SELECT FROM INNER JOIN ON = WHERE ...`**
Returns rows with **matching values** in both tables based on the specified join condition. `WHERE` clause is **optional**.
**Example:**
``SELECT users.name, pets.name FROM users INNER JOIN pets ON users.id = pets.owner_id``
- **`SELECT FROM LEFT JOIN ON = WHERE ...`**
Returns all rows from the **left table**, and the matched rows from the right table.
Rows from the left table with no match will still appear with empty values.
`WHERE` clause is optional.
**Example:**
``SELECT users.name, pets.name FROM users LEFT JOIN pets ON users.id = pets.owner_id``
- **`SELECT FROM RIGHT JOIN ON = WHERE ...`**
Returns all rows from the **right table**, and the matched rows from the left table.
`WHERE` clause is optional.
**Example:**
``SELECT users.name, pets.name FROM users RIGHT JOIN pets ON users.id = pets.owner_id``
- **`SELECT FROM FULL JOIN ON = WHERE ...`**
Returns all rows from both tables. If no match is found, `null` or empty values are returned for the missing side. `WHERE` clause is optional.
**Example:**
``SELECT users.name, pets.name FROM users FULL JOIN pets ON users.id = pets.owner_id``
### Other
- **`SAVE`**
Saves the current state of all databases to a file.
- **`EXIT`**
Exits the application.