Adding persistence layer (storing into databases)
- From python to interact with relational databases we have two apporaches
- Write sql queries and code around for your business logic.
- ORM (Object Relational Mapping): we deal with python objects and ORM translates that into SQL Queries depending on db.
- ORM would require a db driver package
Concepts
- Connection string
- ORM (SQLAlchemy)
ORM – Critical concepts
- Defining models and relationships correctly
- CRUD Operations
- Code first (seed data) or db first
- Migrations (Schema changes)
Problem – 1
- I want to have a db (sqlite to start with) to store my expenses and income and also categorize the spendings
- To do this first come with tables, identify relationships
-
We need to have atleast 5 – 6 categories
- Entertainment
- Utilities
- Bills
- Loans
- Salary
-
Try to make this work from python code using
- SQLAlchemy
- Peewe
Problem – 2
- Try the same for single hotel room reservations
