Тёмный
No video :(

FastAPI with SQLAlchemy Tutorial 

microapis
Подписаться 1,5 тыс.
Просмотров 14 тыс.
50% 1

Опубликовано:

 

22 авг 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 21   
@walterbiffi6988
@walterbiffi6988 2 года назад
Jose, thank you soo much for the content of this series. I will definitely get your book. Again great job!
@microapis
@microapis 2 года назад
Thank you for your kind feedback Walter!
@lfcamacho
@lfcamacho 2 года назад
excellent video! I will definitely use this information on my projects, thanks so much :)
@microapis
@microapis 2 года назад
Thank you so much for your nice feedback! It's very encouraging to hear that you find the information useful!
@cagrKARAYAKA
@cagrKARAYAKA Год назад
I have question i create a schema whic is name bloglistmodel and it has prop comment count and i want to count 1 blog tables comments how can i do
@microapis
@microapis Год назад
Hi çağrı thanks for your question! Not sure what your SQLAlchemy models look like, but if you have a table that represents blog posts and another table that represents comments, and if you have a relationship between the two, getting the count of comments for a post would be as simple as "post.comments.count()". Then return a dictionary in your route, making sure the response validation model is set to bloglistmodel. Not sure if this helps - if you have some code that I can look at I may be able to give a more accurate answer.
@markstevens1169
@markstevens1169 Год назад
Can I connect to DB without using SQLAlchemy?. For eg, I want connec to SQL Server using pyodbc
@microapis
@microapis Год назад
Hi Mark absolutely! You can connect to the database directly using the driver. For pyodbc + SQL Server here's a nice tutorial: learn.microsoft.com/en-us/sql/connect/python/pyodbc/step-3-proof-of-concept-connecting-to-sql-using-pyodbc?view=sql-server-ver16 When you connect with the dirver, you'll be running SQL statements directly against the db and you'll get row objects from each execution. Only thing I need to advise is make sure you parametrize your queries to avoid SQL injection. Unfortunately it's a very common mistake to run unparametrized queries. The tutorial I linked above contains examples of parametrized queries. When using pyodbc, you connect to the database once. pyodbc's cursor is similar to SQLAlchemy's cursor - you get a cursor every time you need to perform a new operation with the db. To avoid having to manage the cursor yourself, use the context manager (github.com/mkleehammer/pyodbc/wiki/Cursor#context-manager) - "with connection.cursor() as cursor". Check out also the documentation about managing transactions with pyodbc (github.com/mkleehammer/pyodbc/wiki/Database-Transaction-Management). Hope this helps!
@mufc5033
@mufc5033 2 года назад
tnx for this tutorial
@microapis
@microapis 2 года назад
My pleasure! Thanks for the nice comment!
@murugarajuperumalla5508
@murugarajuperumalla5508 2 года назад
keep it up
@microapis
@microapis 2 года назад
Thanks for the nice feedback!
@Nickdondo
@Nickdondo 2 года назад
Thank you so much for this tutorial. I have one question about the UUID implementation. Does this only work with certain databases or all SQL databases? I am running MySQL, I implemented it exactly like you did but instead of running a migration I write out my schema by hand. It places the UUID in the response body but when I refresh the page it does not generate a new UUID it only produces a duplicate UUID.
@microapis
@microapis 2 года назад
Hi Nick thanks for your question! Once you create a task with POST, SQLAlchemy should generate the UUID and save it to the database, and it shouldn't change. Are you seeing a different behaviour?
@microapis
@microapis 2 года назад
Forgot to say, thank you for checking the tutorial and for your nice feedback!!
@Nickdondo
@Nickdondo 2 года назад
@@microapis You very welcome, this was a great tutorial. I found where I was making the mistake. When creating our post request in api.py I was not writing out the key value pairs(lines 25-28). I was trying to short cut it by posting it as whole object. It adds the UUID from the sqlalchemy model but since there is no function call on the post request it never updates the UUID. It only runs as a single instance.
@manu5672
@manu5672 2 года назад
You should precise the code is secure if you use an UUID for this id. If not your code is highly insecure. You should warn about it.
@microapis
@microapis 2 года назад
Hi Ma that's a great point actually! A lot of the time I see companies exposing resources with numerical IDs, which opens the door for malicious users to play around with numbers and try to get access to resources that don't belong to them. Thanks for highlighting it!
@MrAntLans
@MrAntLans 2 года назад
Hi, which theme u use for PyCharm in this video?
@microapis
@microapis 2 года назад
Hi Anton thanks for your question! I never thought too much about this so had to check haha. The theme I use is Dracula
@MrAntLans
@MrAntLans 2 года назад
@@microapis hi, thx )
Далее
Setting up Alembic with SQLAlchemy
18:47
Просмотров 33 тыс.
ОБЗОР ПОДАРКОВ 🎁 | WICSUR #shorts
00:55
Build APIs with Flask (the right way)
49:09
Просмотров 9 тыс.
Why You NEED To Learn FastAPI | Hands On Project
21:15
Просмотров 159 тыс.
How to build a FastAPI app with PostgreSQL
27:37
Просмотров 44 тыс.
FastAPI Tutorial - Building RESTful APIs with Python
1:03:10
API Security Fundamentals [2023]
50:35
Просмотров 1,6 тыс.
Solving one of PostgreSQL's biggest weaknesses.
17:12
Просмотров 190 тыс.
Database Sharding and Partitioning
23:53
Просмотров 78 тыс.