@@codingwithroby Yep, a whole series would be great, your way of teaching is really good. Topics like authentication, background tasks etc. would be nice really.
Great video! Can you make a video for Quart (another async framework for Python) ? It's the async version of Flask but recently able to use Flask extensions..which makes it potentially as popular as Flask itself. Liked and subscribed!
@@codingwithroby I have been using Flask for some time, has been contemplating to migrate to Quart due to its native async capabilities...but hesitated due to very limited extension ecosystem compared to Flask. But a couple of months back there's a new development: a library called quart-flask-patch (written by the author of Quart himself) which enables a lot of the most important Flask extensions to be used in Quart. ~ so essentially what "crippled" Quart's potential has disappeared.. I deployed a test page of Quart last week and the async works so good I don't think I would ever go back to a synchronous framework.
Try something similar to: f = Foo(bar=x) session.add(f) session.flush() # At this point, the object f has been pushed to the DB, # and has been automatically assigned a unique primary key id f.id # is None session.refresh(f) # refresh updates given object in the session with its state in the DB # (and can also only refresh certain attributes - search for documentation) f.id # is the automatically assigned primary key ID given in the database.
Pydantic model is for the request coming in. It will do data validation. SQLAlchemy model is for the actual record in the database. Not all requests will match the model in the database exactly the same - in small applications like this sure, but it is best to have them separated 🙂
@@codingwithroby Thanks :) I just skimmed the fastapi docs on relational DBs and found out about ORM mode. Also the seperation of concerns clicked for me when I compared it to a Django model with a DRF serializer.
I had a problem with creating a sqlite db. So, after I created the books.db file it only has id column creating inside, no title, author ... column created. I tried deleted the .db file also the __pycache__.py, then re-run the program but still did work
@@spider279 Actually, I made a silly mistake lol. So in models.py instead of ... title = Column(String) ... I wrote ... title : Column(String) ... also in all other fields. This is why there are no fields created in books.db, except ID field
clear and concise!! I love it. Good job sir!
Glad you enjoyed it! Good luck within your FastAPI journey :-)
Got to learn a lot of things through this video!
Awesome! Glad you are here!
love it! very clear and easy to understand
I am glad you enjoyed it :-)
Very very clear instructions and explanations. Thank you for making this video. :)
I am glad you enjoyed it! 😊
everything i learned yesterday by looking at code in 10mins. i should have checked youtube yesterday...
Thank you! I am glad you are here :-)
most Beautiful and comprehensible video on FASTAPI with database , thanks man +1 follower
You're awesome! Thanks :-)
Great work man, it help me a lot! Keep it going \,,/
Thanks friend!
I love the video, super useful. Thanks for sharing.
Glad you found it useful :) thanks for watching
Subbed! Create more FastAPI content man, know your audience.
Thanks for the kind words! You’re the best. Is there anything you want to see in a future video regarding FastAPI?
@@codingwithroby Yep, a whole series would be great, your way of teaching is really good. Topics like authentication, background tasks etc. would be nice really.
I get models is not a module, even though it is in the same directory
If im working with an already existing database will the same concept work?
It will 🙂
nice work! simple and useful
how about a third video showing how to mock the data in the sql db for testing purposes?
Not a bad idea!
Any chance you will continue and add a video on how to get web templates to interact with your book db? Thank you!
Hey friend, check out my full course on the subject :-) www.udemy.com/course/fastapi-the-complete-course/
LFG!
SQLModel advanced queries up next???!?!?
I’m starting a new series currently on passing coding interview questions. I have multiple videos lining up! First one will be released this week :)
Question ? can we create for other get,post,put and delete method for another BaseModel class ? with the same database
hello please
You can, but it would be better to keep the validation separate from the database models
that was what I exactly needed. Thank you so much!
You're so welcome!
Great video!
Can you make a video for Quart (another async framework for Python) ?
It's the async version of Flask but recently able to use Flask extensions..which makes it potentially as popular as Flask itself.
Liked and subscribed!
Hmm interesting, I will take a look at the Quart framework. Is this something you use often?
@@codingwithroby I have been using Flask for some time, has been contemplating to migrate to Quart due to its native async capabilities...but hesitated due to very limited extension ecosystem compared to Flask. But a couple of months back there's a new development: a library called quart-flask-patch (written by the author of Quart himself) which enables a lot of the most important Flask extensions to be used in Quart.
~ so essentially what "crippled" Quart's potential has disappeared..
I deployed a test page of Quart last week and the async works so good I don't think I would ever go back to a synchronous framework.
does the book id have to be an int or can i make it a string
It can anything you want it to be. Int, String, UUID you choose :)
the autoincrement doesnt work for me ... any tipps?
Hi, after create a new book, I want to take the ID of that inserted raw, how should I do?
Try something similar to:
f = Foo(bar=x)
session.add(f)
session.flush()
# At this point, the object f has been pushed to the DB,
# and has been automatically assigned a unique primary key id
f.id
# is None
session.refresh(f)
# refresh updates given object in the session with its state in the DB
# (and can also only refresh certain attributes - search for documentation)
f.id
# is the automatically assigned primary key ID given in the database.
great job
Thanks a bunch!
is there a way of doing this with a context manager?
Which part are you referring to? Like the opening and closing of the database connection?
Tnx!
Thank you!
HI, I use postgresql and this is URL format I used - "postgresql://user:password@host:port/database_name" is that correct?
It seems unintuitive to me that I would have to manage the SQLAlchemy model and also the pydantic model.
Pydantic model is for the request coming in. It will do data validation. SQLAlchemy model is for the actual record in the database. Not all requests will match the model in the database exactly the same - in small applications like this sure, but it is best to have them separated 🙂
@@codingwithroby Thanks :) I just skimmed the fastapi docs on relational DBs and found out about ORM mode. Also the seperation of concerns clicked for me when I compared it to a Django model with a DRF serializer.
How to implement level 3 Rest with fast API ?
I am not familiar with the term "level 3 Rest" - what is that?
Thank you, I ll love to see it with mongodb
Ohhh, great idea.
I had a problem with creating a sqlite db.
So, after I created the books.db file it only has id column creating inside, no title, author ... column created.
I tried deleted the .db file also the __pycache__.py, then re-run the program but still did work
do you have solution now
@@spider279 Actually, I made a silly mistake lol.
So in models.py instead of ... title = Column(String) ...
I wrote ... title : Column(String) ... also in all other fields.
This is why there are no fields created in books.db, except ID field
Glad you were able to figure it out :-)
You could explain all that in 10 minutes
Thanks for the feedback