diff --git a/internal/codegen/golang/templates/stdlib/queryCode.tmpl b/internal/codegen/golang/templates/stdlib/queryCode.tmpl index 82bd7e017b..66efae4f3d 100644 --- a/internal/codegen/golang/templates/stdlib/queryCode.tmpl +++ b/internal/codegen/golang/templates/stdlib/queryCode.tmpl @@ -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) {; @@ -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 += ";"