Skip to content

Commit

Permalink
Added pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicholas Santi committed Aug 20, 2024
1 parent 430accb commit 2beffb9
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions internal/codegen/golang/templates/stdlib/queryCode.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ type {{.MethodName}}FilterParams struct {
MaxParams []{{.MethodName}}Filter
SortParam string
SortOrder string
Pagination bool
PerPage int
PageNumber int
}

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

if filterParams.Pagination {
query += " LIMIT " + fmt.Sprint(filterParams.PerPage) + " OFFSET " + fmt.Sprint(filterParams.PageNumber * filterParams.PerPage)
}

// If there is not the ; at the end, add it
if !strings.HasSuffix(query, ";") {
query += ";"
Expand Down

0 comments on commit 2beffb9

Please sign in to comment.