Blog
Basically in all of them we want to make the following queryGolang Database Library Orm Example - List
December 14, 2021
In this post, we will look at comparing listing of user resource. We limit the record to the first
thirty records.
SELECT * FROM users ORDER BY id LIMIT 30 OFFSET 0;
In this post, we compare and contrast how these libraries and ORMs handle a record insertion. As a standard approach to all example in these blog series, our controller accepts and parses
client request to a custom ‘request’ struct, and if required, parses query parameter(s). We hash the
password and together with All CRUD operations are done in You should perform validation in production. In our case, we skip this part to keep this blog series
focused.Golang Database Library Orm Example - Create
December 14, 2021CreateUserRequest
we try to insert to database. Then the struct
is passed down to our data access layer.type CreateUserRequest struct {
ID uint `json:"id"`
FirstName string `json:"first_name"`
MiddleName string `json:"middle_name"`
LastName string `json:"last_name"`
Email string `json:"email"`
Password string `json:"password"`
}
crud.go
files of each of the libraries and ORMs directories.
There are a multitude of ways to interact with a SQL database in Go. The most obvious path is to
simply use This post is only an introduction to these packages. I will briefly touch on each of them on what
it is and database operations that we are going to test with. In the next posts, we will cover
common use cases for each. Full source code is available at https://github.com/gmhafiz/golang-database-library-orm-example.Golang Database Library and ORM Example - Introduction
December 14, 2021database/sql
package from the standard library plus a database driver. It is easy to use
and can be sufficient to meet all of your requirements. Using raw SQL directly means you can
leverage what you already know, SQL, and craft complex queries in many ways that an ORM may not
support. However, retrieving (scanning in Go lingo) results from database is verbose and can be
tedious - something that alternatives shine. This series of posts will show how different popular
libraries and ORM available of Go are used. They are sqlx, sqlc,
squirrel, gorm,
sqlboiler, and ent.