本文介绍了如何在GoLang中获取MySQL表的描述的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
com/jinzhu/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
推荐答案
使用 gorm ,您可以执行自定义查询并将其返回到 struct 中,以下是如何显示表说明的示例:
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)
查看更多来自gorm的内容: http://jinzhu.me/gorm/advanced.html#sql-builder
View more by gorm:http://jinzhu.me/gorm/advanced.html#sql-builder
这篇关于如何在GoLang中获取MySQL表的描述的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!