Skip to content

Commit

Permalink
feat: FindByPage return all result when limit<=0
Browse files Browse the repository at this point in the history
  • Loading branch information
tr1v3r committed Apr 7, 2022
1 parent bd3f480 commit 61f3ee2
Showing 1 changed file with 1 addition and 6 deletions.
7 changes: 1 addition & 6 deletions internal/template/method.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,17 +204,12 @@ func ({{.S}} {{.NewStructName}}Do) FirstOrCreate() (*{{.StructInfo.Package}}.{{.
}
func ({{.S}} {{.NewStructName}}Do) FindByPage(offset int, limit int) (result []*{{.StructInfo.Package}}.{{.StructInfo.Type}}, count int64, err error) {
if limit <= 0 {
count, err = {{.S}}.Count()
return
}
result, err = {{.S}}.Offset(offset).Limit(limit).Find()
if err != nil{
return
}
if size := len(result); 0 < size && size < limit {
if size := len(result); 0 < limit && 0 < size && size < limit {
count = int64(size+offset)
return
}
Expand Down

0 comments on commit 61f3ee2

Please sign in to comment.