Why I like Go-GORM + Make Table

In this section I am going to be stating the features or design decisions I thought were effective while writing a back-end with go-gorm, an object relational model. This is going to be the start to a series of making gist like application; follow if you want to see the components.

  1. Why I like Go-Lang
  2. Why I like Go-ORM (You’re here)
  3. Why I like Go-Fiber
  4. Go-Fiber: Request Validation
  5. Go-Long: JSON Web Tokens
  6. Go-Lang: Unit Testing
  7. Go-Fiber: Dependency Injection

Here is an example struct which Go-GORM can use to make a table. Go’s tag system can pass more information to the database. This makes allows you to have as much control as writing the SQL by hand.

type Person struct {
Email string
Password string
type Gist struct {
Snippet string
Writer Person `gorm:"foreignKey:ID"`

Below is an example of making a database connection and migrating the tables.

db, err := gorm.Open( postgres.Open(dsn)) 
if err != nil { panic(err.Error()) }
db.AutoMigrate(Person{}, Gist{})

Looking at other ORM’s Go-GORM simplifies the interaction when dealing with persistent stores. Thanks to structural typing, translations to json or xml are taken care of without additional effort. The downside to GORM is that the GraphQL libraries for Golang don’t play nicely with it.

This is actually similar (in behavior) to how .net deals with database entities.

ORMs tend to have a command line interface to perform migrations. SQL statements or an intermediate representation which the command line interface uses to make tables. When changes need to be made the migration is performed with a command line tool along with SQL scripts. Versioning is then taken care of by the scripts. Go-GORM handles all of this without a command line tool or SQL; my argument being that it is git’s responsibility to manage versions.

Temporary deletion could be useful because of several reasons. The downside is when looking at the resulting SQL statements shows that it isn’t doing the best choices. The upside being that GORM lets you write your own queries; like most ORMs. It also provides generic tools to abstract the business specific tasks effectively. Although you have to be careful because it could be illegal in specific regions; please consult a lawyer if you plan on releasing an application with GORM.

There were features which did not work as expected when I initially downloaded GORM. Since then the bugs have been fixed. I had to test the features I was going use (which is normal when dealing with external libraries). I ended up getting to read through most of the source code. Being honest I’m pretty pleased the GORM community.

awake, software engineer.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store