FastAPI with SQLAlchemy Tutorial

  Рет қаралды 14,764

microapis

microapis

Күн бұрын

Пікірлер: 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!
@cagrKARAYAKA
@cagrKARAYAKA 2 жыл бұрын
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 2 жыл бұрын
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 2 жыл бұрын
Can I connect to DB without using SQLAlchemy?. For eg, I want connec to SQL Server using pyodbc
@microapis
@microapis 2 жыл бұрын
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!
@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!
@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 )
@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.
@mufc5033
@mufc5033 3 жыл бұрын
tnx for this tutorial
@microapis
@microapis 3 жыл бұрын
My pleasure! Thanks for the nice comment!
@murugarajuperumalla5508
@murugarajuperumalla5508 2 жыл бұрын
keep it up
@microapis
@microapis 2 жыл бұрын
Thanks for the nice feedback!
@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!
Setting up Alembic with SQLAlchemy
18:47
microapis
Рет қаралды 34 М.
Why You NEED To Learn FastAPI | Hands On Project
21:15
Travis Media
Рет қаралды 175 М.
Their Boat Engine Fell Off
0:13
Newsflare
Рет қаралды 15 МЛН
SQLAlchemy Makes Using Python Databases EASY
19:08
Eric Roby
Рет қаралды 8 М.
FastAPI with JWT auth tutorial
29:39
microapis
Рет қаралды 7 М.
SQLModel is the Pydantic inspired Python ORM we’ve been waiting for
8:36
John Watson Rooney
Рет қаралды 32 М.
How to Use Async SQLAlchemy in FastAPI
15:20
Pretty Printed
Рет қаралды 33 М.
FastAPI Essentials - CRUD API with a Database and SQLModel
23:03
FastAPI & React - 1 - Creating Models with SQLAlchemy
21:39
How to build a FastAPI app with PostgreSQL
27:37
Eric Roby
Рет қаралды 66 М.