Skip to content

Commit

Permalink
添加gen
Browse files Browse the repository at this point in the history
  • Loading branch information
onenewcode committed May 11, 2024
1 parent 163919d commit 60837cd
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 50 deletions.
9 changes: 0 additions & 9 deletions internal/router/admin/dish_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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);
//}
41 changes: 0 additions & 41 deletions internal/utils/gen.go

This file was deleted.

31 changes: 31 additions & 0 deletions sql/gen.go
Original file line number Diff line number Diff line change
@@ -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()
}

0 comments on commit 60837cd

Please sign in to comment.