Skip to main content

One post tagged with "gorm"

View All Tags

· 5 min read
Ang Xuan Ze

Introduction

Executing a SQL query using gorm is pretty trivial. Normally this is what I'd do:

  1. Write a proto struct that matches the DB table schema
  2. 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
}
  1. Done

However, what if we do not know the schema, or it is virtually impossible to create a struct for all of them?

Huh?!