godal 提供了生成特定 Golang 代码的能力, 旨在提高研发编码的效率。
功能:
- 基于 Mysql 的建表语句快速生成对应 Golang 的 Model,可直接被 ORM 框架 GORM 使用。
- 待更新,欢迎大家提需求,会尽快适配。
godal 已经被加入到 awesome-go, MR link
首先需要golang环境 See the install instructions for Go. See the go blog guide on using Go Modules.
git clone 后 进行 go install
git clone [email protected]:mafulong/godal.git
cd godal
go install
可以使用命令which godal
检验是否已安装
godal gen model --database {your databaseName} {your sqlFile}
在本 repo 的 test 文件夹中有个测试 sql, 可以进行用来测试
godal gen model --database testdb gen_model.sql
example file1:
package testdb
import "time"
type TestTb1 struct {
TestId int `gorm:"Column:test_id" json:"test_id"`
TestTitle string `gorm:"Column:test_title" json:"test_title"`
TestAuthor string `gorm:"Column:test_author" json:"test_author"`
SubmissionDate time.Time `gorm:"Column:submission_date" json:"submission_date"`
}
func (TestTb1) TableName() string {
return "test_tb1"
}
The MIT License (MIT). Please see License File for more information.