Kludex / fastapi-tips

FastAPI Tips by The FastAPI Expert!
2.11k stars 79 forks source link

Any tips about sqlmodel #12

Closed PaleNeutron closed 6 months ago

PaleNeutron commented 6 months ago

I use fastapi in my recent project but I spent a lot of time on structure my model code.

The biggest problem is split models.py to a module. I read a lot of articles and found it is not a acceptable because of pedantic. User have to re-import all referenced model at the end of each file and rebuild models in the file. Is there a more graceful solution?

Another problem is the inherit between sqlmodels with table=True and table=False. I found table=True sqlmodel will be a sqalchemy model created by meta class and table=False is actually pedantic model. If user create a pedantic model based on sqlalchemy model, some unexpected bug may occur.

Can you write some tips about fastapi models?

Kludex commented 6 months ago

I don't have any tips about SQLModel. If something comes up, I'll add it.