英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论