Summary
In this chapter, we started our journey by installing PostgreSQL. We introduced PostgreSQL formally and tried to see all possible SQL queries for CRUD operations. We then saw how to add users and databases in PostgreSQL. We then installed and explained pq
, a Postgres driver for the Go language. We explained how the driver API performs raw SQL queries.Â
Then came the implementation part of the URL shortening service; that REST service takes the original URL and returns a shortened string. It also takes the shortened URL and returns the original URL. We wrote a sample program to illustrate the Base62 algorithm that powers our service. We leveraged this algorithm in our service next and created a REST API.
GORM is a well-known object-relational mapper for Go. Using an ORM, one can easily manage the database operations. GORM provides a few useful functions, such as AutoMigrate
 (create a table if one doesn't exist), for writing intuitive Go code over the traditional database/sql
driver...