@@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