- ✅ PostgreSQL queries implemented & tested
- ✅ FastAPI endpoints with
Swaggerauto-docs - ✅ Async SQLAlchemy for modern, non-blocking query handling
- ✅ Chapter-by-chapter organization mirroring the SQL Cookbook
- ✅ Clean modular structure:
schemas,services,routers - ✅ Practical real-world API integration examples
Clone, configure, and run the project:
-
Clone git clone https://github.com//sql-cookbook.git cd sql-cookbook
-
(Optional) Setup virtual environment python -m venv .venv source .venv/bin/activate # Windows: .venv\Scripts\activate
-
Install dependencies pip install -r requirements.txt
-
Configure .env (at project root) echo "DATABASE_URL=postgresql+asyncpg://user:password@localhost:5432/dbname" > .env
-
Run API uvicorn main:app --reload
📖 Docs available at: http://127.0.0.1:8000/docs
Each chapter is self-contained with models, services, and routers.
This makes it easy to test SQL concepts via live API endpoints.
| # | Chapter Title | Status |
|---|---|---|
| 1 | Retrieving Records | ✅ Done |
| 2 | Sorting Query Results | ✅ Done |
| 3 | Working with Multiple Tables | ✅ Done |
| 4 | Inserting, Updating, and Deleting | 🚧 In Progress |
| 5 | Metadata Queries | ⏳ To Do |
| 6 | Working with Strings | ⏳ To Do |
| 7 | Working with Numbers | ⏳ To Do |
| 8 | Date Arithmetic | ⏳ To Do |
| 9 | Date Manipulation | ⏳ To Do |
| 10 | Working with Ranges | ⏳ To Do |
| 11 | Advanced Searching | ⏳ To Do |
| 12 | Reporting and Reshaping | ⏳ To Do |
| 13 | Hierarchical Queries | ⏳ To Do |
| 14 | Odds ‘n’ Ends | ⏳ To Do |
| 15 | Window Function Refresher | ⏳ To Do |
| 16 | Common Table Expressions (CTEs) | ⏳ To Do |
| 17 | Index | ⏳ To Do |
- Chapter: Retrieving Records
- API Endpoint:
GET /chapter1/employees - Process:
- FastAPI router calls →
chapter1_router.py - Router delegates →
chapter1_service.py - Service executes →
async SQLAlchemy sessionquery - Results validated via →
chapter1_schema.py - Response returned as → clean JSON
- FastAPI router calls →
We welcome contributions! 🎉
- Fork & clone the repo
- Create a feature branch per chapter/topic
- Write clean modular code (
schemas,services,routers) - Run & add tests if possible
- Open a PR with conventional commit messages
A practical, navigable SQL reference:
By working chapter-by-chapter through the SQL Cookbook, with real PostgreSQL queries & FastAPI playground endpoints,
you don’t just read solutions—you run them in production-ready patterns. 🚀
⭐ If you find this project useful, consider giving it a star on GitHub! ⭐