SQLAlchemy
An ORM for the EPIC WINNING
Objectives
- Describe what an ORM is and how it is used
- Use SQLAlchemy syntax to build tables
- Use SQLAlchemy to CRUD our Flask App
- Explore one-to-many relationship with SQLAlchemy
1. What is an ORM?
- ORM - "Object Relational Mapping"
- Used to manage database relationships
- Simplifies SQL statements through abstraction (Models)
What is an ORM?
A conceptual perspective:
SQL Object Oriented Programming (OOP)
Table <-> Class
Column <-> Attribute
Row <-> Instance
ORM's allow us to use SQL using OOP concepts
Your Turn!
Spend 5 minutes and
write an OOP model that creates a book class with:
- A title
- An author
- A publication year
and create a book "Harry Potter" by "J.K. Rowling" from 1997
Discuss it!
Now, turn to a neighbor and discuss for 3 minutes:
How does your model relate to SQL tables, columns, and rows?
Why might it be useful generally to use an ORM?
What might some of the costs to using an ORM be?
2. Use SQLAlchemy to build Tables
Now open your flask_list_app and this:
https://github.com/gSchool/python-curriculum/blob/master/Unit-02/02-flask_sqlalchemy.md
Objectives
- Describe what an ORM is and how it is used
- Use SQLAlchemy syntax to build tables
- Use SQLAlchemy to CRUD our Flask App
- Explore one-to-many relationship with SQLAlchemy
SQL Alchemy and Flask
By Lionel Lints
SQL Alchemy and Flask
- 858