Exploring the JSON store in PostgreSQL
PostgreSQL >9.2 has a prominent feature 9.2" dbid="254735" called the JSON store. PostgreSQL introduced a new data type for storing the JSON data. PostgreSQL allows users to insert a jsonb
field type, which holds the JSON string. It is quite useful in modeling the real-world data that has to be more flexible with the structure. PostgreSQL draws the best of both worlds by allowing us to store JSON strings as well as relational types.
In this section, we will try to realize a few of the JSON models that we defined for e-commerce websites in the previous chapters. But here, we will use the JSON field to store and retrieve items in PostgreSQL. For accessing PostgreSQL's JSON store, the normal pq
library is very tedious. So, in order to handle that better, we can use an Object Relational Mapper (ORM) called GORM.
GORM, a powerful ORM for Go
This ORM has the API for all operations that can be done in the database/sql
package. We can install GORM using this...