FastAPI ORM
FastAPIはSQLAlchemyを使用して、データベース操作を簡素化します。
モデルの定義
Section titled “モデルの定義”from sqlalchemy import Column, Integer, Stringfrom sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
class Book(Base): __tablename__ = 'books'
id = Column(Integer, primary_key=True, index=True) title = Column(String, index=True) author = Column(String, index=True)
declarative_base
: モデルの基底クラスを作成Column
: データベースのカラムを定義