CRUD via SQLAlchemy
Get All
from . import models
from app.database import engine, get_db@app.get("/sqlalchemy")
# We are saving the dependency and session in a variable (db)
def test_post(db: Session = Depends(get_db)):
# We call that variable
# Set to query
# Add the class name from the models.py Table
# Fetch all rows with .all()
posts = db.query(models.Post).all()
return { "data": posts }Get by ID
Create
Delete
Update
Last updated