3 ms·
I see, thanks. Is it required to define models twice as this page seems to recommend? https://fastapi.tiangolo.com/tutorial/sql-databases/ https://fastapi.tia
by mixmastamyk 6y ago
I see, thanks. Is it required to define models twice as this page seems to recommend?
https://fastapi.tiangolo.com/tutorial/sql-databases/ https://fastapi.tiangolo.com/tutorial/sql-databases/
- Bedon292 6y agoYeah, you do end up defining everything more than once, once for SA, and then for pydantic. Create, Read, and Update may all be different pydantic models as well. They are for defining what comes in and out of the actual API. Your create request may not have the id field yet and some optional fields, and then the response has everything. And then an update may have everything as optional except the id. Only been using it a few weeks now, but liking it a lot so far. https://fastapi.tiangolo.com/tutorial/sql-databases/#create-initial-pydantic-models-schemas https://fastapi.tiangolo.com/tutorial/sql-databases/#create-...
- takeda 6y agoFastAPI is database agnostic, although tutorials talk about using SQLAlchemy (probably because it's most popular). I am using asyncpg[1] (much more performant and provides close mapping to PostgreSQL, making it much easier to use its advanced features) through raw SQL statements without problems. [1] https://github.com/MagicStack/asyncpg https://github.com/MagicStack/asyncpg