admin管理员组

文章数量:1296918

in order to have type safety in SQLAlchemy, do I need to define custom constructors for each model? With the current setup there is no type safety at all when creating an object

from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column


class Base(DeclarativeBase):
    pass


class User(Base):
    __tablename__ = "user"

    id: Mapped[int] = mapped_column(primary_key=True)
    name: Mapped[str]
    fullname: Mapped[str]


user = User(namew="Alice", fullname="Alice Smith")

本文标签: pythonsql alchemy constructor typesafetyStack Overflow