This repository has been archived on 2026-01-07. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
Game/Server/common/utils/gen_gorm_test.go

34 lines
604 B
Go

package utils
import (
"gorm.io/driver/mysql"
"gorm.io/gen"
"gorm.io/gorm"
"testing"
)
func TestGenGormStruct(t *testing.T) {
dsn := "user:password@tcp(47.108.184.184:3306)/point?charset=utf8mb4&parseTime=True&loc=Local"
db, err := gorm.Open(mysql.Open(dsn))
if err != nil {
panic(err)
}
g := gen.NewGenerator(gen.Config{
OutPath: "./model", // 生成的 model 文件路径
})
g.UseDB(db)
// 生成所有表的 struct
g.ApplyBasic(g.GenerateAllTable()...)
// 或者指定表
// g.ApplyBasic(
// g.GenerateModel("users"),
// g.GenerateModel("orders"),
// )
g.Execute()
}