diff --git a/internal/router/admin/dish_router.go b/internal/router/admin/dish_router.go index 6d55bb0..85e4133 100644 --- a/internal/router/admin/dish_router.go +++ b/internal/router/admin/dish_router.go @@ -95,12 +95,3 @@ func ListDish(ctx context.Context, c *app.RequestContext) { dish := service.ListDish(&tp) c.JSON(http.StatusOK, common.Result{1, "", dish}) } - -/** - * 清理缓存数据 - * @param pattern - */ -//private void cleanCache(String pattern){ -//Set keys = redisTemplate.keys(pattern); -//redisTemplate.delete(keys); -//} diff --git a/internal/utils/gen.go b/internal/utils/gen.go deleted file mode 100644 index 53fece7..0000000 --- a/internal/utils/gen.go +++ /dev/null @@ -1,41 +0,0 @@ -package utils - -import ( - "fmt" - "gorm.io/driver/mysql" - "gorm.io/gen" - "gorm.io/gorm" -) - -func main() { - g := gen.NewGenerator(gen.Config{ - OutPath: "internal/db", //同时输出结构体和查询方法路径 - Mode: gen.WithoutContext | gen.WithDefaultQuery | gen.WithQueryInterface, // generate mode - }) - - gormdb, _ := gorm.Open(mysql.Open(fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8&parseTime=True&loc=Local", - "root", - "root", - "121.37.143.160:3306", - "sky_take_out"))) - g.UseDB(gormdb) // reuse your gorm db// reuse your gorm db - - // Generate basic type-safe DAO API for struct `models.User` following conventions - - g.ApplyBasic( - // 根据 `user` 表生成结构 `User` - //g.GenerateModel("users"), - - // 根据 `user` 表生成结构 `Employee` ` - //g.GenerateModelAs("users", "Employee"), - - // Generate struct `User` based on table `users` and generating options - //g.GenerateModel("users", gen.FieldIgnore("address"), gen.FieldType("id", "int64")), - ) - g.ApplyBasic( - // 从当前数据库中生成所有表的结构 - g.GenerateAllTable()..., - ) - // Generate the code - g.Execute() -} diff --git a/sql/gen.go b/sql/gen.go new file mode 100644 index 0000000..99e91c3 --- /dev/null +++ b/sql/gen.go @@ -0,0 +1,31 @@ +package main + +import ( + "gorm.io/driver/mysql" + "gorm.io/gen" + "gorm.io/gorm" +) + +// 根据数据库生成表结构 +func main() { + g := gen.NewGenerator(gen.Config{ + // 设置输出路径 + OutPath: "./dal/query", + Mode: gen.WithDefaultQuery, + // 模型结构体字段的数字类型的符号表示是否与表字段的一致, `false`指示都用有符号类型 + FieldSignable: false, // detect integer field's unsigned type, adjust generated data type + // 生成 gorm 标签的字段索引属性 + FieldWithIndexTag: false, // generate with gorm index tag + // 生成 gorm 标签的字段类型属性 + FieldWithTypeTag: true, // generate with gorm column type tag + }) + // 建立数据库连接 + gormdb, _ := gorm.Open(mysql.Open("root:root@(121.37.143.160:3306)/dish?charset=utf8mb4&parseTime=True&loc=Local")) + g.UseDB(gormdb) // 选择数据库连接 + g.ApplyBasic( + // 从当前数据库的所有表生成结构 + g.GenerateAllTable()..., + ) + // 生成代码 + g.Execute() +}