Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
goctl
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Yao Lei
goctl
Commits
1bbd14e5
Commit
1bbd14e5
authored
Sep 20, 2022
by
Yuchao Shen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update paginate
parent
ddc1d670
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
8 deletions
+16
-8
find-one.tpl
1.4.0/model/find-one.tpl
+16
-8
No files found.
1.4.0/model/find-one.tpl
View file @
1bbd14e5
...
...
@@ -138,7 +138,7 @@ func (m *default{{.upperStartCamelObject}}Model) Paginate(ctx context.Context, w
}{}
err := m.QueryCtx(ctx,
&
pagination, {{.cacheKeyVariable}}, func(conn *gorm.DB, v interface{}) error {
db := conn.Model(
&
{{.upperStartCamelObject}}{})
db := conn.Model(
&
{{.upperStartCamelObject}}{})
.Where(where)
if len(columns) > 0 {
db = db.Select(columns)
}
...
...
@@ -146,9 +146,13 @@ func (m *default{{.upperStartCamelObject}}Model) Paginate(ctx context.Context, w
if order != "" {
db = db.Order(order)
}
err := db.Count(
&
pagination.Total).Error
if err == nil {
return err
err := db.Count(
&
total).Error
if err != nil {
return list, total, err
}
if total == 0 {
return list, total, nil
}
if page == 0 {
...
...
@@ -162,7 +166,7 @@ func (m *default{{.upperStartCamelObject}}Model) Paginate(ctx context.Context, w
offset
:=
(page
-
1
)
*
pageSize
db =
db.Offset(offset).Limit(pageSize)
return
db
.
Find
(&
pagination
.
List
,
where
).
Error
return
db
.
Find
(&
pagination
.
List
).
Error
})
if
err =
=
nil
{
return
pagination
.
List
,
pagination
.
Total
,
nil
...
...
@@ -175,7 +179,7 @@ func (m *default{{.upperStartCamelObject}}Model) Paginate(ctx context.Context, w
var
list
[]*{{.
upperStartCamelObject
}}
var
total
int64
db
:=
m.conn.WithContext(ctx).Model(&{{.upperStartCamelObject}}{})
db
:=
m.conn.WithContext(ctx).Model(&{{.upperStartCamelObject}}{})
.Where(where)
if
len
(
columns
)
>
0 {
db = db.Select(columns)
}
...
...
@@ -184,7 +188,11 @@ func (m *default{{.upperStartCamelObject}}Model) Paginate(ctx context.Context, w
db = db.Order(order)
}
err := db.Count(
&
total).Error
if err == nil {
if err != nil {
return list, total, err
}
if total == 0 {
return list, total, nil
}
...
...
@@ -199,7 +207,7 @@ func (m *default{{.upperStartCamelObject}}Model) Paginate(ctx context.Context, w
offset
:=
(page
-
1
)
*
pageSize
db =
db.Offset(offset).Limit(pageSize)
err =
db.Find(&list
,
where
).
Error
err =
db.Find(&list).Error
if
err =
=
nil
{
return
list
,
total
,
nil
}
else
if
errors
.
Is
(
err
,
gorm
.
ErrRecordNotFound
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment