This repository has been archived on 2022-10-02. You can view files and clone it, but cannot push or open issues or pull requests.
2021-07-17 15:22:36 +00:00
|
|
|
package model
|
2020-10-17 10:43:27 +00:00
|
|
|
|
|
|
|
import "github.com/go-pg/pg/v10/orm"
|
|
|
|
|
|
|
|
type DefaultFilter struct {
|
|
|
|
Limit int
|
|
|
|
Offset int
|
|
|
|
Order []string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *DefaultFilter) Apply(q *orm.Query) (*orm.Query, error) {
|
|
|
|
if f.Limit != 0 {
|
|
|
|
q = q.Limit(f.Limit)
|
|
|
|
}
|
|
|
|
if f.Offset != 0 {
|
|
|
|
q = q.Offset(f.Offset)
|
|
|
|
}
|
|
|
|
if len(f.Order) > 0 {
|
|
|
|
q = q.Order(f.Order...)
|
|
|
|
}
|
|
|
|
return q, nil
|
|
|
|
}
|