How to get Description of MySQL Table in GoLang

huangapple go评论90阅读模式
英文:

How to get Description of MySQL Table in GoLang

问题

你可以使用"gorm"和"github.com/go-sql-driver/mysql"包与数据库进行交互,并尝试获取表的描述,但是没有找到相应的函数。请帮忙解决。

英文:

com/jinzhu/gorm" and "github.com/go-sql-driver/mysql" package to interact with my database and trying to get the description of table but didn't found the function. Please help

答案1

得分: 2

使用gorm,您可以执行自定义查询并将其返回到struct中,以下是显示表描述的示例:

type Result struct {
    Field    string
    Type     string
    Null     string
    Key      string
    Default  string
    Extra    string
}

db.Raw("DESCRIBE TABLE_NAME").Scan(&result)

了解更多关于gorm的信息:
http://jinzhu.me/gorm/advanced.html#sql-builder

英文:

With gorm you can perform a custom query and get her return in a struct, the following is an example of how to show the description of table:

type Result struct {
    Field    string
    Type     string
    Null     string
    Key      string
    Default  string
    Extra    string
}

db.Raw("DESCRIBE TABLE_NAME").Scan(&result)

View more by gorm:
http://jinzhu.me/gorm/advanced.html#sql-builder

huangapple
  • 本文由 发表于 2016年12月21日 20:36:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/41262973.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定