How does gorm create data for json fields?

how does gorm create data for json fields?

the official document has an example of creating a record: http://gorm.io/zh_CN/docs/ind.

// 
  db.Create(&Product{Code: "L1212", Price: 1000})

question:
if this Product model has a specification (Spec) field, which is in json format, there are three items:

{
"length":"20cm",
"width":"30cm",
"weight":"40g"
}

how should I write this creation statement? If you write IDE like this, you will get an error:

// 
  db.Create(&Product{Code: "L1212", Price: 1000,Spec:{"length":"20cm","width":"30cm","weight":"40g"}})
Dec.20,2021

the issue of gorm has been asked this question

https://github.com/jinzhu/gor.
https://github.com/jinzhu/gor.
https://github.com/jinzhu/gor.

you can have a look.


this question I have provided specific references and attempts in the issue of the above respondents https://github.com/go-gorm/go.

.
  • Gorm query problem

    package main import ( "database sql driver" "fmt" "time" ) type JSONTime struct { time.Time } MarshalJSON on JSONTime format Time field with %Y-%m-%d %H:%M:%S func (t JSONTime) MarshalJSON() ([]byte, er...

    Jan.08,2022
  • Gorm one-to-many mapping problem

    I use golang s gorm to construct a data model. One posts, one users, one user corresponds to multiple articles posts.go . finally this problem arises, how to solve it ...

    Feb.15,2022
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e5627b-440b5.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e5627b-440b5.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?