Skip to content

Latest commit

 

History

History
61 lines (53 loc) · 1.89 KB

File metadata and controls

61 lines (53 loc) · 1.89 KB

mini_sql_engine

Overview

mini_sql_engine is a minimal, modular, in-memory SQL engine implemented in Python. It supports basic SQL features and is intended as an educational project.

Features

  • Table creation (CREATE TABLE), row insertion (INSERT INTO), selection (SELECT)
  • Filtering (WHERE), ordering (ORDER BY)
  • Type-safe comparisons (INTEGER, TEXT)
  • Error handling for malformed queries, unknown tables/columns, type mismatches, duplicates
  • Extensible architecture for future SQL features
  • CLI and functional API
  • Comprehensive test suite (unit and integration)

Usage

  • Run CLI: python main.py
  • Or use run_query(sql_string) from Python code

Architecture

Project structure:

mini_sql_engine/
├── sql_engine/
│   ├── __init__.py
│   ├── lexer.py        # Tokenizes SQL input
│   ├── parser.py       # Parses tokens into AST
│   ├── ast.py          # AST node definitions
│   ├── table.py        # Table storage and metadata
│   ├── executor.py     # Executes AST nodes
│   └── utils.py        # Utility functions
│
├── tests/
│   ├── test_lexer.py
│   ├── test_parser.py
│   ├── test_executor.py
│   └── test_integration.py
│
├── main.py             # CLI and API
├── requirements.txt    # Dependencies
└── README.md           # Documentation

Example

CREATE TABLE people (id INTEGER, name TEXT, age INTEGER);
INSERT INTO people VALUES (1, 'Alice', 30);
SELECT * FROM people;

Testing

Run all tests with:

pytest mini_sql_engine/tests

Test suite covers:

  • Lexer, parser, executor, integration
  • Edge cases, error handling, type safety, duplicates

Extending and Further Development

Code is modular and documented for easy extension (e.g. add UPDATE, DELETE, JOIN). Feel free to contribute, but I guess I will leave this project as it is now.