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
Yuchao Shen
goctl
Commits
22cd7de8
Commit
22cd7de8
authored
Aug 29, 2022
by
Yuchao Shen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update select
parent
67697009
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
11 deletions
+32
-11
find-one.tpl
1.4.0/model/find-one.tpl
+27
-6
interface-find-one.tpl
1.4.0/model/interface-find-one.tpl
+5
-5
No files found.
1.4.0/model/find-one.tpl
View file @
22cd7de8
...
...
@@ -22,7 +22,7 @@ func (m *default{{.upperStartCamelObject}}Model) FindOne(ctx context.Context, {{
}{
{
end
}
}
}
func (m *default{{.upperStartCamelObject}}Model) Fi
ndOneByWhere(ctx context.Context, condition map[string]
interface{}, columns []string, order string) (*{{.upperStartCamelObject}}, error) {
func (m *default{{.upperStartCamelObject}}Model) Fi
rst(ctx context.Context, condition
interface{}, columns []string, order string) (*{{.upperStartCamelObject}}, error) {
{
{
if
.
withCache
}
}{{.cacheKey}}
var resp {{.upperStartCamelObject}}
err := m.QueryCtx(ctx,
&
resp, {{.cacheKeyVariable}}, func(conn *gorm.DB, v interface{}) error {
...
...
@@ -64,7 +64,7 @@ func (m *default{{.upperStartCamelObject}}Model) FindOneByWhere(ctx context.Cont
}{
{
end
}
}
}
func (m *default{{.upperStartCamelObject}}Model) Find
All(ctx context.Context, where map[string]
interface{}, columns []string, order string) ([]*{{.upperStartCamelObject}}, error) {
func (m *default{{.upperStartCamelObject}}Model) Find
(ctx context.Context, where
interface{}, columns []string, order string) ([]*{{.upperStartCamelObject}}, error) {
{
{
if
.
withCache
}
}{{.cacheKey}}
var resp []*{{.upperStartCamelObject}}
err := m.QueryCtx(ctx,
&
resp, {{.cacheKeyVariable}}, func(conn *gorm.DB, v interface{}) error {
...
...
@@ -106,7 +106,7 @@ func (m *default{{.upperStartCamelObject}}Model) FindAll(ctx context.Context, wh
}{
{
end
}
}
}
func (m *default{{.upperStartCamelObject}}Model) Count(ctx context.Context, where
map[string]
interface{}) (int64, error) {
func (m *default{{.upperStartCamelObject}}Model) Count(ctx context.Context, where interface{}) (int64, error) {
{
{
if
.
withCache
}
}{{.cacheKey}}
var count int64
err := m.QueryCtx(ctx,
&
count, {{.cacheKeyVariable}}, func(conn *gorm.DB, v interface{}) error {
...
...
@@ -130,7 +130,7 @@ func (m *default{{.upperStartCamelObject}}Model) Count(ctx context.Context, wher
}{
{
end
}
}
}
func (m *default{{.upperStartCamelObject}}Model) Paginate(ctx context.Context, where
map[string]interface{}, columns []string, order string, offset int, limit
int) ([]*{{.upperStartCamelObject}}, int64, error) {
func (m *default{{.upperStartCamelObject}}Model) Paginate(ctx context.Context, where
interface{}, columns []string, order string, page int, pageSize
int) ([]*{{.upperStartCamelObject}}, int64, error) {
{
{
if
.
withCache
}
}{{.cacheKey}}
pagination := struct {
List []*UpWorkTags
...
...
@@ -150,7 +150,18 @@ func (m *default{{.upperStartCamelObject}}Model) Paginate(ctx context.Context, w
if err == nil {
return err
}
db = db.Offset(offset).Limit(limit)
if page == 0 {
page = 1
}
if pageSize > 500 {
pageSize = 500
} else if pageSize
<
=
0
{
pageSize =
10
}
offset
:=
(page
-
1
)
*
pageSize
db =
db.Offset(offset).Limit(pageSize)
return
db
.
Find
(&
pagination
.
List
,
where
).
Error
})
if
err =
=
nil
{
...
...
@@ -177,7 +188,17 @@ func (m *default{{.upperStartCamelObject}}Model) Paginate(ctx context.Context, w
return list, total, nil
}
db = db.Offset(offset).Limit(limit)
if page == 0 {
page = 1
}
if pageSize > 500 {
pageSize = 500
} else if pageSize
<
=
0
{
pageSize =
10
}
offset
:=
(page
-
1
)
*
pageSize
db =
db.Offset(offset).Limit(pageSize)
err =
db.Find(&list,
where
).
Error
if
err =
=
nil
{
return
list
,
total
,
nil
...
...
1.4.0/model/interface-find-one.tpl
View file @
22cd7de8
FindOne(ctx context.Context, {{.lowerStartCamelPrimaryKey}} {{.dataType}}) (*{{.upperStartCamelObject}}, error)
FindOneByWhere(ctx context.Context, condition map[string]interface{}, columns []string, order string) (*{{.upperStartCamelObject}}, error)
FindAll(ctx context.Context, where map[string]interface{}, columns []string, order string) ([]*{{.upperStartCamelObject}}, error)
Count(ctx context.Context, where map[string]interface{}) (int64, error)
Paginate(ctx context.Context, where map[string]interface{}, columns []string, order string, offset int, limit int) ([]*{{.upperStartCamelObject}}, int64, error)
\ No newline at end of file
First(ctx context.Context, where interface{}, columns []string, order string) (*{{.upperStartCamelObject}}, error)
Find(ctx context.Context, where interface{}, columns []string, order string) ([]*{{.upperStartCamelObject}}, error)
Count(ctx context.Context, where interface{}) (int64, error)
Paginate(ctx context.Context, where interface{}, columns []string, order string, page int, pageSize int) ([]*{{.upperStartCamelObject}}, int64, error)
\ No newline at end of file
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