Persist JSON Postgres / Golang

1

Hello, is there any way to persist a JSON in postgres with GO language?

I do not want to do a manual insert, I want to map my JSON with a struct and persist, similar to hibernate in Java.

I found this lib link

Convert my JSON to BSON and persist?

How would that look in the code?

    
asked by anonymous 16.04.2015 / 13:36

2 answers

1

Hibernate is a ORM . For Go, there are 4 most popular options :

I've never used them ... And most likely, I never will. I, like many developers, have decided that ORMs are not generally useful. I'd rather write my own SQL because it's not difficult, it gives me better control, which often gives better performance, and means that I always understand what my code is doing.

    
02.05.2015 / 16:55
0

I use GORM and it's pretty easy to tweak.

After giving a read will understand, it is something like this, you can use BSON to generate your string UUID

type Modelo struct {
    UUID string 'gorm:"primary_key"'
    Payload string 'sql:"type:JSONB NOT NULL DEFAULT '{}'::JSONB"'
}

db.Save(&modelo)

For the payload field you do a json.Marshal ();

    
27.05.2017 / 04:13