Python FastAPI Tutorial: How to Connect FastAPI to Database

Поделиться
HTML-код
  • Опубликовано: 12 сен 2024

Комментарии • 62

  • @boy291-z8c
    @boy291-z8c Год назад +1

    clear and concise!! I love it. Good job sir!

    • @codingwithroby
      @codingwithroby  Год назад

      Glad you enjoyed it! Good luck within your FastAPI journey :-)

  • @anujonthemove
    @anujonthemove 10 месяцев назад

    Got to learn a lot of things through this video!

  • @user-tl6yl1fp9x
    @user-tl6yl1fp9x Год назад +1

    love it! very clear and easy to understand

  • @debhasish
    @debhasish Год назад +1

    Very very clear instructions and explanations. Thank you for making this video. :)

  • @bertlemoi431
    @bertlemoi431 Год назад +2

    everything i learned yesterday by looking at code in 10mins. i should have checked youtube yesterday...

  • @spider279
    @spider279 2 года назад

    most Beautiful and comprehensible video on FASTAPI with database , thanks man +1 follower

  • @nicolasaltamirano5572
    @nicolasaltamirano5572 2 года назад +1

    Great work man, it help me a lot! Keep it going \,,/

  • @vinni_codes
    @vinni_codes 2 года назад +1

    I love the video, super useful. Thanks for sharing.

    • @codingwithroby
      @codingwithroby  2 года назад

      Glad you found it useful :) thanks for watching

  • @aviraltiwari3412
    @aviraltiwari3412 Год назад

    Subbed! Create more FastAPI content man, know your audience.

    • @codingwithroby
      @codingwithroby  Год назад +1

      Thanks for the kind words! You’re the best. Is there anything you want to see in a future video regarding FastAPI?

    • @aviraltiwari3412
      @aviraltiwari3412 Год назад +1

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

  • @aadargupta
    @aadargupta 3 месяца назад

    I get models is not a module, even though it is in the same directory

  • @alielshimy9028
    @alielshimy9028 Год назад +1

    If im working with an already existing database will the same concept work?

  • @marcodigennarobari
    @marcodigennarobari Год назад

    nice work! simple and useful
    how about a third video showing how to mock the data in the sql db for testing purposes?

  • @pleabargain
    @pleabargain Год назад

    Any chance you will continue and add a video on how to get web templates to interact with your book db? Thank you!

    • @codingwithroby
      @codingwithroby  Год назад

      Hey friend, check out my full course on the subject :-) www.udemy.com/course/fastapi-the-complete-course/

  • @chriskeo392
    @chriskeo392 2 года назад +1

    LFG!
    SQLModel advanced queries up next???!?!?

    • @codingwithroby
      @codingwithroby  2 года назад

      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 :)

  • @spider279
    @spider279 2 года назад +1

    Question ? can we create for other get,post,put and delete method for another BaseModel class ? with the same database

    • @spider279
      @spider279 2 года назад

      hello please

    • @codingwithroby
      @codingwithroby  Год назад

      You can, but it would be better to keep the validation separate from the database models

  • @robertocorti4859
    @robertocorti4859 Год назад

    that was what I exactly needed. Thank you so much!

  • @pietraderdetective8953
    @pietraderdetective8953 Год назад

    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
      @codingwithroby  Год назад +1

      Hmm interesting, I will take a look at the Quart framework. Is this something you use often?

    • @pietraderdetective8953
      @pietraderdetective8953 Год назад

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

  • @whereismypants69
    @whereismypants69 Год назад

    does the book id have to be an int or can i make it a string

    • @codingwithroby
      @codingwithroby  Год назад

      It can anything you want it to be. Int, String, UUID you choose :)

  • @robinmaurer2645
    @robinmaurer2645 2 года назад

    the autoincrement doesnt work for me ... any tipps?

  • @andreww406
    @andreww406 Год назад

    Hi, after create a new book, I want to take the ID of that inserted raw, how should I do?

    • @codingwithroby
      @codingwithroby  Год назад

      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.

  • @elmouatamidbenatia8754
    @elmouatamidbenatia8754 Год назад

    great job

  • @clearthinking5441
    @clearthinking5441 Год назад

    is there a way of doing this with a context manager?

    • @codingwithroby
      @codingwithroby  Год назад

      Which part are you referring to? Like the opening and closing of the database connection?

  • @daniilpogolovkin8221
    @daniilpogolovkin8221 Год назад

    Tnx!

  • @armaanthadani9709
    @armaanthadani9709 5 месяцев назад

    HI, I use postgresql and this is URL format I used - "postgresql://user:password@host:port/database_name" is that correct?

  • @Lupo9
    @Lupo9 11 месяцев назад

    It seems unintuitive to me that I would have to manage the SQLAlchemy model and also the pydantic model.

    • @codingwithroby
      @codingwithroby  11 месяцев назад

      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 🙂

    • @Lupo9
      @Lupo9 11 месяцев назад +1

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

  • @divyanambiar5009
    @divyanambiar5009 4 месяца назад

    How to implement level 3 Rest with fast API ?

    • @codingwithroby
      @codingwithroby  4 месяца назад

      I am not familiar with the term "level 3 Rest" - what is that?

  • @paagosamuel6716
    @paagosamuel6716 Год назад

    Thank you, I ll love to see it with mongodb

  • @dosengthavong8854
    @dosengthavong8854 2 года назад

    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
      @spider279 2 года назад

      do you have solution now

    • @dosengthavong8854
      @dosengthavong8854 2 года назад

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

    • @codingwithroby
      @codingwithroby  Год назад

      Glad you were able to figure it out :-)

  • @yolowex6876
    @yolowex6876 Месяц назад

    You could explain all that in 10 minutes