-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Peewee usage #84
Comments
I think giving a more concise example might show up my current issue when using peewee rather than SQLAlchemy, so I've made this working minimal example. https://gist.github.com/Kurolox/bd62d486c8c48b8300746f3b479fe5a5 I've also been able to find this mention regarding While technically I can use the |
Hi Kurolox, good question! I am using Peewee myself and are now experimenting with FastAPI. At this moment I am trying out response models using Pydantic, but this only solves the part that the response will have a known "fixed" output structure and does not process the Peewee to dict model (see: https://fastapi.tiangolo.com/tutorial/response-model/) |
I haven't used Peewee a lot myself, but I'll try to replicate it to see what happens. |
I just added support for Pydantic's ORM mode in FastAPI ORM mode is new, but it solves most of these cases. You can see the docs here: https://fastapi.tiangolo.com/tutorial/sql-databases/ The docs use examples with SQLAlchemy, but they should work equally for any other ORM. Actually, any object that has attributes ( It also supports dynamic properties, hybrid attributes, relationships, lazy-loading, etc. You declare the shape that you need to return in your Pydantic models with all the specific attributes and they take care of extracting the data from your ORM object. Also, I'm now using quite a lot of Peewee recently for a project 🤷♂️ 😁 ...Although, I haven't integrated this yet, because I just released it 10 min ago 😂 |
That's great! Thanks for your efforts! |
Assuming the original need was handled, this will be automatically closed now. But feel free to add more comments or create new issues or PRs. |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Description
How can I use peewee ORM with fastapi?
Additional context
I'd love to use peewee rather than sqlalchemy for my API. However, all documentation seems to be oriented to SQLAlchemy.
It seems like I can use peewee directly up to a certain point, however some stuff (like ForeignKey relations) don't really work by default.
The text was updated successfully, but these errors were encountered: