添加gorm的model结构一个表名的入口

This commit is contained in:
eson
2023-07-20 10:13:18 +08:00
parent 20a7149eb6
commit 6264440017
91 changed files with 624 additions and 208 deletions

View File

@@ -342,11 +342,12 @@ func GenFromPath(mdir string, cols []Column, tableName string, tableComment stri
fcontent += importstr + ")\n"
fcontent += fmt.Sprintf(structstr, tableName, tableComment, pTableName, fieldstr)
modelstr := fmt.Sprintf(`type %sModel struct {db *gorm.DB}`, pTableName)
modelstr := fmt.Sprintf(`type %sModel struct {db *gorm.DB
name string}`, pTableName)
fcontent += modelstr
fcontent += "\n"
newfuncstr := fmt.Sprintf(`func New%sModel(db *gorm.DB) *%sModel {return &%sModel{db}}`, pTableName, pTableName, pTableName)
newfuncstr := fmt.Sprintf(`func New%sModel(db *gorm.DB) *%sModel {return &%sModel{db:db,name:"%s"}}`, pTableName, pTableName, pTableName, tableName)
fcontent += newfuncstr
fcontent += "\n"