Skip to content

Commit

Permalink
fix: use new pagination template
Browse files Browse the repository at this point in the history
  • Loading branch information
suyuan32 committed Apr 29, 2024
1 parent 5042871 commit 3e234e2
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
20 changes: 15 additions & 5 deletions ent/pagination.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion ent/template/pagination.tmpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
{{/*
Copyright 2022-present Ryan SU (github.com/suyuan32). All rights reserved.
This source code is licensed under the Apache 2.0 license found
in the LICENSE file in the root directory of this source tree.
*/}}

{{ define "pagination" }}
{{- /*gotype: entgo.io/ent/entc/gen.Graph*/ -}}

Expand Down Expand Up @@ -134,7 +140,9 @@
Size: pageSize,
}

count, err := {{ $r }}.Clone().Count(ctx)
query := {{ $r }}.Clone()
query.ctx.Fields = nil
count, err := query.Count(ctx)

if err != nil {
return nil, err
Expand Down
10 changes: 8 additions & 2 deletions ent/template/set_not_nil.tmpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
{{/*
Copyright 2022-present Ryan SU (github.com/suyuan32). All rights reserved.
This source code is licensed under the Apache 2.0 license found
in the LICENSE file in the root directory of this source tree.
*/}}

{{/* gotype: entgo.io/ent/entc/gen.Graph */}}


Expand All @@ -14,9 +20,9 @@

{{ range $updater := list $n.UpdateName $n.UpdateOneName $n.CreateName}}
// set field if value's pointer is not nil.
func ({{ $n.Receiver }} *{{ $updater }}) SetNotNil{{ $f.StructField }}(value *{{ $f.Type }}) *{{ $updater }} {
func ({{ $n.Receiver }} *{{ $updater }}) SetNotNil{{ $f.StructField }}(value {{if not (hasPrefix $f.Type.String "[]") }}*{{end}}{{ $f.Type }}) *{{ $updater }} {
if value != nil {
return {{ $n.Receiver }}.{{ $set }}(*value)
return {{ $n.Receiver }}.{{ $set }}({{if not (hasPrefix $f.Type.String "[]") }}*{{end}}value)
}
return {{ $n.Receiver }}
}
Expand Down

0 comments on commit 3e234e2

Please sign in to comment.