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.

PostgreSQL also allows JSON storage (called the JSON store) past version 9.2. It allows developers to get the benefits of relational databases with the JSON format. We can create indexes on JSON fields, query on JSON fields, and so on. We implemented a REST API for the e-commerce model we defined in the previous chapters using GORM. PostgreSQL is a well established, open-source relational database that can suffice our enterprise needs. The driver support for Go is exceptional with pq and gorm.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.135.206.254