Golang Gorm JSONB Value & Copy Examples
June 18, 2015
The Golang Gorm package is an excellent ORM library for Golang. We’re utilizing gorm with the Pure Go Postgres driver.
Out of the box Gorm doesn’t include support for the JSONB field type implemented in PostgreSQL 9.4. However, you can pretty painlessly define your own struct type, and write Value() and Copy() functions for this type. Below is an example.
JSONB type Definition
Model Definition
Value() & Copy() examples:
Usage
Now, when interacting with JSONB Fields via Gorm, the values are automatically marshalled and unmarshalled.