PreQL is a lightweight, modular database management system written in modern C++. It provides a simple yet powerful interface for managing relational databases through SQL-like commands.
- SQL-like Interface: Support for basic SQL operations (CREATE, INSERT, SELECT, DELETE)
- Buffer Management: Efficient page management with buffer pool
- Table Management: Create, modify, and manage database tables
- Interactive CLI: User-friendly command-line interface
- Modern C++: Built with C++17 features and best practices
preql/
├── include/ # Header files
│ ├── core/ # Core database functionality
│ ├── buffer/ # Buffer management
│ ├── sql/ # SQL parsing and processing
│ └── ui/ # User interface
├── src/ # Source files
│ ├── core/ # Database implementation
│ ├── buffer/ # Buffer manager implementation
│ ├── sql/ # Parser implementation
│ └── ui/ # CLI implementation
├── tests/ # Test suite
│ ├── database_test.cpp # Database tests
│ ├── buffer_test.cpp # Buffer manager tests
│ ├── parser_test.cpp # Parser tests
│ └── cli_test.cpp # CLI tests
└── CMakeLists.txt # Build configuration
- CMake (version 3.10 or higher)
- C++17 compatible compiler
- Google Test (for running tests)
-
Clone the repository:
git clone https://github.com/yourusername/preql.git cd preql -
Create a build directory:
mkdir build cd build -
Configure and build:
cmake .. make
-
Run tests:
make test
./preqlBasic table creation:
CREATE TABLE users (id INT, name VARCHAR, age INT)Table with multiple columns and types:
CREATE TABLE products (
id INT,
name VARCHAR,
price FLOAT,
description VARCHAR,
in_stock BOOLEAN
)Single row insertion:
INSERT INTO users VALUES (1, 'John Doe', 25)Multiple rows (execute each separately):
INSERT INTO users VALUES (2, 'Jane Smith', 30)
INSERT INTO users VALUES (3, 'Bob Johnson', 35)
INSERT INTO users VALUES (4, 'Alice Brown', 28)Basic selection:
SELECT * FROM usersSelect specific columns:
SELECT name, age FROM usersWith conditions:
SELECT * FROM users WHERE age > 25Complex conditions:
SELECT * FROM users WHERE age > 25 AND name LIKE 'J%'UPDATE users SET age = 26 WHERE name = 'John Doe'Delete specific records:
DELETE FROM users WHERE age < 30Delete all records:
DELETE FROM usersView table structure:
DESCRIBE usersList all tables:
SHOW TABLES- Create a new database and tables:
CREATE TABLE employees (
id INT,
name VARCHAR,
department VARCHAR,
salary FLOAT,
hire_date DATE
)
CREATE TABLE departments (
id INT,
name VARCHAR,
location VARCHAR,
manager_id INT
)- Insert sample data:
INSERT INTO employees VALUES (1, 'John Smith', 'Engineering', 75000, '2020-01-15')
INSERT INTO employees VALUES (2, 'Sarah Johnson', 'Marketing', 65000, '2019-06-01')
INSERT INTO employees VALUES (3, 'Michael Brown', 'Engineering', 80000, '2018-03-10')
INSERT INTO departments VALUES (1, 'Engineering', 'Floor 3', 1)
INSERT INTO departments VALUES (2, 'Marketing', 'Floor 2', 2)- Query the data:
-- Find all employees in Engineering
SELECT * FROM employees WHERE department = 'Engineering'
-- Find departments and their managers
SELECT d.name, e.name as manager_name
FROM departments d
JOIN employees e ON d.manager_id = e.id
-- Find average salary by department
SELECT department, AVG(salary) as avg_salary
FROM employees
GROUP BY department- Update records:
-- Give a raise to all Engineering employees
UPDATE employees
SET salary = salary * 1.1
WHERE department = 'Engineering'- Delete records:
-- Remove employees who left before 2020
DELETE FROM employees
WHERE hire_date < '2020-01-01'-
Database Core
- Table management
- Data storage and retrieval
- Transaction handling
-
Buffer Manager
- Page management
- Buffer pool implementation
- Page replacement policies
-
SQL Parser
- SQL statement parsing
- Query validation
- Statement processing
-
CLI Interface
- Command-line interface
- User interaction
- Result formatting
- PIMPL (Pointer to Implementation) for implementation hiding
- RAII for resource management
- Smart pointers for memory management
- Exception handling for error management
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Modern C++ features and best practices
- Google Test framework for testing
- CMake build system