GORM Playground Link
https://github.com/go-gorm/playground/pull/654
reproduce
func TestDbErr(t *testing.T) {
type config struct {
ID uint `gorm:"primary_key"`
Config map[string]interface{} `gorm:"column:config;serializer:json"`
}
db, _ := gorm.Open(mysql.New(mysql.Config{DSN: "test:123123@tcp(localhost:3306)/test?charset=utf8mb4&parseTime=True&loc=Local"}))
var mob map[string]interface{}
db.AutoMigrate(&config{})
db.Create(&config{Config: map[string]interface{}{"sss": "2#24"}})
db.Model(&config{}).Where("id = 1").Find(&mob)
fmt.Println(mob)
}
func TestDbOk(t *testing.T) {
type config struct {
ID uint `gorm:"primary_key"`
Config map[string]interface{} `gorm:"column:config;serializer:json"`
}
db, _ := gorm.Open(mysql.New(mysql.Config{DSN: "test:123123@tcp(localhost:3306)/test?charset=utf8mb4&parseTime=True&loc=Local"}))
var mob config
db.AutoMigrate(&config{})
db.Create(&config{Config: map[string]interface{}{"sss": "2#24"}})
db.Model(&config{}).Where("id = 1").Find(&mob)
fmt.Println(mob)
}
result
2023/10/10 07:05:34 d:/vsc/go/test/go2_test.go:51 sql: Scan error on column index 1, name "config": unsupported Scan, storing driver.Value type []uint8 into type *map[string]interface {}
[0.000ms] [rows:1] SELECT * FROM `configs` WHERE id = 1
map[config:map[] id:1]
go 1.21.1 gorm 1.25.4 mysql 5.7.26 windows
Comment From: github-actions[bot]
The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking ✨
Comment From: a631807682
https://github.com/go-gorm/datatypes#json