You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.0 KiB
52 lines
1.0 KiB
package main
|
|
|
|
import (
|
|
"flag"
|
|
"zero-files/api/local/internal/config"
|
|
|
|
OrmStructs "zero-files/api/local/orm/structs"
|
|
|
|
"github.com/zeromicro/go-zero/core/conf"
|
|
"gorm.io/driver/mysql"
|
|
"gorm.io/gen"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
func main() {
|
|
var configFile = flag.String("f", "../etc/local-api.yaml", "the config file")
|
|
flag.Parse()
|
|
var c config.Config
|
|
conf.MustLoad(*configFile, &c)
|
|
db, err := gorm.Open(mysql.New(mysql.Config{
|
|
DSN: c.MySQLConn, // DSN data source name
|
|
}), &gorm.Config{})
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
// 自动迁移
|
|
err = db.AutoMigrate(&OrmStructs.File{})
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
// 自动迁移
|
|
err = db.AutoMigrate(&OrmStructs.Path{})
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
// 配置生成器
|
|
g := gen.NewGenerator(gen.Config{
|
|
OutPath: "./dal",
|
|
Mode: gen.WithoutContext | gen.WithDefaultQuery | gen.WithQueryInterface, // generate mode
|
|
})
|
|
// 使用数据库
|
|
g.UseDB(db)
|
|
|
|
g.ApplyBasic(
|
|
// 生成所有表
|
|
g.GenerateAllTable()...,
|
|
)
|
|
// 执行
|
|
g.Execute()
|
|
}
|
|
|