Using GORM
In the previous chapters, we explored how to interact with databases using Go’s standard database/sql package and how to enhance our experience with SQL query builders such as SQuirrel. Both approaches give us great control over the SQL queries we execute, but they require us to handle the conversion between Go structures and database data manually. In this chapter, we’ll explore Go Object Relational Mapper (GORM), an object-relational mapper (ORM) for Go that offers a more abstract, object-oriented alternative for working with databases.
Throughout this chapter, we’ll learn about the following:
- What an GORM is and why you might want to use one
- How to set up GORM for your project
- How to define models in GORM
- How to perform Create, Retrieve, Update, Delete (CRUD) operations with GORM
- Working with relationships
- How to migrate our shopping list API to use GORM