Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions bun/bunpaginate/pagination_query_options.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package bunpaginate

import (
"encoding/json"

"github.com/formancehq/go-libs/query"
)

Expand All @@ -10,6 +12,29 @@ type PaginatedQueryOptions[T any] struct {
Options T `json:"options"`
}

func (pqo *PaginatedQueryOptions[T]) UnmarshalJSON(data []byte) error {
type base struct {
PageSize uint64 `json:"pageSize"`
Options T `json:"options"`
}
var b base
if err := json.Unmarshal(data, &b); err != nil {
return err
}
pqo.PageSize = b.PageSize
pqo.Options = b.Options
var dataMap map[string]json.RawMessage
if err := json.Unmarshal(data, &dataMap); err != nil {
return err
}
qb, err := query.ParseJSON(string(dataMap["qb"]))
if err != nil {
return err
}
pqo.QueryBuilder = qb
return nil
}

func (opts PaginatedQueryOptions[T]) WithQueryBuilder(qb query.Builder) PaginatedQueryOptions[T] {
opts.QueryBuilder = qb

Expand Down