add customized.tpl for model template (#4086)

Co-authored-by: sudaoxyz <sudaoxyz@gmail.com>
This commit is contained in:
suyhuai
2024-04-18 22:40:54 +08:00
committed by GitHub
parent 1540bdc4c9
commit e1f15efb3b
5 changed files with 144 additions and 20 deletions

View File

@@ -36,16 +36,17 @@ type (
Option func(generator *defaultGenerator)
code struct {
importsCode string
varsCode string
typesCode string
newCode string
insertCode string
findCode []string
updateCode string
deleteCode string
cacheExtra string
tableName string
importsCode string
varsCode string
typesCode string
newCode string
insertCode string
findCode []string
updateCode string
deleteCode string
cacheExtra string
tableName string
customizedCode string
}
codeTuple struct {
@@ -323,17 +324,23 @@ func (g *defaultGenerator) genModel(in parser.Table, withCache bool) (string, er
return "", err
}
customizedCode, err := genCustomized(table, withCache, g.isPostgreSql)
if err != nil {
return "", err
}
code := &code{
importsCode: importsCode,
varsCode: varsCode,
typesCode: typesCode,
newCode: newCode,
insertCode: insertCode,
findCode: findCode,
updateCode: updateCode,
deleteCode: deleteCode,
cacheExtra: ret.cacheExtra,
tableName: tableName,
importsCode: importsCode,
varsCode: varsCode,
typesCode: typesCode,
newCode: newCode,
insertCode: insertCode,
findCode: findCode,
updateCode: updateCode,
deleteCode: deleteCode,
cacheExtra: ret.cacheExtra,
tableName: tableName,
customizedCode: customizedCode,
}
output, err := g.executeModel(table, code)
@@ -387,6 +394,7 @@ func (g *defaultGenerator) executeModel(table Table, code *code) (*bytes.Buffer,
"extraMethod": code.cacheExtra,
"tableName": code.tableName,
"data": table,
"customized": code.customizedCode,
})
if err != nil {
return nil, err