It is a thin layer on top of Pydantic and SQLAlchemy. I haven't used it yet, so can't speak out of experience, but I think it is basically exactly what you describe.
It is a thin layer on top of Pydantic and SQLAlchemy. I haven't used it yet, so can't speak out of experience, but I think it is basically exactly what you describe.
At first sight it seems like you still have to write a "schema" for the SQLModel based on your SQLALchemy model - so basically, two sources of truth.
If you edit your SQLAlchemy model, you'll also have to edit your SQLModel.
sqlalchemy-marshmallow allows you to build your schema based on your SQLAlchemy model.
Other than that, I'm still somewhat intrigued.
Thanks for the suggestion.
> That class Hero is a SQLModel model... But at the same time, it is a SQLAlchemy model... And at the same time, it is also a Pydantic model
looks good.
As I understood you don't, as SQLModel inherits from sqlalchemy ORM base classes. From the user guide, this is an example how to define the model and generate the table.
class Hero(SQLModel, table=True):
id: Optional[int] = Field(default=None, primary_key=True)
name: str
secret_name: str
age: Optional[int] = None
engine = create_engine(sqlite_url, echo=True)
SQLModel.metadata.create_all(engine)looks good.