Documentation
¶
Overview ¶
Package pagination provides pagination utilities.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Pagination ¶
Pagination holds pagination parameters.
func New ¶
func New(page, perPage int) Pagination
New creates a new Pagination with defaults applied.
func (Pagination) Limit ¶
func (p Pagination) Limit() int
Limit returns the limit for database queries.
func (Pagination) Offset ¶
func (p Pagination) Offset() int
Offset returns the offset for database queries.
type Result ¶
type Result[T any] struct { Data []T `json:"data"` Total int64 `json:"total"` Page int `json:"page"` PerPage int `json:"per_page"` TotalPages int `json:"total_pages"` }
Result represents a paginated result set.
type SortOption ¶
type SortOption struct {
// contains filtered or unexported fields
}
SortOption represents a parsed sort option with validation.
func NewSortOption ¶
func NewSortOption(allowedFields map[string]string) *SortOption
NewSortOption creates a new SortOption with allowed fields. allowedFields maps user-facing field names to database column names. Example: {"created_at": "created_at", "name": "name", "updated_at": "updated_at"}
func (*SortOption) IsEmpty ¶
func (s *SortOption) IsEmpty() bool
IsEmpty returns true if no sorts are specified.
func (*SortOption) Parse ¶
func (s *SortOption) Parse(sortStr string) *SortOption
Parse parses a sort string and validates fields. Format: "-created_at,name" means ORDER BY created_at DESC, name ASC Prefix "-" means descending order.
func (*SortOption) SQL ¶
func (s *SortOption) SQL() string
SQL returns the ORDER BY clause without the "ORDER BY" prefix. Returns empty string if no sorts. Example: "created_at DESC, name ASC"
func (*SortOption) SQLWithDefault ¶
func (s *SortOption) SQLWithDefault(defaultSort string) string
SQLWithDefault returns the ORDER BY clause, using defaultSort if no sorts specified.
func (*SortOption) Sorts ¶
func (s *SortOption) Sorts() []Sort
Sorts returns the parsed sort specifications.