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!
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.
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!
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
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.
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
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!
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.
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
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.
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
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
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
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.
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.
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
@@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.
@@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.
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
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!
thx, I'm glad you got some value out of it 👍
Agree :)
I rarely see a video discussing best practices, most tutorials just do the whole thing in-line.
Really appreciate it 👍
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.
thx for the idea. Will add it to my list of potential topics 👍
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!
thx Gabor, I hope it helps 👍
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
thx, I'm glad it was helpful 👍
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
Best knex video... thanks Jan 🙂, keep up your good work
Glad you enjoyed it!
really good video!. I am a junior and i learn a lot from this video. please keep this up.
thx Omid
What do you think about this video?
Let me know in the comments.
Thank you so much for this video bro. Best knex tutorial I've seen so far.
Thx, I'm glad it helped 👍
Nice one, love the folder structure !!!
thx damon 👍
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.
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
@@jgoebel Thank you for the information.
Thank you for this tutorial. I like the way you explain, very clearly. 🙏🙏
thx, I'm glad you found it useful 👍
Thanks dude was great intro to knex, learned a lot
Glad I could help
thank you brother this was very neat. Do you also have any tutorials on PEAN stack?
Thank You so much . I have complete a task. by following for video.
glad to hear!
Thank you very much for this tutorial! It helped me a lot! Keep up the good work!
thx Gustavo 👍
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!!
thx Matt, I'm glad you found it useful 👍
Great tutorial, thank you so much.
thx
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!
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.
@@jgoebel do you have any videos focusing on Express server design using these abstractions? i.e.. DAO, service, controller
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
Whats the purpose of dropping the table? In knex migrations.
Super helpful, thank you!
you're welcome David!
Thanks for this tutorial, your a life saver
Hi Emyboy, I'm glad it helped! 👍
perfect tutorial. thanks a lot!
You're welcome!
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.
Hello! I’m novice and don’t understand how you logining in adminer. Can you explain it please
so premium content
thx
This is a very nice tutorial.
thx Fahad, I'm glad you liked it 👍
Really Great content ! thanks man !
thx Gallagan, I'm glad you liked it!
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
How to give a value each field before I run migartion? Example id int(5) name varchar(25)
Solid video!
thx Fullflex 👍
Would there be much change to add GraphQL to this example?
This is lit
👍
Why did you destructure the createPerson as [id] at your dao? Isn't what returns an object? Also, does it have an id property?
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
At 12:00 I have an error: unknown option '--migrations'
Hi Kazik, did you use the exact command: npx knex migrate:make init --migrations-directory db/migrations
I had the same problem.
Solution:
Uses "cd .." and reuses "npx knex migrate:make init --migrations-directory db/migrations"
Very nice
thx
This error shows up while using the post method:An error occurred while creating new person error: password authentication failed for user "postgres"
seems like either your password is wrong or the user you are trying to use ("postgres") does not exist.
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
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.
how to put id in PersonDao when update person ?
thank you!
you're welcome 👍
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.
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
@@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.
@@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.
thanks a lot
thanks Orkhan, you're welcome 👍
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
horrible