I want to use dynamic column blob data type in mariadb and use in Go project. when fetch data from database with gorm blob field is nil, Why?
type QrController struct {
}
func (controller *QrController) GetQrInfo(context context.Context) {
qrCode := context.FormValue("qr")
db, err := gorm.Open("mysql", "root:@/payro_db?charset=utf8&parseTime=True&loc=Local")
if (err != nil) {
fmt.Println(err.Error())
return
}
defer db.Close()
var qr model.BrcQr
if db.First(&qr, "code=?", qrCode).RecordNotFound() {
}
context.JSON(qr)
}
result is
{"qr_id":0,"code":"","type":0,"data":null,"created_at":"0001-01-01T00:00:00Z","created_by":null,"status":0}
but the data field must be "{"merchant_id":1}
this is Brc_Qr struct:
package model
import (
"api/user"
"database/sql"
"time"
"github.com/guregu/null"
)
var (
_ = time.Second
_ = sql.LevelDefault
_ = null.Bool{}
)
type BrcQr struct {
QrID int `gorm:"column:qr_id;primary_key" json:"qr_id"`
Code string `gorm:"column:code" json:"code"`
Type int `gorm:"column:type" json:"type"`
Data []byte `gorm:"column:data" json:"data"`
CreatedAt time.Time `gorm:"column:created_at" json:"created_at"`
CreatedBy null.Int `gorm:"column:created_by" json:"created_by"`
Status int `gorm:"column:status" json:"status"`
}
// TableName sets the insert table name for this struct type
func (b *BrcQr) TableName() string {
return "brc_qr"
}