Skip to content

Commit

Permalink
refactor(Scopes): Refactored the Scopes method
Browse files Browse the repository at this point in the history
Signed-off-by: Flc゛ <[email protected]>
  • Loading branch information
flc1125 committed Jan 19, 2024
1 parent d70b4a3 commit 370127a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 10 additions & 2 deletions internal/template/method.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,16 @@ func ({{.S}} {{.QueryStructName}}Do) Offset(offset int) {{.ReturnObject}} {
return {{.S}}.withDO({{.S}}.DO.Offset(offset))
}
func ({{.S}} {{.QueryStructName}}Do) Scopes(funcs ...func(gen.Dao) gen.Dao) {{.ReturnObject}} {
return {{.S}}.withDO({{.S}}.DO.Scopes(funcs...))
func ({{.S}} {{.QueryStructName}}Do) Scopes(funcs ...func({{.ReturnObject}}) {{.ReturnObject}}) {{.ReturnObject}} {
if funcs = nil {
return {{.ReturnObject}}
}
for _, f := range funcs {
{{.ReturnObject}} = f({{.ReturnObject}})
}
return {{.ReturnObject}}
}
func ({{.S}} {{.QueryStructName}}Do) Unscoped() {{.ReturnObject}} {
Expand Down
2 changes: 1 addition & 1 deletion internal/template/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ type I{{.ModelStructName}}Do interface {
Limit(limit int) I{{.ModelStructName}}Do
Offset(offset int) I{{.ModelStructName}}Do
Count() (count int64, err error)
Scopes(funcs ...func(gen.Dao) gen.Dao) I{{.ModelStructName}}Do
Scopes(funcs ...func(I{{.ModelStructName}}Do) I{{.ModelStructName}}Do) I{{.ModelStructName}}Do
Unscoped() I{{.ModelStructName}}Do
Create(values ...*{{.StructInfo.Package}}.{{.StructInfo.Type}}) error
CreateInBatches(values []*{{.StructInfo.Package}}.{{.StructInfo.Type}}, batchSize int) error
Expand Down

0 comments on commit 370127a

Please sign in to comment.