3 ms·
looks promising. 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
by shroompasta 5y ago
looks promising.
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.
- fantod 5y agoI think SQLModel actually exists precisely so that you don't have to do that. According to [1]: > 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 [1] https://sqlmodel.tiangolo.com/#sqlalchemy-and-pydantic https://sqlmodel.tiangolo.com/#sqlalchemy-and-pydantic
- shroompasta 5y agoAh, I must've missed something in the first lookaround. looks good.
- smoe 5y ago> so basically, two sources of truth. 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)
- shroompasta 5y agoYeah, that was my bad. Went by a bit too quickly. looks good.