Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,12 @@ func (g *Generator) ApplyInterface(fc interface{}, models ...interface{}) {
g.apply(fc, structs)
}

func (g *Generator) ApplyCustomTemplateForModel(templateText string) {
for _, modelMeta := range g.models {
modelMeta.CustomTemplates = append(modelMeta.CustomTemplates, templateText)
}
}

func (g *Generator) apply(fc interface{}, structs []*generate.QueryStructMeta) {
interfacePaths, err := parser.GetInterfacePath(fc)
if err != nil {
Expand Down Expand Up @@ -522,6 +528,14 @@ func (g *Generator) generateModelFile() error {
return
}

for _, customTemplate := range data.CustomTemplates {
err = render(customTemplate, &buf, data)
if err != nil {
errChan <- err
return
}
}

for _, method := range data.ModelMethods {
err = render(tmpl.ModelMethod, &buf, method)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions internal/generate/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type QueryStructMeta struct {
Source model.SourceCode
ImportPkgPaths []string
ModelMethods []*parser.Method // user custom method bind to db base struct
CustomTemplates []string // custom template text

interfaceMode bool

Expand Down
Loading