Introduction
Executing a SQL query using gorm is pretty trivial. Normally this is what I'd do:
- Write a proto struct that matches the DB table schema
- Run query using gorm and
Scan
into the struct
var auditDb *pb.DataInjectionAuditLogDb
if err := orm.DataHelperDbInstance(g.c).Raw(q).Scan(&auditDb).Error; err != nil {
hlog.CtxErrorf(g.c, err.Error())
return nil, err
}
- Done
However, what if we do not know the schema, or it is virtually impossible to create a struct for all of them?
Huh?!