Django-வைப் போலல்லாமல், FastAPI databases-ஐப் பற்றி unopinionated-ஆக உள்ளது — நீங்கள் library-ஐத் தேர்ந்தெடுக்கிறீர்கள். பொதுவான தேர்வு SQLAlchemy (பெரும்பாலும் SQLModel-உடன், FastAPI-இன் author-ஆல், இது SQLAlchemy + Pydantic-ஐ இணைக்கிறது). Database sessions dependency injection மூலம் வழங்கப்படுகின்றன.
SQLAlchemy setup
sqlalchemy create_engine
sqlalchemy.orm sessionmaker, declarative_base
engine = create_engine()
SessionLocal = sessionmaker(bind=engine)
Base = declarative_base()
():
__tablename__ =
= Column(Integer, primary_key=)
name = Column(String)
email = Column(String, unique=)
