1.golang sql2struct
1.1 go代碼實現
package main
import (
"fmt"
"github.com/gohouse/converter"
)
func main() {
err := converter.NewTable2Struct().
SavePath("/home/xxx/Desktop/model.go").
Dsn("root:123456@tcp(localhost:3306)/test?charset=utf8").
Run()
fmt.Println(err)
}
1.2 命令行模式
//1.下載二進制文件
https://github.com/gohouse/converter/releases
//2.執行命令
./table2struct-linux.v0.0.3.bin -file /home/xxx/Desktop/mode.go -dsn "root:123456@tcp(localhost:3306)/test?charset=utf8"
//3.參數說明
-dsn string 數據庫dsn配置
-enableJsonTag bool 是否添加json的tag
-file string 保存路徑
-packageName string 包名
-prefix string 表前綴
-realNameMethod string 結構體對應的表名
-table string 要遷移的表
-tagKey string tag的key
相關鏈接
https://github.com/gohouse/converter/releases