Databases #
Like dependency injection, talking to databases is a topic the Go community likes to be particularly opinionated about. Coming from Java, Ruby on Rails, or any sort of well-known framework you will certainly look for the cushioned comfort of Hibernate, or your favorite Object Relational Mapper (ORM) of choice.
Which is I am starting this section with a word of caution, because the term ORM is quite a loaded one among the community. Not that you don’t have decent options - it’s just that everyone is trying to talk you out of using them.
NOTE: This section is still in progress. While waiting, I’d suggest that you have a look at this fantastic 11-post series below, which goes into detail on the well-known database access options in the Go world.
When it comes to working with databases in Go, there are really only 3 viable options:
- Talk to the DB directly, using the standard library’s
db/sql
package.- Can be very, very boilerplate-y.
- Use a reflection-based ORM (ORM is a bit of a dirty word in the Go world, but yeah, a few of those exist).
- Use code generation to ease your life and tuck the generated boilerplate away.
Helpful References #
Comparing GraphQL with ORM and plain SQL #Golang pic.twitter.com/ptpLUgDcPK
— 🦄 stephan@amazingcto.social (@KingOfCoders) November 28, 2022