Skip to content

Commit 2beffb9

Browse files
author
Nicholas Santi
committed
Added pagination
1 parent 430accb commit 2beffb9

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

internal/codegen/golang/templates/stdlib/queryCode.tmpl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ type {{.MethodName}}FilterParams struct {
6060
MaxParams []{{.MethodName}}Filter
6161
SortParam string
6262
SortOrder string
63+
Pagination bool
64+
PerPage int
65+
PageNumber int
6366
}
6467

6568
func (q *Queries) {{.MethodName}}(ctx context.Context, schema string, filterParams {{.MethodName}}FilterParams, {{ dbarg }} {{.Arg.Pair}}) ([]{{.Ret.DefineType}}, error) {;
@@ -317,6 +320,10 @@ func (q *Queries) {{.MethodName}}(ctx context.Context, {{ dbarg }} {{.Arg.Pair}}
317320
query += " ORDER BY " + filterParams.SortParam + " " + filterParams.SortOrder
318321
}
319322

323+
if filterParams.Pagination {
324+
query += " LIMIT " + fmt.Sprint(filterParams.PerPage) + " OFFSET " + fmt.Sprint(filterParams.PageNumber * filterParams.PerPage)
325+
}
326+
320327
// If there is not the ; at the end, add it
321328
if !strings.HasSuffix(query, ";") {
322329
query += ";"

0 commit comments

Comments
 (0)