DEV Community

Cover image for Connecting to PostgreSQL using GORM

Connecting to PostgreSQL using GORM

Karan Pratap Singh on December 01, 2021

This article builds up on the last part where we built a simple REST API with Go. Now, let's connect our API with a real database! Here, we will us...
Collapse
 
sharandec22 profile image
Shiva Sharan

Great tutorial. Appreciate the effort. Cheers

Collapse
 
karanpratapsingh profile image
Karan Pratap Singh

Thanks!

Collapse
 
htetlinlinnaing profile image
HtetLinLinNaing

Great Tutorial I've ever found.
I try this with another example. I want to divide 2 more folders under handlers (one for horror and one for fantasy). Under each folder I want to add 4 go file for CRUD functions.
But everything is ok when I write like this.
But in the main.go file, there is an error like
"h.GetAllCategory undefined (type content.handler has no field or method GetAllCategory)" .
What should I do?

Collapse
 
karanpratapsingh profile image
Karan Pratap Singh

Thank you! I belive if you divide folders, you'll need to create new packages. Example, package a and package b. Then use it like: a.MethodX or b.MethodY. I can help more if I can see a github repo

Collapse
 
htetlinlinnaing profile image
HtetLinLinNaing

Thanks for your reply. I got the answer. You're right. I needed to create new packages and import the package when I need to call from another package. Plz create and write more post about advanced Golang. Your posts help a lot for newbies like me.

Thread Thread
 
karanpratapsingh profile image
Karan Pratap Singh

Thank you! I created a Go course, Chapter IV has some advanced topics that you might like

Thread Thread
 
htetlinlinnaing profile image
HtetLinLinNaing

Thank you..

Collapse
 
nsavelyeva profile image
Natallia Savelyeva

Hello Karan, thanks for the tutorial!
I am looking forward to your next post. In particular, I am very interested in writing unit tests for the database layer. With GORM V1 github.com/jinzhu/gorm I used go-mocket github.com/selvatico/go-mocket, and now I am looking for a way to migrate to GORM V2 and update unit tests.

Collapse
 
karanpratapsingh profile image
Karan Pratap Singh

Thank you Natallia, means a lot!

Collapse
 
jimmystrife profile image
Omar Felipe Rojas Torres

Great, help me with some doubts I had with the grom library.

Collapse
 
thiago_pereiraalves_950d profile image
Thiago Pereira Alves

Obrigado pelo tutorial!