douyi2107
2016-12-21 12:36
浏览 203
已采纳

如何在GoLang中获取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

图片转代码服务由CSDN问答提供 功能建议

com / jinzhu / gorm“和” github.com/go-sql-driver/mysql“软件包进行交互 我的数据库并尝试获取表的描述,但未找到该函数。请帮助

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doufu9947 2016-12-21 13:14
    已采纳

    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

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题