pagi is a Go package designed to simplify pagination in your applications. It provides utility functions and types to handle pagination parameters, sorting, filtering, and generating pagination links.
To install pagi, use go get
:
go get -u github.com/billowdev/pagi
import "github.com/billowdev/pagi"
The PagingParams
type represents pagination parameters including limits, page numbers, sorting, and filtering.
The SortParams
type defines parameters for sorting, including the field to sort by, sorting order, and default sorting order.
The CommonTimeFilters
type contains common time-based filters such as date ranges and timestamps.
func AddWhereClauseIfNotEmpty(query *gorm.DB, columnName string, filterValue string, filterType string) *gorm.DB
Adds a WHERE clause to the query if the filter value is not empty, based on the provided column name, filter value, and filter type.
func ApplyFilter(query *gorm.DB, column string, value interface{}, filterType string) *gorm.DB
Applies filtering to the query based on the provided column, value, and filter type.
func ApplyCommaFilter(query *gorm.DB, columnName, filterValue string) *gorm.DB
Applies filtering to the query for comma-separated values in the specified column.
func ApplyCommaFilterWithJoin(query *gorm.DB, joinTable, joinCondition, columnName, filterValue string) *gorm.DB
Applies filtering to the query with a JOIN condition for comma-separated values.
func ApplyDatetimeFilters(query *gorm.DB, filter CommonTimeFilters) *gorm.DB
Applies datetime filtering to the query based on the provided CommonTimeFilters.
func ApplyDatetimePreloadFilters(query *gorm.DB, filter CommonTimeFilters, preloadKey string) *gorm.DB
Applies datetime filtering with preloading to the query based on the provided CommonTimeFilters.
params := pagi.PagingParams{}
params.Limit = 10
params.Page = 1
params.Sort = "id"
params.Order = "asc"
params.BaseURL = "https://example.com"
pagi is licensed under the MIT License. See the LICENSE file for details.
- Contributions are welcome! Feel free to open issues or submit pull requests on the GitHub repository.