R
R
Roman Rakzin2016-09-25 19:40:03
PostgreSQL
Roman Rakzin, 2016-09-25 19:40:03

How to use jsonb (PostgreSQL) in Gorm in golang?

I decided to store the information in a field like jsonb(PostgreSQL) .
How to work with such fields in golang?
You need to write down the values ​​and make a selection. Or just insert SQL code?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladislav, 2016-09-29
@ghostiam

To auto-create a field with the required data type, you need to put a tag describing the type:
If you need a JSONB data type in Go itself, you can look here:
Gorm JSONB

A
alexander_astashov, 2017-10-16
@alexander_astashov

I use GORM and this helped me:
https://github.com/jinzhu/gorm/issues/516
Plus this

type ClassRoom struct {
    gorm.Model
    State string `sql:"type:JSONB NOT NULL DEFAULT '{}'::JSONB"`
  }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question