Learn knex.js with Postgres and express in 35 minutes

Поділитися
Вставка
  • Опубліковано 6 лис 2024

КОМЕНТАРІ • 88

  • @benmar000
    @benmar000 3 роки тому +34

    I really like that you take the time to explain how the setup is done in a real world context using best practices. Other channels are less helpful because they use quick and dirty methods that are not good for production. Thanks!

    • @jgoebel
      @jgoebel  3 роки тому +7

      thx, I'm glad you got some value out of it 👍

    • @kiliusz
      @kiliusz 7 місяців тому

      Agree :)

  • @abdulazeez.98
    @abdulazeez.98 Рік тому +3

    I rarely see a video discussing best practices, most tutorials just do the whole thing in-line.
    Really appreciate it 👍

  • @mshowkat5321
    @mshowkat5321 3 роки тому +3

    there aren't that much video about knex js. so far you video is the best about this topic. make a video play list for beginner also. that would help tons of people.

    • @jgoebel
      @jgoebel  3 роки тому +1

      thx for the idea. Will add it to my list of potential topics 👍

  • @PfalzerGbr
    @PfalzerGbr 3 роки тому +5

    Great video, huge help for me as a beginner. I tried to implement layers by myself before, this one managed to clarify it even more. Amazing to see videos where the structure is not dumbed down, just because the example is simple. Thank you for your work!

    • @jgoebel
      @jgoebel  3 роки тому

      thx Gabor, I hope it helps 👍

  • @chibuokemibezim7402
    @chibuokemibezim7402 3 роки тому +7

    This is a great tutorial, very helpful one, the fact that you also use best practises as much as you can while on it is great

    • @jgoebel
      @jgoebel  3 роки тому

      thx, I'm glad it was helpful 👍

  • @htouqeer938
    @htouqeer938 2 роки тому

    I really like that you take the time to explain how the setup is done in a real world context using best practices. How can I complete CRUD in this.
    Please replay

  • @jackjones5207
    @jackjones5207 8 місяців тому

    Best knex video... thanks Jan 🙂, keep up your good work

    • @jgoebel
      @jgoebel  8 місяців тому

      Glad you enjoyed it!

  • @omidnejadabbasi2171
    @omidnejadabbasi2171 2 роки тому

    really good video!. I am a junior and i learn a lot from this video. please keep this up.

  • @jgoebel
    @jgoebel  3 роки тому +2

    What do you think about this video?
    Let me know in the comments.

  • @PlayRiteProductions
    @PlayRiteProductions 3 роки тому

    Thank you so much for this video bro. Best knex tutorial I've seen so far.

    • @jgoebel
      @jgoebel  3 роки тому

      Thx, I'm glad it helped 👍

  • @damonwu8018
    @damonwu8018 3 роки тому +2

    Nice one, love the folder structure !!!

    • @jgoebel
      @jgoebel  3 роки тому

      thx damon 👍

  • @EricOnYouTube
    @EricOnYouTube 2 роки тому +1

    You showed how to build using the migrations. Nice would have been how to destroy and how to add to migrations after there are changes while already in production.

    • @jgoebel
      @jgoebel  2 роки тому +2

      Hi Eric, you never destroy or delete migrations, you only add new migrations that might undo changes you did before. And even then, it is rare to delete columns. If you were to change the migration history, web servers can crash in spectacular ways. Because for example migration 3 now is not doing the exact same thing ans 2 weeks ago because you modified the migrations a few days back

    • @EricOnYouTube
      @EricOnYouTube 2 роки тому +1

      @@jgoebel Thank you for the information.

  • @Mi-rinconcito
    @Mi-rinconcito 2 роки тому

    Thank you for this tutorial. I like the way you explain, very clearly. 🙏🙏

    • @jgoebel
      @jgoebel  2 роки тому

      thx, I'm glad you found it useful 👍

  • @invalidred
    @invalidred 2 роки тому

    Thanks dude was great intro to knex, learned a lot

    • @jgoebel
      @jgoebel  2 роки тому

      Glad I could help

  • @dnyaneshkale8293
    @dnyaneshkale8293 2 роки тому +1

    thank you brother this was very neat. Do you also have any tutorials on PEAN stack?

  • @toufikurrahmantoufik5368
    @toufikurrahmantoufik5368 3 місяці тому

    Thank You so much . I have complete a task. by following for video.

    • @jgoebel
      @jgoebel  3 місяці тому

      glad to hear!

  • @gustavobraganti5547
    @gustavobraganti5547 3 роки тому

    Thank you very much for this tutorial! It helped me a lot! Keep up the good work!

    • @jgoebel
      @jgoebel  3 роки тому

      thx Gustavo 👍

  • @maltman126
    @maltman126 3 роки тому

    Thanks for this...good video that was well explained. I'm a bit of a newbie, and and had to pause a few times....but at the end it worked!!

    • @jgoebel
      @jgoebel  3 роки тому

      thx Matt, I'm glad you found it useful 👍

  • @cbton_
    @cbton_ Рік тому

    Great tutorial, thank you so much.

  • @a10gamerr
    @a10gamerr 3 роки тому +1

    Thank you so much for the knex crash course.
    Would you please explain more about the service layer? Should the validation logic be added in the service layer and error response in the controller?
    Thanks!

    • @jgoebel
      @jgoebel  3 роки тому +1

      In the service layer, you would add any business logic, e.g. making a REST call to anotherr web service (e.g. sending the reset password email, checking if password hashes match) Basically the "actual" business logic. And in the controller, you would just group together the different REST endpoints so that you don't implement them in the routes directory.
      If the service is simple, then you can leave out the controller level or even the service layer. As the code base grows and as you want to test more things independently, putting the logic inside of services makes more and more sense imo.

    • @ZachBradyisBrachZady
      @ZachBradyisBrachZady 2 роки тому +1

      @@jgoebel do you have any videos focusing on Express server design using these abstractions? i.e.. DAO, service, controller

  • @AhSoh7091
    @AhSoh7091 Рік тому

    could you share some idea that how unit test for this? i watched your another video for the dependancy injection but still not idea how to implement into this

  • @jeremyAr
    @jeremyAr 9 місяців тому

    Whats the purpose of dropping the table? In knex migrations.

  • @davidgan298
    @davidgan298 2 роки тому

    Super helpful, thank you!

    • @jgoebel
      @jgoebel  2 роки тому

      you're welcome David!

  • @emyboybeats4330
    @emyboybeats4330 3 роки тому

    Thanks for this tutorial, your a life saver

    • @jgoebel
      @jgoebel  3 роки тому

      Hi Emyboy, I'm glad it helped! 👍

  • @developerfriendly
    @developerfriendly 2 роки тому

    perfect tutorial. thanks a lot!

    • @jgoebel
      @jgoebel  2 роки тому

      You're welcome!

  • @ヒマワリ-y4z
    @ヒマワリ-y4z 2 роки тому

    This is a great tutorial, very helpful one, Thanks a lot!
    I really appreciate you if you could tell me more about reference information regarding to patch and delete method in dao layer. I struggled to implement such methods as using req.params.id or req.body in dao layer but I couldn't figured it out... when I put arguments in dao layer to set id or update value, they are undefined. I want to know how I could pass req.params.id or req.body to service layer and dao layer.

  • @neilarmstrong8927
    @neilarmstrong8927 2 роки тому

    Hello! I’m novice and don’t understand how you logining in adminer. Can you explain it please

  • @TawfikShalash
    @TawfikShalash 2 роки тому

    so premium content

  • @fahadsid
    @fahadsid 3 роки тому

    This is a very nice tutorial.

    • @jgoebel
      @jgoebel  3 роки тому

      thx Fahad, I'm glad you liked it 👍

  • @Gallagan
    @Gallagan 3 роки тому

    Really Great content ! thanks man !

    • @jgoebel
      @jgoebel  3 роки тому

      thx Gallagan, I'm glad you liked it!

  • @olipaype
    @olipaype 2 роки тому

    I´ve really tried to check every single line of your code... basically I've copied all but, when i try to seed an error emerged and said that the role does not exist.... referencing my "general" user instead of database assigned user--- I would appreciate any help

  • @opmHebat0404
    @opmHebat0404 2 роки тому

    How to give a value each field before I run migartion? Example id int(5) name varchar(25)

  • @Fullflexno
    @Fullflexno 3 роки тому

    Solid video!

    • @jgoebel
      @jgoebel  3 роки тому +1

      thx Fullflex 👍

  • @paulywill
    @paulywill 2 роки тому

    Would there be much change to add GraphQL to this example?

  • @FriedRiceNigguh
    @FriedRiceNigguh 3 роки тому +2

    This is lit

  • @russellp.4005
    @russellp.4005 3 роки тому

    Why did you destructure the createPerson as [id] at your dao? Isn't what returns an object? Also, does it have an id property?

    • @jgoebel
      @jgoebel  3 роки тому

      Hi Russel, id is the primary key of the table and it is autoincrement. So the database generates the number for us when a record is inserted. You only know the id after the record was inserted. That's why it is very common to use UUIDs as primary keys because then you know the id upfront. But UUIDs as primary keys are little bit harder to understand, that's why I use integer and autoincrement as primary key.
      The returning method is also specific for Postgres. On MySQL it would be different: knexjs.org/#Builder-returning

  • @BelegaerTheGreat
    @BelegaerTheGreat 3 роки тому +2

    At 12:00 I have an error: unknown option '--migrations'

    • @jgoebel
      @jgoebel  3 роки тому

      Hi Kazik, did you use the exact command: npx knex migrate:make init --migrations-directory db/migrations

    • @nosmoke98
      @nosmoke98 3 роки тому +1

      I had the same problem.
      Solution:
      Uses "cd .." and reuses "npx knex migrate:make init --migrations-directory db/migrations"

  • @LuthfanMursyidanM
    @LuthfanMursyidanM Рік тому

    Very nice

  • @tahersaid2431
    @tahersaid2431 2 роки тому

    This error shows up while using the post method:An error occurred while creating new person error: password authentication failed for user "postgres"

    • @jgoebel
      @jgoebel  2 роки тому

      seems like either your password is wrong or the user you are trying to use ("postgres") does not exist.

  • @sebastianionel5134
    @sebastianionel5134 3 роки тому +1

    Uhh... yeah, as a beginner I am really confused right now and the fact that you have a person.js in ~4 folders and 2 indexes.js made this video harder to me to understand. Some of your commands didn't work for me so I needed to research by myself to find out what is the right command. Maybe it s because I am a newbie. And at the end I cannot escape from this error: UnhandledPromiseRejectionWarning: Error: Unable to acquire a connection

    • @jgoebel
      @jgoebel  3 роки тому

      Hi Sebastian, your error looks like something is wrong with your database connection. Did you update the credentials in db/knexfile.js? Did you make sure your local db is running? If you look at package.json I added the migration command as a script there so you can copy and paste it if needed.

  • @vikymuhamad4226
    @vikymuhamad4226 3 роки тому

    how to put id in PersonDao when update person ?

  • @microwavecoffee
    @microwavecoffee 3 роки тому

    thank you!

    • @jgoebel
      @jgoebel  3 роки тому +1

      you're welcome 👍

  • @teckyify
    @teckyify 3 роки тому

    Looks like an overkill of abstraction which Oren Oeini addresses all the time. You have an ORM which already abstracts away your data access. At least selects can be executed directly on the ORM.

    • @jgoebel
      @jgoebel  3 роки тому

      you could, but what happens if you change the ORM? In that case you would need to refactor the whole code. If you encapsulate it in a dedicated layer, you only have to change that layer

    • @teckyify
      @teckyify 3 роки тому

      @@jgoebel each query I have is tailored for one route and I don't reuse them because it would be semantic nonsense. And if (this is a big if in enterprise) I would switch the ORM, then I have still only unique places that need to be modified.

    • @jgoebel
      @jgoebel  3 роки тому

      @@teckyify I think the idea is to not use knex or the db package in a lot of different locations. This makes it easier to refactor and test. If you have all db logic in one layer, you can easily stub this layer if you are testing something other than the db access.

  • @orkhan9999
    @orkhan9999 3 роки тому

    thanks a lot

    • @jgoebel
      @jgoebel  3 роки тому

      thanks Orkhan, you're welcome 👍

  • @FirstLast-gk6lg
    @FirstLast-gk6lg 2 роки тому

    It doesn't work. I have spent the last 3 days troubleshooting PostgreSQL & PGAdmin, I absolutely cannot get this to work. I have worked through dozens and dozens of possible solutions and I ALWAYS have yet another error. I cannot run the command migrate:latest and I cannot seem to get my PGAdmin to cooperate.
    This is my least favorite part of being a programmer, all of this software worked the last time I used it just a few months ago. All of it worked without issue. Now a few months later I attempt to do the exact same things I did back then and absolutely nothing will work, the simplest commands then simplest steps, nothing is working. I fucking hate this feeling

  • @viekva
    @viekva 2 роки тому

    horrible