Skip to content

Adapts SQL Cookbook’s PostgreSQL recipes into a runnable FastAPI project: each chapter’s queries become HTTP endpoints via async SQLAlchemy—adding an API layer, typed schemas, and clean structure for interactive exploration and real-world reuse.

Notifications You must be signed in to change notification settings

ishrakabir/SQL-CookBook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Postgres FastAPI SQLAlchemy

📘 SQL Cookbook Solutions
PostgreSQL Queries • FastAPI Endpoints • Async SQLAlchemy


✨ Features

  • PostgreSQL queries implemented & tested
  • FastAPI endpoints with Swagger auto-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

🚀 Getting Started

Clone, configure, and run the project:

  1. Clone git clone https://github.com//sql-cookbook.git cd sql-cookbook

  2. (Optional) Setup virtual environment python -m venv .venv source .venv/bin/activate # Windows: .venv\Scripts\activate

  3. Install dependencies pip install -r requirements.txt

  4. Configure .env (at project root) echo "DATABASE_URL=postgresql+asyncpg://user:password@localhost:5432/dbname" > .env

  5. Run API uvicorn main:app --reload

📖 Docs available at: http://127.0.0.1:8000/docs


📚 Chapters Implemented

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


⚡ Example Endpoint Workflow

  • Chapter: Retrieving Records
  • API Endpoint: GET /chapter1/employees
  • Process:
    1. FastAPI router calls → chapter1_router.py
    2. Router delegates → chapter1_service.py
    3. Service executes → async SQLAlchemy session query
    4. Results validated via → chapter1_schema.py
    5. Response returned as → clean JSON

🤝 Contributing

We welcome contributions! 🎉

  1. Fork & clone the repo
  2. Create a feature branch per chapter/topic
  3. Write clean modular code (schemas, services, routers)
  4. Run & add tests if possible
  5. Open a PR with conventional commit messages

🌍 Vision

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! ⭐

About

Adapts SQL Cookbook’s PostgreSQL recipes into a runnable FastAPI project: each chapter’s queries become HTTP endpoints via async SQLAlchemy—adding an API layer, typed schemas, and clean structure for interactive exploration and real-world reuse.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published